Completed
Branch FET-9222-rest-api-writes (9a0487)
by
unknown
71:42 queued 58:38
created
core/libraries/messages/messenger/EE_Pdf_messenger.class.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Event Espresso
7 7
  * @subpackage messages
8 8
  */
9
-if (!defined('EVENT_ESPRESSO_VERSION') )
9
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
10 10
 	exit('NO direct script access allowed');
11 11
 
12 12
 /**
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  * @subpackage		messages
21 21
  * @author			Darren Ethier
22 22
  */
23
-class EE_Pdf_messenger extends EE_messenger  {
23
+class EE_Pdf_messenger extends EE_messenger {
24 24
 
25 25
 
26 26
 	/**
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * @see abstract declaration in EE_messenger for details.
94 94
 	 */
95 95
 	protected function _set_admin_pages() {
96
-		$this->admin_registered_pages = array( 'events_edit' => false );
96
+		$this->admin_registered_pages = array('events_edit' => false);
97 97
 	}
98 98
 
99 99
 
@@ -113,10 +113,10 @@  discard block
 block discarded – undo
113 113
 	protected function _set_validator_config() {
114 114
 		$this->_validator_config = array(
115 115
 			'subject' => array(
116
-				'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email','event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
116
+				'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
117 117
 				),
118 118
 			'content' => array(
119
-				'shortcodes' => array( 'recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email','event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
119
+				'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime')
120 120
 				),
121 121
 			'attendee_list' => array(
122 122
 				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 				'required' => array('[EVENT_LIST]')
128 128
 				),
129 129
 			'ticket_list' => array(
130
-				'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list','primary_registration_details', 'recipient_details'),
130
+				'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'primary_registration_details', 'recipient_details'),
131 131
 				'required' => array('[TICKET_LIST]')
132 132
 				),
133 133
 			'datetime_list' => array(
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	 */
148 148
 	public  function enqueue_scripts_styles() {
149 149
 		parent::enqueue_scripts_styles();
150
-		do_action( 'AHEE__EE_Pdf_messenger__enqueue_scripts_styles');
150
+		do_action('AHEE__EE_Pdf_messenger__enqueue_scripts_styles');
151 151
 	}
152 152
 
153 153
 
@@ -273,18 +273,18 @@  discard block
 block discarded – undo
273 273
 	 */
274 274
 	protected function _send_message() {
275 275
 		$this->_template_args = array(
276
-			'page_title' => html_entity_decode( stripslashes( $this->_subject ), ENT_QUOTES, "UTF-8"),
277
-			'base_css' => $this->get_variation( $this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'base', $this->_variation ),
278
-			'print_css' => $this->get_variation( $this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'print', $this->_variation ),
279
-			'main_css' => $this->get_variation( $this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'main', $this->_variation ),
280
-			'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css',
281
-			'main_body' => apply_filters( 'FHEE__EE_Pdf_messenger___send_message__main_body', wpautop(stripslashes_deep( html_entity_decode($this->_content,  ENT_QUOTES,"UTF-8" ) )), $this->_content )
276
+			'page_title' => html_entity_decode(stripslashes($this->_subject), ENT_QUOTES, "UTF-8"),
277
+			'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'base', $this->_variation),
278
+			'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'print', $this->_variation),
279
+			'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, TRUE, 'main', $this->_variation),
280
+			'extra_css' => EE_LIBRARIES_URL.'messages/defaults/default/variations/pdf_base_default.css',
281
+			'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop(stripslashes_deep(html_entity_decode($this->_content, ENT_QUOTES, "UTF-8"))), $this->_content)
282 282
 			);
283 283
 		$this->_deregister_wp_hooks();
284
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts_styles' ) );
284
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
285 285
 		$content = $this->_get_main_template();
286 286
 //		die( $content );
287
-		$this->_do_pdf( $content );
287
+		$this->_do_pdf($content);
288 288
 		exit(0);
289 289
 	}
290 290
 
@@ -308,8 +308,8 @@  discard block
 block discarded – undo
308 308
 
309 309
 		//just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
310 310
 		add_action('wp_head', 'wp_enqueue_scripts');
311
-		add_action( 'wp_footer', 'wp_print_footer_scripts' );
312
-		add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' );
311
+		add_action('wp_footer', 'wp_print_footer_scripts');
312
+		add_action('wp_print_footer_scripts', '_wp_footer_scripts');
313 313
 	}
314 314
 
315 315
 
@@ -322,11 +322,11 @@  discard block
 block discarded – undo
322 322
 	 * @param bool $preview
323 323
 	 * @return string
324 324
 	 */
325
-	protected function _get_main_template( $preview = FALSE ) {
326
-		$wrapper_template = $this->_tmp_pack->get_wrapper( 'html', 'main' );
325
+	protected function _get_main_template($preview = FALSE) {
326
+		$wrapper_template = $this->_tmp_pack->get_wrapper('html', 'main');
327 327
 		//add message type to template_args
328 328
 		$this->_template_args['message_type'] = $this->_incoming_message_type;
329
-		return EEH_Template::display_template( $wrapper_template, $this->_template_args, TRUE );
329
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, TRUE);
330 330
 	}
331 331
 
332 332
 
@@ -339,15 +339,15 @@  discard block
 block discarded – undo
339 339
 	 *
340 340
 	 * @return void
341 341
 	 */
342
-	protected function _do_pdf( $content = '' ) {
343
-		$invoice_name = html_entity_decode( $this->_subject, ENT_QUOTES, "UTF-8");
342
+	protected function _do_pdf($content = '') {
343
+		$invoice_name = html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8");
344 344
 
345 345
 		//only load dompdf if nobody else has yet...
346
-		if( ! defined('DOMPDF_DIR')){
346
+		if ( ! defined('DOMPDF_DIR')) {
347 347
 			define('DOMPDF_ENABLE_REMOTE', TRUE);
348 348
 			define('DOMPDF_ENABLE_JAVASCRIPT', FALSE);
349 349
 			define('DOMPDF_ENABLE_CSS_FLOAT', TRUE);
350
-			require_once(EE_THIRD_PARTY . 'dompdf/dompdf_config.inc.php');
350
+			require_once(EE_THIRD_PARTY.'dompdf/dompdf_config.inc.php');
351 351
 		}
352 352
 		$dompdf = new DOMPDF();
353 353
 		if (defined('DOMPDF_DEFAULT_PAPER_SIZE')) {
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 		$dompdf->load_html($content);
357 357
 		$dompdf->render();
358 358
 		//forcing the browser to open a download dialog.
359
-		$dompdf->stream($invoice_name . ".pdf", array( 'Attachment' => TRUE ));
359
+		$dompdf->stream($invoice_name.".pdf", array('Attachment' => TRUE));
360 360
 	}
361 361
 
362 362
 
Please login to merge, or discard this patch.
core/admin/EE_Admin_List_Table.core.php 2 patches
Indentation   +834 added lines, -834 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 defined('EVENT_ESPRESSO_VERSION') || exit('No direct access allowed.');
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
 
@@ -22,847 +22,847 @@  discard block
 block discarded – undo
22 22
 abstract class EE_Admin_List_Table extends WP_List_Table
23 23
 {
24 24
 
25
-    /**
26
-     * holds the data that will be processed for the table
27
-     *
28
-     * @var array $_data
29
-     */
30
-    protected $_data;
31
-
32
-
33
-    /**
34
-     * This holds the value of all the data available for the given view (for all pages).
35
-     *
36
-     * @var int $_all_data_count
37
-     */
38
-    protected $_all_data_count;
39
-
40
-
41
-    /**
42
-     * Will contain the count of trashed items for the view label.
43
-     *
44
-     * @var int $_trashed_count
45
-     */
46
-    protected $_trashed_count;
47
-
48
-
49
-    /**
50
-     * This is what will be referenced as the slug for the current screen
51
-     *
52
-     * @var string $_screen
53
-     */
54
-    protected $_screen;
55
-
56
-
57
-    /**
58
-     * this is the EE_Admin_Page object
59
-     *
60
-     * @var EE_Admin_Page $_admin_page
61
-     */
62
-    protected $_admin_page;
63
-
64
-
65
-    /**
66
-     * The current view
67
-     *
68
-     * @var string $_view
69
-     */
70
-    protected $_view;
71
-
72
-
73
-    /**
74
-     * array of possible views for this table
75
-     *
76
-     * @var array $_views
77
-     */
78
-    protected $_views;
79
-
80
-
81
-    /**
82
-     * An array of key => value pairs containing information about the current table
83
-     * array(
84
-     *        'plural' => 'plural label',
85
-     *        'singular' => 'singular label',
86
-     *        'ajax' => false, //whether to use ajax or not
87
-     *        'screen' => null, //string used to reference what screen this is
88
-     *        (WP_List_table converts to screen object)
89
-     * )
90
-     *
91
-     * @var array $_wp_list_args
92
-     */
93
-    protected $_wp_list_args;
94
-
95
-    /**
96
-     * an array of column names
97
-     * array(
98
-     *    'internal-name' => 'Title'
99
-     * )
100
-     *
101
-     * @var array $_columns
102
-     */
103
-    protected $_columns;
104
-
105
-    /**
106
-     * An array of sortable columns
107
-     * array(
108
-     *    'internal-name' => 'orderby' //or
109
-     *    'internal-name' => array( 'orderby', true )
110
-     * )
111
-     *
112
-     * @var array $_sortable_columns
113
-     */
114
-    protected $_sortable_columns;
115
-
116
-    /**
117
-     * callback method used to perform AJAX row reordering
118
-     *
119
-     * @var string $_ajax_sorting_callback
120
-     */
121
-    protected $_ajax_sorting_callback;
122
-
123
-    /**
124
-     * An array of hidden columns (if needed)
125
-     * array('internal-name', 'internal-name')
126
-     *
127
-     * @var array $_hidden_columns
128
-     */
129
-    protected $_hidden_columns;
130
-
131
-    /**
132
-     * holds the per_page value
133
-     *
134
-     * @var int $_per_page
135
-     */
136
-    protected $_per_page;
137
-
138
-    /**
139
-     * holds what page number is currently being viewed
140
-     *
141
-     * @var int $_current_page
142
-     */
143
-    protected $_current_page;
144
-
145
-    /**
146
-     * the reference string for the nonce_action
147
-     *
148
-     * @var string $_nonce_action_ref
149
-     */
150
-    protected $_nonce_action_ref;
151
-
152
-    /**
153
-     * property to hold incoming request data (as set by the admin_page_core)
154
-     *
155
-     * @var array $_req_data
156
-     */
157
-    protected $_req_data;
158
-
159
-
160
-    /**
161
-     * yes / no array for admin form fields
162
-     *
163
-     * @var array $_yes_no
164
-     */
165
-    protected $_yes_no = array();
166
-
167
-    /**
168
-     * Array describing buttons that should appear at the bottom of the page
169
-     * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
170
-     * and the values are another array with the following keys
171
-     * array(
172
-     *    'route' => 'page_route',
173
-     *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
174
-     * )
175
-     *
176
-     * @var array $_bottom_buttons
177
-     */
178
-    protected $_bottom_buttons = array();
179
-
180
-
181
-    /**
182
-     * Used to indicate what should be the primary column for the list table.
183
-     * If not present then falls back to what WP calculates
184
-     * as the primary column.
185
-     *
186
-     * @type string $_primary_column
187
-     */
188
-    protected $_primary_column = '';
189
-
190
-
191
-    /**
192
-     * Used to indicate whether the table has a checkbox column or not.
193
-     *
194
-     * @type bool $_has_checkbox_column
195
-     */
196
-    protected $_has_checkbox_column = false;
197
-
198
-
199
-    /**
200
-     * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
201
-     */
202
-    public function __construct(EE_Admin_Page $admin_page)
203
-    {
204
-        $this->_admin_page   = $admin_page;
205
-        $this->_req_data     = $this->_admin_page->get_request_data();
206
-        $this->_view         = $this->_admin_page->get_view();
207
-        $this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
208
-        $this->_current_page = $this->get_pagenum();
209
-        $this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
210
-        $this->_yes_no       = array(__('No', 'event_espresso'), __('Yes', 'event_espresso'));
211
-
212
-        $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10);
213
-
214
-        $this->_setup_data();
215
-        $this->_add_view_counts();
216
-
217
-        $this->_nonce_action_ref = $this->_view;
218
-
219
-        $this->_set_properties();
220
-
221
-        //set primary column
222
-        add_filter('list_table_primary_column', array($this, 'set_primary_column'));
223
-
224
-        //set parent defaults
225
-        parent::__construct($this->_wp_list_args);
226
-
227
-        $this->prepare_items();
228
-    }
229
-
230
-
231
-    /**
232
-     * _setup_data
233
-     * this method is used to setup the $_data, $_all_data_count, and _per_page properties
234
-     *
235
-     * @uses $this->_admin_page
236
-     * @return void
237
-     */
238
-    abstract protected function _setup_data();
239
-
240
-
241
-    /**
242
-     * set the properties that this class needs to be able to execute wp_list_table properly
243
-     * properties set:
244
-     * _wp_list_args = what the arguments required for the parent _wp_list_table.
245
-     * _columns = set the columns in an array.
246
-     * _sortable_columns = columns that are sortable (array).
247
-     * _hidden_columns = columns that are hidden (array)
248
-     * _default_orderby = the default orderby for sorting.
249
-     *
250
-     * @abstract
251
-     * @access protected
252
-     * @return void
253
-     */
254
-    abstract protected function _set_properties();
255
-
256
-
257
-    /**
258
-     * _get_table_filters
259
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
260
-     * get's shown in the table.
261
-     *
262
-     * @abstract
263
-     * @access protected
264
-     * @return string
265
-     */
266
-    abstract protected function _get_table_filters();
267
-
268
-
269
-    /**
270
-     * this is a method that child class will do to add counts to the views array so when views are displayed the
271
-     * counts of the views is accurate.
272
-     *
273
-     * @abstract
274
-     * @access protected
275
-     * @return void
276
-     */
277
-    abstract protected function _add_view_counts();
278
-
279
-
280
-    /**
281
-     * _get_hidden_fields
282
-     * returns a html string of hidden fields so if any table filters are used the current view will be respected.
283
-     *
284
-     * @return string
285
-     */
286
-    protected function _get_hidden_fields()
287
-    {
288
-        $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
289
-        $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
290
-        //if action is STILL empty, then we set it to default
291
-        $action = empty($action) ? 'default' : $action;
292
-        $field  = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n";
293
-        $field  .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/
294
-        $field  .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n";
295
-
296
-        $bulk_actions = $this->_get_bulk_actions();
297
-        foreach ($bulk_actions as $bulk_action => $label) {
298
-            $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
299
-                . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
300
-        }
301
-
302
-        return $field;
303
-    }
304
-
305
-
306
-    /**
307
-     * _set_column_info
308
-     * we're using this to set the column headers property.
309
-     *
310
-     * @access protected
311
-     * @return void
312
-     */
313
-    protected function _set_column_info()
314
-    {
315
-        $columns   = $this->get_columns();
316
-        $hidden    = $this->get_hidden_columns();
317
-        $_sortable = $this->get_sortable_columns();
318
-
319
-        /**
320
-         * Dynamic hook allowing for adding sortable columns in this list table.
321
-         * Note that $this->screen->id is in the format
322
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
323
-         * table it is: event-espresso_page_espresso_messages.
324
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
325
-         * hook prefix ("event-espresso") will be different.
326
-         *
327
-         * @var array
328
-         */
329
-        $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
330
-
331
-        $sortable = array();
332
-        foreach ($_sortable as $id => $data) {
333
-            if (empty($data)) {
334
-                continue;
335
-            }
336
-            //fix for offset errors with WP_List_Table default get_columninfo()
337
-            if (is_array($data)) {
338
-                $_data[0] = key($data);
339
-                $_data[1] = isset($data[1]) ? $data[1] : false;
340
-            } else {
341
-                $_data[0] = $data;
342
-            }
343
-
344
-            $data = (array)$data;
345
-
346
-            if (! isset($data[1])) {
347
-                $_data[1] = false;
348
-            }
349
-
350
-            $sortable[$id] = $_data;
351
-        }
352
-        $primary               = $this->get_primary_column_name();
353
-        $this->_column_headers = array($columns, $hidden, $sortable, $primary);
354
-    }
355
-
356
-
357
-    /**
358
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
359
-     *
360
-     * @return string
361
-     */
362
-    protected function get_primary_column_name()
363
-    {
364
-        foreach (class_parents($this) as $parent) {
365
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
366
-                return parent::get_primary_column_name();
367
-            }
368
-        }
369
-        return $this->_primary_column;
370
-    }
371
-
372
-
373
-    /**
374
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
375
-     *
376
-     * @param EE_Base_Class $item
377
-     * @param string        $column_name
378
-     * @param string        $primary
379
-     * @return string
380
-     */
381
-    protected function handle_row_actions($item, $column_name, $primary)
382
-    {
383
-        foreach (class_parents($this) as $parent) {
384
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
385
-                return parent::handle_row_actions($item, $column_name, $primary);
386
-            }
387
-        }
388
-        return '';
389
-    }
390
-
391
-
392
-    /**
393
-     * _get_bulk_actions
394
-     * This is a wrapper called by WP_List_Table::get_bulk_actions()
395
-     *
396
-     * @access protected
397
-     * @return array bulk_actions
398
-     */
399
-    protected function _get_bulk_actions()
400
-    {
401
-        $actions = array();
402
-        //the _views property should have the bulk_actions, so let's go through and extract them into a properly
403
-        // formatted array for the wp_list_table();
404
-        foreach ($this->_views as $view => $args) {
405
-            if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
406
-                //each bulk action will correspond with a admin page route, so we can check whatever the capability is
407
-                // for that page route and skip adding the bulk action if no access for the current logged in user.
408
-                foreach ($args['bulk_action'] as $route => $label) {
409
-                    if ($this->_admin_page->check_user_access($route, true)) {
410
-                        $actions[$route] = $label;
411
-                    }
412
-                }
413
-            }
414
-        }
415
-        return $actions;
416
-    }
417
-
418
-
419
-    /**
420
-     * Generate the table navigation above or below the table.
421
-     * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
422
-     *
423
-     * @since 4.9.44.rc.001
424
-     */
425
-    public function display_tablenav($which)
426
-    {
427
-        if ('top' === $which) {
428
-            wp_nonce_field('bulk-' . $this->_args['plural']);
429
-        }
430
-        ?>
25
+	/**
26
+	 * holds the data that will be processed for the table
27
+	 *
28
+	 * @var array $_data
29
+	 */
30
+	protected $_data;
31
+
32
+
33
+	/**
34
+	 * This holds the value of all the data available for the given view (for all pages).
35
+	 *
36
+	 * @var int $_all_data_count
37
+	 */
38
+	protected $_all_data_count;
39
+
40
+
41
+	/**
42
+	 * Will contain the count of trashed items for the view label.
43
+	 *
44
+	 * @var int $_trashed_count
45
+	 */
46
+	protected $_trashed_count;
47
+
48
+
49
+	/**
50
+	 * This is what will be referenced as the slug for the current screen
51
+	 *
52
+	 * @var string $_screen
53
+	 */
54
+	protected $_screen;
55
+
56
+
57
+	/**
58
+	 * this is the EE_Admin_Page object
59
+	 *
60
+	 * @var EE_Admin_Page $_admin_page
61
+	 */
62
+	protected $_admin_page;
63
+
64
+
65
+	/**
66
+	 * The current view
67
+	 *
68
+	 * @var string $_view
69
+	 */
70
+	protected $_view;
71
+
72
+
73
+	/**
74
+	 * array of possible views for this table
75
+	 *
76
+	 * @var array $_views
77
+	 */
78
+	protected $_views;
79
+
80
+
81
+	/**
82
+	 * An array of key => value pairs containing information about the current table
83
+	 * array(
84
+	 *        'plural' => 'plural label',
85
+	 *        'singular' => 'singular label',
86
+	 *        'ajax' => false, //whether to use ajax or not
87
+	 *        'screen' => null, //string used to reference what screen this is
88
+	 *        (WP_List_table converts to screen object)
89
+	 * )
90
+	 *
91
+	 * @var array $_wp_list_args
92
+	 */
93
+	protected $_wp_list_args;
94
+
95
+	/**
96
+	 * an array of column names
97
+	 * array(
98
+	 *    'internal-name' => 'Title'
99
+	 * )
100
+	 *
101
+	 * @var array $_columns
102
+	 */
103
+	protected $_columns;
104
+
105
+	/**
106
+	 * An array of sortable columns
107
+	 * array(
108
+	 *    'internal-name' => 'orderby' //or
109
+	 *    'internal-name' => array( 'orderby', true )
110
+	 * )
111
+	 *
112
+	 * @var array $_sortable_columns
113
+	 */
114
+	protected $_sortable_columns;
115
+
116
+	/**
117
+	 * callback method used to perform AJAX row reordering
118
+	 *
119
+	 * @var string $_ajax_sorting_callback
120
+	 */
121
+	protected $_ajax_sorting_callback;
122
+
123
+	/**
124
+	 * An array of hidden columns (if needed)
125
+	 * array('internal-name', 'internal-name')
126
+	 *
127
+	 * @var array $_hidden_columns
128
+	 */
129
+	protected $_hidden_columns;
130
+
131
+	/**
132
+	 * holds the per_page value
133
+	 *
134
+	 * @var int $_per_page
135
+	 */
136
+	protected $_per_page;
137
+
138
+	/**
139
+	 * holds what page number is currently being viewed
140
+	 *
141
+	 * @var int $_current_page
142
+	 */
143
+	protected $_current_page;
144
+
145
+	/**
146
+	 * the reference string for the nonce_action
147
+	 *
148
+	 * @var string $_nonce_action_ref
149
+	 */
150
+	protected $_nonce_action_ref;
151
+
152
+	/**
153
+	 * property to hold incoming request data (as set by the admin_page_core)
154
+	 *
155
+	 * @var array $_req_data
156
+	 */
157
+	protected $_req_data;
158
+
159
+
160
+	/**
161
+	 * yes / no array for admin form fields
162
+	 *
163
+	 * @var array $_yes_no
164
+	 */
165
+	protected $_yes_no = array();
166
+
167
+	/**
168
+	 * Array describing buttons that should appear at the bottom of the page
169
+	 * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
170
+	 * and the values are another array with the following keys
171
+	 * array(
172
+	 *    'route' => 'page_route',
173
+	 *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
174
+	 * )
175
+	 *
176
+	 * @var array $_bottom_buttons
177
+	 */
178
+	protected $_bottom_buttons = array();
179
+
180
+
181
+	/**
182
+	 * Used to indicate what should be the primary column for the list table.
183
+	 * If not present then falls back to what WP calculates
184
+	 * as the primary column.
185
+	 *
186
+	 * @type string $_primary_column
187
+	 */
188
+	protected $_primary_column = '';
189
+
190
+
191
+	/**
192
+	 * Used to indicate whether the table has a checkbox column or not.
193
+	 *
194
+	 * @type bool $_has_checkbox_column
195
+	 */
196
+	protected $_has_checkbox_column = false;
197
+
198
+
199
+	/**
200
+	 * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
201
+	 */
202
+	public function __construct(EE_Admin_Page $admin_page)
203
+	{
204
+		$this->_admin_page   = $admin_page;
205
+		$this->_req_data     = $this->_admin_page->get_request_data();
206
+		$this->_view         = $this->_admin_page->get_view();
207
+		$this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
208
+		$this->_current_page = $this->get_pagenum();
209
+		$this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
210
+		$this->_yes_no       = array(__('No', 'event_espresso'), __('Yes', 'event_espresso'));
211
+
212
+		$this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10);
213
+
214
+		$this->_setup_data();
215
+		$this->_add_view_counts();
216
+
217
+		$this->_nonce_action_ref = $this->_view;
218
+
219
+		$this->_set_properties();
220
+
221
+		//set primary column
222
+		add_filter('list_table_primary_column', array($this, 'set_primary_column'));
223
+
224
+		//set parent defaults
225
+		parent::__construct($this->_wp_list_args);
226
+
227
+		$this->prepare_items();
228
+	}
229
+
230
+
231
+	/**
232
+	 * _setup_data
233
+	 * this method is used to setup the $_data, $_all_data_count, and _per_page properties
234
+	 *
235
+	 * @uses $this->_admin_page
236
+	 * @return void
237
+	 */
238
+	abstract protected function _setup_data();
239
+
240
+
241
+	/**
242
+	 * set the properties that this class needs to be able to execute wp_list_table properly
243
+	 * properties set:
244
+	 * _wp_list_args = what the arguments required for the parent _wp_list_table.
245
+	 * _columns = set the columns in an array.
246
+	 * _sortable_columns = columns that are sortable (array).
247
+	 * _hidden_columns = columns that are hidden (array)
248
+	 * _default_orderby = the default orderby for sorting.
249
+	 *
250
+	 * @abstract
251
+	 * @access protected
252
+	 * @return void
253
+	 */
254
+	abstract protected function _set_properties();
255
+
256
+
257
+	/**
258
+	 * _get_table_filters
259
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
260
+	 * get's shown in the table.
261
+	 *
262
+	 * @abstract
263
+	 * @access protected
264
+	 * @return string
265
+	 */
266
+	abstract protected function _get_table_filters();
267
+
268
+
269
+	/**
270
+	 * this is a method that child class will do to add counts to the views array so when views are displayed the
271
+	 * counts of the views is accurate.
272
+	 *
273
+	 * @abstract
274
+	 * @access protected
275
+	 * @return void
276
+	 */
277
+	abstract protected function _add_view_counts();
278
+
279
+
280
+	/**
281
+	 * _get_hidden_fields
282
+	 * returns a html string of hidden fields so if any table filters are used the current view will be respected.
283
+	 *
284
+	 * @return string
285
+	 */
286
+	protected function _get_hidden_fields()
287
+	{
288
+		$action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
289
+		$action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
290
+		//if action is STILL empty, then we set it to default
291
+		$action = empty($action) ? 'default' : $action;
292
+		$field  = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n";
293
+		$field  .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/
294
+		$field  .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n";
295
+
296
+		$bulk_actions = $this->_get_bulk_actions();
297
+		foreach ($bulk_actions as $bulk_action => $label) {
298
+			$field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
299
+				. ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
300
+		}
301
+
302
+		return $field;
303
+	}
304
+
305
+
306
+	/**
307
+	 * _set_column_info
308
+	 * we're using this to set the column headers property.
309
+	 *
310
+	 * @access protected
311
+	 * @return void
312
+	 */
313
+	protected function _set_column_info()
314
+	{
315
+		$columns   = $this->get_columns();
316
+		$hidden    = $this->get_hidden_columns();
317
+		$_sortable = $this->get_sortable_columns();
318
+
319
+		/**
320
+		 * Dynamic hook allowing for adding sortable columns in this list table.
321
+		 * Note that $this->screen->id is in the format
322
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
323
+		 * table it is: event-espresso_page_espresso_messages.
324
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
325
+		 * hook prefix ("event-espresso") will be different.
326
+		 *
327
+		 * @var array
328
+		 */
329
+		$_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
330
+
331
+		$sortable = array();
332
+		foreach ($_sortable as $id => $data) {
333
+			if (empty($data)) {
334
+				continue;
335
+			}
336
+			//fix for offset errors with WP_List_Table default get_columninfo()
337
+			if (is_array($data)) {
338
+				$_data[0] = key($data);
339
+				$_data[1] = isset($data[1]) ? $data[1] : false;
340
+			} else {
341
+				$_data[0] = $data;
342
+			}
343
+
344
+			$data = (array)$data;
345
+
346
+			if (! isset($data[1])) {
347
+				$_data[1] = false;
348
+			}
349
+
350
+			$sortable[$id] = $_data;
351
+		}
352
+		$primary               = $this->get_primary_column_name();
353
+		$this->_column_headers = array($columns, $hidden, $sortable, $primary);
354
+	}
355
+
356
+
357
+	/**
358
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
359
+	 *
360
+	 * @return string
361
+	 */
362
+	protected function get_primary_column_name()
363
+	{
364
+		foreach (class_parents($this) as $parent) {
365
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
366
+				return parent::get_primary_column_name();
367
+			}
368
+		}
369
+		return $this->_primary_column;
370
+	}
371
+
372
+
373
+	/**
374
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
375
+	 *
376
+	 * @param EE_Base_Class $item
377
+	 * @param string        $column_name
378
+	 * @param string        $primary
379
+	 * @return string
380
+	 */
381
+	protected function handle_row_actions($item, $column_name, $primary)
382
+	{
383
+		foreach (class_parents($this) as $parent) {
384
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
385
+				return parent::handle_row_actions($item, $column_name, $primary);
386
+			}
387
+		}
388
+		return '';
389
+	}
390
+
391
+
392
+	/**
393
+	 * _get_bulk_actions
394
+	 * This is a wrapper called by WP_List_Table::get_bulk_actions()
395
+	 *
396
+	 * @access protected
397
+	 * @return array bulk_actions
398
+	 */
399
+	protected function _get_bulk_actions()
400
+	{
401
+		$actions = array();
402
+		//the _views property should have the bulk_actions, so let's go through and extract them into a properly
403
+		// formatted array for the wp_list_table();
404
+		foreach ($this->_views as $view => $args) {
405
+			if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
406
+				//each bulk action will correspond with a admin page route, so we can check whatever the capability is
407
+				// for that page route and skip adding the bulk action if no access for the current logged in user.
408
+				foreach ($args['bulk_action'] as $route => $label) {
409
+					if ($this->_admin_page->check_user_access($route, true)) {
410
+						$actions[$route] = $label;
411
+					}
412
+				}
413
+			}
414
+		}
415
+		return $actions;
416
+	}
417
+
418
+
419
+	/**
420
+	 * Generate the table navigation above or below the table.
421
+	 * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
422
+	 *
423
+	 * @since 4.9.44.rc.001
424
+	 */
425
+	public function display_tablenav($which)
426
+	{
427
+		if ('top' === $which) {
428
+			wp_nonce_field('bulk-' . $this->_args['plural']);
429
+		}
430
+		?>
431 431
         <div class="tablenav <?php echo esc_attr($which); ?>">
432 432
             <?php if ($this->_get_bulk_actions()) { ?>
433 433
                 <div class="alignleft actions bulkactions">
434 434
                     <?php $this->bulk_actions(); ?>
435 435
                 </div>
436 436
             <?php }
437
-            $this->extra_tablenav($which);
438
-            $this->pagination($which);
439
-            ?>
437
+			$this->extra_tablenav($which);
438
+			$this->pagination($which);
439
+			?>
440 440
 
441 441
             <br class="clear"/>
442 442
         </div>
443 443
         <?php
444
-    }
445
-
446
-
447
-    /**
448
-     * _filters
449
-     * This receives the filters array from children _get_table_filters() and assembles the string including the filter
450
-     * button.
451
-     *
452
-     * @access private
453
-     * @return string html showing filters
454
-     */
455
-    private function _filters()
456
-    {
457
-        $classname = get_class($this);
458
-        $filters   = apply_filters(
459
-            "FHEE__{$classname}__filters",
460
-            (array) $this->_get_table_filters(),
461
-            $this,
462
-            $this->_screen
463
-        );
464
-
465
-        if (empty($filters)) {
466
-            return;
467
-        }
468
-        foreach ($filters as $filter) {
469
-            echo $filter;
470
-        }
471
-        //add filter button at end
472
-        echo '<input type="submit" class="button-secondary" value="'
473
-             . esc_html__('Filter', 'event_espresso')
474
-             . '" id="post-query-submit" />';
475
-        //add reset filters button at end
476
-        echo '<a class="button button-secondary"  href="'
477
-             . $this->_admin_page->get_current_page_view_url()
478
-             . '" style="display:inline-block">'
479
-             . esc_html__('Reset Filters', 'event_espresso')
480
-             . '</a>';
481
-    }
482
-
483
-
484
-    /**
485
-     * Callback for 'list_table_primary_column' WordPress filter
486
-     * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
487
-     * column when class is instantiated.
488
-     *
489
-     * @see WP_List_Table::get_primary_column_name
490
-     * @param string $column_name
491
-     * @return string
492
-     */
493
-    public function set_primary_column($column_name)
494
-    {
495
-        return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
496
-    }
497
-
498
-
499
-    /**
500
-     *
501
-     */
502
-    public function prepare_items()
503
-    {
504
-
505
-        $this->_set_column_info();
506
-        //$this->_column_headers = $this->get_column_info();
507
-        $total_items = $this->_all_data_count;
508
-        $this->process_bulk_action();
509
-
510
-        $this->items = $this->_data;
511
-        $this->set_pagination_args(
512
-            array(
513
-                'total_items' => $total_items,
514
-                'per_page'    => $this->_per_page,
515
-                'total_pages' => ceil($total_items / $this->_per_page),
516
-            )
517
-        );
518
-    }
519
-
520
-
521
-    /**
522
-     * This column is the default for when there is no defined column method for a registered column.
523
-     * This can be overridden by child classes, but allows for hooking in for custom columns.
524
-     *
525
-     * @param EE_Base_Class $item
526
-     * @param string        $column_name The column being called.
527
-     * @return string html content for the column
528
-     */
529
-    public function column_default($item, $column_name)
530
-    {
531
-        /**
532
-         * Dynamic hook allowing for adding additional column content in this list table.
533
-         * Note that $this->screen->id is in the format
534
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
535
-         * table it is: event-espresso_page_espresso_messages.
536
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
537
-         * hook prefix ("event-espresso") will be different.
538
-         */
539
-        do_action(
540
-            'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
541
-            $item,
542
-            $this->_screen
543
-        );
544
-    }
545
-
546
-
547
-    /**
548
-     * Get a list of columns. The format is:
549
-     * 'internal-name' => 'Title'
550
-     *
551
-     * @since  3.1.0
552
-     * @access public
553
-     * @abstract
554
-     * @return array
555
-     */
556
-    public function get_columns()
557
-    {
558
-        /**
559
-         * Dynamic hook allowing for adding additional columns in this list table.
560
-         * Note that $this->screen->id is in the format
561
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
562
-         * table it is: event-espresso_page_espresso_messages.
563
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
564
-         * hook prefix ("event-espresso") will be different.
565
-         *
566
-         * @var array
567
-         */
568
-        $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
569
-        return $columns;
570
-    }
571
-
572
-
573
-    /**
574
-     * Get an associative array ( id => link ) with the list
575
-     * of views available on this table.
576
-     *
577
-     * @since  3.1.0
578
-     * @access protected
579
-     * @return array
580
-     */
581
-    public function get_views()
582
-    {
583
-        return $this->_views;
584
-    }
585
-
586
-
587
-    /**
588
-     * Generate the views html.
589
-     */
590
-    public function display_views()
591
-    {
592
-        $views           = $this->get_views();
593
-        $assembled_views = array();
594
-
595
-        if (empty($views)) {
596
-            return;
597
-        }
598
-        echo "<ul class='subsubsub'>\n";
599
-        foreach ($views as $view) {
600
-            $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
601
-            if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
602
-                $assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>"
603
-                                                  . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>'
604
-                                                  . ' <span class="count">(' . $count . ')</span>';
605
-            }
606
-        }
607
-
608
-        echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : '';
609
-        echo "</ul>";
610
-    }
611
-
612
-
613
-    /**
614
-     * Generates content for a single row of the table
615
-     *
616
-     * @since  4.1
617
-     * @access public
618
-     * @param EE_Base_Class $item The current item
619
-     */
620
-    public function single_row($item)
621
-    {
622
-        $row_class = $this->_get_row_class($item);
623
-        echo '<tr class="' . esc_attr($row_class) . '">';
624
-        $this->single_row_columns($item);
625
-        echo '</tr>';
626
-    }
627
-
628
-
629
-    /**
630
-     * This simply sets up the row class for the table rows.
631
-     * Allows for easier overriding of child methods for setting up sorting.
632
-     *
633
-     * @param  EE_Base_Class $item the current item
634
-     * @return string
635
-     */
636
-    protected function _get_row_class($item)
637
-    {
638
-        static $row_class = '';
639
-        $row_class = ($row_class === '' ? 'alternate' : '');
640
-
641
-        $new_row_class = $row_class;
642
-
643
-        if (! empty($this->_ajax_sorting_callback)) {
644
-            $new_row_class .= ' rowsortable';
645
-        }
646
-
647
-        return $new_row_class;
648
-    }
649
-
650
-
651
-    /**
652
-     * @return array
653
-     */
654
-    public function get_sortable_columns()
655
-    {
656
-        return (array)$this->_sortable_columns;
657
-    }
658
-
659
-
660
-    /**
661
-     * @return string
662
-     */
663
-    public function get_ajax_sorting_callback()
664
-    {
665
-        return $this->_ajax_sorting_callback;
666
-    }
667
-
668
-
669
-    /**
670
-     * @return array
671
-     */
672
-    public function get_hidden_columns()
673
-    {
674
-        $user_id     = get_current_user_id();
675
-        $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
676
-        if (empty($has_default) && ! empty($this->_hidden_columns)) {
677
-            update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
678
-            update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
679
-        }
680
-        $ref = 'manage' . $this->screen->id . 'columnshidden';
681
-        return (array) get_user_option($ref, $user_id);
682
-    }
683
-
684
-
685
-    /**
686
-     * Generates the columns for a single row of the table.
687
-     * Overridden from wp_list_table so as to allow us to filter the column content for a given
688
-     * column.
689
-     *
690
-     * @since 3.1.0
691
-     * @param EE_Base_Class $item The current item
692
-     */
693
-    public function single_row_columns($item)
694
-    {
695
-        list($columns, $hidden, $sortable, $primary) = $this->get_column_info();
696
-
697
-        global $wp_version;
698
-        $use_hidden_class = version_compare($wp_version, '4.3-RC', '>=');
699
-
700
-        foreach ($columns as $column_name => $column_display_name) {
701
-
702
-            /**
703
-             * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
704
-             * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
705
-             */
706
-            $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : '';
707
-            $style        = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : '';
708
-
709
-            $classes = $column_name . ' column-' . $column_name . $hidden_class;
710
-            if ($primary === $column_name) {
711
-                $classes .= ' has-row-actions column-primary';
712
-            }
713
-
714
-            $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
715
-
716
-            $class = "class='$classes'";
717
-
718
-            $attributes = "$class$style$data";
719
-
720
-            if ($column_name === 'cb') {
721
-                echo '<th scope="row" class="check-column">';
722
-                echo apply_filters(
723
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
724
-                    $this->column_cb($item),
725
-                    $item,
726
-                    $this
727
-                );
728
-                echo '</th>';
729
-            } elseif (method_exists($this, 'column_' . $column_name)) {
730
-                echo "<td $attributes>";
731
-                echo apply_filters(
732
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
733
-                    call_user_func(array($this, 'column_' . $column_name), $item),
734
-                    $item,
735
-                    $this
736
-                );
737
-                echo $this->handle_row_actions($item, $column_name, $primary);
738
-                echo "</td>";
739
-            } else {
740
-                echo "<td $attributes>";
741
-                echo apply_filters(
742
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
743
-                    $this->column_default($item, $column_name),
744
-                    $item,
745
-                    $column_name,
746
-                    $this
747
-                );
748
-                echo $this->handle_row_actions($item, $column_name, $primary);
749
-                echo "</td>";
750
-            }
751
-        }
752
-    }
753
-
754
-
755
-    /**
756
-     * Extra controls to be displayed between bulk actions and pagination
757
-     *
758
-     * @access public
759
-     * @param string $which
760
-     * @throws \EE_Error
761
-     */
762
-    public function extra_tablenav($which)
763
-    {
764
-        if ($which === 'top') {
765
-            $this->_filters();
766
-            echo $this->_get_hidden_fields();
767
-        } else {
768
-            echo '<div class="list-table-bottom-buttons alignleft actions">';
769
-            foreach ($this->_bottom_buttons as $type => $action) {
770
-                $route         = isset($action['route']) ? $action['route'] : '';
771
-                $extra_request = isset($action['extra_request']) ? $action['extra_request'] : '';
772
-                echo $this->_admin_page->get_action_link_or_button(
773
-                    $route,
774
-                    $type,
775
-                    $extra_request,
776
-                    'button button-secondary',
777
-                    '',
778
-                    false
779
-                );
780
-            }
781
-            do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
782
-            echo '</div>';
783
-        }
784
-        //echo $this->_entries_per_page_dropdown;
785
-    }
786
-
787
-
788
-    /**
789
-     * Get an associative array ( option_name => option_title ) with the list
790
-     * of bulk actions available on this table.
791
-     *
792
-     * @since  3.1.0
793
-     * @access protected
794
-     * @return array
795
-     */
796
-    public function get_bulk_actions()
797
-    {
798
-        return (array) $this->_get_bulk_actions();
799
-    }
800
-
801
-    /**
802
-     * Processing bulk actions.
803
-     */
804
-    public function process_bulk_action()
805
-    {
806
-        //this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
807
-        //reference in case there is a case where it gets used.
808
-    }
809
-
810
-
811
-    /**
812
-     * returns the EE admin page this list table is associated with
813
-     *
814
-     * @return EE_Admin_Page
815
-     */
816
-    public function get_admin_page()
817
-    {
818
-        return $this->_admin_page;
819
-    }
820
-
821
-
822
-    /**
823
-     * A "helper" function for all children to provide an html string of
824
-     * actions to output in their content.  It is preferable for child classes
825
-     * to use this method for generating their actions content so that it's
826
-     * filterable by plugins
827
-     *
828
-     * @param string        $action_container           what are the html container
829
-     *                                                  elements for this actions string?
830
-     * @param string        $action_class               What class is for the container
831
-     *                                                  element.
832
-     * @param string        $action_items               The contents for the action items
833
-     *                                                  container.  This is filtered before
834
-     *                                                  returned.
835
-     * @param string        $action_id                  What id (optional) is used for the
836
-     *                                                  container element.
837
-     * @param EE_Base_Class $item                       The object for the column displaying
838
-     *                                                  the actions.
839
-     * @return string The assembled action elements container.
840
-     */
841
-    protected function _action_string(
842
-        $action_items,
843
-        $item,
844
-        $action_container = 'ul',
845
-        $action_class = '',
846
-        $action_id = ''
847
-    ) {
848
-        $content      = '';
849
-        $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : '';
850
-        $action_id    = ! empty($action_id) ? ' id="' . $action_id . '"' : '';
851
-        $content      .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
852
-        try {
853
-            $content .= apply_filters(
854
-                'FHEE__EE_Admin_List_Table___action_string__action_items',
855
-                $action_items,
856
-                $item,
857
-                $this
858
-            );
859
-        } catch (\Exception $e) {
860
-            if (WP_DEBUG) {
861
-                \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
862
-            }
863
-            $content .= $action_items;
864
-        }
865
-        $content .= ! empty($action_container) ? '</' . $action_container . '>' : '';
866
-        return $content;
867
-    }
444
+	}
445
+
446
+
447
+	/**
448
+	 * _filters
449
+	 * This receives the filters array from children _get_table_filters() and assembles the string including the filter
450
+	 * button.
451
+	 *
452
+	 * @access private
453
+	 * @return string html showing filters
454
+	 */
455
+	private function _filters()
456
+	{
457
+		$classname = get_class($this);
458
+		$filters   = apply_filters(
459
+			"FHEE__{$classname}__filters",
460
+			(array) $this->_get_table_filters(),
461
+			$this,
462
+			$this->_screen
463
+		);
464
+
465
+		if (empty($filters)) {
466
+			return;
467
+		}
468
+		foreach ($filters as $filter) {
469
+			echo $filter;
470
+		}
471
+		//add filter button at end
472
+		echo '<input type="submit" class="button-secondary" value="'
473
+			 . esc_html__('Filter', 'event_espresso')
474
+			 . '" id="post-query-submit" />';
475
+		//add reset filters button at end
476
+		echo '<a class="button button-secondary"  href="'
477
+			 . $this->_admin_page->get_current_page_view_url()
478
+			 . '" style="display:inline-block">'
479
+			 . esc_html__('Reset Filters', 'event_espresso')
480
+			 . '</a>';
481
+	}
482
+
483
+
484
+	/**
485
+	 * Callback for 'list_table_primary_column' WordPress filter
486
+	 * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
487
+	 * column when class is instantiated.
488
+	 *
489
+	 * @see WP_List_Table::get_primary_column_name
490
+	 * @param string $column_name
491
+	 * @return string
492
+	 */
493
+	public function set_primary_column($column_name)
494
+	{
495
+		return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
496
+	}
497
+
498
+
499
+	/**
500
+	 *
501
+	 */
502
+	public function prepare_items()
503
+	{
504
+
505
+		$this->_set_column_info();
506
+		//$this->_column_headers = $this->get_column_info();
507
+		$total_items = $this->_all_data_count;
508
+		$this->process_bulk_action();
509
+
510
+		$this->items = $this->_data;
511
+		$this->set_pagination_args(
512
+			array(
513
+				'total_items' => $total_items,
514
+				'per_page'    => $this->_per_page,
515
+				'total_pages' => ceil($total_items / $this->_per_page),
516
+			)
517
+		);
518
+	}
519
+
520
+
521
+	/**
522
+	 * This column is the default for when there is no defined column method for a registered column.
523
+	 * This can be overridden by child classes, but allows for hooking in for custom columns.
524
+	 *
525
+	 * @param EE_Base_Class $item
526
+	 * @param string        $column_name The column being called.
527
+	 * @return string html content for the column
528
+	 */
529
+	public function column_default($item, $column_name)
530
+	{
531
+		/**
532
+		 * Dynamic hook allowing for adding additional column content in this list table.
533
+		 * Note that $this->screen->id is in the format
534
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
535
+		 * table it is: event-espresso_page_espresso_messages.
536
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
537
+		 * hook prefix ("event-espresso") will be different.
538
+		 */
539
+		do_action(
540
+			'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
541
+			$item,
542
+			$this->_screen
543
+		);
544
+	}
545
+
546
+
547
+	/**
548
+	 * Get a list of columns. The format is:
549
+	 * 'internal-name' => 'Title'
550
+	 *
551
+	 * @since  3.1.0
552
+	 * @access public
553
+	 * @abstract
554
+	 * @return array
555
+	 */
556
+	public function get_columns()
557
+	{
558
+		/**
559
+		 * Dynamic hook allowing for adding additional columns in this list table.
560
+		 * Note that $this->screen->id is in the format
561
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
562
+		 * table it is: event-espresso_page_espresso_messages.
563
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
564
+		 * hook prefix ("event-espresso") will be different.
565
+		 *
566
+		 * @var array
567
+		 */
568
+		$columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
569
+		return $columns;
570
+	}
571
+
572
+
573
+	/**
574
+	 * Get an associative array ( id => link ) with the list
575
+	 * of views available on this table.
576
+	 *
577
+	 * @since  3.1.0
578
+	 * @access protected
579
+	 * @return array
580
+	 */
581
+	public function get_views()
582
+	{
583
+		return $this->_views;
584
+	}
585
+
586
+
587
+	/**
588
+	 * Generate the views html.
589
+	 */
590
+	public function display_views()
591
+	{
592
+		$views           = $this->get_views();
593
+		$assembled_views = array();
594
+
595
+		if (empty($views)) {
596
+			return;
597
+		}
598
+		echo "<ul class='subsubsub'>\n";
599
+		foreach ($views as $view) {
600
+			$count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
601
+			if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
602
+				$assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>"
603
+												  . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>'
604
+												  . ' <span class="count">(' . $count . ')</span>';
605
+			}
606
+		}
607
+
608
+		echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : '';
609
+		echo "</ul>";
610
+	}
611
+
612
+
613
+	/**
614
+	 * Generates content for a single row of the table
615
+	 *
616
+	 * @since  4.1
617
+	 * @access public
618
+	 * @param EE_Base_Class $item The current item
619
+	 */
620
+	public function single_row($item)
621
+	{
622
+		$row_class = $this->_get_row_class($item);
623
+		echo '<tr class="' . esc_attr($row_class) . '">';
624
+		$this->single_row_columns($item);
625
+		echo '</tr>';
626
+	}
627
+
628
+
629
+	/**
630
+	 * This simply sets up the row class for the table rows.
631
+	 * Allows for easier overriding of child methods for setting up sorting.
632
+	 *
633
+	 * @param  EE_Base_Class $item the current item
634
+	 * @return string
635
+	 */
636
+	protected function _get_row_class($item)
637
+	{
638
+		static $row_class = '';
639
+		$row_class = ($row_class === '' ? 'alternate' : '');
640
+
641
+		$new_row_class = $row_class;
642
+
643
+		if (! empty($this->_ajax_sorting_callback)) {
644
+			$new_row_class .= ' rowsortable';
645
+		}
646
+
647
+		return $new_row_class;
648
+	}
649
+
650
+
651
+	/**
652
+	 * @return array
653
+	 */
654
+	public function get_sortable_columns()
655
+	{
656
+		return (array)$this->_sortable_columns;
657
+	}
658
+
659
+
660
+	/**
661
+	 * @return string
662
+	 */
663
+	public function get_ajax_sorting_callback()
664
+	{
665
+		return $this->_ajax_sorting_callback;
666
+	}
667
+
668
+
669
+	/**
670
+	 * @return array
671
+	 */
672
+	public function get_hidden_columns()
673
+	{
674
+		$user_id     = get_current_user_id();
675
+		$has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
676
+		if (empty($has_default) && ! empty($this->_hidden_columns)) {
677
+			update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
678
+			update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
679
+		}
680
+		$ref = 'manage' . $this->screen->id . 'columnshidden';
681
+		return (array) get_user_option($ref, $user_id);
682
+	}
683
+
684
+
685
+	/**
686
+	 * Generates the columns for a single row of the table.
687
+	 * Overridden from wp_list_table so as to allow us to filter the column content for a given
688
+	 * column.
689
+	 *
690
+	 * @since 3.1.0
691
+	 * @param EE_Base_Class $item The current item
692
+	 */
693
+	public function single_row_columns($item)
694
+	{
695
+		list($columns, $hidden, $sortable, $primary) = $this->get_column_info();
696
+
697
+		global $wp_version;
698
+		$use_hidden_class = version_compare($wp_version, '4.3-RC', '>=');
699
+
700
+		foreach ($columns as $column_name => $column_display_name) {
701
+
702
+			/**
703
+			 * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
704
+			 * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
705
+			 */
706
+			$hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : '';
707
+			$style        = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : '';
708
+
709
+			$classes = $column_name . ' column-' . $column_name . $hidden_class;
710
+			if ($primary === $column_name) {
711
+				$classes .= ' has-row-actions column-primary';
712
+			}
713
+
714
+			$data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
715
+
716
+			$class = "class='$classes'";
717
+
718
+			$attributes = "$class$style$data";
719
+
720
+			if ($column_name === 'cb') {
721
+				echo '<th scope="row" class="check-column">';
722
+				echo apply_filters(
723
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
724
+					$this->column_cb($item),
725
+					$item,
726
+					$this
727
+				);
728
+				echo '</th>';
729
+			} elseif (method_exists($this, 'column_' . $column_name)) {
730
+				echo "<td $attributes>";
731
+				echo apply_filters(
732
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
733
+					call_user_func(array($this, 'column_' . $column_name), $item),
734
+					$item,
735
+					$this
736
+				);
737
+				echo $this->handle_row_actions($item, $column_name, $primary);
738
+				echo "</td>";
739
+			} else {
740
+				echo "<td $attributes>";
741
+				echo apply_filters(
742
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
743
+					$this->column_default($item, $column_name),
744
+					$item,
745
+					$column_name,
746
+					$this
747
+				);
748
+				echo $this->handle_row_actions($item, $column_name, $primary);
749
+				echo "</td>";
750
+			}
751
+		}
752
+	}
753
+
754
+
755
+	/**
756
+	 * Extra controls to be displayed between bulk actions and pagination
757
+	 *
758
+	 * @access public
759
+	 * @param string $which
760
+	 * @throws \EE_Error
761
+	 */
762
+	public function extra_tablenav($which)
763
+	{
764
+		if ($which === 'top') {
765
+			$this->_filters();
766
+			echo $this->_get_hidden_fields();
767
+		} else {
768
+			echo '<div class="list-table-bottom-buttons alignleft actions">';
769
+			foreach ($this->_bottom_buttons as $type => $action) {
770
+				$route         = isset($action['route']) ? $action['route'] : '';
771
+				$extra_request = isset($action['extra_request']) ? $action['extra_request'] : '';
772
+				echo $this->_admin_page->get_action_link_or_button(
773
+					$route,
774
+					$type,
775
+					$extra_request,
776
+					'button button-secondary',
777
+					'',
778
+					false
779
+				);
780
+			}
781
+			do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
782
+			echo '</div>';
783
+		}
784
+		//echo $this->_entries_per_page_dropdown;
785
+	}
786
+
787
+
788
+	/**
789
+	 * Get an associative array ( option_name => option_title ) with the list
790
+	 * of bulk actions available on this table.
791
+	 *
792
+	 * @since  3.1.0
793
+	 * @access protected
794
+	 * @return array
795
+	 */
796
+	public function get_bulk_actions()
797
+	{
798
+		return (array) $this->_get_bulk_actions();
799
+	}
800
+
801
+	/**
802
+	 * Processing bulk actions.
803
+	 */
804
+	public function process_bulk_action()
805
+	{
806
+		//this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
807
+		//reference in case there is a case where it gets used.
808
+	}
809
+
810
+
811
+	/**
812
+	 * returns the EE admin page this list table is associated with
813
+	 *
814
+	 * @return EE_Admin_Page
815
+	 */
816
+	public function get_admin_page()
817
+	{
818
+		return $this->_admin_page;
819
+	}
820
+
821
+
822
+	/**
823
+	 * A "helper" function for all children to provide an html string of
824
+	 * actions to output in their content.  It is preferable for child classes
825
+	 * to use this method for generating their actions content so that it's
826
+	 * filterable by plugins
827
+	 *
828
+	 * @param string        $action_container           what are the html container
829
+	 *                                                  elements for this actions string?
830
+	 * @param string        $action_class               What class is for the container
831
+	 *                                                  element.
832
+	 * @param string        $action_items               The contents for the action items
833
+	 *                                                  container.  This is filtered before
834
+	 *                                                  returned.
835
+	 * @param string        $action_id                  What id (optional) is used for the
836
+	 *                                                  container element.
837
+	 * @param EE_Base_Class $item                       The object for the column displaying
838
+	 *                                                  the actions.
839
+	 * @return string The assembled action elements container.
840
+	 */
841
+	protected function _action_string(
842
+		$action_items,
843
+		$item,
844
+		$action_container = 'ul',
845
+		$action_class = '',
846
+		$action_id = ''
847
+	) {
848
+		$content      = '';
849
+		$action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : '';
850
+		$action_id    = ! empty($action_id) ? ' id="' . $action_id . '"' : '';
851
+		$content      .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
852
+		try {
853
+			$content .= apply_filters(
854
+				'FHEE__EE_Admin_List_Table___action_string__action_items',
855
+				$action_items,
856
+				$item,
857
+				$this
858
+			);
859
+		} catch (\Exception $e) {
860
+			if (WP_DEBUG) {
861
+				\EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
862
+			}
863
+			$content .= $action_items;
864
+		}
865
+		$content .= ! empty($action_container) ? '</' . $action_container . '>' : '';
866
+		return $content;
867
+	}
868 868
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@  discard block
 block discarded – undo
2 2
 
3 3
 defined('EVENT_ESPRESSO_VERSION') || exit('No direct access allowed.');
4 4
 
5
-if (! class_exists('WP_List_Table')) {
6
-    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
+if ( ! class_exists('WP_List_Table')) {
6
+    require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php';
7 7
 }
8 8
 
9 9
 
@@ -206,10 +206,10 @@  discard block
 block discarded – undo
206 206
         $this->_view         = $this->_admin_page->get_view();
207 207
         $this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
208 208
         $this->_current_page = $this->get_pagenum();
209
-        $this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
209
+        $this->_screen       = $this->_admin_page->get_current_page().'_'.$this->_admin_page->get_current_view();
210 210
         $this->_yes_no       = array(__('No', 'event_espresso'), __('Yes', 'event_espresso'));
211 211
 
212
-        $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10);
212
+        $this->_per_page = $this->get_items_per_page($this->_screen.'_per_page', 10);
213 213
 
214 214
         $this->_setup_data();
215 215
         $this->_add_view_counts();
@@ -289,14 +289,14 @@  discard block
 block discarded – undo
289 289
         $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
290 290
         //if action is STILL empty, then we set it to default
291 291
         $action = empty($action) ? 'default' : $action;
292
-        $field  = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n";
293
-        $field  .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/
294
-        $field  .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n";
292
+        $field  = '<input type="hidden" name="page" value="'.$this->_req_data['page'].'" />'."\n";
293
+        $field  .= '<input type="hidden" name="route" value="'.$action.'" />'."\n"; /**/
294
+        $field  .= '<input type="hidden" name="perpage" value="'.$this->_per_page.'" />'."\n";
295 295
 
296 296
         $bulk_actions = $this->_get_bulk_actions();
297 297
         foreach ($bulk_actions as $bulk_action => $label) {
298
-            $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
299
-                . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
298
+            $field .= '<input type="hidden" name="'.$bulk_action.'_nonce"'
299
+                . ' value="'.wp_create_nonce($bulk_action.'_nonce').'" />'."\n";
300 300
         }
301 301
 
302 302
         return $field;
@@ -341,9 +341,9 @@  discard block
 block discarded – undo
341 341
                 $_data[0] = $data;
342 342
             }
343 343
 
344
-            $data = (array)$data;
344
+            $data = (array) $data;
345 345
 
346
-            if (! isset($data[1])) {
346
+            if ( ! isset($data[1])) {
347 347
                 $_data[1] = false;
348 348
             }
349 349
 
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
     public function display_tablenav($which)
426 426
     {
427 427
         if ('top' === $which) {
428
-            wp_nonce_field('bulk-' . $this->_args['plural']);
428
+            wp_nonce_field('bulk-'.$this->_args['plural']);
429 429
         }
430 430
         ?>
431 431
         <div class="tablenav <?php echo esc_attr($which); ?>">
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
          * hook prefix ("event-espresso") will be different.
538 538
          */
539 539
         do_action(
540
-            'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
540
+            'AHEE__EE_Admin_List_Table__column_'.$column_name.'__'.$this->screen->id,
541 541
             $item,
542 542
             $this->_screen
543 543
         );
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
          *
566 566
          * @var array
567 567
          */
568
-        $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
568
+        $columns = apply_filters('FHEE_manage_'.$this->screen->id.'_columns', $this->_columns, $this->_screen);
569 569
         return $columns;
570 570
     }
571 571
 
@@ -599,13 +599,13 @@  discard block
 block discarded – undo
599 599
         foreach ($views as $view) {
600 600
             $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
601 601
             if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
602
-                $assembled_views[$view['slug']] = "\t<li class='" . $view['class'] . "'>"
603
-                                                  . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>'
604
-                                                  . ' <span class="count">(' . $count . ')</span>';
602
+                $assembled_views[$view['slug']] = "\t<li class='".$view['class']."'>"
603
+                                                  . '<a href="'.$view['url'].'">'.$view['label'].'</a>'
604
+                                                  . ' <span class="count">('.$count.')</span>';
605 605
             }
606 606
         }
607 607
 
608
-        echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : '';
608
+        echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views)."</li>\n" : '';
609 609
         echo "</ul>";
610 610
     }
611 611
 
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
     public function single_row($item)
621 621
     {
622 622
         $row_class = $this->_get_row_class($item);
623
-        echo '<tr class="' . esc_attr($row_class) . '">';
623
+        echo '<tr class="'.esc_attr($row_class).'">';
624 624
         $this->single_row_columns($item);
625 625
         echo '</tr>';
626 626
     }
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 
641 641
         $new_row_class = $row_class;
642 642
 
643
-        if (! empty($this->_ajax_sorting_callback)) {
643
+        if ( ! empty($this->_ajax_sorting_callback)) {
644 644
             $new_row_class .= ' rowsortable';
645 645
         }
646 646
 
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
      */
654 654
     public function get_sortable_columns()
655 655
     {
656
-        return (array)$this->_sortable_columns;
656
+        return (array) $this->_sortable_columns;
657 657
     }
658 658
 
659 659
 
@@ -672,12 +672,12 @@  discard block
 block discarded – undo
672 672
     public function get_hidden_columns()
673 673
     {
674 674
         $user_id     = get_current_user_id();
675
-        $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
675
+        $has_default = get_user_option('default'.$this->screen->id.'columnshidden', $user_id);
676 676
         if (empty($has_default) && ! empty($this->_hidden_columns)) {
677
-            update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
678
-            update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
677
+            update_user_option($user_id, 'default'.$this->screen->id.'columnshidden', true);
678
+            update_user_option($user_id, 'manage'.$this->screen->id.'columnshidden', $this->_hidden_columns, true);
679 679
         }
680
-        $ref = 'manage' . $this->screen->id . 'columnshidden';
680
+        $ref = 'manage'.$this->screen->id.'columnshidden';
681 681
         return (array) get_user_option($ref, $user_id);
682 682
     }
683 683
 
@@ -706,12 +706,12 @@  discard block
 block discarded – undo
706 706
             $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : '';
707 707
             $style        = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : '';
708 708
 
709
-            $classes = $column_name . ' column-' . $column_name . $hidden_class;
709
+            $classes = $column_name.' column-'.$column_name.$hidden_class;
710 710
             if ($primary === $column_name) {
711 711
                 $classes .= ' has-row-actions column-primary';
712 712
             }
713 713
 
714
-            $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
714
+            $data = ' data-colname="'.wp_strip_all_tags($column_display_name).'"';
715 715
 
716 716
             $class = "class='$classes'";
717 717
 
@@ -726,11 +726,11 @@  discard block
 block discarded – undo
726 726
                     $this
727 727
                 );
728 728
                 echo '</th>';
729
-            } elseif (method_exists($this, 'column_' . $column_name)) {
729
+            } elseif (method_exists($this, 'column_'.$column_name)) {
730 730
                 echo "<td $attributes>";
731 731
                 echo apply_filters(
732
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
733
-                    call_user_func(array($this, 'column_' . $column_name), $item),
732
+                    'FHEE__EE_Admin_List_Table__single_row_columns__column_'.$column_name.'__column_content',
733
+                    call_user_func(array($this, 'column_'.$column_name), $item),
734 734
                     $item,
735 735
                     $this
736 736
                 );
@@ -846,9 +846,9 @@  discard block
 block discarded – undo
846 846
         $action_id = ''
847 847
     ) {
848 848
         $content      = '';
849
-        $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : '';
850
-        $action_id    = ! empty($action_id) ? ' id="' . $action_id . '"' : '';
851
-        $content      .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
849
+        $action_class = ! empty($action_class) ? ' class="'.$action_class.'"' : '';
850
+        $action_id    = ! empty($action_id) ? ' id="'.$action_id.'"' : '';
851
+        $content .= ! empty($action_container) ? '<'.$action_container.$action_class.$action_id.'>' : '';
852 852
         try {
853 853
             $content .= apply_filters(
854 854
                 'FHEE__EE_Admin_List_Table___action_string__action_items',
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
             }
863 863
             $content .= $action_items;
864 864
         }
865
-        $content .= ! empty($action_container) ? '</' . $action_container . '>' : '';
865
+        $content .= ! empty($action_container) ? '</'.$action_container.'>' : '';
866 866
         return $content;
867 867
     }
868 868
 }
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 1 patch
Indentation   +3632 added lines, -3632 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('NO direct script access allowed');
2
+	exit('NO direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -17,2222 +17,2222 @@  discard block
 block discarded – undo
17 17
 class Messages_Admin_Page extends EE_Admin_Page
18 18
 {
19 19
     
20
-    /**
21
-     * @type EE_Message_Resource_Manager $_message_resource_manager
22
-     */
23
-    protected $_message_resource_manager;
24
-    
25
-    /**
26
-     * @type string $_active_message_type_name
27
-     */
28
-    protected $_active_message_type_name = '';
29
-    
30
-    /**
31
-     * @type EE_messenger $_active_messenger
32
-     */
33
-    protected $_active_messenger;
34
-    protected $_activate_state;
35
-    protected $_activate_meta_box_type;
36
-    protected $_current_message_meta_box;
37
-    protected $_current_message_meta_box_object;
38
-    protected $_context_switcher;
39
-    protected $_shortcodes = array();
40
-    protected $_active_messengers = array();
41
-    protected $_active_message_types = array();
42
-    
43
-    /**
44
-     * @var EE_Message_Template_Group $_message_template_group
45
-     */
46
-    protected $_message_template_group;
47
-    protected $_m_mt_settings = array();
48
-    
49
-    
50
-    /**
51
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
52
-     * IF there is no group then it gets automatically set to the Default template pack.
53
-     *
54
-     * @since 4.5.0
55
-     *
56
-     * @var EE_Messages_Template_Pack
57
-     */
58
-    protected $_template_pack;
59
-    
60
-    
61
-    /**
62
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
63
-     * group is.  If there is no group then it automatically gets set to default.
64
-     *
65
-     * @since 4.5.0
66
-     *
67
-     * @var string
68
-     */
69
-    protected $_variation;
70
-    
71
-    
72
-    /**
73
-     * @param bool $routing
74
-     */
75
-    public function __construct($routing = true)
76
-    {
77
-        //make sure messages autoloader is running
78
-        EED_Messages::set_autoloaders();
79
-        parent::__construct($routing);
80
-    }
81
-    
82
-    
83
-    protected function _init_page_props()
84
-    {
85
-        $this->page_slug        = EE_MSG_PG_SLUG;
86
-        $this->page_label       = __('Messages Settings', 'event_espresso');
87
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
88
-        $this->_admin_base_path = EE_MSG_ADMIN;
89
-        
90
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
91
-        
92
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
93
-        $this->_load_message_resource_manager();
94
-    }
95
-    
96
-    
97
-    /**
98
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
99
-     *
100
-     *
101
-     * @throws EE_Error
102
-     */
103
-    protected function _load_message_resource_manager()
104
-    {
105
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
106
-    }
107
-    
108
-    
109
-    /**
110
-     * @deprecated 4.9.9.rc.014
111
-     * @return array
112
-     */
113
-    public function get_messengers_for_list_table()
114
-    {
115
-        EE_Error::doing_it_wrong(
116
-            __METHOD__,
117
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
20
+	/**
21
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
22
+	 */
23
+	protected $_message_resource_manager;
24
+    
25
+	/**
26
+	 * @type string $_active_message_type_name
27
+	 */
28
+	protected $_active_message_type_name = '';
29
+    
30
+	/**
31
+	 * @type EE_messenger $_active_messenger
32
+	 */
33
+	protected $_active_messenger;
34
+	protected $_activate_state;
35
+	protected $_activate_meta_box_type;
36
+	protected $_current_message_meta_box;
37
+	protected $_current_message_meta_box_object;
38
+	protected $_context_switcher;
39
+	protected $_shortcodes = array();
40
+	protected $_active_messengers = array();
41
+	protected $_active_message_types = array();
42
+    
43
+	/**
44
+	 * @var EE_Message_Template_Group $_message_template_group
45
+	 */
46
+	protected $_message_template_group;
47
+	protected $_m_mt_settings = array();
48
+    
49
+    
50
+	/**
51
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
52
+	 * IF there is no group then it gets automatically set to the Default template pack.
53
+	 *
54
+	 * @since 4.5.0
55
+	 *
56
+	 * @var EE_Messages_Template_Pack
57
+	 */
58
+	protected $_template_pack;
59
+    
60
+    
61
+	/**
62
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
63
+	 * group is.  If there is no group then it automatically gets set to default.
64
+	 *
65
+	 * @since 4.5.0
66
+	 *
67
+	 * @var string
68
+	 */
69
+	protected $_variation;
70
+    
71
+    
72
+	/**
73
+	 * @param bool $routing
74
+	 */
75
+	public function __construct($routing = true)
76
+	{
77
+		//make sure messages autoloader is running
78
+		EED_Messages::set_autoloaders();
79
+		parent::__construct($routing);
80
+	}
81
+    
82
+    
83
+	protected function _init_page_props()
84
+	{
85
+		$this->page_slug        = EE_MSG_PG_SLUG;
86
+		$this->page_label       = __('Messages Settings', 'event_espresso');
87
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
88
+		$this->_admin_base_path = EE_MSG_ADMIN;
89
+        
90
+		$this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
91
+        
92
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
93
+		$this->_load_message_resource_manager();
94
+	}
95
+    
96
+    
97
+	/**
98
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
99
+	 *
100
+	 *
101
+	 * @throws EE_Error
102
+	 */
103
+	protected function _load_message_resource_manager()
104
+	{
105
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
106
+	}
107
+    
108
+    
109
+	/**
110
+	 * @deprecated 4.9.9.rc.014
111
+	 * @return array
112
+	 */
113
+	public function get_messengers_for_list_table()
114
+	{
115
+		EE_Error::doing_it_wrong(
116
+			__METHOD__,
117
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
118 118
 			values for use in creating a messenger filter dropdown which is now generated differently via
119 119
 			 Messages_Admin_Page::get_messengers_select_input', 'event_espresso'),
120
-            '4.9.9.rc.014'
121
-        );
122
-        
123
-        $m_values          = array();
124
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
125
-        //setup messengers for selects
126
-        $i = 1;
127
-        foreach ($active_messengers as $active_messenger) {
128
-            if ($active_messenger instanceof EE_Message) {
129
-                $m_values[$i]['id']   = $active_messenger->messenger();
130
-                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
131
-                $i++;
132
-            }
133
-        }
134
-        
135
-        return $m_values;
136
-    }
137
-    
138
-    
139
-    /**
140
-     * @deprecated 4.9.9.rc.014
141
-     * @return array
142
-     */
143
-    public function get_message_types_for_list_table()
144
-    {
145
-        EE_Error::doing_it_wrong(
146
-            __METHOD__,
147
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
120
+			'4.9.9.rc.014'
121
+		);
122
+        
123
+		$m_values          = array();
124
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
125
+		//setup messengers for selects
126
+		$i = 1;
127
+		foreach ($active_messengers as $active_messenger) {
128
+			if ($active_messenger instanceof EE_Message) {
129
+				$m_values[$i]['id']   = $active_messenger->messenger();
130
+				$m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
131
+				$i++;
132
+			}
133
+		}
134
+        
135
+		return $m_values;
136
+	}
137
+    
138
+    
139
+	/**
140
+	 * @deprecated 4.9.9.rc.014
141
+	 * @return array
142
+	 */
143
+	public function get_message_types_for_list_table()
144
+	{
145
+		EE_Error::doing_it_wrong(
146
+			__METHOD__,
147
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
148 148
 			values for use in creating a message type filter dropdown which is now generated differently via
149 149
 			 Messages_Admin_Page::get_message_types_select_input', 'event_espresso'),
150
-            '4.9.9.rc.014'
151
-        );
152
-        
153
-        $mt_values       = array();
154
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
155
-        $i               = 1;
156
-        foreach ($active_messages as $active_message) {
157
-            if ($active_message instanceof EE_Message) {
158
-                $mt_values[$i]['id']   = $active_message->message_type();
159
-                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
160
-                $i++;
161
-            }
162
-        }
163
-        
164
-        return $mt_values;
165
-    }
166
-    
167
-    
168
-    /**
169
-     * @deprecated 4.9.9.rc.014
170
-     * @return array
171
-     */
172
-    public function get_contexts_for_message_types_for_list_table()
173
-    {
174
-        EE_Error::doing_it_wrong(
175
-            __METHOD__,
176
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
150
+			'4.9.9.rc.014'
151
+		);
152
+        
153
+		$mt_values       = array();
154
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
155
+		$i               = 1;
156
+		foreach ($active_messages as $active_message) {
157
+			if ($active_message instanceof EE_Message) {
158
+				$mt_values[$i]['id']   = $active_message->message_type();
159
+				$mt_values[$i]['text'] = ucwords($active_message->message_type_label());
160
+				$i++;
161
+			}
162
+		}
163
+        
164
+		return $mt_values;
165
+	}
166
+    
167
+    
168
+	/**
169
+	 * @deprecated 4.9.9.rc.014
170
+	 * @return array
171
+	 */
172
+	public function get_contexts_for_message_types_for_list_table()
173
+	{
174
+		EE_Error::doing_it_wrong(
175
+			__METHOD__,
176
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
177 177
 			values for use in creating a message type context filter dropdown which is now generated differently via
178 178
 			 Messages_Admin_Page::get_contexts_for_message_types_select_input', 'event_espresso'),
179
-            '4.9.9.rc.014'
180
-        );
181
-        
182
-        $contexts                = array();
183
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
184
-        foreach ($active_message_contexts as $active_message) {
185
-            if ($active_message instanceof EE_Message) {
186
-                $message_type = $active_message->message_type_object();
187
-                if ($message_type instanceof EE_message_type) {
188
-                    $message_type_contexts = $message_type->get_contexts();
189
-                    foreach ($message_type_contexts as $context => $context_details) {
190
-                        $contexts[$context] = $context_details['label'];
191
-                    }
192
-                }
193
-            }
194
-        }
195
-        
196
-        return $contexts;
197
-    }
198
-    
199
-    
200
-    /**
201
-     * Generate select input with provided messenger options array.
202
-     *
203
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
204
-     *                                 labels.
205
-     *
206
-     * @return string
207
-     */
208
-    public function get_messengers_select_input($messenger_options)
209
-    {
210
-        //if empty or just one value then just return an empty string
211
-        if (empty($messenger_options)
212
-            || ! is_array($messenger_options)
213
-            || count($messenger_options) === 1
214
-        ) {
215
-            return '';
216
-        }
217
-        //merge in default
218
-        $messenger_options = array_merge(
219
-            array('none_selected' => __('Show All Messengers', 'event_espresso')),
220
-            $messenger_options
221
-        );
222
-        $input             = new EE_Select_Input(
223
-            $messenger_options,
224
-            array(
225
-                'html_name'  => 'ee_messenger_filter_by',
226
-                'html_id'    => 'ee_messenger_filter_by',
227
-                'html_class' => 'wide',
228
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
229
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
230
-                    : 'none_selected'
231
-            )
232
-        );
233
-        
234
-        return $input->get_html_for_input();
235
-    }
236
-    
237
-    
238
-    /**
239
-     * Generate select input with provided message type options array.
240
-     *
241
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
242
-     *                                    message type labels
243
-     *
244
-     * @return string
245
-     */
246
-    public function get_message_types_select_input($message_type_options)
247
-    {
248
-        //if empty or count of options is 1 then just return an empty string
249
-        if (empty($message_type_options)
250
-            || ! is_array($message_type_options)
251
-            || count($message_type_options) === 1
252
-        ) {
253
-            return '';
254
-        }
255
-        //merge in default
256
-        $message_type_options = array_merge(
257
-            array('none_selected' => __('Show All Message Types', 'event_espresso')),
258
-            $message_type_options
259
-        );
260
-        $input                = new EE_Select_Input(
261
-            $message_type_options,
262
-            array(
263
-                'html_name'  => 'ee_message_type_filter_by',
264
-                'html_id'    => 'ee_message_type_filter_by',
265
-                'html_class' => 'wide',
266
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
267
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
268
-                    : 'none_selected',
269
-            )
270
-        );
271
-        
272
-        return $input->get_html_for_input();
273
-    }
274
-    
275
-    
276
-    /**
277
-     * Generate select input with provide message type contexts array.
278
-     *
279
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
280
-     *                               context label.
281
-     *
282
-     * @return string
283
-     */
284
-    public function get_contexts_for_message_types_select_input($context_options)
285
-    {
286
-        //if empty or count of options is one then just return empty string
287
-        if (empty($context_options)
288
-            || ! is_array($context_options)
289
-            || count($context_options) === 1
290
-        ) {
291
-            return '';
292
-        }
293
-        //merge in default
294
-        $context_options = array_merge(
295
-            array('none_selected' => __('Show all Contexts', 'event_espresso')),
296
-            $context_options
297
-        );
298
-        $input           = new EE_Select_Input(
299
-            $context_options,
300
-            array(
301
-                'html_name'  => 'ee_context_filter_by',
302
-                'html_id'    => 'ee_context_filter_by',
303
-                'html_class' => 'wide',
304
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
305
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
306
-                    : 'none_selected',
307
-            )
308
-        );
309
-        
310
-        return $input->get_html_for_input();
311
-    }
312
-    
313
-    
314
-    protected function _ajax_hooks()
315
-    {
316
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
317
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
318
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
319
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
320
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
321
-    }
322
-    
323
-    
324
-    protected function _define_page_props()
325
-    {
326
-        $this->_admin_page_title = $this->page_label;
327
-        $this->_labels           = array(
328
-            'buttons'    => array(
329
-                'add'    => __('Add New Message Template', 'event_espresso'),
330
-                'edit'   => __('Edit Message Template', 'event_espresso'),
331
-                'delete' => __('Delete Message Template', 'event_espresso')
332
-            ),
333
-            'publishbox' => __('Update Actions', 'event_espresso')
334
-        );
335
-    }
336
-    
337
-    
338
-    /**
339
-     *        an array for storing key => value pairs of request actions and their corresponding methods
340
-     * @access protected
341
-     * @return void
342
-     */
343
-    protected function _set_page_routes()
344
-    {
345
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
346
-            ? $this->_req_data['GRP_ID']
347
-            : 0;
348
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
349
-            ? $this->_req_data['id']
350
-            : $grp_id;
351
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
352
-            ? $this->_req_data['MSG_ID']
353
-            : 0;
354
-        
355
-        $this->_page_routes = array(
356
-            'default'                          => array(
357
-                'func'       => '_message_queue_list_table',
358
-                'capability' => 'ee_read_global_messages'
359
-            ),
360
-            'global_mtps'                      => array(
361
-                'func'       => '_ee_default_messages_overview_list_table',
362
-                'capability' => 'ee_read_global_messages'
363
-            ),
364
-            'custom_mtps'                      => array(
365
-                'func'       => '_custom_mtps_preview',
366
-                'capability' => 'ee_read_messages'
367
-            ),
368
-            'add_new_message_template'         => array(
369
-                'func'       => '_add_message_template',
370
-                'capability' => 'ee_edit_messages',
371
-                'noheader'   => true
372
-            ),
373
-            'edit_message_template'            => array(
374
-                'func'       => '_edit_message_template',
375
-                'capability' => 'ee_edit_message',
376
-                'obj_id'     => $grp_id
377
-            ),
378
-            'preview_message'                  => array(
379
-                'func'               => '_preview_message',
380
-                'capability'         => 'ee_read_message',
381
-                'obj_id'             => $grp_id,
382
-                'noheader'           => true,
383
-                'headers_sent_route' => 'display_preview_message'
384
-            ),
385
-            'display_preview_message'          => array(
386
-                'func'       => '_display_preview_message',
387
-                'capability' => 'ee_read_message',
388
-                'obj_id'     => $grp_id
389
-            ),
390
-            'insert_message_template'          => array(
391
-                'func'       => '_insert_or_update_message_template',
392
-                'capability' => 'ee_edit_messages',
393
-                'args'       => array('new_template' => true),
394
-                'noheader'   => true
395
-            ),
396
-            'update_message_template'          => array(
397
-                'func'       => '_insert_or_update_message_template',
398
-                'capability' => 'ee_edit_message',
399
-                'obj_id'     => $grp_id,
400
-                'args'       => array('new_template' => false),
401
-                'noheader'   => true
402
-            ),
403
-            'trash_message_template'           => array(
404
-                'func'       => '_trash_or_restore_message_template',
405
-                'capability' => 'ee_delete_message',
406
-                'obj_id'     => $grp_id,
407
-                'args'       => array('trash' => true, 'all' => true),
408
-                'noheader'   => true
409
-            ),
410
-            'trash_message_template_context'   => array(
411
-                'func'       => '_trash_or_restore_message_template',
412
-                'capability' => 'ee_delete_message',
413
-                'obj_id'     => $grp_id,
414
-                'args'       => array('trash' => true),
415
-                'noheader'   => true
416
-            ),
417
-            'restore_message_template'         => array(
418
-                'func'       => '_trash_or_restore_message_template',
419
-                'capability' => 'ee_delete_message',
420
-                'obj_id'     => $grp_id,
421
-                'args'       => array('trash' => false, 'all' => true),
422
-                'noheader'   => true
423
-            ),
424
-            'restore_message_template_context' => array(
425
-                'func'       => '_trash_or_restore_message_template',
426
-                'capability' => 'ee_delete_message',
427
-                'obj_id'     => $grp_id,
428
-                'args'       => array('trash' => false),
429
-                'noheader'   => true
430
-            ),
431
-            'delete_message_template'          => array(
432
-                'func'       => '_delete_message_template',
433
-                'capability' => 'ee_delete_message',
434
-                'obj_id'     => $grp_id,
435
-                'noheader'   => true
436
-            ),
437
-            'reset_to_default'                 => array(
438
-                'func'       => '_reset_to_default_template',
439
-                'capability' => 'ee_edit_message',
440
-                'obj_id'     => $grp_id,
441
-                'noheader'   => true
442
-            ),
443
-            'settings'                         => array(
444
-                'func'       => '_settings',
445
-                'capability' => 'manage_options'
446
-            ),
447
-            'update_global_settings'           => array(
448
-                'func'       => '_update_global_settings',
449
-                'capability' => 'manage_options',
450
-                'noheader'   => true
451
-            ),
452
-            'generate_now'                     => array(
453
-                'func'       => '_generate_now',
454
-                'capability' => 'ee_send_message',
455
-                'noheader'   => true
456
-            ),
457
-            'generate_and_send_now'            => array(
458
-                'func'       => '_generate_and_send_now',
459
-                'capability' => 'ee_send_message',
460
-                'noheader'   => true
461
-            ),
462
-            'queue_for_resending'              => array(
463
-                'func'       => '_queue_for_resending',
464
-                'capability' => 'ee_send_message',
465
-                'noheader'   => true
466
-            ),
467
-            'send_now'                         => array(
468
-                'func'       => '_send_now',
469
-                'capability' => 'ee_send_message',
470
-                'noheader'   => true
471
-            ),
472
-            'delete_ee_message'                => array(
473
-                'func'       => '_delete_ee_messages',
474
-                'capability' => 'ee_delete_message',
475
-                'noheader'   => true
476
-            ),
477
-            'delete_ee_messages'               => array(
478
-                'func'       => '_delete_ee_messages',
479
-                'capability' => 'ee_delete_messages',
480
-                'noheader'   => true,
481
-                'obj_id'     => $msg_id
482
-            )
483
-        );
484
-    }
485
-    
486
-    
487
-    protected function _set_page_config()
488
-    {
489
-        $this->_page_config = array(
490
-            'default'                  => array(
491
-                'nav'           => array(
492
-                    'label' => __('Message Activity', 'event_espresso'),
493
-                    'order' => 10
494
-                ),
495
-                'list_table'    => 'EE_Message_List_Table',
496
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
497
-                'require_nonce' => false
498
-            ),
499
-            'global_mtps'              => array(
500
-                'nav'           => array(
501
-                    'label' => __('Default Message Templates', 'event_espresso'),
502
-                    'order' => 20
503
-                ),
504
-                'list_table'    => 'Messages_Template_List_Table',
505
-                'help_tabs'     => array(
506
-                    'messages_overview_help_tab'                                => array(
507
-                        'title'    => __('Messages Overview', 'event_espresso'),
508
-                        'filename' => 'messages_overview'
509
-                    ),
510
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
511
-                        'title'    => __('Messages Table Column Headings', 'event_espresso'),
512
-                        'filename' => 'messages_overview_table_column_headings'
513
-                    ),
514
-                    'messages_overview_messages_filters_help_tab'               => array(
515
-                        'title'    => __('Message Filters', 'event_espresso'),
516
-                        'filename' => 'messages_overview_filters'
517
-                    ),
518
-                    'messages_overview_messages_views_help_tab'                 => array(
519
-                        'title'    => __('Message Views', 'event_espresso'),
520
-                        'filename' => 'messages_overview_views'
521
-                    ),
522
-                    'message_overview_message_types_help_tab'                   => array(
523
-                        'title'    => __('Message Types', 'event_espresso'),
524
-                        'filename' => 'messages_overview_types'
525
-                    ),
526
-                    'messages_overview_messengers_help_tab'                     => array(
527
-                        'title'    => __('Messengers', 'event_espresso'),
528
-                        'filename' => 'messages_overview_messengers',
529
-                    ),
530
-                ),
531
-                'help_tour'     => array('Messages_Overview_Help_Tour'),
532
-                'require_nonce' => false
533
-            ),
534
-            'custom_mtps'              => array(
535
-                'nav'           => array(
536
-                    'label' => __('Custom Message Templates', 'event_espresso'),
537
-                    'order' => 30
538
-                ),
539
-                'help_tabs'     => array(),
540
-                'help_tour'     => array(),
541
-                'require_nonce' => false
542
-            ),
543
-            'add_new_message_template' => array(
544
-                'nav'           => array(
545
-                    'label'      => __('Add New Message Templates', 'event_espresso'),
546
-                    'order'      => 5,
547
-                    'persistent' => false
548
-                ),
549
-                'require_nonce' => false
550
-            ),
551
-            'edit_message_template'    => array(
552
-                'labels'        => array(
553
-                    'buttons'    => array(
554
-                        'reset' => __('Reset Templates'),
555
-                    ),
556
-                    'publishbox' => __('Update Actions', 'event_espresso')
557
-                ),
558
-                'nav'           => array(
559
-                    'label'      => __('Edit Message Templates', 'event_espresso'),
560
-                    'order'      => 5,
561
-                    'persistent' => false,
562
-                    'url'        => ''
563
-                ),
564
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
565
-                'has_metaboxes' => true,
566
-                'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
567
-                'help_tabs'     => array(
568
-                    'edit_message_template'       => array(
569
-                        'title'    => __('Message Template Editor', 'event_espresso'),
570
-                        'callback' => 'edit_message_template_help_tab'
571
-                    ),
572
-                    'message_templates_help_tab'  => array(
573
-                        'title'    => __('Message Templates', 'event_espresso'),
574
-                        'filename' => 'messages_templates'
575
-                    ),
576
-                    'message_template_shortcodes' => array(
577
-                        'title'    => __('Message Shortcodes', 'event_espresso'),
578
-                        'callback' => 'message_template_shortcodes_help_tab'
579
-                    ),
580
-                    'message_preview_help_tab'    => array(
581
-                        'title'    => __('Message Preview', 'event_espresso'),
582
-                        'filename' => 'messages_preview'
583
-                    ),
584
-                    'messages_overview_other_help_tab'                          => array(
585
-                        'title'    => __('Messages Other', 'event_espresso'),
586
-                        'filename' => 'messages_overview_other',
587
-                    ),
588
-                ),
589
-                'require_nonce' => false
590
-            ),
591
-            'display_preview_message'  => array(
592
-                'nav'           => array(
593
-                    'label'      => __('Message Preview', 'event_espresso'),
594
-                    'order'      => 5,
595
-                    'url'        => '',
596
-                    'persistent' => false
597
-                ),
598
-                'help_tabs'     => array(
599
-                    'preview_message' => array(
600
-                        'title'    => __('About Previews', 'event_espresso'),
601
-                        'callback' => 'preview_message_help_tab'
602
-                    )
603
-                ),
604
-                'require_nonce' => false
605
-            ),
606
-            'settings'                 => array(
607
-                'nav'           => array(
608
-                    'label' => __('Settings', 'event_espresso'),
609
-                    'order' => 40
610
-                ),
611
-                'metaboxes'     => array('_messages_settings_metaboxes'),
612
-                'help_tabs'     => array(
613
-                    'messages_settings_help_tab'               => array(
614
-                        'title'    => __('Messages Settings', 'event_espresso'),
615
-                        'filename' => 'messages_settings'
616
-                    ),
617
-                    'messages_settings_message_types_help_tab' => array(
618
-                        'title'    => __('Activating / Deactivating Message Types', 'event_espresso'),
619
-                        'filename' => 'messages_settings_message_types'
620
-                    ),
621
-                    'messages_settings_messengers_help_tab'    => array(
622
-                        'title'    => __('Activating / Deactivating Messengers', 'event_espresso'),
623
-                        'filename' => 'messages_settings_messengers'
624
-                    ),
625
-                ),
626
-                'help_tour'     => array('Messages_Settings_Help_Tour'),
627
-                'require_nonce' => false
628
-            )
629
-        );
630
-    }
631
-    
632
-    
633
-    protected function _add_screen_options()
634
-    {
635
-        //todo
636
-    }
637
-    
638
-    
639
-    protected function _add_screen_options_global_mtps()
640
-    {
641
-        /**
642
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
643
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
644
-         */
645
-        $page_title              = $this->_admin_page_title;
646
-        $this->_admin_page_title = __('Global Message Templates', 'event_espresso');
647
-        $this->_per_page_screen_option();
648
-        $this->_admin_page_title = $page_title;
649
-    }
650
-    
651
-    
652
-    protected function _add_screen_options_default()
653
-    {
654
-        $this->_admin_page_title = __('Message Activity', 'event_espresso');
655
-        $this->_per_page_screen_option();
656
-    }
657
-    
658
-    
659
-    //none of the below group are currently used for Messages
660
-    protected function _add_feature_pointers()
661
-    {
662
-    }
663
-    
664
-    public function admin_init()
665
-    {
666
-    }
667
-    
668
-    public function admin_notices()
669
-    {
670
-    }
671
-    
672
-    public function admin_footer_scripts()
673
-    {
674
-    }
675
-    
676
-    
677
-    public function messages_help_tab()
678
-    {
679
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
680
-    }
681
-    
682
-    
683
-    public function messengers_help_tab()
684
-    {
685
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
686
-    }
687
-    
688
-    
689
-    public function message_types_help_tab()
690
-    {
691
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
692
-    }
693
-    
694
-    
695
-    public function messages_overview_help_tab()
696
-    {
697
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
698
-    }
699
-    
700
-    
701
-    public function message_templates_help_tab()
702
-    {
703
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
704
-    }
705
-    
706
-    
707
-    public function edit_message_template_help_tab()
708
-    {
709
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title',
710
-                'event_espresso') . '" />';
711
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview',
712
-                'event_espresso') . '" />';
713
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields',
714
-                'event_espresso') . '" />';
715
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox',
716
-                'event_espresso') . '" />';
717
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox',
718
-                'event_espresso') . '" />';
719
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
720
-            $args);
721
-    }
722
-    
723
-    
724
-    public function message_template_shortcodes_help_tab()
725
-    {
726
-        $this->_set_shortcodes();
727
-        $args['shortcodes'] = $this->_shortcodes;
728
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
729
-            $args);
730
-    }
179
+			'4.9.9.rc.014'
180
+		);
181
+        
182
+		$contexts                = array();
183
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
184
+		foreach ($active_message_contexts as $active_message) {
185
+			if ($active_message instanceof EE_Message) {
186
+				$message_type = $active_message->message_type_object();
187
+				if ($message_type instanceof EE_message_type) {
188
+					$message_type_contexts = $message_type->get_contexts();
189
+					foreach ($message_type_contexts as $context => $context_details) {
190
+						$contexts[$context] = $context_details['label'];
191
+					}
192
+				}
193
+			}
194
+		}
195
+        
196
+		return $contexts;
197
+	}
198
+    
199
+    
200
+	/**
201
+	 * Generate select input with provided messenger options array.
202
+	 *
203
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
204
+	 *                                 labels.
205
+	 *
206
+	 * @return string
207
+	 */
208
+	public function get_messengers_select_input($messenger_options)
209
+	{
210
+		//if empty or just one value then just return an empty string
211
+		if (empty($messenger_options)
212
+			|| ! is_array($messenger_options)
213
+			|| count($messenger_options) === 1
214
+		) {
215
+			return '';
216
+		}
217
+		//merge in default
218
+		$messenger_options = array_merge(
219
+			array('none_selected' => __('Show All Messengers', 'event_espresso')),
220
+			$messenger_options
221
+		);
222
+		$input             = new EE_Select_Input(
223
+			$messenger_options,
224
+			array(
225
+				'html_name'  => 'ee_messenger_filter_by',
226
+				'html_id'    => 'ee_messenger_filter_by',
227
+				'html_class' => 'wide',
228
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
229
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
230
+					: 'none_selected'
231
+			)
232
+		);
233
+        
234
+		return $input->get_html_for_input();
235
+	}
236
+    
237
+    
238
+	/**
239
+	 * Generate select input with provided message type options array.
240
+	 *
241
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
242
+	 *                                    message type labels
243
+	 *
244
+	 * @return string
245
+	 */
246
+	public function get_message_types_select_input($message_type_options)
247
+	{
248
+		//if empty or count of options is 1 then just return an empty string
249
+		if (empty($message_type_options)
250
+			|| ! is_array($message_type_options)
251
+			|| count($message_type_options) === 1
252
+		) {
253
+			return '';
254
+		}
255
+		//merge in default
256
+		$message_type_options = array_merge(
257
+			array('none_selected' => __('Show All Message Types', 'event_espresso')),
258
+			$message_type_options
259
+		);
260
+		$input                = new EE_Select_Input(
261
+			$message_type_options,
262
+			array(
263
+				'html_name'  => 'ee_message_type_filter_by',
264
+				'html_id'    => 'ee_message_type_filter_by',
265
+				'html_class' => 'wide',
266
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
267
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
268
+					: 'none_selected',
269
+			)
270
+		);
271
+        
272
+		return $input->get_html_for_input();
273
+	}
274
+    
275
+    
276
+	/**
277
+	 * Generate select input with provide message type contexts array.
278
+	 *
279
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
280
+	 *                               context label.
281
+	 *
282
+	 * @return string
283
+	 */
284
+	public function get_contexts_for_message_types_select_input($context_options)
285
+	{
286
+		//if empty or count of options is one then just return empty string
287
+		if (empty($context_options)
288
+			|| ! is_array($context_options)
289
+			|| count($context_options) === 1
290
+		) {
291
+			return '';
292
+		}
293
+		//merge in default
294
+		$context_options = array_merge(
295
+			array('none_selected' => __('Show all Contexts', 'event_espresso')),
296
+			$context_options
297
+		);
298
+		$input           = new EE_Select_Input(
299
+			$context_options,
300
+			array(
301
+				'html_name'  => 'ee_context_filter_by',
302
+				'html_id'    => 'ee_context_filter_by',
303
+				'html_class' => 'wide',
304
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
305
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
306
+					: 'none_selected',
307
+			)
308
+		);
309
+        
310
+		return $input->get_html_for_input();
311
+	}
312
+    
313
+    
314
+	protected function _ajax_hooks()
315
+	{
316
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
317
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
318
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
319
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
320
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
321
+	}
322
+    
323
+    
324
+	protected function _define_page_props()
325
+	{
326
+		$this->_admin_page_title = $this->page_label;
327
+		$this->_labels           = array(
328
+			'buttons'    => array(
329
+				'add'    => __('Add New Message Template', 'event_espresso'),
330
+				'edit'   => __('Edit Message Template', 'event_espresso'),
331
+				'delete' => __('Delete Message Template', 'event_espresso')
332
+			),
333
+			'publishbox' => __('Update Actions', 'event_espresso')
334
+		);
335
+	}
336
+    
337
+    
338
+	/**
339
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
340
+	 * @access protected
341
+	 * @return void
342
+	 */
343
+	protected function _set_page_routes()
344
+	{
345
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
346
+			? $this->_req_data['GRP_ID']
347
+			: 0;
348
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
349
+			? $this->_req_data['id']
350
+			: $grp_id;
351
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
352
+			? $this->_req_data['MSG_ID']
353
+			: 0;
354
+        
355
+		$this->_page_routes = array(
356
+			'default'                          => array(
357
+				'func'       => '_message_queue_list_table',
358
+				'capability' => 'ee_read_global_messages'
359
+			),
360
+			'global_mtps'                      => array(
361
+				'func'       => '_ee_default_messages_overview_list_table',
362
+				'capability' => 'ee_read_global_messages'
363
+			),
364
+			'custom_mtps'                      => array(
365
+				'func'       => '_custom_mtps_preview',
366
+				'capability' => 'ee_read_messages'
367
+			),
368
+			'add_new_message_template'         => array(
369
+				'func'       => '_add_message_template',
370
+				'capability' => 'ee_edit_messages',
371
+				'noheader'   => true
372
+			),
373
+			'edit_message_template'            => array(
374
+				'func'       => '_edit_message_template',
375
+				'capability' => 'ee_edit_message',
376
+				'obj_id'     => $grp_id
377
+			),
378
+			'preview_message'                  => array(
379
+				'func'               => '_preview_message',
380
+				'capability'         => 'ee_read_message',
381
+				'obj_id'             => $grp_id,
382
+				'noheader'           => true,
383
+				'headers_sent_route' => 'display_preview_message'
384
+			),
385
+			'display_preview_message'          => array(
386
+				'func'       => '_display_preview_message',
387
+				'capability' => 'ee_read_message',
388
+				'obj_id'     => $grp_id
389
+			),
390
+			'insert_message_template'          => array(
391
+				'func'       => '_insert_or_update_message_template',
392
+				'capability' => 'ee_edit_messages',
393
+				'args'       => array('new_template' => true),
394
+				'noheader'   => true
395
+			),
396
+			'update_message_template'          => array(
397
+				'func'       => '_insert_or_update_message_template',
398
+				'capability' => 'ee_edit_message',
399
+				'obj_id'     => $grp_id,
400
+				'args'       => array('new_template' => false),
401
+				'noheader'   => true
402
+			),
403
+			'trash_message_template'           => array(
404
+				'func'       => '_trash_or_restore_message_template',
405
+				'capability' => 'ee_delete_message',
406
+				'obj_id'     => $grp_id,
407
+				'args'       => array('trash' => true, 'all' => true),
408
+				'noheader'   => true
409
+			),
410
+			'trash_message_template_context'   => array(
411
+				'func'       => '_trash_or_restore_message_template',
412
+				'capability' => 'ee_delete_message',
413
+				'obj_id'     => $grp_id,
414
+				'args'       => array('trash' => true),
415
+				'noheader'   => true
416
+			),
417
+			'restore_message_template'         => array(
418
+				'func'       => '_trash_or_restore_message_template',
419
+				'capability' => 'ee_delete_message',
420
+				'obj_id'     => $grp_id,
421
+				'args'       => array('trash' => false, 'all' => true),
422
+				'noheader'   => true
423
+			),
424
+			'restore_message_template_context' => array(
425
+				'func'       => '_trash_or_restore_message_template',
426
+				'capability' => 'ee_delete_message',
427
+				'obj_id'     => $grp_id,
428
+				'args'       => array('trash' => false),
429
+				'noheader'   => true
430
+			),
431
+			'delete_message_template'          => array(
432
+				'func'       => '_delete_message_template',
433
+				'capability' => 'ee_delete_message',
434
+				'obj_id'     => $grp_id,
435
+				'noheader'   => true
436
+			),
437
+			'reset_to_default'                 => array(
438
+				'func'       => '_reset_to_default_template',
439
+				'capability' => 'ee_edit_message',
440
+				'obj_id'     => $grp_id,
441
+				'noheader'   => true
442
+			),
443
+			'settings'                         => array(
444
+				'func'       => '_settings',
445
+				'capability' => 'manage_options'
446
+			),
447
+			'update_global_settings'           => array(
448
+				'func'       => '_update_global_settings',
449
+				'capability' => 'manage_options',
450
+				'noheader'   => true
451
+			),
452
+			'generate_now'                     => array(
453
+				'func'       => '_generate_now',
454
+				'capability' => 'ee_send_message',
455
+				'noheader'   => true
456
+			),
457
+			'generate_and_send_now'            => array(
458
+				'func'       => '_generate_and_send_now',
459
+				'capability' => 'ee_send_message',
460
+				'noheader'   => true
461
+			),
462
+			'queue_for_resending'              => array(
463
+				'func'       => '_queue_for_resending',
464
+				'capability' => 'ee_send_message',
465
+				'noheader'   => true
466
+			),
467
+			'send_now'                         => array(
468
+				'func'       => '_send_now',
469
+				'capability' => 'ee_send_message',
470
+				'noheader'   => true
471
+			),
472
+			'delete_ee_message'                => array(
473
+				'func'       => '_delete_ee_messages',
474
+				'capability' => 'ee_delete_message',
475
+				'noheader'   => true
476
+			),
477
+			'delete_ee_messages'               => array(
478
+				'func'       => '_delete_ee_messages',
479
+				'capability' => 'ee_delete_messages',
480
+				'noheader'   => true,
481
+				'obj_id'     => $msg_id
482
+			)
483
+		);
484
+	}
485
+    
486
+    
487
+	protected function _set_page_config()
488
+	{
489
+		$this->_page_config = array(
490
+			'default'                  => array(
491
+				'nav'           => array(
492
+					'label' => __('Message Activity', 'event_espresso'),
493
+					'order' => 10
494
+				),
495
+				'list_table'    => 'EE_Message_List_Table',
496
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
497
+				'require_nonce' => false
498
+			),
499
+			'global_mtps'              => array(
500
+				'nav'           => array(
501
+					'label' => __('Default Message Templates', 'event_espresso'),
502
+					'order' => 20
503
+				),
504
+				'list_table'    => 'Messages_Template_List_Table',
505
+				'help_tabs'     => array(
506
+					'messages_overview_help_tab'                                => array(
507
+						'title'    => __('Messages Overview', 'event_espresso'),
508
+						'filename' => 'messages_overview'
509
+					),
510
+					'messages_overview_messages_table_column_headings_help_tab' => array(
511
+						'title'    => __('Messages Table Column Headings', 'event_espresso'),
512
+						'filename' => 'messages_overview_table_column_headings'
513
+					),
514
+					'messages_overview_messages_filters_help_tab'               => array(
515
+						'title'    => __('Message Filters', 'event_espresso'),
516
+						'filename' => 'messages_overview_filters'
517
+					),
518
+					'messages_overview_messages_views_help_tab'                 => array(
519
+						'title'    => __('Message Views', 'event_espresso'),
520
+						'filename' => 'messages_overview_views'
521
+					),
522
+					'message_overview_message_types_help_tab'                   => array(
523
+						'title'    => __('Message Types', 'event_espresso'),
524
+						'filename' => 'messages_overview_types'
525
+					),
526
+					'messages_overview_messengers_help_tab'                     => array(
527
+						'title'    => __('Messengers', 'event_espresso'),
528
+						'filename' => 'messages_overview_messengers',
529
+					),
530
+				),
531
+				'help_tour'     => array('Messages_Overview_Help_Tour'),
532
+				'require_nonce' => false
533
+			),
534
+			'custom_mtps'              => array(
535
+				'nav'           => array(
536
+					'label' => __('Custom Message Templates', 'event_espresso'),
537
+					'order' => 30
538
+				),
539
+				'help_tabs'     => array(),
540
+				'help_tour'     => array(),
541
+				'require_nonce' => false
542
+			),
543
+			'add_new_message_template' => array(
544
+				'nav'           => array(
545
+					'label'      => __('Add New Message Templates', 'event_espresso'),
546
+					'order'      => 5,
547
+					'persistent' => false
548
+				),
549
+				'require_nonce' => false
550
+			),
551
+			'edit_message_template'    => array(
552
+				'labels'        => array(
553
+					'buttons'    => array(
554
+						'reset' => __('Reset Templates'),
555
+					),
556
+					'publishbox' => __('Update Actions', 'event_espresso')
557
+				),
558
+				'nav'           => array(
559
+					'label'      => __('Edit Message Templates', 'event_espresso'),
560
+					'order'      => 5,
561
+					'persistent' => false,
562
+					'url'        => ''
563
+				),
564
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
565
+				'has_metaboxes' => true,
566
+				'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
567
+				'help_tabs'     => array(
568
+					'edit_message_template'       => array(
569
+						'title'    => __('Message Template Editor', 'event_espresso'),
570
+						'callback' => 'edit_message_template_help_tab'
571
+					),
572
+					'message_templates_help_tab'  => array(
573
+						'title'    => __('Message Templates', 'event_espresso'),
574
+						'filename' => 'messages_templates'
575
+					),
576
+					'message_template_shortcodes' => array(
577
+						'title'    => __('Message Shortcodes', 'event_espresso'),
578
+						'callback' => 'message_template_shortcodes_help_tab'
579
+					),
580
+					'message_preview_help_tab'    => array(
581
+						'title'    => __('Message Preview', 'event_espresso'),
582
+						'filename' => 'messages_preview'
583
+					),
584
+					'messages_overview_other_help_tab'                          => array(
585
+						'title'    => __('Messages Other', 'event_espresso'),
586
+						'filename' => 'messages_overview_other',
587
+					),
588
+				),
589
+				'require_nonce' => false
590
+			),
591
+			'display_preview_message'  => array(
592
+				'nav'           => array(
593
+					'label'      => __('Message Preview', 'event_espresso'),
594
+					'order'      => 5,
595
+					'url'        => '',
596
+					'persistent' => false
597
+				),
598
+				'help_tabs'     => array(
599
+					'preview_message' => array(
600
+						'title'    => __('About Previews', 'event_espresso'),
601
+						'callback' => 'preview_message_help_tab'
602
+					)
603
+				),
604
+				'require_nonce' => false
605
+			),
606
+			'settings'                 => array(
607
+				'nav'           => array(
608
+					'label' => __('Settings', 'event_espresso'),
609
+					'order' => 40
610
+				),
611
+				'metaboxes'     => array('_messages_settings_metaboxes'),
612
+				'help_tabs'     => array(
613
+					'messages_settings_help_tab'               => array(
614
+						'title'    => __('Messages Settings', 'event_espresso'),
615
+						'filename' => 'messages_settings'
616
+					),
617
+					'messages_settings_message_types_help_tab' => array(
618
+						'title'    => __('Activating / Deactivating Message Types', 'event_espresso'),
619
+						'filename' => 'messages_settings_message_types'
620
+					),
621
+					'messages_settings_messengers_help_tab'    => array(
622
+						'title'    => __('Activating / Deactivating Messengers', 'event_espresso'),
623
+						'filename' => 'messages_settings_messengers'
624
+					),
625
+				),
626
+				'help_tour'     => array('Messages_Settings_Help_Tour'),
627
+				'require_nonce' => false
628
+			)
629
+		);
630
+	}
631
+    
632
+    
633
+	protected function _add_screen_options()
634
+	{
635
+		//todo
636
+	}
637
+    
638
+    
639
+	protected function _add_screen_options_global_mtps()
640
+	{
641
+		/**
642
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
643
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
644
+		 */
645
+		$page_title              = $this->_admin_page_title;
646
+		$this->_admin_page_title = __('Global Message Templates', 'event_espresso');
647
+		$this->_per_page_screen_option();
648
+		$this->_admin_page_title = $page_title;
649
+	}
650
+    
651
+    
652
+	protected function _add_screen_options_default()
653
+	{
654
+		$this->_admin_page_title = __('Message Activity', 'event_espresso');
655
+		$this->_per_page_screen_option();
656
+	}
657
+    
658
+    
659
+	//none of the below group are currently used for Messages
660
+	protected function _add_feature_pointers()
661
+	{
662
+	}
663
+    
664
+	public function admin_init()
665
+	{
666
+	}
667
+    
668
+	public function admin_notices()
669
+	{
670
+	}
671
+    
672
+	public function admin_footer_scripts()
673
+	{
674
+	}
675
+    
676
+    
677
+	public function messages_help_tab()
678
+	{
679
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
680
+	}
681
+    
682
+    
683
+	public function messengers_help_tab()
684
+	{
685
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
686
+	}
687
+    
688
+    
689
+	public function message_types_help_tab()
690
+	{
691
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
692
+	}
693
+    
694
+    
695
+	public function messages_overview_help_tab()
696
+	{
697
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
698
+	}
699
+    
700
+    
701
+	public function message_templates_help_tab()
702
+	{
703
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
704
+	}
705
+    
706
+    
707
+	public function edit_message_template_help_tab()
708
+	{
709
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title',
710
+				'event_espresso') . '" />';
711
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview',
712
+				'event_espresso') . '" />';
713
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields',
714
+				'event_espresso') . '" />';
715
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox',
716
+				'event_espresso') . '" />';
717
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox',
718
+				'event_espresso') . '" />';
719
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
720
+			$args);
721
+	}
722
+    
723
+    
724
+	public function message_template_shortcodes_help_tab()
725
+	{
726
+		$this->_set_shortcodes();
727
+		$args['shortcodes'] = $this->_shortcodes;
728
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
729
+			$args);
730
+	}
731 731
     
732 732
     
733
-    public function preview_message_help_tab()
734
-    {
735
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
736
-    }
733
+	public function preview_message_help_tab()
734
+	{
735
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
736
+	}
737 737
     
738
-    
739
-    public function settings_help_tab()
740
-    {
741
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab',
742
-                'event_espresso') . '" />';
743
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab',
744
-                'event_espresso') . '" />';
745
-        $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';
746
-        $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';
747
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
748
-    }
738
+    
739
+	public function settings_help_tab()
740
+	{
741
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab',
742
+				'event_espresso') . '" />';
743
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab',
744
+				'event_espresso') . '" />';
745
+		$args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';
746
+		$args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';
747
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
748
+	}
749 749
     
750 750
     
751
-    public function load_scripts_styles()
752
-    {
753
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
754
-        wp_enqueue_style('espresso_ee_msg');
751
+	public function load_scripts_styles()
752
+	{
753
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
754
+		wp_enqueue_style('espresso_ee_msg');
755 755
         
756
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
757
-            array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
758
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
759
-            array('ee-dialog'), EVENT_ESPRESSO_VERSION);
760
-    }
756
+		wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
757
+			array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
758
+		wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
759
+			array('ee-dialog'), EVENT_ESPRESSO_VERSION);
760
+	}
761 761
     
762 762
     
763
-    public function load_scripts_styles_default()
764
-    {
765
-        wp_enqueue_script('ee-msg-list-table-js');
766
-    }
763
+	public function load_scripts_styles_default()
764
+	{
765
+		wp_enqueue_script('ee-msg-list-table-js');
766
+	}
767 767
     
768 768
     
769
-    public function wp_editor_css($mce_css)
770
-    {
771
-        //if we're on the edit_message_template route
772
-        if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
773
-            $message_type_name = $this->_active_message_type_name;
769
+	public function wp_editor_css($mce_css)
770
+	{
771
+		//if we're on the edit_message_template route
772
+		if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
773
+			$message_type_name = $this->_active_message_type_name;
774 774
             
775
-            //we're going to REPLACE the existing mce css
776
-            //we need to get the css file location from the active messenger
777
-            $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
778
-                'wpeditor', $this->_variation);
779
-        }
775
+			//we're going to REPLACE the existing mce css
776
+			//we need to get the css file location from the active messenger
777
+			$mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
778
+				'wpeditor', $this->_variation);
779
+		}
780 780
         
781
-        return $mce_css;
782
-    }
781
+		return $mce_css;
782
+	}
783 783
     
784 784
     
785
-    public function load_scripts_styles_edit_message_template()
786
-    {
785
+	public function load_scripts_styles_edit_message_template()
786
+	{
787 787
         
788
-        $this->_set_shortcodes();
788
+		$this->_set_shortcodes();
789 789
         
790
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
791
-            __('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.',
792
-                'event_espresso'),
793
-            $this->_message_template_group->messenger_obj()->label['singular'],
794
-            $this->_message_template_group->message_type_obj()->label['singular']
795
-        );
796
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('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?',
797
-            'event_espresso');
790
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
791
+			__('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.',
792
+				'event_espresso'),
793
+			$this->_message_template_group->messenger_obj()->label['singular'],
794
+			$this->_message_template_group->message_type_obj()->label['singular']
795
+		);
796
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('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?',
797
+			'event_espresso');
798 798
         
799
-        wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
800
-            EVENT_ESPRESSO_VERSION);
799
+		wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
800
+			EVENT_ESPRESSO_VERSION);
801 801
         
802
-        wp_enqueue_script('ee_admin_js');
803
-        wp_enqueue_script('ee_msgs_edit_js');
802
+		wp_enqueue_script('ee_admin_js');
803
+		wp_enqueue_script('ee_msgs_edit_js');
804 804
         
805
-        //add in special css for tiny_mce
806
-        add_filter('mce_css', array($this, 'wp_editor_css'));
807
-    }
805
+		//add in special css for tiny_mce
806
+		add_filter('mce_css', array($this, 'wp_editor_css'));
807
+	}
808 808
     
809 809
     
810
-    public function load_scripts_styles_display_preview_message()
811
-    {
810
+	public function load_scripts_styles_display_preview_message()
811
+	{
812 812
         
813
-        $this->_set_message_template_group();
813
+		$this->_set_message_template_group();
814 814
         
815
-        if (isset($this->_req_data['messenger'])) {
816
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
817
-        }
815
+		if (isset($this->_req_data['messenger'])) {
816
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
817
+		}
818 818
         
819
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
819
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
820 820
         
821 821
         
822
-        wp_enqueue_style('espresso_preview_css',
823
-            $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview',
824
-                $this->_variation));
825
-    }
822
+		wp_enqueue_style('espresso_preview_css',
823
+			$this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview',
824
+				$this->_variation));
825
+	}
826 826
     
827 827
     
828
-    public function load_scripts_styles_settings()
829
-    {
830
-        wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(),
831
-            EVENT_ESPRESSO_VERSION);
832
-        wp_enqueue_style('ee-text-links');
833
-        wp_enqueue_style('ee-message-settings');
828
+	public function load_scripts_styles_settings()
829
+	{
830
+		wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(),
831
+			EVENT_ESPRESSO_VERSION);
832
+		wp_enqueue_style('ee-text-links');
833
+		wp_enqueue_style('ee-message-settings');
834 834
         
835
-        wp_enqueue_script('ee-messages-settings');
836
-    }
835
+		wp_enqueue_script('ee-messages-settings');
836
+	}
837 837
     
838 838
     
839
-    /**
840
-     * set views array for List Table
841
-     */
842
-    public function _set_list_table_views_global_mtps()
843
-    {
844
-        $this->_views = array(
845
-            'in_use' => array(
846
-                'slug'        => 'in_use',
847
-                'label'       => __('In Use', 'event_espresso'),
848
-                'count'       => 0,
849
-            )
850
-        );
851
-    }
839
+	/**
840
+	 * set views array for List Table
841
+	 */
842
+	public function _set_list_table_views_global_mtps()
843
+	{
844
+		$this->_views = array(
845
+			'in_use' => array(
846
+				'slug'        => 'in_use',
847
+				'label'       => __('In Use', 'event_espresso'),
848
+				'count'       => 0,
849
+			)
850
+		);
851
+	}
852 852
 
853 853
 
854
-    /**
855
-     * Set views array for the Custom Template List Table
856
-     */
857
-    public function _set_list_table_views_custom_mtps()
858
-    {
859
-        $this->_set_list_table_views_global_mtps();
860
-        $this->_views['in_use']['bulk_action'] = array(
861
-                'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
862
-        );
863
-    }
864
-    
865
-    
866
-    /**
867
-     * set views array for message queue list table
868
-     */
869
-    public function _set_list_table_views_default()
870
-    {
871
-        EE_Registry::instance()->load_helper('Template');
872
-        
873
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message',
874
-            'message_list_table_bulk_actions')
875
-            ? array(
876
-                'generate_now'          => __('Generate Now', 'event_espresso'),
877
-                'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'),
878
-                'queue_for_resending'   => __('Queue for Resending', 'event_espresso'),
879
-                'send_now'              => __('Send Now', 'event_espresso')
880
-            )
881
-            : array();
882
-        
883
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages',
884
-            'message_list_table_bulk_actions')
885
-            ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso'))
886
-            : array();
887
-        
888
-        
889
-        $this->_views = array(
890
-            'all' => array(
891
-                'slug'        => 'all',
892
-                'label'       => __('All', 'event_espresso'),
893
-                'count'       => 0,
894
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
895
-            )
896
-        );
897
-        
898
-        
899
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
900
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
901
-                continue;
902
-            }
903
-            $status_bulk_actions = $common_bulk_actions;
904
-            //unset bulk actions not applying to status
905
-            if (! empty($status_bulk_actions)) {
906
-                switch ($status) {
907
-                    case EEM_Message::status_idle:
908
-                    case EEM_Message::status_resend:
909
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
910
-                        break;
854
+	/**
855
+	 * Set views array for the Custom Template List Table
856
+	 */
857
+	public function _set_list_table_views_custom_mtps()
858
+	{
859
+		$this->_set_list_table_views_global_mtps();
860
+		$this->_views['in_use']['bulk_action'] = array(
861
+				'trash_message_template' => esc_html__('Move to Trash', 'event_espresso')
862
+		);
863
+	}
864
+    
865
+    
866
+	/**
867
+	 * set views array for message queue list table
868
+	 */
869
+	public function _set_list_table_views_default()
870
+	{
871
+		EE_Registry::instance()->load_helper('Template');
872
+        
873
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message',
874
+			'message_list_table_bulk_actions')
875
+			? array(
876
+				'generate_now'          => __('Generate Now', 'event_espresso'),
877
+				'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'),
878
+				'queue_for_resending'   => __('Queue for Resending', 'event_espresso'),
879
+				'send_now'              => __('Send Now', 'event_espresso')
880
+			)
881
+			: array();
882
+        
883
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages',
884
+			'message_list_table_bulk_actions')
885
+			? array('delete_ee_messages' => __('Delete Messages', 'event_espresso'))
886
+			: array();
887
+        
888
+        
889
+		$this->_views = array(
890
+			'all' => array(
891
+				'slug'        => 'all',
892
+				'label'       => __('All', 'event_espresso'),
893
+				'count'       => 0,
894
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
895
+			)
896
+		);
897
+        
898
+        
899
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
900
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
901
+				continue;
902
+			}
903
+			$status_bulk_actions = $common_bulk_actions;
904
+			//unset bulk actions not applying to status
905
+			if (! empty($status_bulk_actions)) {
906
+				switch ($status) {
907
+					case EEM_Message::status_idle:
908
+					case EEM_Message::status_resend:
909
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
910
+						break;
911 911
                     
912
-                    case EEM_Message::status_failed:
913
-                    case EEM_Message::status_debug_only:
914
-                    case EEM_Message::status_messenger_executing:
915
-                        $status_bulk_actions = array();
916
-                        break;
912
+					case EEM_Message::status_failed:
913
+					case EEM_Message::status_debug_only:
914
+					case EEM_Message::status_messenger_executing:
915
+						$status_bulk_actions = array();
916
+						break;
917 917
                     
918
-                    case EEM_Message::status_incomplete:
919
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
920
-                        break;
918
+					case EEM_Message::status_incomplete:
919
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
920
+						break;
921 921
                     
922
-                    case EEM_Message::status_retry:
923
-                    case EEM_Message::status_sent:
924
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
925
-                        break;
926
-                }
927
-            }
922
+					case EEM_Message::status_retry:
923
+					case EEM_Message::status_sent:
924
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
925
+						break;
926
+				}
927
+			}
928 928
 
929
-            //skip adding messenger executing status to views because it will be included with the Failed view.
930
-            if ( $status === EEM_Message::status_messenger_executing ) {
931
-                continue;
932
-            }
929
+			//skip adding messenger executing status to views because it will be included with the Failed view.
930
+			if ( $status === EEM_Message::status_messenger_executing ) {
931
+				continue;
932
+			}
933 933
             
934
-            $this->_views[strtolower($status)] = array(
935
-                'slug'        => strtolower($status),
936
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
937
-                'count'       => 0,
938
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
939
-            );
940
-        }
941
-    }
942
-    
943
-    
944
-    protected function _ee_default_messages_overview_list_table()
945
-    {
946
-        $this->_admin_page_title = __('Default Message Templates', 'event_espresso');
947
-        $this->display_admin_list_table_page_with_no_sidebar();
948
-    }
949
-    
950
-    
951
-    protected function _message_queue_list_table()
952
-    {
953
-        $this->_search_btn_label                   = __('Message Activity', 'event_espresso');
954
-        $this->_template_args['per_column']        = 6;
955
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
956
-        $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
957
-        $this->display_admin_list_table_page_with_no_sidebar();
958
-    }
959
-    
960
-    
961
-    protected function _message_legend_items()
962
-    {
963
-        
964
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
965
-        $action_items       = array();
966
-        
967
-        foreach ($action_css_classes as $action_item => $action_details) {
968
-            if ($action_item === 'see_notifications_for') {
969
-                continue;
970
-            }
971
-            $action_items[$action_item] = array(
972
-                'class' => $action_details['css_class'],
973
-                'desc'  => $action_details['label']
974
-            );
975
-        }
976
-        
977
-        /** @type array $status_items status legend setup */
978
-        $status_items = array(
979
-            'sent_status'       => array(
980
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
981
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
982
-            ),
983
-            'idle_status'       => array(
984
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
985
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
986
-            ),
987
-            'failed_status'     => array(
988
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
989
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
990
-            ),
991
-            'messenger_executing_status' => array(
992
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
993
-                'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
994
-            ),
995
-            'resend_status'     => array(
996
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
997
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
998
-            ),
999
-            'incomplete_status' => array(
1000
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1001
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1002
-            ),
1003
-            'retry_status'      => array(
1004
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1005
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1006
-            )
1007
-        );
1008
-        if (EEM_Message::debug()) {
1009
-            $status_items['debug_only_status'] = array(
1010
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1011
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1012
-            );
1013
-        }
1014
-        
1015
-        return array_merge($action_items, $status_items);
1016
-    }
1017
-    
1018
-    
1019
-    protected function _custom_mtps_preview()
1020
-    {
1021
-        $this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1022
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1023
-                'event_espresso') . '" />';
1024
-        $this->_template_args['preview_text'] = '<strong>' . __('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.',
1025
-                'event_espresso') . '</strong>';
1026
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1027
-    }
1028
-    
1029
-    
1030
-    /**
1031
-     * get_message_templates
1032
-     * This gets all the message templates for listing on the overview list.
1033
-     *
1034
-     * @access public
1035
-     *
1036
-     * @param int    $perpage the amount of templates groups to show per page
1037
-     * @param string $type    the current _view we're getting templates for
1038
-     * @param bool   $count   return count?
1039
-     * @param bool   $all     disregard any paging info (get all data);
1040
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1041
-     *
1042
-     * @return array
1043
-     */
1044
-    public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)
1045
-    {
1046
-        
1047
-        $MTP = EEM_Message_Template_Group::instance();
1048
-        
1049
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1050
-        $orderby                    = $this->_req_data['orderby'];
1051
-        
1052
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
1053
-        
1054
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1055
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;
1056
-        
1057
-        $offset = ($current_page - 1) * $per_page;
1058
-        $limit  = $all ? null : array($offset, $per_page);
1059
-        
1060
-        
1061
-        //options will match what is in the _views array property
1062
-        switch ($type) {
934
+			$this->_views[strtolower($status)] = array(
935
+				'slug'        => strtolower($status),
936
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
937
+				'count'       => 0,
938
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
939
+			);
940
+		}
941
+	}
942
+    
943
+    
944
+	protected function _ee_default_messages_overview_list_table()
945
+	{
946
+		$this->_admin_page_title = __('Default Message Templates', 'event_espresso');
947
+		$this->display_admin_list_table_page_with_no_sidebar();
948
+	}
949
+    
950
+    
951
+	protected function _message_queue_list_table()
952
+	{
953
+		$this->_search_btn_label                   = __('Message Activity', 'event_espresso');
954
+		$this->_template_args['per_column']        = 6;
955
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
956
+		$this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
957
+		$this->display_admin_list_table_page_with_no_sidebar();
958
+	}
959
+    
960
+    
961
+	protected function _message_legend_items()
962
+	{
963
+        
964
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
965
+		$action_items       = array();
966
+        
967
+		foreach ($action_css_classes as $action_item => $action_details) {
968
+			if ($action_item === 'see_notifications_for') {
969
+				continue;
970
+			}
971
+			$action_items[$action_item] = array(
972
+				'class' => $action_details['css_class'],
973
+				'desc'  => $action_details['label']
974
+			);
975
+		}
976
+        
977
+		/** @type array $status_items status legend setup */
978
+		$status_items = array(
979
+			'sent_status'       => array(
980
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
981
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
982
+			),
983
+			'idle_status'       => array(
984
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
985
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
986
+			),
987
+			'failed_status'     => array(
988
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
989
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
990
+			),
991
+			'messenger_executing_status' => array(
992
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
993
+				'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
994
+			),
995
+			'resend_status'     => array(
996
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
997
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
998
+			),
999
+			'incomplete_status' => array(
1000
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1001
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
1002
+			),
1003
+			'retry_status'      => array(
1004
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1005
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
1006
+			)
1007
+		);
1008
+		if (EEM_Message::debug()) {
1009
+			$status_items['debug_only_status'] = array(
1010
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1011
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1012
+			);
1013
+		}
1014
+        
1015
+		return array_merge($action_items, $status_items);
1016
+	}
1017
+    
1018
+    
1019
+	protected function _custom_mtps_preview()
1020
+	{
1021
+		$this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1022
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1023
+				'event_espresso') . '" />';
1024
+		$this->_template_args['preview_text'] = '<strong>' . __('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.',
1025
+				'event_espresso') . '</strong>';
1026
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1027
+	}
1028
+    
1029
+    
1030
+	/**
1031
+	 * get_message_templates
1032
+	 * This gets all the message templates for listing on the overview list.
1033
+	 *
1034
+	 * @access public
1035
+	 *
1036
+	 * @param int    $perpage the amount of templates groups to show per page
1037
+	 * @param string $type    the current _view we're getting templates for
1038
+	 * @param bool   $count   return count?
1039
+	 * @param bool   $all     disregard any paging info (get all data);
1040
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1041
+	 *
1042
+	 * @return array
1043
+	 */
1044
+	public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)
1045
+	{
1046
+        
1047
+		$MTP = EEM_Message_Template_Group::instance();
1048
+        
1049
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1050
+		$orderby                    = $this->_req_data['orderby'];
1051
+        
1052
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
1053
+        
1054
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1055
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;
1056
+        
1057
+		$offset = ($current_page - 1) * $per_page;
1058
+		$limit  = $all ? null : array($offset, $per_page);
1059
+        
1060
+        
1061
+		//options will match what is in the _views array property
1062
+		switch ($type) {
1063 1063
             
1064
-            case 'in_use':
1065
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1066
-                break;
1064
+			case 'in_use':
1065
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1066
+				break;
1067 1067
             
1068
-            default:
1069
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1068
+			default:
1069
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1070 1070
             
1071
-        }
1072
-        
1073
-        return $templates;
1074
-    }
1075
-    
1076
-    
1077
-    /**
1078
-     * filters etc might need a list of installed message_types
1079
-     * @return array an array of message type objects
1080
-     */
1081
-    public function get_installed_message_types()
1082
-    {
1083
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1084
-        $installed               = array();
1085
-        
1086
-        foreach ($installed_message_types as $message_type) {
1087
-            $installed[$message_type->name] = $message_type;
1088
-        }
1089
-        
1090
-        return $installed;
1091
-    }
1092
-    
1093
-    
1094
-    /**
1095
-     * _add_message_template
1096
-     *
1097
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1098
-     *
1099
-     * @param string $message_type
1100
-     * @param string $messenger
1101
-     * @param string $GRP_ID
1102
-     *
1103
-     * @throws EE_error
1104
-     */
1105
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1106
-    {
1107
-        //set values override any request data
1108
-        $message_type = ! empty($message_type) ? $message_type : '';
1109
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;
1110
-        
1111
-        $messenger = ! empty($messenger) ? $messenger : '';
1112
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;
1113
-        
1114
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1115
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1116
-        
1117
-        //we need messenger and message type.  They should be coming from the event editor. If not here then return error
1118
-        if (empty($message_type) || empty($messenger)) {
1119
-            throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1120
-                'event_espresso'));
1121
-        }
1122
-        
1123
-        //we need the GRP_ID for the template being used as the base for the new template
1124
-        if (empty($GRP_ID)) {
1125
-            throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1126
-                'event_espresso'));
1127
-        }
1128
-        
1129
-        //let's just make sure the template gets generated!
1130
-        
1131
-        //we need to reassign some variables for what the insert is expecting
1132
-        $this->_req_data['MTP_messenger']    = $messenger;
1133
-        $this->_req_data['MTP_message_type'] = $message_type;
1134
-        $this->_req_data['GRP_ID']           = $GRP_ID;
1135
-        $this->_insert_or_update_message_template(true);
1136
-    }
1137
-    
1138
-    
1139
-    /**
1140
-     * public wrapper for the _add_message_template method
1141
-     *
1142
-     * @param string $message_type     message type slug
1143
-     * @param string $messenger        messenger slug
1144
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1145
-     *                                 off of.
1146
-     */
1147
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1148
-    {
1149
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1150
-    }
1151
-    
1152
-    
1153
-    /**
1154
-     * _edit_message_template
1155
-     *
1156
-     * @access protected
1157
-     * @return void
1158
-     */
1159
-    protected function _edit_message_template()
1160
-    {
1161
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1162
-        $template_fields = '';
1163
-        $sidebar_fields  = '';
1164
-        //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.
1165
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1166
-        
1167
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1168
-            ? absint($this->_req_data['id'])
1169
-            : false;
1170
-        
1171
-        $this->_set_shortcodes(); //this also sets the _message_template property.
1172
-        $message_template_group = $this->_message_template_group;
1173
-        $c_label                = $message_template_group->context_label();
1174
-        $c_config               = $message_template_group->contexts_config();
1175
-        
1176
-        reset($c_config);
1177
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1178
-            ? strtolower($this->_req_data['context'])
1179
-            : key($c_config);
1180
-        
1181
-        
1182
-        if (empty($GRP_ID)) {
1183
-            $action = 'insert_message_template';
1184
-            //$button_both = false;
1185
-            //$button_text = array( __( 'Save','event_espresso') );
1186
-            //$button_actions = array('something_different');
1187
-            //$referrer = false;
1188
-            $edit_message_template_form_url = add_query_arg(
1189
-                array('action' => $action, 'noheader' => true),
1190
-                EE_MSG_ADMIN_URL
1191
-            );
1192
-        } else {
1193
-            $action = 'update_message_template';
1194
-            //$button_both = true;
1195
-            //$button_text = array();
1196
-            //$button_actions = array();
1197
-            //$referrer = $this->_admin_base_url;
1198
-            $edit_message_template_form_url = add_query_arg(
1199
-                array('action' => $action, 'noheader' => true),
1200
-                EE_MSG_ADMIN_URL
1201
-            );
1202
-        }
1203
-        
1204
-        //set active messenger for this view
1205
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1206
-            $message_template_group->messenger()
1207
-        );
1208
-        $this->_active_message_type_name = $message_template_group->message_type();
1209
-        
1210
-        
1211
-        //Do we have any validation errors?
1212
-        $validators = $this->_get_transient();
1213
-        $v_fields   = ! empty($validators) ? array_keys($validators) : array();
1214
-        
1215
-        
1216
-        //we need to assemble the title from Various details
1217
-        $context_label = sprintf(
1218
-            __('(%s %s)', 'event_espresso'),
1219
-            $c_config[$context]['label'],
1220
-            ucwords($c_label['label'])
1221
-        );
1222
-        
1223
-        $title = sprintf(
1224
-            __(' %s %s Template %s', 'event_espresso'),
1225
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1226
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1227
-            $context_label
1228
-        );
1229
-        
1230
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1231
-        $this->_template_args['message_template'] = $message_template_group;
1232
-        $this->_template_args['is_extra_fields']  = false;
1233
-        
1234
-        
1235
-        //let's get EEH_MSG_Template so we can get template form fields
1236
-        $template_field_structure = EEH_MSG_Template::get_fields(
1237
-            $message_template_group->messenger(),
1238
-            $message_template_group->message_type()
1239
-        );
1240
-        
1241
-        if ( ! $template_field_structure) {
1242
-            $template_field_structure = false;
1243
-            $template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)',
1244
-                'event_espresso');
1245
-        }
1246
-        
1247
-        
1248
-        $message_templates = $message_template_group->context_templates();
1249
-        
1250
-        
1251
-        //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array.
1252
-        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1253
-            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1254
-                unset($template_field_structure[$context][$reference_field]);
1255
-            }
1256
-        }
1257
-        
1258
-        //let's loop through the template_field_structure and actually assemble the input fields!
1259
-        if ( ! empty($template_field_structure)) {
1260
-            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1261
-                //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them.
1262
-                if ($template_field == 'extra') {
1263
-                    $this->_template_args['is_extra_fields'] = true;
1264
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1265
-                        $message_template = $message_templates[$context][$reference_field];
1266
-                        $content          = $message_template instanceof EE_Message_Template
1267
-                            ? $message_template->get('MTP_content')
1268
-                            : '';
1269
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1270
-                            //let's verify if we need this extra field via the shortcodes parameter.
1271
-                            $continue = false;
1272
-                            if (isset($extra_array['shortcodes_required'])) {
1273
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1274
-                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1275
-                                        $continue = true;
1276
-                                    }
1277
-                                }
1278
-                                if ($continue) {
1279
-                                    continue;
1280
-                                }
1281
-                            }
1071
+		}
1072
+        
1073
+		return $templates;
1074
+	}
1075
+    
1076
+    
1077
+	/**
1078
+	 * filters etc might need a list of installed message_types
1079
+	 * @return array an array of message type objects
1080
+	 */
1081
+	public function get_installed_message_types()
1082
+	{
1083
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1084
+		$installed               = array();
1085
+        
1086
+		foreach ($installed_message_types as $message_type) {
1087
+			$installed[$message_type->name] = $message_type;
1088
+		}
1089
+        
1090
+		return $installed;
1091
+	}
1092
+    
1093
+    
1094
+	/**
1095
+	 * _add_message_template
1096
+	 *
1097
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1098
+	 *
1099
+	 * @param string $message_type
1100
+	 * @param string $messenger
1101
+	 * @param string $GRP_ID
1102
+	 *
1103
+	 * @throws EE_error
1104
+	 */
1105
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1106
+	{
1107
+		//set values override any request data
1108
+		$message_type = ! empty($message_type) ? $message_type : '';
1109
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;
1110
+        
1111
+		$messenger = ! empty($messenger) ? $messenger : '';
1112
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;
1113
+        
1114
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1115
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1116
+        
1117
+		//we need messenger and message type.  They should be coming from the event editor. If not here then return error
1118
+		if (empty($message_type) || empty($messenger)) {
1119
+			throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1120
+				'event_espresso'));
1121
+		}
1122
+        
1123
+		//we need the GRP_ID for the template being used as the base for the new template
1124
+		if (empty($GRP_ID)) {
1125
+			throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1126
+				'event_espresso'));
1127
+		}
1128
+        
1129
+		//let's just make sure the template gets generated!
1130
+        
1131
+		//we need to reassign some variables for what the insert is expecting
1132
+		$this->_req_data['MTP_messenger']    = $messenger;
1133
+		$this->_req_data['MTP_message_type'] = $message_type;
1134
+		$this->_req_data['GRP_ID']           = $GRP_ID;
1135
+		$this->_insert_or_update_message_template(true);
1136
+	}
1137
+    
1138
+    
1139
+	/**
1140
+	 * public wrapper for the _add_message_template method
1141
+	 *
1142
+	 * @param string $message_type     message type slug
1143
+	 * @param string $messenger        messenger slug
1144
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1145
+	 *                                 off of.
1146
+	 */
1147
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1148
+	{
1149
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1150
+	}
1151
+    
1152
+    
1153
+	/**
1154
+	 * _edit_message_template
1155
+	 *
1156
+	 * @access protected
1157
+	 * @return void
1158
+	 */
1159
+	protected function _edit_message_template()
1160
+	{
1161
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1162
+		$template_fields = '';
1163
+		$sidebar_fields  = '';
1164
+		//we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.
1165
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1166
+        
1167
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1168
+			? absint($this->_req_data['id'])
1169
+			: false;
1170
+        
1171
+		$this->_set_shortcodes(); //this also sets the _message_template property.
1172
+		$message_template_group = $this->_message_template_group;
1173
+		$c_label                = $message_template_group->context_label();
1174
+		$c_config               = $message_template_group->contexts_config();
1175
+        
1176
+		reset($c_config);
1177
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1178
+			? strtolower($this->_req_data['context'])
1179
+			: key($c_config);
1180
+        
1181
+        
1182
+		if (empty($GRP_ID)) {
1183
+			$action = 'insert_message_template';
1184
+			//$button_both = false;
1185
+			//$button_text = array( __( 'Save','event_espresso') );
1186
+			//$button_actions = array('something_different');
1187
+			//$referrer = false;
1188
+			$edit_message_template_form_url = add_query_arg(
1189
+				array('action' => $action, 'noheader' => true),
1190
+				EE_MSG_ADMIN_URL
1191
+			);
1192
+		} else {
1193
+			$action = 'update_message_template';
1194
+			//$button_both = true;
1195
+			//$button_text = array();
1196
+			//$button_actions = array();
1197
+			//$referrer = $this->_admin_base_url;
1198
+			$edit_message_template_form_url = add_query_arg(
1199
+				array('action' => $action, 'noheader' => true),
1200
+				EE_MSG_ADMIN_URL
1201
+			);
1202
+		}
1203
+        
1204
+		//set active messenger for this view
1205
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1206
+			$message_template_group->messenger()
1207
+		);
1208
+		$this->_active_message_type_name = $message_template_group->message_type();
1209
+        
1210
+        
1211
+		//Do we have any validation errors?
1212
+		$validators = $this->_get_transient();
1213
+		$v_fields   = ! empty($validators) ? array_keys($validators) : array();
1214
+        
1215
+        
1216
+		//we need to assemble the title from Various details
1217
+		$context_label = sprintf(
1218
+			__('(%s %s)', 'event_espresso'),
1219
+			$c_config[$context]['label'],
1220
+			ucwords($c_label['label'])
1221
+		);
1222
+        
1223
+		$title = sprintf(
1224
+			__(' %s %s Template %s', 'event_espresso'),
1225
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1226
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1227
+			$context_label
1228
+		);
1229
+        
1230
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1231
+		$this->_template_args['message_template'] = $message_template_group;
1232
+		$this->_template_args['is_extra_fields']  = false;
1233
+        
1234
+        
1235
+		//let's get EEH_MSG_Template so we can get template form fields
1236
+		$template_field_structure = EEH_MSG_Template::get_fields(
1237
+			$message_template_group->messenger(),
1238
+			$message_template_group->message_type()
1239
+		);
1240
+        
1241
+		if ( ! $template_field_structure) {
1242
+			$template_field_structure = false;
1243
+			$template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)',
1244
+				'event_espresso');
1245
+		}
1246
+        
1247
+        
1248
+		$message_templates = $message_template_group->context_templates();
1249
+        
1250
+        
1251
+		//if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array.
1252
+		if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1253
+			foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1254
+				unset($template_field_structure[$context][$reference_field]);
1255
+			}
1256
+		}
1257
+        
1258
+		//let's loop through the template_field_structure and actually assemble the input fields!
1259
+		if ( ! empty($template_field_structure)) {
1260
+			foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1261
+				//if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them.
1262
+				if ($template_field == 'extra') {
1263
+					$this->_template_args['is_extra_fields'] = true;
1264
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1265
+						$message_template = $message_templates[$context][$reference_field];
1266
+						$content          = $message_template instanceof EE_Message_Template
1267
+							? $message_template->get('MTP_content')
1268
+							: '';
1269
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1270
+							//let's verify if we need this extra field via the shortcodes parameter.
1271
+							$continue = false;
1272
+							if (isset($extra_array['shortcodes_required'])) {
1273
+								foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1274
+									if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1275
+										$continue = true;
1276
+									}
1277
+								}
1278
+								if ($continue) {
1279
+									continue;
1280
+								}
1281
+							}
1282 1282
                             
1283
-                            $field_id                                = $reference_field . '-' . $extra_field . '-content';
1284
-                            $template_form_fields[$field_id]         = $extra_array;
1285
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1286
-                            $css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1283
+							$field_id                                = $reference_field . '-' . $extra_field . '-content';
1284
+							$template_form_fields[$field_id]         = $extra_array;
1285
+							$template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1286
+							$css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1287 1287
                             
1288
-                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1289
-                                                                            && in_array($extra_field, $v_fields)
1290
-                                                                            &&
1291
-                                                                            (
1292
-                                                                                is_array($validators[$extra_field])
1293
-                                                                                && isset($validators[$extra_field]['msg'])
1294
-                                                                            )
1295
-                                ? 'validate-error ' . $css_class
1296
-                                : $css_class;
1288
+							$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1289
+																			&& in_array($extra_field, $v_fields)
1290
+																			&&
1291
+																			(
1292
+																				is_array($validators[$extra_field])
1293
+																				&& isset($validators[$extra_field]['msg'])
1294
+																			)
1295
+								? 'validate-error ' . $css_class
1296
+								: $css_class;
1297 1297
                             
1298
-                            $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
1299
-                                ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1300
-                                : '';
1298
+							$template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
1299
+								? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1300
+								: '';
1301 1301
                             
1302
-                            //do we have a validation error?  if we do then let's use that value instead
1303
-                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];
1302
+							//do we have a validation error?  if we do then let's use that value instead
1303
+							$template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];
1304 1304
                             
1305 1305
                             
1306
-                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1306
+							$template_form_fields[$field_id]['db-col'] = 'MTP_content';
1307 1307
                             
1308
-                            //shortcode selector
1309
-                            $field_name_to_use                                 = $extra_field == 'main' ? 'content' : $extra_field;
1310
-                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1311
-                                $field_name_to_use,
1312
-                                $field_id
1313
-                            );
1308
+							//shortcode selector
1309
+							$field_name_to_use                                 = $extra_field == 'main' ? 'content' : $extra_field;
1310
+							$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1311
+								$field_name_to_use,
1312
+								$field_id
1313
+							);
1314 1314
                             
1315
-                            if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') {
1316
-                                //we want to decode the entities
1317
-                                $template_form_fields[$field_id]['value'] = stripslashes(
1318
-                                    html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")
1319
-                                );
1315
+							if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') {
1316
+								//we want to decode the entities
1317
+								$template_form_fields[$field_id]['value'] = stripslashes(
1318
+									html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")
1319
+								);
1320 1320
                                 
1321
-                            }/**/
1322
-                        }
1323
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1324
-                        $templatefield_templatename_id = $reference_field . '-name';
1321
+							}/**/
1322
+						}
1323
+						$templatefield_MTP_id          = $reference_field . '-MTP_ID';
1324
+						$templatefield_templatename_id = $reference_field . '-name';
1325 1325
                         
1326
-                        $template_form_fields[$templatefield_MTP_id] = array(
1327
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1328
-                            'label'      => null,
1329
-                            'input'      => 'hidden',
1330
-                            'type'       => 'int',
1331
-                            'required'   => false,
1332
-                            'validation' => false,
1333
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1334
-                            'css_class'  => '',
1335
-                            'format'     => '%d',
1336
-                            'db-col'     => 'MTP_ID'
1337
-                        );
1326
+						$template_form_fields[$templatefield_MTP_id] = array(
1327
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1328
+							'label'      => null,
1329
+							'input'      => 'hidden',
1330
+							'type'       => 'int',
1331
+							'required'   => false,
1332
+							'validation' => false,
1333
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1334
+							'css_class'  => '',
1335
+							'format'     => '%d',
1336
+							'db-col'     => 'MTP_ID'
1337
+						);
1338 1338
                         
1339
-                        $template_form_fields[$templatefield_templatename_id] = array(
1340
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1341
-                            'label'      => null,
1342
-                            'input'      => 'hidden',
1343
-                            'type'       => 'string',
1344
-                            'required'   => false,
1345
-                            'validation' => true,
1346
-                            'value'      => $reference_field,
1347
-                            'css_class'  => '',
1348
-                            'format'     => '%s',
1349
-                            'db-col'     => 'MTP_template_field'
1350
-                        );
1351
-                    }
1352
-                    continue; //skip the next stuff, we got the necessary fields here for this dataset.
1353
-                } else {
1354
-                    $field_id                                 = $template_field . '-content';
1355
-                    $template_form_fields[$field_id]          = $field_setup_array;
1356
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1357
-                    $message_template                         = isset($message_templates[$context][$template_field])
1358
-                        ? $message_templates[$context][$template_field]
1359
-                        : null;
1360
-                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1361
-                                                                && is_array($message_templates[$context])
1362
-                                                                && $message_template instanceof EE_Message_Template
1363
-                        ? $message_template->get('MTP_content')
1364
-                        : '';
1339
+						$template_form_fields[$templatefield_templatename_id] = array(
1340
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1341
+							'label'      => null,
1342
+							'input'      => 'hidden',
1343
+							'type'       => 'string',
1344
+							'required'   => false,
1345
+							'validation' => true,
1346
+							'value'      => $reference_field,
1347
+							'css_class'  => '',
1348
+							'format'     => '%s',
1349
+							'db-col'     => 'MTP_template_field'
1350
+						);
1351
+					}
1352
+					continue; //skip the next stuff, we got the necessary fields here for this dataset.
1353
+				} else {
1354
+					$field_id                                 = $template_field . '-content';
1355
+					$template_form_fields[$field_id]          = $field_setup_array;
1356
+					$template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1357
+					$message_template                         = isset($message_templates[$context][$template_field])
1358
+						? $message_templates[$context][$template_field]
1359
+						: null;
1360
+					$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1361
+																&& is_array($message_templates[$context])
1362
+																&& $message_template instanceof EE_Message_Template
1363
+						? $message_template->get('MTP_content')
1364
+						: '';
1365 1365
                     
1366
-                    //do we have a validator error for this field?  if we do then we'll use that value instead
1367
-                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1368
-                        ? $validators[$template_field]['value']
1369
-                        : $template_form_fields[$field_id]['value'];
1366
+					//do we have a validator error for this field?  if we do then we'll use that value instead
1367
+					$template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1368
+						? $validators[$template_field]['value']
1369
+						: $template_form_fields[$field_id]['value'];
1370 1370
                     
1371 1371
                     
1372
-                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1373
-                    $css_class                                    = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';
1374
-                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1375
-                                                                    && in_array($template_field, $v_fields)
1376
-                                                                    && isset($validators[$template_field]['msg'])
1377
-                        ? 'validate-error ' . $css_class
1378
-                        : $css_class;
1372
+					$template_form_fields[$field_id]['db-col']    = 'MTP_content';
1373
+					$css_class                                    = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';
1374
+					$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1375
+																	&& in_array($template_field, $v_fields)
1376
+																	&& isset($validators[$template_field]['msg'])
1377
+						? 'validate-error ' . $css_class
1378
+						: $css_class;
1379 1379
                     
1380
-                    //shortcode selector
1381
-                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1382
-                        $template_field, $field_id
1383
-                    );
1384
-                }
1380
+					//shortcode selector
1381
+					$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1382
+						$template_field, $field_id
1383
+					);
1384
+				}
1385 1385
                 
1386
-                //k took care of content field(s) now let's take care of others.
1386
+				//k took care of content field(s) now let's take care of others.
1387 1387
                 
1388
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1389
-                $templatefield_field_templatename_id = $template_field . '-name';
1388
+				$templatefield_MTP_id                = $template_field . '-MTP_ID';
1389
+				$templatefield_field_templatename_id = $template_field . '-name';
1390 1390
                 
1391
-                //foreach template field there are actually two form fields created
1392
-                $template_form_fields[$templatefield_MTP_id] = array(
1393
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1394
-                    'label'      => null,
1395
-                    'input'      => 'hidden',
1396
-                    'type'       => 'int',
1397
-                    'required'   => false,
1398
-                    'validation' => true,
1399
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1400
-                    'css_class'  => '',
1401
-                    'format'     => '%d',
1402
-                    'db-col'     => 'MTP_ID'
1403
-                );
1391
+				//foreach template field there are actually two form fields created
1392
+				$template_form_fields[$templatefield_MTP_id] = array(
1393
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1394
+					'label'      => null,
1395
+					'input'      => 'hidden',
1396
+					'type'       => 'int',
1397
+					'required'   => false,
1398
+					'validation' => true,
1399
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1400
+					'css_class'  => '',
1401
+					'format'     => '%d',
1402
+					'db-col'     => 'MTP_ID'
1403
+				);
1404 1404
                 
1405
-                $template_form_fields[$templatefield_field_templatename_id] = array(
1406
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1407
-                    'label'      => null,
1408
-                    'input'      => 'hidden',
1409
-                    'type'       => 'string',
1410
-                    'required'   => false,
1411
-                    'validation' => true,
1412
-                    'value'      => $template_field,
1413
-                    'css_class'  => '',
1414
-                    'format'     => '%s',
1415
-                    'db-col'     => 'MTP_template_field'
1416
-                );
1405
+				$template_form_fields[$templatefield_field_templatename_id] = array(
1406
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1407
+					'label'      => null,
1408
+					'input'      => 'hidden',
1409
+					'type'       => 'string',
1410
+					'required'   => false,
1411
+					'validation' => true,
1412
+					'value'      => $template_field,
1413
+					'css_class'  => '',
1414
+					'format'     => '%s',
1415
+					'db-col'     => 'MTP_template_field'
1416
+				);
1417 1417
                 
1418
-            }
1418
+			}
1419 1419
             
1420
-            //add other fields
1421
-            $template_form_fields['ee-msg-current-context'] = array(
1422
-                'name'       => 'MTP_context',
1423
-                'label'      => null,
1424
-                'input'      => 'hidden',
1425
-                'type'       => 'string',
1426
-                'required'   => false,
1427
-                'validation' => true,
1428
-                'value'      => $context,
1429
-                'css_class'  => '',
1430
-                'format'     => '%s',
1431
-                'db-col'     => 'MTP_context'
1432
-            );
1420
+			//add other fields
1421
+			$template_form_fields['ee-msg-current-context'] = array(
1422
+				'name'       => 'MTP_context',
1423
+				'label'      => null,
1424
+				'input'      => 'hidden',
1425
+				'type'       => 'string',
1426
+				'required'   => false,
1427
+				'validation' => true,
1428
+				'value'      => $context,
1429
+				'css_class'  => '',
1430
+				'format'     => '%s',
1431
+				'db-col'     => 'MTP_context'
1432
+			);
1433 1433
             
1434
-            $template_form_fields['ee-msg-grp-id'] = array(
1435
-                'name'       => 'GRP_ID',
1436
-                'label'      => null,
1437
-                'input'      => 'hidden',
1438
-                'type'       => 'int',
1439
-                'required'   => false,
1440
-                'validation' => true,
1441
-                'value'      => $GRP_ID,
1442
-                'css_class'  => '',
1443
-                'format'     => '%d',
1444
-                'db-col'     => 'GRP_ID'
1445
-            );
1434
+			$template_form_fields['ee-msg-grp-id'] = array(
1435
+				'name'       => 'GRP_ID',
1436
+				'label'      => null,
1437
+				'input'      => 'hidden',
1438
+				'type'       => 'int',
1439
+				'required'   => false,
1440
+				'validation' => true,
1441
+				'value'      => $GRP_ID,
1442
+				'css_class'  => '',
1443
+				'format'     => '%d',
1444
+				'db-col'     => 'GRP_ID'
1445
+			);
1446 1446
             
1447
-            $template_form_fields['ee-msg-messenger'] = array(
1448
-                'name'       => 'MTP_messenger',
1449
-                'label'      => null,
1450
-                'input'      => 'hidden',
1451
-                'type'       => 'string',
1452
-                'required'   => false,
1453
-                'validation' => true,
1454
-                'value'      => $message_template_group->messenger(),
1455
-                'css_class'  => '',
1456
-                'format'     => '%s',
1457
-                'db-col'     => 'MTP_messenger'
1458
-            );
1447
+			$template_form_fields['ee-msg-messenger'] = array(
1448
+				'name'       => 'MTP_messenger',
1449
+				'label'      => null,
1450
+				'input'      => 'hidden',
1451
+				'type'       => 'string',
1452
+				'required'   => false,
1453
+				'validation' => true,
1454
+				'value'      => $message_template_group->messenger(),
1455
+				'css_class'  => '',
1456
+				'format'     => '%s',
1457
+				'db-col'     => 'MTP_messenger'
1458
+			);
1459 1459
             
1460
-            $template_form_fields['ee-msg-message-type'] = array(
1461
-                'name'       => 'MTP_message_type',
1462
-                'label'      => null,
1463
-                'input'      => 'hidden',
1464
-                'type'       => 'string',
1465
-                'required'   => false,
1466
-                'validation' => true,
1467
-                'value'      => $message_template_group->message_type(),
1468
-                'css_class'  => '',
1469
-                'format'     => '%s',
1470
-                'db-col'     => 'MTP_message_type'
1471
-            );
1460
+			$template_form_fields['ee-msg-message-type'] = array(
1461
+				'name'       => 'MTP_message_type',
1462
+				'label'      => null,
1463
+				'input'      => 'hidden',
1464
+				'type'       => 'string',
1465
+				'required'   => false,
1466
+				'validation' => true,
1467
+				'value'      => $message_template_group->message_type(),
1468
+				'css_class'  => '',
1469
+				'format'     => '%s',
1470
+				'db-col'     => 'MTP_message_type'
1471
+			);
1472 1472
             
1473
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1474
-                'name'       => 'MTP_is_global',
1475
-                'label'      => __('Global Template', 'event_espresso'),
1476
-                'input'      => 'hidden',
1477
-                'type'       => 'int',
1478
-                'required'   => false,
1479
-                'validation' => true,
1480
-                'value'      => $message_template_group->get('MTP_is_global'),
1481
-                'css_class'  => '',
1482
-                'format'     => '%d',
1483
-                'db-col'     => 'MTP_is_global'
1484
-            );
1473
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1474
+				'name'       => 'MTP_is_global',
1475
+				'label'      => __('Global Template', 'event_espresso'),
1476
+				'input'      => 'hidden',
1477
+				'type'       => 'int',
1478
+				'required'   => false,
1479
+				'validation' => true,
1480
+				'value'      => $message_template_group->get('MTP_is_global'),
1481
+				'css_class'  => '',
1482
+				'format'     => '%d',
1483
+				'db-col'     => 'MTP_is_global'
1484
+			);
1485 1485
             
1486
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1487
-                'name'       => 'MTP_is_override',
1488
-                'label'      => __('Override all custom', 'event_espresso'),
1489
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1490
-                'type'       => 'int',
1491
-                'required'   => false,
1492
-                'validation' => true,
1493
-                'value'      => $message_template_group->get('MTP_is_override'),
1494
-                'css_class'  => '',
1495
-                'format'     => '%d',
1496
-                'db-col'     => 'MTP_is_override'
1497
-            );
1486
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1487
+				'name'       => 'MTP_is_override',
1488
+				'label'      => __('Override all custom', 'event_espresso'),
1489
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1490
+				'type'       => 'int',
1491
+				'required'   => false,
1492
+				'validation' => true,
1493
+				'value'      => $message_template_group->get('MTP_is_override'),
1494
+				'css_class'  => '',
1495
+				'format'     => '%d',
1496
+				'db-col'     => 'MTP_is_override'
1497
+			);
1498 1498
             
1499
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1500
-                'name'       => 'MTP_is_active',
1501
-                'label'      => __('Active Template', 'event_espresso'),
1502
-                'input'      => 'hidden',
1503
-                'type'       => 'int',
1504
-                'required'   => false,
1505
-                'validation' => true,
1506
-                'value'      => $message_template_group->is_active(),
1507
-                'css_class'  => '',
1508
-                'format'     => '%d',
1509
-                'db-col'     => 'MTP_is_active'
1510
-            );
1499
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1500
+				'name'       => 'MTP_is_active',
1501
+				'label'      => __('Active Template', 'event_espresso'),
1502
+				'input'      => 'hidden',
1503
+				'type'       => 'int',
1504
+				'required'   => false,
1505
+				'validation' => true,
1506
+				'value'      => $message_template_group->is_active(),
1507
+				'css_class'  => '',
1508
+				'format'     => '%d',
1509
+				'db-col'     => 'MTP_is_active'
1510
+			);
1511 1511
             
1512
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1513
-                'name'       => 'MTP_deleted',
1514
-                'label'      => null,
1515
-                'input'      => 'hidden',
1516
-                'type'       => 'int',
1517
-                'required'   => false,
1518
-                'validation' => true,
1519
-                'value'      => $message_template_group->get('MTP_deleted'),
1520
-                'css_class'  => '',
1521
-                'format'     => '%d',
1522
-                'db-col'     => 'MTP_deleted'
1523
-            );
1524
-            $sidebar_form_fields['ee-msg-author']  = array(
1525
-                'name'       => 'MTP_user_id',
1526
-                'label'      => __('Author', 'event_espresso'),
1527
-                'input'      => 'hidden',
1528
-                'type'       => 'int',
1529
-                'required'   => false,
1530
-                'validation' => false,
1531
-                'value'      => $message_template_group->user(),
1532
-                'format'     => '%d',
1533
-                'db-col'     => 'MTP_user_id'
1534
-            );
1512
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1513
+				'name'       => 'MTP_deleted',
1514
+				'label'      => null,
1515
+				'input'      => 'hidden',
1516
+				'type'       => 'int',
1517
+				'required'   => false,
1518
+				'validation' => true,
1519
+				'value'      => $message_template_group->get('MTP_deleted'),
1520
+				'css_class'  => '',
1521
+				'format'     => '%d',
1522
+				'db-col'     => 'MTP_deleted'
1523
+			);
1524
+			$sidebar_form_fields['ee-msg-author']  = array(
1525
+				'name'       => 'MTP_user_id',
1526
+				'label'      => __('Author', 'event_espresso'),
1527
+				'input'      => 'hidden',
1528
+				'type'       => 'int',
1529
+				'required'   => false,
1530
+				'validation' => false,
1531
+				'value'      => $message_template_group->user(),
1532
+				'format'     => '%d',
1533
+				'db-col'     => 'MTP_user_id'
1534
+			);
1535 1535
             
1536
-            $sidebar_form_fields['ee-msg-route'] = array(
1537
-                'name'  => 'action',
1538
-                'input' => 'hidden',
1539
-                'type'  => 'string',
1540
-                'value' => $action
1541
-            );
1536
+			$sidebar_form_fields['ee-msg-route'] = array(
1537
+				'name'  => 'action',
1538
+				'input' => 'hidden',
1539
+				'type'  => 'string',
1540
+				'value' => $action
1541
+			);
1542 1542
             
1543
-            $sidebar_form_fields['ee-msg-id']        = array(
1544
-                'name'  => 'id',
1545
-                'input' => 'hidden',
1546
-                'type'  => 'int',
1547
-                'value' => $GRP_ID
1548
-            );
1549
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1550
-                'name'  => $action . '_nonce',
1551
-                'input' => 'hidden',
1552
-                'type'  => 'string',
1553
-                'value' => wp_create_nonce($action . '_nonce')
1554
-            );
1543
+			$sidebar_form_fields['ee-msg-id']        = array(
1544
+				'name'  => 'id',
1545
+				'input' => 'hidden',
1546
+				'type'  => 'int',
1547
+				'value' => $GRP_ID
1548
+			);
1549
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1550
+				'name'  => $action . '_nonce',
1551
+				'input' => 'hidden',
1552
+				'type'  => 'string',
1553
+				'value' => wp_create_nonce($action . '_nonce')
1554
+			);
1555 1555
             
1556
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1557
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1558
-                    'name'  => 'template_switch',
1559
-                    'input' => 'hidden',
1560
-                    'type'  => 'int',
1561
-                    'value' => 1
1562
-                );
1563
-            }
1556
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1557
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1558
+					'name'  => 'template_switch',
1559
+					'input' => 'hidden',
1560
+					'type'  => 'int',
1561
+					'value' => 1
1562
+				);
1563
+			}
1564 1564
             
1565 1565
             
1566
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1567
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1566
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1567
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1568 1568
             
1569 1569
             
1570
-        } //end if ( !empty($template_field_structure) )
1570
+		} //end if ( !empty($template_field_structure) )
1571 1571
         
1572
-        //set extra content for publish box
1573
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1574
-        $this->_set_publish_post_box_vars(
1575
-            'id',
1576
-            $GRP_ID,
1577
-            false,
1578
-            add_query_arg(
1579
-                array('action' => 'global_mtps'),
1580
-                $this->_admin_base_url
1581
-            )
1582
-        );
1583
-        
1584
-        //add preview button
1585
-        $preview_url    = parent::add_query_args_and_nonce(
1586
-            array(
1587
-                'message_type' => $message_template_group->message_type(),
1588
-                'messenger'    => $message_template_group->messenger(),
1589
-                'context'      => $context,
1590
-                'GRP_ID'       => $GRP_ID,
1591
-                'action'       => 'preview_message'
1592
-            ),
1593
-            $this->_admin_base_url
1594
-        );
1595
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1596
-                'event_espresso') . '</a>';
1597
-        
1598
-        
1599
-        //setup context switcher
1600
-        $context_switcher_args = array(
1601
-            'page'    => 'espresso_messages',
1602
-            'action'  => 'edit_message_template',
1603
-            'id'      => $GRP_ID,
1604
-            'context' => $context,
1605
-            'extra'   => $preview_button
1606
-        );
1607
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1608
-        
1609
-        
1610
-        //main box
1611
-        $this->_template_args['template_fields']                         = $template_fields;
1612
-        $this->_template_args['sidebar_box_id']                          = 'details';
1613
-        $this->_template_args['action']                                  = $action;
1614
-        $this->_template_args['context']                                 = $context;
1615
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1616
-        $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();
1617
-        
1618
-        
1619
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1620
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1621
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1622
-        
1623
-        $this->_template_path = $this->_template_args['GRP_ID']
1624
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1625
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1626
-        
1627
-        //send along EE_Message_Template_Group object for further template use.
1628
-        $this->_template_args['MTP'] = $message_template_group;
1629
-        
1630
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
1631
-            $this->_template_args, true);
1632
-        
1633
-        
1634
-        //finally, let's set the admin_page title
1635
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1636
-        
1637
-        
1638
-        //we need to take care of setting the shortcodes property for use elsewhere.
1639
-        $this->_set_shortcodes();
1640
-        
1641
-        
1642
-        //final template wrapper
1643
-        $this->display_admin_page_with_sidebar();
1644
-    }
1645
-    
1646
-    
1647
-    public function filter_tinymce_init($mceInit, $editor_id)
1648
-    {
1649
-        return $mceInit;
1650
-    }
1651
-    
1652
-    
1653
-    public function add_context_switcher()
1654
-    {
1655
-        return $this->_context_switcher;
1656
-    }
1657
-    
1658
-    public function _add_form_element_before()
1659
-    {
1660
-        return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1661
-    }
1662
-    
1663
-    public function _add_form_element_after()
1664
-    {
1665
-        return '</form>';
1666
-    }
1667
-    
1668
-    
1669
-    /**
1670
-     * This executes switching the template pack for a message template.
1671
-     *
1672
-     * @since 4.5.0
1673
-     *
1674
-     */
1675
-    public function switch_template_pack()
1676
-    {
1677
-        $GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1678
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1679
-        
1680
-        //verify we have needed values.
1681
-        if (empty($GRP_ID) || empty($template_pack)) {
1682
-            $this->_template_args['error'] = true;
1683
-            EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'),
1684
-                __FILE__, __FUNCTION__, __LINE__);
1685
-        } else {
1686
-            //get template, set the new template_pack and then reset to default
1687
-            /** @type EE_Message_Template_Group $message_template_group */
1688
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1572
+		//set extra content for publish box
1573
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1574
+		$this->_set_publish_post_box_vars(
1575
+			'id',
1576
+			$GRP_ID,
1577
+			false,
1578
+			add_query_arg(
1579
+				array('action' => 'global_mtps'),
1580
+				$this->_admin_base_url
1581
+			)
1582
+		);
1583
+        
1584
+		//add preview button
1585
+		$preview_url    = parent::add_query_args_and_nonce(
1586
+			array(
1587
+				'message_type' => $message_template_group->message_type(),
1588
+				'messenger'    => $message_template_group->messenger(),
1589
+				'context'      => $context,
1590
+				'GRP_ID'       => $GRP_ID,
1591
+				'action'       => 'preview_message'
1592
+			),
1593
+			$this->_admin_base_url
1594
+		);
1595
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1596
+				'event_espresso') . '</a>';
1597
+        
1598
+        
1599
+		//setup context switcher
1600
+		$context_switcher_args = array(
1601
+			'page'    => 'espresso_messages',
1602
+			'action'  => 'edit_message_template',
1603
+			'id'      => $GRP_ID,
1604
+			'context' => $context,
1605
+			'extra'   => $preview_button
1606
+		);
1607
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1608
+        
1609
+        
1610
+		//main box
1611
+		$this->_template_args['template_fields']                         = $template_fields;
1612
+		$this->_template_args['sidebar_box_id']                          = 'details';
1613
+		$this->_template_args['action']                                  = $action;
1614
+		$this->_template_args['context']                                 = $context;
1615
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1616
+		$this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();
1617
+        
1618
+        
1619
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1620
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1621
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1622
+        
1623
+		$this->_template_path = $this->_template_args['GRP_ID']
1624
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1625
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1626
+        
1627
+		//send along EE_Message_Template_Group object for further template use.
1628
+		$this->_template_args['MTP'] = $message_template_group;
1629
+        
1630
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
1631
+			$this->_template_args, true);
1632
+        
1633
+        
1634
+		//finally, let's set the admin_page title
1635
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1636
+        
1637
+        
1638
+		//we need to take care of setting the shortcodes property for use elsewhere.
1639
+		$this->_set_shortcodes();
1640
+        
1641
+        
1642
+		//final template wrapper
1643
+		$this->display_admin_page_with_sidebar();
1644
+	}
1645
+    
1646
+    
1647
+	public function filter_tinymce_init($mceInit, $editor_id)
1648
+	{
1649
+		return $mceInit;
1650
+	}
1651
+    
1652
+    
1653
+	public function add_context_switcher()
1654
+	{
1655
+		return $this->_context_switcher;
1656
+	}
1657
+    
1658
+	public function _add_form_element_before()
1659
+	{
1660
+		return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1661
+	}
1662
+    
1663
+	public function _add_form_element_after()
1664
+	{
1665
+		return '</form>';
1666
+	}
1667
+    
1668
+    
1669
+	/**
1670
+	 * This executes switching the template pack for a message template.
1671
+	 *
1672
+	 * @since 4.5.0
1673
+	 *
1674
+	 */
1675
+	public function switch_template_pack()
1676
+	{
1677
+		$GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1678
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1679
+        
1680
+		//verify we have needed values.
1681
+		if (empty($GRP_ID) || empty($template_pack)) {
1682
+			$this->_template_args['error'] = true;
1683
+			EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'),
1684
+				__FILE__, __FUNCTION__, __LINE__);
1685
+		} else {
1686
+			//get template, set the new template_pack and then reset to default
1687
+			/** @type EE_Message_Template_Group $message_template_group */
1688
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1689 1689
             
1690
-            $message_template_group->set_template_pack_name($template_pack);
1691
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1692
-            $this->_req_data['mt']   = $message_template_group->message_type();
1690
+			$message_template_group->set_template_pack_name($template_pack);
1691
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1692
+			$this->_req_data['mt']   = $message_template_group->message_type();
1693 1693
             
1694
-            $query_args = $this->_reset_to_default_template();
1694
+			$query_args = $this->_reset_to_default_template();
1695 1695
             
1696
-            if (empty($query_args['id'])) {
1697
-                EE_Error::add_error(
1698
-                    __(
1699
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1700
-                        'event_espresso'
1701
-                    ),
1702
-                    __FILE__, __FUNCTION__, __LINE__
1703
-                );
1704
-                $this->_template_args['error'] = true;
1705
-            } else {
1706
-                $template_label       = $message_template_group->get_template_pack()->label;
1707
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1708
-                EE_Error::add_success(
1709
-                    sprintf(
1710
-                        __(
1711
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1712
-                            'event_espresso'
1713
-                        ),
1714
-                        $template_label,
1715
-                        $template_pack_labels->template_pack
1716
-                    )
1717
-                );
1718
-                //generate the redirect url for js.
1719
-                $url                                          = self::add_query_args_and_nonce($query_args,
1720
-                    $this->_admin_base_url);
1721
-                $this->_template_args['data']['redirect_url'] = $url;
1722
-                $this->_template_args['success']              = true;
1723
-            }
1696
+			if (empty($query_args['id'])) {
1697
+				EE_Error::add_error(
1698
+					__(
1699
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1700
+						'event_espresso'
1701
+					),
1702
+					__FILE__, __FUNCTION__, __LINE__
1703
+				);
1704
+				$this->_template_args['error'] = true;
1705
+			} else {
1706
+				$template_label       = $message_template_group->get_template_pack()->label;
1707
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1708
+				EE_Error::add_success(
1709
+					sprintf(
1710
+						__(
1711
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1712
+							'event_espresso'
1713
+						),
1714
+						$template_label,
1715
+						$template_pack_labels->template_pack
1716
+					)
1717
+				);
1718
+				//generate the redirect url for js.
1719
+				$url                                          = self::add_query_args_and_nonce($query_args,
1720
+					$this->_admin_base_url);
1721
+				$this->_template_args['data']['redirect_url'] = $url;
1722
+				$this->_template_args['success']              = true;
1723
+			}
1724 1724
             
1725
-            $this->_return_json();
1725
+			$this->_return_json();
1726 1726
             
1727
-        }
1728
-    }
1729
-    
1730
-    
1731
-    /**
1732
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1733
-     * they want.
1734
-     *
1735
-     * @access protected
1736
-     * @return array|null
1737
-     */
1738
-    protected function _reset_to_default_template()
1739
-    {
1740
-        
1741
-        $templates = array();
1742
-        $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1743
-        //we need to make sure we've got the info we need.
1744
-        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
1745
-            EE_Error::add_error(
1746
-                __(
1747
-                    '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.',
1748
-                    'event_espresso'
1749
-                ),
1750
-                __FILE__, __FUNCTION__, __LINE__
1751
-            );
1752
-        }
1753
-        
1754
-        // all templates will be reset to whatever the defaults are
1755
-        // for the global template matching the messenger and message type.
1756
-        $success = ! empty($GRP_ID) ? true : false;
1757
-        
1758
-        if ($success) {
1727
+		}
1728
+	}
1729
+    
1730
+    
1731
+	/**
1732
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1733
+	 * they want.
1734
+	 *
1735
+	 * @access protected
1736
+	 * @return array|null
1737
+	 */
1738
+	protected function _reset_to_default_template()
1739
+	{
1740
+        
1741
+		$templates = array();
1742
+		$GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1743
+		//we need to make sure we've got the info we need.
1744
+		if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
1745
+			EE_Error::add_error(
1746
+				__(
1747
+					'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.',
1748
+					'event_espresso'
1749
+				),
1750
+				__FILE__, __FUNCTION__, __LINE__
1751
+			);
1752
+		}
1753
+        
1754
+		// all templates will be reset to whatever the defaults are
1755
+		// for the global template matching the messenger and message type.
1756
+		$success = ! empty($GRP_ID) ? true : false;
1757
+        
1758
+		if ($success) {
1759 1759
             
1760
-            //let's first determine if the incoming template is a global template,
1761
-            // if it isn't then we need to get the global template matching messenger and message type.
1762
-            //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
1760
+			//let's first determine if the incoming template is a global template,
1761
+			// if it isn't then we need to get the global template matching messenger and message type.
1762
+			//$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
1763 1763
             
1764 1764
             
1765
-            //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1766
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
1765
+			//note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1766
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
1767 1767
             
1768
-            if ($success) {
1769
-                // if successfully deleted, lets generate the new ones.
1770
-                // Note. We set GLOBAL to true, because resets on ANY template
1771
-                // will use the related global template defaults for regeneration.
1772
-                // This means that if a custom template is reset it resets to whatever the related global template is.
1773
-                // HOWEVER, we DO keep the template pack and template variation set
1774
-                // for the current custom template when resetting.
1775
-                $templates = $this->_generate_new_templates(
1776
-                    $this->_req_data['msgr'],
1777
-                    $this->_req_data['mt'],
1778
-                    $GRP_ID,
1779
-                    true
1780
-                );
1781
-            }
1768
+			if ($success) {
1769
+				// if successfully deleted, lets generate the new ones.
1770
+				// Note. We set GLOBAL to true, because resets on ANY template
1771
+				// will use the related global template defaults for regeneration.
1772
+				// This means that if a custom template is reset it resets to whatever the related global template is.
1773
+				// HOWEVER, we DO keep the template pack and template variation set
1774
+				// for the current custom template when resetting.
1775
+				$templates = $this->_generate_new_templates(
1776
+					$this->_req_data['msgr'],
1777
+					$this->_req_data['mt'],
1778
+					$GRP_ID,
1779
+					true
1780
+				);
1781
+			}
1782 1782
             
1783
-        }
1784
-        
1785
-        //any error messages?
1786
-        if ( ! $success) {
1787
-            EE_Error::add_error(
1788
-                __('Something went wrong with deleting existing templates. Unable to reset to default',
1789
-                    'event_espresso'),
1790
-                __FILE__, __FUNCTION__, __LINE__
1791
-            );
1792
-        }
1793
-        
1794
-        //all good, let's add a success message!
1795
-        if ($success && ! empty($templates)) {
1796
-            $templates = $templates[0]; //the info for the template we generated is the first element in the returned array.
1797
-            EE_Error::overwrite_success();
1798
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
1799
-        }
1800
-        
1801
-        
1802
-        $query_args = array(
1803
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
1804
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
1805
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
1806
-        );
1807
-        
1808
-        //if called via ajax then we return query args otherwise redirect
1809
-        if (defined('DOING_AJAX') && DOING_AJAX) {
1810
-            return $query_args;
1811
-        } else {
1812
-            $this->_redirect_after_action(false, '', '', $query_args, true);
1783
+		}
1784
+        
1785
+		//any error messages?
1786
+		if ( ! $success) {
1787
+			EE_Error::add_error(
1788
+				__('Something went wrong with deleting existing templates. Unable to reset to default',
1789
+					'event_espresso'),
1790
+				__FILE__, __FUNCTION__, __LINE__
1791
+			);
1792
+		}
1793
+        
1794
+		//all good, let's add a success message!
1795
+		if ($success && ! empty($templates)) {
1796
+			$templates = $templates[0]; //the info for the template we generated is the first element in the returned array.
1797
+			EE_Error::overwrite_success();
1798
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
1799
+		}
1800
+        
1801
+        
1802
+		$query_args = array(
1803
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
1804
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
1805
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
1806
+		);
1807
+        
1808
+		//if called via ajax then we return query args otherwise redirect
1809
+		if (defined('DOING_AJAX') && DOING_AJAX) {
1810
+			return $query_args;
1811
+		} else {
1812
+			$this->_redirect_after_action(false, '', '', $query_args, true);
1813 1813
             
1814
-            return null;
1815
-        }
1816
-    }
1817
-    
1818
-    
1819
-    /**
1820
-     * Retrieve and set the message preview for display.
1821
-     *
1822
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1823
-     *
1824
-     * @return string
1825
-     */
1826
-    public function _preview_message($send = false)
1827
-    {
1828
-        //first make sure we've got the necessary parameters
1829
-        if (
1830
-        ! isset(
1831
-            $this->_req_data['message_type'],
1832
-            $this->_req_data['messenger'],
1833
-            $this->_req_data['messenger'],
1834
-            $this->_req_data['GRP_ID']
1835
-        )
1836
-        ) {
1837
-            EE_Error::add_error(
1838
-                __('Missing necessary parameters for displaying preview', 'event_espresso'),
1839
-                __FILE__, __FUNCTION__, __LINE__
1840
-            );
1841
-        }
1842
-        
1843
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
1844
-        
1845
-        
1846
-        //get the preview!
1847
-        $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
1848
-            $this->_req_data['messenger'], $send);
1849
-        
1850
-        if ($send) {
1851
-            return $preview;
1852
-        }
1853
-        
1854
-        //let's add a button to go back to the edit view
1855
-        $query_args             = array(
1856
-            'id'      => $this->_req_data['GRP_ID'],
1857
-            'context' => $this->_req_data['context'],
1858
-            'action'  => 'edit_message_template'
1859
-        );
1860
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1861
-        $preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1862
-                'event_espresso') . '</a>';
1863
-        $message_types          = $this->get_installed_message_types();
1864
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1865
-        $active_messenger_label = $active_messenger instanceof EE_messenger
1866
-            ? ucwords($active_messenger->label['singular'])
1867
-            : esc_html__('Unknown Messenger', 'event_espresso');
1868
-        //let's provide a helpful title for context
1869
-        $preview_title = sprintf(
1870
-            __('Viewing Preview for %s %s Message Template', 'event_espresso'),
1871
-            $active_messenger_label,
1872
-            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
1873
-        );
1874
-        //setup display of preview.
1875
-        $this->_admin_page_title                    = $preview_title;
1876
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1877
-        $this->_template_args['data']['force_json'] = true;
1878
-        
1879
-        return '';
1880
-    }
1881
-    
1882
-    
1883
-    /**
1884
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
1885
-     * gets called automatically.
1886
-     *
1887
-     * @since 4.5.0
1888
-     *
1889
-     * @return string
1890
-     */
1891
-    protected function _display_preview_message()
1892
-    {
1893
-        $this->display_admin_page_with_no_sidebar();
1894
-    }
1895
-    
1896
-    
1897
-    /**
1898
-     * registers metaboxes that should show up on the "edit_message_template" page
1899
-     *
1900
-     * @access protected
1901
-     * @return void
1902
-     */
1903
-    protected function _register_edit_meta_boxes()
1904
-    {
1905
-        add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'),
1906
-            array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');
1907
-        add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'),
1908
-            $this->_current_screen->id, 'side', 'high');
1909
-        add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'),
1910
-            $this->_current_screen->id, 'side', 'high');
1911
-    }
1912
-    
1913
-    
1914
-    /**
1915
-     * metabox content for all template pack and variation selection.
1916
-     *
1917
-     * @since 4.5.0
1918
-     *
1919
-     * @return string
1920
-     */
1921
-    public function template_pack_meta_box()
1922
-    {
1923
-        $this->_set_message_template_group();
1924
-        
1925
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
1926
-        
1927
-        $tp_select_values = array();
1928
-        
1929
-        foreach ($tp_collection as $tp) {
1930
-            //only include template packs that support this messenger and message type!
1931
-            $supports = $tp->get_supports();
1932
-            if (
1933
-                ! isset($supports[$this->_message_template_group->messenger()])
1934
-                || ! in_array(
1935
-                    $this->_message_template_group->message_type(),
1936
-                    $supports[$this->_message_template_group->messenger()]
1937
-                )
1938
-            ) {
1939
-                //not supported
1940
-                continue;
1941
-            }
1814
+			return null;
1815
+		}
1816
+	}
1817
+    
1818
+    
1819
+	/**
1820
+	 * Retrieve and set the message preview for display.
1821
+	 *
1822
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1823
+	 *
1824
+	 * @return string
1825
+	 */
1826
+	public function _preview_message($send = false)
1827
+	{
1828
+		//first make sure we've got the necessary parameters
1829
+		if (
1830
+		! isset(
1831
+			$this->_req_data['message_type'],
1832
+			$this->_req_data['messenger'],
1833
+			$this->_req_data['messenger'],
1834
+			$this->_req_data['GRP_ID']
1835
+		)
1836
+		) {
1837
+			EE_Error::add_error(
1838
+				__('Missing necessary parameters for displaying preview', 'event_espresso'),
1839
+				__FILE__, __FUNCTION__, __LINE__
1840
+			);
1841
+		}
1842
+        
1843
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
1844
+        
1845
+        
1846
+		//get the preview!
1847
+		$preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
1848
+			$this->_req_data['messenger'], $send);
1849
+        
1850
+		if ($send) {
1851
+			return $preview;
1852
+		}
1853
+        
1854
+		//let's add a button to go back to the edit view
1855
+		$query_args             = array(
1856
+			'id'      => $this->_req_data['GRP_ID'],
1857
+			'context' => $this->_req_data['context'],
1858
+			'action'  => 'edit_message_template'
1859
+		);
1860
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1861
+		$preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1862
+				'event_espresso') . '</a>';
1863
+		$message_types          = $this->get_installed_message_types();
1864
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1865
+		$active_messenger_label = $active_messenger instanceof EE_messenger
1866
+			? ucwords($active_messenger->label['singular'])
1867
+			: esc_html__('Unknown Messenger', 'event_espresso');
1868
+		//let's provide a helpful title for context
1869
+		$preview_title = sprintf(
1870
+			__('Viewing Preview for %s %s Message Template', 'event_espresso'),
1871
+			$active_messenger_label,
1872
+			ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
1873
+		);
1874
+		//setup display of preview.
1875
+		$this->_admin_page_title                    = $preview_title;
1876
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1877
+		$this->_template_args['data']['force_json'] = true;
1878
+        
1879
+		return '';
1880
+	}
1881
+    
1882
+    
1883
+	/**
1884
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
1885
+	 * gets called automatically.
1886
+	 *
1887
+	 * @since 4.5.0
1888
+	 *
1889
+	 * @return string
1890
+	 */
1891
+	protected function _display_preview_message()
1892
+	{
1893
+		$this->display_admin_page_with_no_sidebar();
1894
+	}
1895
+    
1896
+    
1897
+	/**
1898
+	 * registers metaboxes that should show up on the "edit_message_template" page
1899
+	 *
1900
+	 * @access protected
1901
+	 * @return void
1902
+	 */
1903
+	protected function _register_edit_meta_boxes()
1904
+	{
1905
+		add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'),
1906
+			array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');
1907
+		add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'),
1908
+			$this->_current_screen->id, 'side', 'high');
1909
+		add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'),
1910
+			$this->_current_screen->id, 'side', 'high');
1911
+	}
1912
+    
1913
+    
1914
+	/**
1915
+	 * metabox content for all template pack and variation selection.
1916
+	 *
1917
+	 * @since 4.5.0
1918
+	 *
1919
+	 * @return string
1920
+	 */
1921
+	public function template_pack_meta_box()
1922
+	{
1923
+		$this->_set_message_template_group();
1924
+        
1925
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
1926
+        
1927
+		$tp_select_values = array();
1928
+        
1929
+		foreach ($tp_collection as $tp) {
1930
+			//only include template packs that support this messenger and message type!
1931
+			$supports = $tp->get_supports();
1932
+			if (
1933
+				! isset($supports[$this->_message_template_group->messenger()])
1934
+				|| ! in_array(
1935
+					$this->_message_template_group->message_type(),
1936
+					$supports[$this->_message_template_group->messenger()]
1937
+				)
1938
+			) {
1939
+				//not supported
1940
+				continue;
1941
+			}
1942 1942
             
1943
-            $tp_select_values[] = array(
1944
-                'text' => $tp->label,
1945
-                'id'   => $tp->dbref
1946
-            );
1947
-        }
1948
-        
1949
-        //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack.  This still allows for the odd template pack to override.
1950
-        if (empty($tp_select_values)) {
1951
-            $tp_select_values[] = array(
1952
-                'text' => __('Default', 'event_espresso'),
1953
-                'id'   => 'default'
1954
-            );
1955
-        }
1956
-        
1957
-        //setup variation select values for the currently selected template.
1958
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
1959
-            $this->_message_template_group->messenger(),
1960
-            $this->_message_template_group->message_type()
1961
-        );
1962
-        $variations_select_values = array();
1963
-        foreach ($variations as $variation => $label) {
1964
-            $variations_select_values[] = array(
1965
-                'text' => $label,
1966
-                'id'   => $variation
1967
-            );
1968
-        }
1969
-        
1970
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1971
-        
1972
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1973
-            'MTP_template_pack',
1974
-            $tp_select_values,
1975
-            $this->_message_template_group->get_template_pack_name()
1976
-        );
1977
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
1978
-            'MTP_template_variation',
1979
-            $variations_select_values,
1980
-            $this->_message_template_group->get_template_pack_variation()
1981
-        );
1982
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
1983
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
1984
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1985
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1986
-        
1987
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1988
-        
1989
-        EEH_Template::display_template($template, $template_args);
1990
-    }
1991
-    
1992
-    
1993
-    /**
1994
-     * This meta box holds any extra actions related to Message Templates
1995
-     * For now, this includes Resetting templates to defaults and sending a test email.
1996
-     *
1997
-     * @access  public
1998
-     * @return void
1999
-     * @throws \EE_Error
2000
-     */
2001
-    public function extra_actions_meta_box()
2002
-    {
2003
-        $template_form_fields = array();
2004
-        
2005
-        $extra_args = array(
2006
-            'msgr'   => $this->_message_template_group->messenger(),
2007
-            'mt'     => $this->_message_template_group->message_type(),
2008
-            'GRP_ID' => $this->_message_template_group->GRP_ID()
2009
-        );
2010
-        //first we need to see if there are any fields
2011
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2012
-        
2013
-        if ( ! empty($fields)) {
2014
-            //yup there be fields
2015
-            foreach ($fields as $field => $config) {
2016
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2017
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2018
-                $default  = isset($config['default']) ? $config['default'] : '';
2019
-                $default  = isset($config['value']) ? $config['value'] : $default;
1943
+			$tp_select_values[] = array(
1944
+				'text' => $tp->label,
1945
+				'id'   => $tp->dbref
1946
+			);
1947
+		}
1948
+        
1949
+		//if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack.  This still allows for the odd template pack to override.
1950
+		if (empty($tp_select_values)) {
1951
+			$tp_select_values[] = array(
1952
+				'text' => __('Default', 'event_espresso'),
1953
+				'id'   => 'default'
1954
+			);
1955
+		}
1956
+        
1957
+		//setup variation select values for the currently selected template.
1958
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
1959
+			$this->_message_template_group->messenger(),
1960
+			$this->_message_template_group->message_type()
1961
+		);
1962
+		$variations_select_values = array();
1963
+		foreach ($variations as $variation => $label) {
1964
+			$variations_select_values[] = array(
1965
+				'text' => $label,
1966
+				'id'   => $variation
1967
+			);
1968
+		}
1969
+        
1970
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1971
+        
1972
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1973
+			'MTP_template_pack',
1974
+			$tp_select_values,
1975
+			$this->_message_template_group->get_template_pack_name()
1976
+		);
1977
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
1978
+			'MTP_template_variation',
1979
+			$variations_select_values,
1980
+			$this->_message_template_group->get_template_pack_variation()
1981
+		);
1982
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
1983
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
1984
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1985
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1986
+        
1987
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1988
+        
1989
+		EEH_Template::display_template($template, $template_args);
1990
+	}
1991
+    
1992
+    
1993
+	/**
1994
+	 * This meta box holds any extra actions related to Message Templates
1995
+	 * For now, this includes Resetting templates to defaults and sending a test email.
1996
+	 *
1997
+	 * @access  public
1998
+	 * @return void
1999
+	 * @throws \EE_Error
2000
+	 */
2001
+	public function extra_actions_meta_box()
2002
+	{
2003
+		$template_form_fields = array();
2004
+        
2005
+		$extra_args = array(
2006
+			'msgr'   => $this->_message_template_group->messenger(),
2007
+			'mt'     => $this->_message_template_group->message_type(),
2008
+			'GRP_ID' => $this->_message_template_group->GRP_ID()
2009
+		);
2010
+		//first we need to see if there are any fields
2011
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2012
+        
2013
+		if ( ! empty($fields)) {
2014
+			//yup there be fields
2015
+			foreach ($fields as $field => $config) {
2016
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2017
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2018
+				$default  = isset($config['default']) ? $config['default'] : '';
2019
+				$default  = isset($config['value']) ? $config['value'] : $default;
2020 2020
                 
2021
-                // if type is hidden and the value is empty
2022
-                // something may have gone wrong so let's correct with the defaults
2023
-                $fix              = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])
2024
-                    ? $default
2025
-                    : '';
2026
-                $existing[$field] = isset($existing[$field]) && empty($fix)
2027
-                    ? $existing[$field]
2028
-                    : $fix;
2021
+				// if type is hidden and the value is empty
2022
+				// something may have gone wrong so let's correct with the defaults
2023
+				$fix              = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])
2024
+					? $default
2025
+					: '';
2026
+				$existing[$field] = isset($existing[$field]) && empty($fix)
2027
+					? $existing[$field]
2028
+					: $fix;
2029 2029
                 
2030
-                $template_form_fields[$field_id] = array(
2031
-                    'name'       => 'test_settings_fld[' . $field . ']',
2032
-                    'label'      => $config['label'],
2033
-                    'input'      => $config['input'],
2034
-                    'type'       => $config['type'],
2035
-                    'required'   => $config['required'],
2036
-                    'validation' => $config['validation'],
2037
-                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2038
-                    'css_class'  => $config['css_class'],
2039
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2040
-                    'default'    => $default,
2041
-                    'format'     => $config['format']
2042
-                );
2043
-            }
2044
-        }
2045
-        
2046
-        $test_settings_fields = ! empty($template_form_fields)
2047
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2048
-            : '';
2049
-        
2050
-        $test_settings_html = '';
2051
-        //print out $test_settings_fields
2052
-        if ( ! empty($test_settings_fields)) {
2053
-            echo $test_settings_fields;
2054
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2055
-            $test_settings_html .= 'name="test_button" value="';
2056
-            $test_settings_html .= __('Test Send', 'event_espresso');
2057
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2058
-        }
2059
-        
2060
-        //and button
2061
-        $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2062
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2063
-        $test_settings_html .= $this->get_action_link_or_button(
2064
-            'reset_to_default',
2065
-            'reset',
2066
-            $extra_args,
2067
-            'button-primary reset-default-button'
2068
-        );
2069
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2070
-        echo $test_settings_html;
2071
-    }
2072
-    
2073
-    
2074
-    /**
2075
-     * This returns the shortcode selector skeleton for a given context and field.
2076
-     *
2077
-     * @since 4.9.rc.000
2078
-     *
2079
-     * @param string $field           The name of the field retrieving shortcodes for.
2080
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2081
-     *
2082
-     * @return string
2083
-     */
2084
-    protected function _get_shortcode_selector($field, $linked_input_id)
2085
-    {
2086
-        $template_args = array(
2087
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2088
-            'fieldname'       => $field,
2089
-            'linked_input_id' => $linked_input_id
2090
-        );
2091
-        
2092
-        return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2093
-            $template_args, true);
2094
-    }
2095
-    
2096
-    
2097
-    /**
2098
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2099
-     * page)
2100
-     *
2101
-     * @access public
2102
-     * @return void
2103
-     */
2104
-    public function shortcode_meta_box()
2105
-    {
2106
-        $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2107
-        //$messenger = $this->_message_template_group->messenger_obj();
2108
-        //now let's set the content depending on the status of the shortcodes array
2109
-        if (empty($shortcodes)) {
2110
-            $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2111
-            echo $content;
2112
-        } else {
2113
-            //$alt = 0;
2114
-            ?>
2030
+				$template_form_fields[$field_id] = array(
2031
+					'name'       => 'test_settings_fld[' . $field . ']',
2032
+					'label'      => $config['label'],
2033
+					'input'      => $config['input'],
2034
+					'type'       => $config['type'],
2035
+					'required'   => $config['required'],
2036
+					'validation' => $config['validation'],
2037
+					'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2038
+					'css_class'  => $config['css_class'],
2039
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2040
+					'default'    => $default,
2041
+					'format'     => $config['format']
2042
+				);
2043
+			}
2044
+		}
2045
+        
2046
+		$test_settings_fields = ! empty($template_form_fields)
2047
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2048
+			: '';
2049
+        
2050
+		$test_settings_html = '';
2051
+		//print out $test_settings_fields
2052
+		if ( ! empty($test_settings_fields)) {
2053
+			echo $test_settings_fields;
2054
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2055
+			$test_settings_html .= 'name="test_button" value="';
2056
+			$test_settings_html .= __('Test Send', 'event_espresso');
2057
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2058
+		}
2059
+        
2060
+		//and button
2061
+		$test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2062
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2063
+		$test_settings_html .= $this->get_action_link_or_button(
2064
+			'reset_to_default',
2065
+			'reset',
2066
+			$extra_args,
2067
+			'button-primary reset-default-button'
2068
+		);
2069
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2070
+		echo $test_settings_html;
2071
+	}
2072
+    
2073
+    
2074
+	/**
2075
+	 * This returns the shortcode selector skeleton for a given context and field.
2076
+	 *
2077
+	 * @since 4.9.rc.000
2078
+	 *
2079
+	 * @param string $field           The name of the field retrieving shortcodes for.
2080
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2081
+	 *
2082
+	 * @return string
2083
+	 */
2084
+	protected function _get_shortcode_selector($field, $linked_input_id)
2085
+	{
2086
+		$template_args = array(
2087
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2088
+			'fieldname'       => $field,
2089
+			'linked_input_id' => $linked_input_id
2090
+		);
2091
+        
2092
+		return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2093
+			$template_args, true);
2094
+	}
2095
+    
2096
+    
2097
+	/**
2098
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2099
+	 * page)
2100
+	 *
2101
+	 * @access public
2102
+	 * @return void
2103
+	 */
2104
+	public function shortcode_meta_box()
2105
+	{
2106
+		$shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2107
+		//$messenger = $this->_message_template_group->messenger_obj();
2108
+		//now let's set the content depending on the status of the shortcodes array
2109
+		if (empty($shortcodes)) {
2110
+			$content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2111
+			echo $content;
2112
+		} else {
2113
+			//$alt = 0;
2114
+			?>
2115 2115
             <div
2116 2116
                 style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div>
2117 2117
             <p class="small-text"><?php printf(__('You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2118
-                    'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>
2118
+					'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>
2119 2119
             <?php
2120
-        }
2121
-        
2122
-        
2123
-    }
2124
-    
2125
-    
2126
-    /**
2127
-     * used to set the $_shortcodes property for when its needed elsewhere.
2128
-     *
2129
-     * @access protected
2130
-     * @return void
2131
-     */
2132
-    protected function _set_shortcodes()
2133
-    {
2134
-        
2135
-        //no need to run this if the property is already set
2136
-        if ( ! empty($this->_shortcodes)) {
2137
-            return;
2138
-        }
2139
-        
2140
-        $this->_shortcodes = $this->_get_shortcodes();
2141
-    }
2142
-    
2143
-    
2144
-    /**
2145
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2146
-     * property)
2147
-     *
2148
-     * @access  protected
2149
-     *
2150
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2151
-     *                         for. Defaults to all (for the given context)
2152
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2153
-     *
2154
-     * @return array          Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2155
-     *                        true just an array of shortcode/label pairs.
2156
-     */
2157
-    protected function _get_shortcodes($fields = array(), $merged = true)
2158
-    {
2159
-        $this->_set_message_template_group();
2160
-        
2161
-        //we need the messenger and message template to retrieve the valid shortcodes array.
2162
-        $GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;
2163
-        $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());
2164
-        
2165
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2166
-    }
2167
-    
2168
-    
2169
-    /**
2170
-     * This sets the _message_template property (containing the called message_template object)
2171
-     *
2172
-     * @access protected
2173
-     * @return  void
2174
-     */
2175
-    protected function _set_message_template_group()
2176
-    {
2177
-        
2178
-        if ( ! empty($this->_message_template_group)) {
2179
-            return;
2180
-        } //get out if this is already set.
2181
-        
2182
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2183
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2184
-        
2185
-        //let's get the message templates
2186
-        $MTP = EEM_Message_Template_Group::instance();
2187
-        
2188
-        if (empty($GRP_ID)) {
2189
-            $this->_message_template_group = $MTP->create_default_object();
2190
-        } else {
2191
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2192
-        }
2193
-        
2194
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2195
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2196
-        
2197
-    }
2198
-    
2199
-    
2200
-    /**
2201
-     * sets up a context switcher for edit forms
2202
-     *
2203
-     * @access  protected
2204
-     *
2205
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2206
-     * @param array                      $args                  various things the context switcher needs.
2207
-     *
2208
-     */
2209
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2210
-    {
2211
-        $context_details = $template_group_object->contexts_config();
2212
-        $context_label   = $template_group_object->context_label();
2213
-        ob_start();
2214
-        ?>
2120
+		}
2121
+        
2122
+        
2123
+	}
2124
+    
2125
+    
2126
+	/**
2127
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2128
+	 *
2129
+	 * @access protected
2130
+	 * @return void
2131
+	 */
2132
+	protected function _set_shortcodes()
2133
+	{
2134
+        
2135
+		//no need to run this if the property is already set
2136
+		if ( ! empty($this->_shortcodes)) {
2137
+			return;
2138
+		}
2139
+        
2140
+		$this->_shortcodes = $this->_get_shortcodes();
2141
+	}
2142
+    
2143
+    
2144
+	/**
2145
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2146
+	 * property)
2147
+	 *
2148
+	 * @access  protected
2149
+	 *
2150
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2151
+	 *                         for. Defaults to all (for the given context)
2152
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2153
+	 *
2154
+	 * @return array          Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2155
+	 *                        true just an array of shortcode/label pairs.
2156
+	 */
2157
+	protected function _get_shortcodes($fields = array(), $merged = true)
2158
+	{
2159
+		$this->_set_message_template_group();
2160
+        
2161
+		//we need the messenger and message template to retrieve the valid shortcodes array.
2162
+		$GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;
2163
+		$context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());
2164
+        
2165
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2166
+	}
2167
+    
2168
+    
2169
+	/**
2170
+	 * This sets the _message_template property (containing the called message_template object)
2171
+	 *
2172
+	 * @access protected
2173
+	 * @return  void
2174
+	 */
2175
+	protected function _set_message_template_group()
2176
+	{
2177
+        
2178
+		if ( ! empty($this->_message_template_group)) {
2179
+			return;
2180
+		} //get out if this is already set.
2181
+        
2182
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2183
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2184
+        
2185
+		//let's get the message templates
2186
+		$MTP = EEM_Message_Template_Group::instance();
2187
+        
2188
+		if (empty($GRP_ID)) {
2189
+			$this->_message_template_group = $MTP->create_default_object();
2190
+		} else {
2191
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2192
+		}
2193
+        
2194
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2195
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2196
+        
2197
+	}
2198
+    
2199
+    
2200
+	/**
2201
+	 * sets up a context switcher for edit forms
2202
+	 *
2203
+	 * @access  protected
2204
+	 *
2205
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2206
+	 * @param array                      $args                  various things the context switcher needs.
2207
+	 *
2208
+	 */
2209
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2210
+	{
2211
+		$context_details = $template_group_object->contexts_config();
2212
+		$context_label   = $template_group_object->context_label();
2213
+		ob_start();
2214
+		?>
2215 2215
         <div class="ee-msg-switcher-container">
2216 2216
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2217 2217
                 <?php
2218
-                foreach ($args as $name => $value) {
2219
-                    if ($name == 'context' || empty($value) || $name == 'extra') {
2220
-                        continue;
2221
-                    }
2222
-                    ?>
2218
+				foreach ($args as $name => $value) {
2219
+					if ($name == 'context' || empty($value) || $name == 'extra') {
2220
+						continue;
2221
+					}
2222
+					?>
2223 2223
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2224 2224
                     <?php
2225
-                }
2226
-                //setup nonce_url
2227
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2228
-                ?>
2225
+				}
2226
+				//setup nonce_url
2227
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2228
+				?>
2229 2229
                 <select name="context">
2230 2230
                     <?php
2231
-                    $context_templates = $template_group_object->context_templates();
2232
-                    if (is_array($context_templates)) :
2233
-                        foreach ($context_templates as $context => $template_fields) :
2234
-                            $checked = ($context == $args['context']) ? 'selected="selected"' : '';
2235
-                            ?>
2231
+					$context_templates = $template_group_object->context_templates();
2232
+					if (is_array($context_templates)) :
2233
+						foreach ($context_templates as $context => $template_fields) :
2234
+							$checked = ($context == $args['context']) ? 'selected="selected"' : '';
2235
+							?>
2236 2236
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2237 2237
                                 <?php echo $context_details[$context]['label']; ?>
2238 2238
                             </option>
@@ -2245,1584 +2245,1584 @@  discard block
 block discarded – undo
2245 2245
             <?php echo $args['extra']; ?>
2246 2246
         </div> <!-- end .ee-msg-switcher-container -->
2247 2247
         <?php
2248
-        $output = ob_get_contents();
2249
-        ob_clean();
2250
-        $this->_context_switcher = $output;
2251
-    }
2252
-    
2253
-    
2254
-    /**
2255
-     * utility for sanitizing new values coming in.
2256
-     * Note: this is only used when updating a context.
2257
-     *
2258
-     * @access protected
2259
-     *
2260
-     * @param int $index This helps us know which template field to select from the request array.
2261
-     *
2262
-     * @return array
2263
-     */
2264
-    protected function _set_message_template_column_values($index)
2265
-    {
2266
-        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2267
-            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2268
-                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2269
-            }
2270
-        } /*else {
2248
+		$output = ob_get_contents();
2249
+		ob_clean();
2250
+		$this->_context_switcher = $output;
2251
+	}
2252
+    
2253
+    
2254
+	/**
2255
+	 * utility for sanitizing new values coming in.
2256
+	 * Note: this is only used when updating a context.
2257
+	 *
2258
+	 * @access protected
2259
+	 *
2260
+	 * @param int $index This helps us know which template field to select from the request array.
2261
+	 *
2262
+	 * @return array
2263
+	 */
2264
+	protected function _set_message_template_column_values($index)
2265
+	{
2266
+		if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2267
+			foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2268
+				$this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2269
+			}
2270
+		} /*else {
2271 2271
 			$this->_req_data['MTP_template_fields'][$index]['content'] = $this->_req_data['MTP_template_fields'][$index]['content'];
2272 2272
 		}*/
2273 2273
         
2274 2274
         
2275
-        $set_column_values = array(
2276
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2277
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2278
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2279
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2280
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2281
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2282
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2283
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2284
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2285
-                ? absint($this->_req_data['MTP_is_global'])
2286
-                : 0,
2287
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2288
-                ? absint($this->_req_data['MTP_is_override'])
2289
-                : 0,
2290
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2291
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2292
-        );
2293
-        
2294
-        
2295
-        return $set_column_values;
2296
-    }
2297
-    
2298
-    
2299
-    protected function _insert_or_update_message_template($new = false)
2300
-    {
2301
-        
2302
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2303
-        $success  = 0;
2304
-        $override = false;
2305
-        
2306
-        //setup notices description
2307
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2308
-        
2309
-        //need the message type and messenger objects to be able to use the labels for the notices
2310
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2311
-        $messenger_label  = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';
2312
-        
2313
-        $message_type_slug   = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';
2314
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2315
-        
2316
-        $message_type_label = $message_type_object instanceof EE_message_type
2317
-            ? ucwords($message_type_object->label['singular'])
2318
-            : '';
2319
-        
2320
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2321
-            ? $this->_req_data['MTP_context']
2322
-            : '';
2323
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2324
-        
2325
-        $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2326
-        $item_desc .= 'Message Template';
2327
-        $query_args  = array();
2328
-        $edit_array  = array();
2329
-        $action_desc = '';
2330
-        
2331
-        //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.
2332
-        if ($new) {
2333
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2334
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2335
-                if (empty($edit_array)) {
2336
-                    $success = 0;
2337
-                } else {
2338
-                    $success    = 1;
2339
-                    $edit_array = $edit_array[0];
2340
-                    $query_args = array(
2341
-                        'id'      => $edit_array['GRP_ID'],
2342
-                        'context' => $edit_array['MTP_context'],
2343
-                        'action'  => 'edit_message_template'
2344
-                    );
2345
-                }
2346
-            }
2347
-            $action_desc = 'created';
2348
-        } else {
2349
-            $MTPG = EEM_Message_Template_Group::instance();
2350
-            $MTP  = EEM_Message_Template::instance();
2275
+		$set_column_values = array(
2276
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2277
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2278
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2279
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2280
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2281
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2282
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2283
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2284
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2285
+				? absint($this->_req_data['MTP_is_global'])
2286
+				: 0,
2287
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2288
+				? absint($this->_req_data['MTP_is_override'])
2289
+				: 0,
2290
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2291
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2292
+		);
2293
+        
2294
+        
2295
+		return $set_column_values;
2296
+	}
2297
+    
2298
+    
2299
+	protected function _insert_or_update_message_template($new = false)
2300
+	{
2301
+        
2302
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2303
+		$success  = 0;
2304
+		$override = false;
2305
+        
2306
+		//setup notices description
2307
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2308
+        
2309
+		//need the message type and messenger objects to be able to use the labels for the notices
2310
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2311
+		$messenger_label  = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';
2312
+        
2313
+		$message_type_slug   = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';
2314
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2315
+        
2316
+		$message_type_label = $message_type_object instanceof EE_message_type
2317
+			? ucwords($message_type_object->label['singular'])
2318
+			: '';
2319
+        
2320
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2321
+			? $this->_req_data['MTP_context']
2322
+			: '';
2323
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2324
+        
2325
+		$item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2326
+		$item_desc .= 'Message Template';
2327
+		$query_args  = array();
2328
+		$edit_array  = array();
2329
+		$action_desc = '';
2330
+        
2331
+		//if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.
2332
+		if ($new) {
2333
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2334
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2335
+				if (empty($edit_array)) {
2336
+					$success = 0;
2337
+				} else {
2338
+					$success    = 1;
2339
+					$edit_array = $edit_array[0];
2340
+					$query_args = array(
2341
+						'id'      => $edit_array['GRP_ID'],
2342
+						'context' => $edit_array['MTP_context'],
2343
+						'action'  => 'edit_message_template'
2344
+					);
2345
+				}
2346
+			}
2347
+			$action_desc = 'created';
2348
+		} else {
2349
+			$MTPG = EEM_Message_Template_Group::instance();
2350
+			$MTP  = EEM_Message_Template::instance();
2351 2351
             
2352 2352
             
2353
-            //run update for each template field in displayed context
2354
-            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2355
-                EE_Error::add_error(
2356
-                    __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2357
-                        'event_espresso'),
2358
-                    __FILE__, __FUNCTION__, __LINE__
2359
-                );
2360
-                $success = 0;
2353
+			//run update for each template field in displayed context
2354
+			if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2355
+				EE_Error::add_error(
2356
+					__('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2357
+						'event_espresso'),
2358
+					__FILE__, __FUNCTION__, __LINE__
2359
+				);
2360
+				$success = 0;
2361 2361
                 
2362
-            } else {
2363
-                //first validate all fields!
2364
-                $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2365
-                    $message_type_slug);
2362
+			} else {
2363
+				//first validate all fields!
2364
+				$validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2365
+					$message_type_slug);
2366 2366
                 
2367
-                //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.  WE need to make sure there is no actual error messages in validates.
2368
-                if (is_array($validates) && ! empty($validates)) {
2369
-                    //add the transient so when the form loads we know which fields to highlight
2370
-                    $this->_add_transient('edit_message_template', $validates);
2367
+				//if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.  WE need to make sure there is no actual error messages in validates.
2368
+				if (is_array($validates) && ! empty($validates)) {
2369
+					//add the transient so when the form loads we know which fields to highlight
2370
+					$this->_add_transient('edit_message_template', $validates);
2371 2371
                     
2372
-                    $success = 0;
2372
+					$success = 0;
2373 2373
                     
2374
-                    //setup notices
2375
-                    foreach ($validates as $field => $error) {
2376
-                        if (isset($error['msg'])) {
2377
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2378
-                        }
2379
-                    }
2374
+					//setup notices
2375
+					foreach ($validates as $field => $error) {
2376
+						if (isset($error['msg'])) {
2377
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2378
+						}
2379
+					}
2380 2380
                     
2381
-                } else {
2382
-                    $set_column_values = array();
2383
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2384
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2381
+				} else {
2382
+					$set_column_values = array();
2383
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2384
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2385 2385
                         
2386
-                        $where_cols_n_values = array(
2387
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2388
-                        );
2386
+						$where_cols_n_values = array(
2387
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2388
+						);
2389 2389
                         
2390
-                        $message_template_fields = array(
2391
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2392
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2393
-                            'MTP_context'        => $set_column_values['MTP_context'],
2394
-                            'MTP_content'        => $set_column_values['MTP_content']
2395
-                        );
2396
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2397
-                            if ($updated === false) {
2398
-                                EE_Error::add_error(
2399
-                                    sprintf(
2400
-                                        __('%s field was NOT updated for some reason', 'event_espresso'),
2401
-                                        $template_field
2402
-                                    ),
2403
-                                    __FILE__, __FUNCTION__, __LINE__
2404
-                                );
2405
-                            } else {
2406
-                                $success = 1;
2407
-                            }
2408
-                        }
2409
-                        $action_desc = 'updated';
2410
-                    }
2390
+						$message_template_fields = array(
2391
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2392
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2393
+							'MTP_context'        => $set_column_values['MTP_context'],
2394
+							'MTP_content'        => $set_column_values['MTP_content']
2395
+						);
2396
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2397
+							if ($updated === false) {
2398
+								EE_Error::add_error(
2399
+									sprintf(
2400
+										__('%s field was NOT updated for some reason', 'event_espresso'),
2401
+										$template_field
2402
+									),
2403
+									__FILE__, __FUNCTION__, __LINE__
2404
+								);
2405
+							} else {
2406
+								$success = 1;
2407
+							}
2408
+						}
2409
+						$action_desc = 'updated';
2410
+					}
2411 2411
                     
2412
-                    //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2413
-                    $mtpg_fields = array(
2414
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2415
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2416
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2417
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2418
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2419
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2420
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2421
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2422
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2423
-                            : '',
2424
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2425
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2426
-                            : ''
2427
-                    );
2412
+					//we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2413
+					$mtpg_fields = array(
2414
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2415
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2416
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2417
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2418
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2419
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2420
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2421
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2422
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2423
+							: '',
2424
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2425
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2426
+							: ''
2427
+					);
2428 2428
                     
2429
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2430
-                    $updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2429
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2430
+					$updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2431 2431
                     
2432
-                    if ($updated === false) {
2433
-                        EE_Error::add_error(
2434
-                            sprintf(
2435
-                                __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'),
2436
-                                $set_column_values['GRP_ID']
2437
-                            ),
2438
-                            __FILE__, __FUNCTION__, __LINE__
2439
-                        );
2440
-                    } else {
2441
-                        //k now we need to ensure the template_pack and template_variation fields are set.
2442
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2443
-                            ? $this->_req_data['MTP_template_pack']
2444
-                            : 'default';
2432
+					if ($updated === false) {
2433
+						EE_Error::add_error(
2434
+							sprintf(
2435
+								__('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'),
2436
+								$set_column_values['GRP_ID']
2437
+							),
2438
+							__FILE__, __FUNCTION__, __LINE__
2439
+						);
2440
+					} else {
2441
+						//k now we need to ensure the template_pack and template_variation fields are set.
2442
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2443
+							? $this->_req_data['MTP_template_pack']
2444
+							: 'default';
2445 2445
                         
2446
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2447
-                            ? $this->_req_data['MTP_template_variation']
2448
-                            : 'default';
2446
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2447
+							? $this->_req_data['MTP_template_variation']
2448
+							: 'default';
2449 2449
                         
2450
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2451
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2452
-                            $mtpg_obj->set_template_pack_name($template_pack);
2453
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2454
-                        }
2455
-                        $success = 1;
2456
-                    }
2457
-                }
2458
-            }
2450
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2451
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2452
+							$mtpg_obj->set_template_pack_name($template_pack);
2453
+							$mtpg_obj->set_template_pack_variation($template_variation);
2454
+						}
2455
+						$success = 1;
2456
+					}
2457
+				}
2458
+			}
2459 2459
             
2460
-        }
2461
-        
2462
-        //we return things differently if doing ajax
2463
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2464
-            $this->_template_args['success'] = $success;
2465
-            $this->_template_args['error']   = ! $success ? true : false;
2466
-            $this->_template_args['content'] = '';
2467
-            $this->_template_args['data']    = array(
2468
-                'grpID'        => $edit_array['GRP_ID'],
2469
-                'templateName' => $edit_array['template_name']
2470
-            );
2471
-            if ($success) {
2472
-                EE_Error::overwrite_success();
2473
-                EE_Error::add_success(__('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.',
2474
-                    'event_espresso'));
2475
-            }
2460
+		}
2461
+        
2462
+		//we return things differently if doing ajax
2463
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2464
+			$this->_template_args['success'] = $success;
2465
+			$this->_template_args['error']   = ! $success ? true : false;
2466
+			$this->_template_args['content'] = '';
2467
+			$this->_template_args['data']    = array(
2468
+				'grpID'        => $edit_array['GRP_ID'],
2469
+				'templateName' => $edit_array['template_name']
2470
+			);
2471
+			if ($success) {
2472
+				EE_Error::overwrite_success();
2473
+				EE_Error::add_success(__('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.',
2474
+					'event_espresso'));
2475
+			}
2476 2476
             
2477
-            $this->_return_json();
2478
-        }
2479
-        
2480
-        
2481
-        //was a test send triggered?
2482
-        if (isset($this->_req_data['test_button'])) {
2483
-            EE_Error::overwrite_success();
2484
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2485
-            $override = true;
2486
-        }
2487
-        
2488
-        if (empty($query_args)) {
2489
-            $query_args = array(
2490
-                'id'      => $this->_req_data['GRP_ID'],
2491
-                'context' => $context_slug,
2492
-                'action'  => 'edit_message_template'
2493
-            );
2494
-        }
2495
-        
2496
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2497
-    }
2498
-    
2499
-    
2500
-    /**
2501
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2502
-     *
2503
-     * @param  string $context      what context being tested
2504
-     * @param  string $messenger    messenger being tested
2505
-     * @param  string $message_type message type being tested
2506
-     *
2507
-     */
2508
-    protected function _do_test_send($context, $messenger, $message_type)
2509
-    {
2510
-        //set things up for preview
2511
-        $this->_req_data['messenger']    = $messenger;
2512
-        $this->_req_data['message_type'] = $message_type;
2513
-        $this->_req_data['context']      = $context;
2514
-        $this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2515
-        $active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2516
-        
2517
-        //let's save any existing fields that might be required by the messenger
2518
-        if (
2519
-            isset($this->_req_data['test_settings_fld'])
2520
-            && $active_messenger instanceof EE_messenger
2521
-            && apply_filters(
2522
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2523
-                true,
2524
-                $this->_req_data['test_settings_fld'],
2525
-                $active_messenger
2526
-            )
2527
-        ) {
2528
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2529
-        }
2530
-        
2531
-        $success = $this->_preview_message(true);
2532
-        
2533
-        if ($success) {
2534
-            EE_Error::add_success(__('Test message sent', 'event_espresso'));
2535
-        } else {
2536
-            EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__,
2537
-                __LINE__);
2538
-        }
2539
-    }
2540
-    
2541
-    
2542
-    /**
2543
-     * _generate_new_templates
2544
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2545
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2546
-     * for the event.
2547
-     *
2548
-     *
2549
-     * @param  string $messenger     the messenger we are generating templates for
2550
-     * @param array   $message_types array of message types that the templates are generated for.
2551
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2552
-     *                               indicate the message_template_group being used as the base.
2553
-     *
2554
-     * @param bool    $global
2555
-     *
2556
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
2557
-     *                               encountering problems.
2558
-     * @throws \EE_Error
2559
-     */
2560
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2561
-    {
2562
-        
2563
-        //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates.
2564
-        if (empty($message_types)) {
2565
-            return true;
2566
-        }
2567
-        
2568
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2569
-    }
2570
-    
2571
-    
2572
-    /**
2573
-     * [_trash_or_restore_message_template]
2574
-     *
2575
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2576
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2577
-     *                        an individual context (FALSE).
2578
-     *
2579
-     * @return void
2580
-     */
2581
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
2582
-    {
2583
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2584
-        $MTP = EEM_Message_Template_Group::instance();
2585
-        
2586
-        $success = 1;
2587
-        
2588
-        //incoming GRP_IDs
2589
-        if ($all) {
2590
-            //Checkboxes
2591
-            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2592
-                //if array has more than one element then success message should be plural.
2593
-                //todo: what about nonce?
2594
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2477
+			$this->_return_json();
2478
+		}
2479
+        
2480
+        
2481
+		//was a test send triggered?
2482
+		if (isset($this->_req_data['test_button'])) {
2483
+			EE_Error::overwrite_success();
2484
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2485
+			$override = true;
2486
+		}
2487
+        
2488
+		if (empty($query_args)) {
2489
+			$query_args = array(
2490
+				'id'      => $this->_req_data['GRP_ID'],
2491
+				'context' => $context_slug,
2492
+				'action'  => 'edit_message_template'
2493
+			);
2494
+		}
2495
+        
2496
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2497
+	}
2498
+    
2499
+    
2500
+	/**
2501
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2502
+	 *
2503
+	 * @param  string $context      what context being tested
2504
+	 * @param  string $messenger    messenger being tested
2505
+	 * @param  string $message_type message type being tested
2506
+	 *
2507
+	 */
2508
+	protected function _do_test_send($context, $messenger, $message_type)
2509
+	{
2510
+		//set things up for preview
2511
+		$this->_req_data['messenger']    = $messenger;
2512
+		$this->_req_data['message_type'] = $message_type;
2513
+		$this->_req_data['context']      = $context;
2514
+		$this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2515
+		$active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2516
+        
2517
+		//let's save any existing fields that might be required by the messenger
2518
+		if (
2519
+			isset($this->_req_data['test_settings_fld'])
2520
+			&& $active_messenger instanceof EE_messenger
2521
+			&& apply_filters(
2522
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2523
+				true,
2524
+				$this->_req_data['test_settings_fld'],
2525
+				$active_messenger
2526
+			)
2527
+		) {
2528
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2529
+		}
2530
+        
2531
+		$success = $this->_preview_message(true);
2532
+        
2533
+		if ($success) {
2534
+			EE_Error::add_success(__('Test message sent', 'event_espresso'));
2535
+		} else {
2536
+			EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__,
2537
+				__LINE__);
2538
+		}
2539
+	}
2540
+    
2541
+    
2542
+	/**
2543
+	 * _generate_new_templates
2544
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2545
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2546
+	 * for the event.
2547
+	 *
2548
+	 *
2549
+	 * @param  string $messenger     the messenger we are generating templates for
2550
+	 * @param array   $message_types array of message types that the templates are generated for.
2551
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2552
+	 *                               indicate the message_template_group being used as the base.
2553
+	 *
2554
+	 * @param bool    $global
2555
+	 *
2556
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
2557
+	 *                               encountering problems.
2558
+	 * @throws \EE_Error
2559
+	 */
2560
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2561
+	{
2562
+        
2563
+		//if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates.
2564
+		if (empty($message_types)) {
2565
+			return true;
2566
+		}
2567
+        
2568
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2569
+	}
2570
+    
2571
+    
2572
+	/**
2573
+	 * [_trash_or_restore_message_template]
2574
+	 *
2575
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2576
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2577
+	 *                        an individual context (FALSE).
2578
+	 *
2579
+	 * @return void
2580
+	 */
2581
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
2582
+	{
2583
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2584
+		$MTP = EEM_Message_Template_Group::instance();
2585
+        
2586
+		$success = 1;
2587
+        
2588
+		//incoming GRP_IDs
2589
+		if ($all) {
2590
+			//Checkboxes
2591
+			if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2592
+				//if array has more than one element then success message should be plural.
2593
+				//todo: what about nonce?
2594
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2595 2595
                 
2596
-                //cycle through checkboxes
2597
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2598
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2599
-                    if ( ! $trashed_or_restored) {
2600
-                        $success = 0;
2601
-                    }
2602
-                }
2603
-            } else {
2604
-                //grab single GRP_ID and handle
2605
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
2606
-                if ( ! empty($GRP_ID)) {
2607
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2608
-                    if ( ! $trashed_or_restored) {
2609
-                        $success = 0;
2610
-                    }
2611
-                } else {
2612
-                    $success = 0;
2613
-                }
2614
-            }
2596
+				//cycle through checkboxes
2597
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2598
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2599
+					if ( ! $trashed_or_restored) {
2600
+						$success = 0;
2601
+					}
2602
+				}
2603
+			} else {
2604
+				//grab single GRP_ID and handle
2605
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
2606
+				if ( ! empty($GRP_ID)) {
2607
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2608
+					if ( ! $trashed_or_restored) {
2609
+						$success = 0;
2610
+					}
2611
+				} else {
2612
+					$success = 0;
2613
+				}
2614
+			}
2615 2615
             
2616
-        }
2616
+		}
2617 2617
         
2618
-        $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2618
+		$action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2619 2619
         
2620
-        $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc;
2620
+		$action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc;
2621 2621
         
2622
-        $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
2623
-            'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2622
+		$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
2623
+			'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2624 2624
         
2625
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
2626
-            'event_espresso') : $item_desc;
2625
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
2626
+			'event_espresso') : $item_desc;
2627 2627
         
2628
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
2628
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
2629 2629
         
2630
-    }
2630
+	}
2631 2631
     
2632 2632
     
2633
-    /**
2634
-     * [_delete_message_template]
2635
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2636
-     * @return void
2637
-     */
2638
-    protected function _delete_message_template()
2639
-    {
2640
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2633
+	/**
2634
+	 * [_delete_message_template]
2635
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2636
+	 * @return void
2637
+	 */
2638
+	protected function _delete_message_template()
2639
+	{
2640
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2641 2641
         
2642
-        //checkboxes
2643
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2644
-            //if array has more than one element then success message should be plural
2645
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2642
+		//checkboxes
2643
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2644
+			//if array has more than one element then success message should be plural
2645
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2646 2646
             
2647
-            //cycle through bulk action checkboxes
2648
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2649
-                $success = $this->_delete_mtp_permanently($GRP_ID);
2650
-            }
2651
-        } else {
2652
-            //grab single grp_id and delete
2653
-            $GRP_ID  = absint($this->_req_data['id']);
2654
-            $success = $this->_delete_mtp_permanently($GRP_ID);
2655
-        }
2656
-        
2657
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
2658
-        
2659
-    }
2660
-    
2661
-    
2662
-    /**
2663
-     * helper for permanently deleting a mtP group and all related message_templates
2664
-     *
2665
-     * @param  int  $GRP_ID        The group being deleted
2666
-     * @param  bool $include_group whether to delete the Message Template Group as well.
2667
-     *
2668
-     * @return bool        boolean to indicate the success of the deletes or not.
2669
-     */
2670
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
2671
-    {
2672
-        $success = 1;
2673
-        $MTPG    = EEM_Message_Template_Group::instance();
2674
-        //first let's GET this group
2675
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
2676
-        //then delete permanently all the related Message Templates
2677
-        $deleted = $MTG->delete_related_permanently('Message_Template');
2678
-        
2679
-        if ($deleted === 0) {
2680
-            $success = 0;
2681
-        }
2682
-        
2683
-        //now delete permanently this particular group
2684
-        
2685
-        if ($include_group && ! $MTG->delete_permanently()) {
2686
-            $success = 0;
2687
-        }
2688
-        
2689
-        return $success;
2690
-    }
2691
-    
2692
-    
2693
-    /**
2694
-     *    _learn_more_about_message_templates_link
2695
-     * @access protected
2696
-     * @return string
2697
-     */
2698
-    protected function _learn_more_about_message_templates_link()
2699
-    {
2700
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2701
-            'event_espresso') . '</a>';
2702
-    }
2703
-    
2704
-    
2705
-    /**
2706
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2707
-     * ajax and other routes.
2708
-     * @return void
2709
-     */
2710
-    protected function _settings()
2711
-    {
2712
-        
2713
-        
2714
-        $this->_set_m_mt_settings();
2715
-        
2716
-        $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2717
-        
2718
-        //let's setup the messenger tabs
2719
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],
2720
-            'messenger_links', '|', $selected_messenger);
2721
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2722
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2723
-        
2724
-        $this->display_admin_page_with_sidebar();
2725
-        
2726
-    }
2727
-    
2728
-    
2729
-    /**
2730
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2731
-     *
2732
-     * @access protected
2733
-     * @return void
2734
-     */
2735
-    protected function _set_m_mt_settings()
2736
-    {
2737
-        //first if this is already set then lets get out no need to regenerate data.
2738
-        if ( ! empty($this->_m_mt_settings)) {
2739
-            return;
2740
-        }
2741
-        
2742
-        //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';
2743
-        
2744
-        //get all installed messengers and message_types
2745
-        /** @type EE_messenger[] $messengers */
2746
-        $messengers = $this->_message_resource_manager->installed_messengers();
2747
-        /** @type EE_message_type[] $message_types */
2748
-        $message_types = $this->_message_resource_manager->installed_message_types();
2749
-        
2750
-        
2751
-        //assemble the array for the _tab_text_links helper
2752
-        
2753
-        foreach ($messengers as $messenger) {
2754
-            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
2755
-                'label' => ucwords($messenger->label['singular']),
2756
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',
2757
-                'href'  => $messenger->name,
2758
-                'title' => __('Modify this Messenger', 'event_espresso'),
2759
-                'slug'  => $messenger->name,
2760
-                'obj'   => $messenger
2761
-            );
2647
+			//cycle through bulk action checkboxes
2648
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2649
+				$success = $this->_delete_mtp_permanently($GRP_ID);
2650
+			}
2651
+		} else {
2652
+			//grab single grp_id and delete
2653
+			$GRP_ID  = absint($this->_req_data['id']);
2654
+			$success = $this->_delete_mtp_permanently($GRP_ID);
2655
+		}
2656
+        
2657
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
2658
+        
2659
+	}
2660
+    
2661
+    
2662
+	/**
2663
+	 * helper for permanently deleting a mtP group and all related message_templates
2664
+	 *
2665
+	 * @param  int  $GRP_ID        The group being deleted
2666
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
2667
+	 *
2668
+	 * @return bool        boolean to indicate the success of the deletes or not.
2669
+	 */
2670
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
2671
+	{
2672
+		$success = 1;
2673
+		$MTPG    = EEM_Message_Template_Group::instance();
2674
+		//first let's GET this group
2675
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
2676
+		//then delete permanently all the related Message Templates
2677
+		$deleted = $MTG->delete_related_permanently('Message_Template');
2678
+        
2679
+		if ($deleted === 0) {
2680
+			$success = 0;
2681
+		}
2682
+        
2683
+		//now delete permanently this particular group
2684
+        
2685
+		if ($include_group && ! $MTG->delete_permanently()) {
2686
+			$success = 0;
2687
+		}
2688
+        
2689
+		return $success;
2690
+	}
2691
+    
2692
+    
2693
+	/**
2694
+	 *    _learn_more_about_message_templates_link
2695
+	 * @access protected
2696
+	 * @return string
2697
+	 */
2698
+	protected function _learn_more_about_message_templates_link()
2699
+	{
2700
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2701
+			'event_espresso') . '</a>';
2702
+	}
2703
+    
2704
+    
2705
+	/**
2706
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2707
+	 * ajax and other routes.
2708
+	 * @return void
2709
+	 */
2710
+	protected function _settings()
2711
+	{
2712
+        
2713
+        
2714
+		$this->_set_m_mt_settings();
2715
+        
2716
+		$selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2717
+        
2718
+		//let's setup the messenger tabs
2719
+		$this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],
2720
+			'messenger_links', '|', $selected_messenger);
2721
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2722
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2723
+        
2724
+		$this->display_admin_page_with_sidebar();
2725
+        
2726
+	}
2727
+    
2728
+    
2729
+	/**
2730
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2731
+	 *
2732
+	 * @access protected
2733
+	 * @return void
2734
+	 */
2735
+	protected function _set_m_mt_settings()
2736
+	{
2737
+		//first if this is already set then lets get out no need to regenerate data.
2738
+		if ( ! empty($this->_m_mt_settings)) {
2739
+			return;
2740
+		}
2741
+        
2742
+		//$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';
2743
+        
2744
+		//get all installed messengers and message_types
2745
+		/** @type EE_messenger[] $messengers */
2746
+		$messengers = $this->_message_resource_manager->installed_messengers();
2747
+		/** @type EE_message_type[] $message_types */
2748
+		$message_types = $this->_message_resource_manager->installed_message_types();
2749
+        
2750
+        
2751
+		//assemble the array for the _tab_text_links helper
2752
+        
2753
+		foreach ($messengers as $messenger) {
2754
+			$this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
2755
+				'label' => ucwords($messenger->label['singular']),
2756
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',
2757
+				'href'  => $messenger->name,
2758
+				'title' => __('Modify this Messenger', 'event_espresso'),
2759
+				'slug'  => $messenger->name,
2760
+				'obj'   => $messenger
2761
+			);
2762 2762
             
2763 2763
             
2764
-            $message_types_for_messenger = $messenger->get_valid_message_types();
2764
+			$message_types_for_messenger = $messenger->get_valid_message_types();
2765 2765
             
2766
-            foreach ($message_types as $message_type) {
2767
-                //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox.
2768
-                if ( ! in_array($message_type->name, $message_types_for_messenger)) {
2769
-                    continue;
2770
-                }
2766
+			foreach ($message_types as $message_type) {
2767
+				//first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox.
2768
+				if ( ! in_array($message_type->name, $message_types_for_messenger)) {
2769
+					continue;
2770
+				}
2771 2771
                 
2772
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,
2773
-                    $message_type->name) ? 'active' : 'inactive';
2772
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,
2773
+					$message_type->name) ? 'active' : 'inactive';
2774 2774
                 
2775
-                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2776
-                    'label'    => ucwords($message_type->label['singular']),
2777
-                    'class'    => 'message-type-' . $a_or_i,
2778
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2779
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2780
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2781
-                    'title'    => $a_or_i == 'active'
2782
-                        ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2783
-                        : __('Drag this message type to the messenger to activate', 'event_espresso'),
2784
-                    'content'  => $a_or_i == 'active'
2785
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
2786
-                        : $this->_message_type_settings_content($message_type, $messenger),
2787
-                    'slug'     => $message_type->name,
2788
-                    'active'   => $a_or_i == 'active' ? true : false,
2789
-                    'obj'      => $message_type
2790
-                );
2791
-            }
2792
-        }
2793
-    }
2794
-    
2795
-    
2796
-    /**
2797
-     * This just prepares the content for the message type settings
2798
-     *
2799
-     * @param  object  $message_type The message type object
2800
-     * @param  object  $messenger    The messenger object
2801
-     * @param  boolean $active       Whether the message type is active or not
2802
-     *
2803
-     * @return string                html output for the content
2804
-     */
2805
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
2806
-    {
2807
-        //get message type fields
2808
-        $fields                                         = $message_type->get_admin_settings_fields();
2809
-        $settings_template_args['template_form_fields'] = '';
2810
-        
2811
-        if ( ! empty($fields) && $active) {
2775
+				$this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2776
+					'label'    => ucwords($message_type->label['singular']),
2777
+					'class'    => 'message-type-' . $a_or_i,
2778
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2779
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2780
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2781
+					'title'    => $a_or_i == 'active'
2782
+						? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2783
+						: __('Drag this message type to the messenger to activate', 'event_espresso'),
2784
+					'content'  => $a_or_i == 'active'
2785
+						? $this->_message_type_settings_content($message_type, $messenger, true)
2786
+						: $this->_message_type_settings_content($message_type, $messenger),
2787
+					'slug'     => $message_type->name,
2788
+					'active'   => $a_or_i == 'active' ? true : false,
2789
+					'obj'      => $message_type
2790
+				);
2791
+			}
2792
+		}
2793
+	}
2794
+    
2795
+    
2796
+	/**
2797
+	 * This just prepares the content for the message type settings
2798
+	 *
2799
+	 * @param  object  $message_type The message type object
2800
+	 * @param  object  $messenger    The messenger object
2801
+	 * @param  boolean $active       Whether the message type is active or not
2802
+	 *
2803
+	 * @return string                html output for the content
2804
+	 */
2805
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
2806
+	{
2807
+		//get message type fields
2808
+		$fields                                         = $message_type->get_admin_settings_fields();
2809
+		$settings_template_args['template_form_fields'] = '';
2810
+        
2811
+		if ( ! empty($fields) && $active) {
2812 2812
             
2813
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2813
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2814 2814
             
2815
-            foreach ($fields as $fldname => $fldprops) {
2816
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2817
-                $template_form_field[$field_id] = array(
2818
-                    'name'       => 'message_type_settings[' . $fldname . ']',
2819
-                    'label'      => $fldprops['label'],
2820
-                    'input'      => $fldprops['field_type'],
2821
-                    'type'       => $fldprops['value_type'],
2822
-                    'required'   => $fldprops['required'],
2823
-                    'validation' => $fldprops['validation'],
2824
-                    'value'      => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2825
-                    'options'    => isset($fldprops['options']) ? $fldprops['options'] : array(),
2826
-                    'default'    => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2827
-                    'css_class'  => 'no-drag',
2828
-                    'format'     => $fldprops['format']
2829
-                );
2830
-            }
2815
+			foreach ($fields as $fldname => $fldprops) {
2816
+				$field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2817
+				$template_form_field[$field_id] = array(
2818
+					'name'       => 'message_type_settings[' . $fldname . ']',
2819
+					'label'      => $fldprops['label'],
2820
+					'input'      => $fldprops['field_type'],
2821
+					'type'       => $fldprops['value_type'],
2822
+					'required'   => $fldprops['required'],
2823
+					'validation' => $fldprops['validation'],
2824
+					'value'      => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2825
+					'options'    => isset($fldprops['options']) ? $fldprops['options'] : array(),
2826
+					'default'    => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2827
+					'css_class'  => 'no-drag',
2828
+					'format'     => $fldprops['format']
2829
+				);
2830
+			}
2831 2831
             
2832 2832
             
2833
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,
2834
-                'string', 'ee_mt_activate_form') : '';
2835
-        }
2836
-        
2837
-        $settings_template_args['description'] = $message_type->description;
2838
-        //we also need some hidden fields
2839
-        $settings_template_args['hidden_fields'] = array(
2840
-            'message_type_settings[messenger]'    => array(
2841
-                'type'  => 'hidden',
2842
-                'value' => $messenger->name
2843
-            ),
2844
-            'message_type_settings[message_type]' => array(
2845
-                'type'  => 'hidden',
2846
-                'value' => $message_type->name
2847
-            ),
2848
-            'type'                                => array(
2849
-                'type'  => 'hidden',
2850
-                'value' => 'message_type'
2851
-            )
2852
-        );
2853
-        
2854
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],
2855
-            'array');
2856
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2857
-        
2858
-        
2859
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2860
-        $content  = EEH_Template::display_template($template, $settings_template_args, true);
2861
-        
2862
-        return $content;
2863
-    }
2864
-    
2865
-    
2866
-    /**
2867
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
2868
-     *
2869
-     * @access protected
2870
-     * @return void
2871
-     */
2872
-    protected function _messages_settings_metaboxes()
2873
-    {
2874
-        $this->_set_m_mt_settings();
2875
-        $m_boxes         = $mt_boxes = array();
2876
-        $m_template_args = $mt_template_args = array();
2877
-        
2878
-        $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2879
-        
2880
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
2881
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
2882
-                $hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
2883
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
2884
-                //messenger meta boxes
2885
-                $active                                 = $selected_messenger == $messenger ? true : false;
2886
-                $active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2887
-                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2888
-                    : '';
2889
-                $m_boxes[$messenger . '_a_box']         = sprintf(
2890
-                    __('%s Settings', 'event_espresso'),
2891
-                    $tab_array['label']
2892
-                );
2893
-                $m_template_args[$messenger . '_a_box'] = array(
2894
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2895
-                    'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2896
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2897
-                        : '',
2898
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
2899
-                    'hidden'                 => $active ? '' : ' hidden',
2900
-                    'hide_on_message'        => $hide_on_message,
2901
-                    'messenger'              => $messenger,
2902
-                    'active'                 => $active
2903
-                );
2904
-                // message type meta boxes
2905
-                // (which is really just the inactive container for each messenger
2906
-                // showing inactive message types for that messenger)
2907
-                $mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2908
-                $mt_template_args[$messenger . '_i_box'] = array(
2909
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2910
-                    'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2911
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2912
-                        : '',
2913
-                    'hidden'                 => $active ? '' : ' hidden',
2914
-                    'hide_on_message'        => $hide_on_message,
2915
-                    'hide_off_message'       => $hide_off_message,
2916
-                    'messenger'              => $messenger,
2917
-                    'active'                 => $active
2918
-                );
2919
-            }
2920
-        }
2921
-        
2922
-        
2923
-        //register messenger metaboxes
2924
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2925
-        foreach ($m_boxes as $box => $label) {
2926
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2927
-            $msgr          = str_replace('_a_box', '', $box);
2928
-            add_meta_box(
2929
-                'espresso_' . $msgr . '_settings',
2930
-                $label,
2931
-                function ($post, $metabox) {
2932
-                    echo EEH_Template::display_template($metabox["args"]["template_path"],
2933
-                        $metabox["args"]["template_args"], true);
2934
-                },
2935
-                $this->_current_screen->id,
2936
-                'normal',
2937
-                'high',
2938
-                $callback_args
2939
-            );
2940
-        }
2941
-        
2942
-        //register message type metaboxes
2943
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2944
-        foreach ($mt_boxes as $box => $label) {
2945
-            $callback_args = array(
2946
-                'template_path' => $mt_template_path,
2947
-                'template_args' => $mt_template_args[$box]
2948
-            );
2949
-            $mt            = str_replace('_i_box', '', $box);
2950
-            add_meta_box(
2951
-                'espresso_' . $mt . '_inactive_mts',
2952
-                $label,
2953
-                function ($post, $metabox) {
2954
-                    echo EEH_Template::display_template($metabox["args"]["template_path"],
2955
-                        $metabox["args"]["template_args"], true);
2956
-                },
2957
-                $this->_current_screen->id,
2958
-                'side',
2959
-                'high',
2960
-                $callback_args
2961
-            );
2962
-        }
2963
-        
2964
-        //register metabox for global messages settings but only when on the main site.  On single site installs this will
2965
-        //always result in the metabox showing, on multisite installs the metabox will only show on the main site.
2966
-        if (is_main_site()) {
2967
-            add_meta_box(
2968
-                'espresso_global_message_settings',
2969
-                __('Global Message Settings', 'event_espresso'),
2970
-                array($this, 'global_messages_settings_metabox_content'),
2971
-                $this->_current_screen->id,
2972
-                'normal',
2973
-                'low',
2974
-                array()
2975
-            );
2976
-        }
2977
-        
2978
-    }
2979
-    
2980
-    
2981
-    /**
2982
-     *  This generates the content for the global messages settings metabox.
2983
-     * @return string
2984
-     */
2985
-    public function global_messages_settings_metabox_content()
2986
-    {
2987
-        $form = $this->_generate_global_settings_form();
2988
-        echo $form->form_open(
2989
-                $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
2990
-                'POST'
2991
-            )
2992
-             . $form->get_html()
2993
-             . $form->form_close();
2994
-    }
2995
-    
2996
-    
2997
-    /**
2998
-     * This generates and returns the form object for the global messages settings.
2999
-     * @return EE_Form_Section_Proper
3000
-     */
3001
-    protected function _generate_global_settings_form()
3002
-    {
3003
-        EE_Registry::instance()->load_helper('HTML');
3004
-        /** @var EE_Network_Core_Config $network_config */
3005
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3006
-        
3007
-        return new EE_Form_Section_Proper(
3008
-            array(
3009
-                'name'            => 'global_messages_settings',
3010
-                'html_id'         => 'global_messages_settings',
3011
-                'html_class'      => 'form-table',
3012
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3013
-                'subsections'     => apply_filters(
3014
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3015
-                    array(
3016
-                        'do_messages_on_same_request' => new EE_Select_Input(
3017
-                            array(
3018
-                                true  => esc_html__("On the same request", "event_espresso"),
3019
-                                false => esc_html__("On a separate request", "event_espresso")
3020
-                            ),
3021
-                            array(
3022
-                                'default'         => $network_config->do_messages_on_same_request,
3023
-                                'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'),
3024
-                                'html_help_text'  => esc_html__('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.',
3025
-                                    'event_espresso'),
3026
-                            )
3027
-                        ),
3028
-                        'delete_threshold' => new EE_Select_Input(
3029
-                            array(
3030
-                                0 => esc_html__('Forever', 'event_espresso'),
3031
-                                3 => esc_html__('3 Months', 'event_espresso'),
3032
-                                6 => esc_html__('6 Months', 'event_espresso'),
3033
-                                9 => esc_html__('9 Months', 'event_espresso'),
3034
-                                12 => esc_html__('12 Months', 'event_espresso'),
3035
-                                24 => esc_html__('24 Months', 'event_espresso'),
3036
-                                36 => esc_html__('36 Months', 'event_espresso')
3037
-                            ),
3038
-                            array(
3039
-                                'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3040
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3041
-                                'html_help_text' => esc_html__('You can control how long a record of processed messages is kept 
2833
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,
2834
+				'string', 'ee_mt_activate_form') : '';
2835
+		}
2836
+        
2837
+		$settings_template_args['description'] = $message_type->description;
2838
+		//we also need some hidden fields
2839
+		$settings_template_args['hidden_fields'] = array(
2840
+			'message_type_settings[messenger]'    => array(
2841
+				'type'  => 'hidden',
2842
+				'value' => $messenger->name
2843
+			),
2844
+			'message_type_settings[message_type]' => array(
2845
+				'type'  => 'hidden',
2846
+				'value' => $message_type->name
2847
+			),
2848
+			'type'                                => array(
2849
+				'type'  => 'hidden',
2850
+				'value' => 'message_type'
2851
+			)
2852
+		);
2853
+        
2854
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],
2855
+			'array');
2856
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2857
+        
2858
+        
2859
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2860
+		$content  = EEH_Template::display_template($template, $settings_template_args, true);
2861
+        
2862
+		return $content;
2863
+	}
2864
+    
2865
+    
2866
+	/**
2867
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
2868
+	 *
2869
+	 * @access protected
2870
+	 * @return void
2871
+	 */
2872
+	protected function _messages_settings_metaboxes()
2873
+	{
2874
+		$this->_set_m_mt_settings();
2875
+		$m_boxes         = $mt_boxes = array();
2876
+		$m_template_args = $mt_template_args = array();
2877
+        
2878
+		$selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2879
+        
2880
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
2881
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
2882
+				$hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
2883
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
2884
+				//messenger meta boxes
2885
+				$active                                 = $selected_messenger == $messenger ? true : false;
2886
+				$active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2887
+					? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2888
+					: '';
2889
+				$m_boxes[$messenger . '_a_box']         = sprintf(
2890
+					__('%s Settings', 'event_espresso'),
2891
+					$tab_array['label']
2892
+				);
2893
+				$m_template_args[$messenger . '_a_box'] = array(
2894
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2895
+					'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2896
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2897
+						: '',
2898
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
2899
+					'hidden'                 => $active ? '' : ' hidden',
2900
+					'hide_on_message'        => $hide_on_message,
2901
+					'messenger'              => $messenger,
2902
+					'active'                 => $active
2903
+				);
2904
+				// message type meta boxes
2905
+				// (which is really just the inactive container for each messenger
2906
+				// showing inactive message types for that messenger)
2907
+				$mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2908
+				$mt_template_args[$messenger . '_i_box'] = array(
2909
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2910
+					'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2911
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2912
+						: '',
2913
+					'hidden'                 => $active ? '' : ' hidden',
2914
+					'hide_on_message'        => $hide_on_message,
2915
+					'hide_off_message'       => $hide_off_message,
2916
+					'messenger'              => $messenger,
2917
+					'active'                 => $active
2918
+				);
2919
+			}
2920
+		}
2921
+        
2922
+        
2923
+		//register messenger metaboxes
2924
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2925
+		foreach ($m_boxes as $box => $label) {
2926
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2927
+			$msgr          = str_replace('_a_box', '', $box);
2928
+			add_meta_box(
2929
+				'espresso_' . $msgr . '_settings',
2930
+				$label,
2931
+				function ($post, $metabox) {
2932
+					echo EEH_Template::display_template($metabox["args"]["template_path"],
2933
+						$metabox["args"]["template_args"], true);
2934
+				},
2935
+				$this->_current_screen->id,
2936
+				'normal',
2937
+				'high',
2938
+				$callback_args
2939
+			);
2940
+		}
2941
+        
2942
+		//register message type metaboxes
2943
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2944
+		foreach ($mt_boxes as $box => $label) {
2945
+			$callback_args = array(
2946
+				'template_path' => $mt_template_path,
2947
+				'template_args' => $mt_template_args[$box]
2948
+			);
2949
+			$mt            = str_replace('_i_box', '', $box);
2950
+			add_meta_box(
2951
+				'espresso_' . $mt . '_inactive_mts',
2952
+				$label,
2953
+				function ($post, $metabox) {
2954
+					echo EEH_Template::display_template($metabox["args"]["template_path"],
2955
+						$metabox["args"]["template_args"], true);
2956
+				},
2957
+				$this->_current_screen->id,
2958
+				'side',
2959
+				'high',
2960
+				$callback_args
2961
+			);
2962
+		}
2963
+        
2964
+		//register metabox for global messages settings but only when on the main site.  On single site installs this will
2965
+		//always result in the metabox showing, on multisite installs the metabox will only show on the main site.
2966
+		if (is_main_site()) {
2967
+			add_meta_box(
2968
+				'espresso_global_message_settings',
2969
+				__('Global Message Settings', 'event_espresso'),
2970
+				array($this, 'global_messages_settings_metabox_content'),
2971
+				$this->_current_screen->id,
2972
+				'normal',
2973
+				'low',
2974
+				array()
2975
+			);
2976
+		}
2977
+        
2978
+	}
2979
+    
2980
+    
2981
+	/**
2982
+	 *  This generates the content for the global messages settings metabox.
2983
+	 * @return string
2984
+	 */
2985
+	public function global_messages_settings_metabox_content()
2986
+	{
2987
+		$form = $this->_generate_global_settings_form();
2988
+		echo $form->form_open(
2989
+				$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
2990
+				'POST'
2991
+			)
2992
+			 . $form->get_html()
2993
+			 . $form->form_close();
2994
+	}
2995
+    
2996
+    
2997
+	/**
2998
+	 * This generates and returns the form object for the global messages settings.
2999
+	 * @return EE_Form_Section_Proper
3000
+	 */
3001
+	protected function _generate_global_settings_form()
3002
+	{
3003
+		EE_Registry::instance()->load_helper('HTML');
3004
+		/** @var EE_Network_Core_Config $network_config */
3005
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3006
+        
3007
+		return new EE_Form_Section_Proper(
3008
+			array(
3009
+				'name'            => 'global_messages_settings',
3010
+				'html_id'         => 'global_messages_settings',
3011
+				'html_class'      => 'form-table',
3012
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3013
+				'subsections'     => apply_filters(
3014
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3015
+					array(
3016
+						'do_messages_on_same_request' => new EE_Select_Input(
3017
+							array(
3018
+								true  => esc_html__("On the same request", "event_espresso"),
3019
+								false => esc_html__("On a separate request", "event_espresso")
3020
+							),
3021
+							array(
3022
+								'default'         => $network_config->do_messages_on_same_request,
3023
+								'html_label_text' => esc_html__('Generate and send all messages:', 'event_espresso'),
3024
+								'html_help_text'  => esc_html__('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.',
3025
+									'event_espresso'),
3026
+							)
3027
+						),
3028
+						'delete_threshold' => new EE_Select_Input(
3029
+							array(
3030
+								0 => esc_html__('Forever', 'event_espresso'),
3031
+								3 => esc_html__('3 Months', 'event_espresso'),
3032
+								6 => esc_html__('6 Months', 'event_espresso'),
3033
+								9 => esc_html__('9 Months', 'event_espresso'),
3034
+								12 => esc_html__('12 Months', 'event_espresso'),
3035
+								24 => esc_html__('24 Months', 'event_espresso'),
3036
+								36 => esc_html__('36 Months', 'event_espresso')
3037
+							),
3038
+							array(
3039
+								'default' => EE_Registry::instance()->CFG->messages->delete_threshold,
3040
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3041
+								'html_help_text' => esc_html__('You can control how long a record of processed messages is kept 
3042 3042
                                                     via this option.', 'event_espresso'),
3043
-                            )
3044
-                        ),
3045
-                        'update_settings'             => new EE_Submit_Input(
3046
-                            array(
3047
-                                'default'         => esc_html__('Update', 'event_espresso'),
3048
-                                'html_label_text' => '&nbsp'
3049
-                            )
3050
-                        )
3051
-                    )
3052
-                )
3053
-            )
3054
-        );
3055
-    }
3056
-    
3057
-    
3058
-    /**
3059
-     * This handles updating the global settings set on the admin page.
3060
-     * @throws \EE_Error
3061
-     */
3062
-    protected function _update_global_settings()
3063
-    {
3064
-        /** @var EE_Network_Core_Config $network_config */
3065
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3066
-        $messages_config = EE_Registry::instance()->CFG->messages;
3067
-        $form           = $this->_generate_global_settings_form();
3068
-        if ($form->was_submitted()) {
3069
-            $form->receive_form_submission();
3070
-            if ($form->is_valid()) {
3071
-                $valid_data = $form->valid_data();
3072
-                foreach ($valid_data as $property => $value) {
3073
-                    $setter = 'set_' . $property;
3074
-                    if (method_exists($network_config, $setter)) {
3075
-                        $network_config->{$setter}($value);
3076
-                    } else if (
3077
-                        property_exists($network_config, $property)
3078
-                        && $network_config->{$property} !== $value
3079
-                    ) {
3080
-                        $network_config->{$property} = $value;
3081
-                    } else if (
3082
-                        property_exists($messages_config, $property)
3083
-                        && $messages_config->{$property} !== $value
3084
-                    ) {
3085
-                        $messages_config->{$property} = $value;
3086
-                    }
3087
-                }
3088
-                //only update if the form submission was valid!
3089
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3090
-                EE_Registry::instance()->CFG->update_espresso_config();
3091
-                EE_Error::overwrite_success();
3092
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3093
-            }
3094
-        }
3095
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3096
-    }
3097
-    
3098
-    
3099
-    /**
3100
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3101
-     *
3102
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3103
-     *
3104
-     * @return string            html formatted tabs
3105
-     */
3106
-    protected function _get_mt_tabs($tab_array)
3107
-    {
3108
-        $tab_array = (array)$tab_array;
3109
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3110
-        $tabs      = '';
3111
-        
3112
-        foreach ($tab_array as $tab) {
3113
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3114
-        }
3115
-        
3116
-        return $tabs;
3117
-    }
3118
-    
3119
-    
3120
-    /**
3121
-     * This prepares the content of the messenger meta box admin settings
3122
-     *
3123
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3124
-     *
3125
-     * @return string            html formatted content
3126
-     */
3127
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3128
-    {
3129
-        
3130
-        $fields                                         = $messenger->get_admin_settings_fields();
3131
-        $settings_template_args['template_form_fields'] = '';
3132
-        
3133
-        //is $messenger active?
3134
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3135
-        
3136
-        
3137
-        if ( ! empty($fields)) {
3043
+							)
3044
+						),
3045
+						'update_settings'             => new EE_Submit_Input(
3046
+							array(
3047
+								'default'         => esc_html__('Update', 'event_espresso'),
3048
+								'html_label_text' => '&nbsp'
3049
+							)
3050
+						)
3051
+					)
3052
+				)
3053
+			)
3054
+		);
3055
+	}
3056
+    
3057
+    
3058
+	/**
3059
+	 * This handles updating the global settings set on the admin page.
3060
+	 * @throws \EE_Error
3061
+	 */
3062
+	protected function _update_global_settings()
3063
+	{
3064
+		/** @var EE_Network_Core_Config $network_config */
3065
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3066
+		$messages_config = EE_Registry::instance()->CFG->messages;
3067
+		$form           = $this->_generate_global_settings_form();
3068
+		if ($form->was_submitted()) {
3069
+			$form->receive_form_submission();
3070
+			if ($form->is_valid()) {
3071
+				$valid_data = $form->valid_data();
3072
+				foreach ($valid_data as $property => $value) {
3073
+					$setter = 'set_' . $property;
3074
+					if (method_exists($network_config, $setter)) {
3075
+						$network_config->{$setter}($value);
3076
+					} else if (
3077
+						property_exists($network_config, $property)
3078
+						&& $network_config->{$property} !== $value
3079
+					) {
3080
+						$network_config->{$property} = $value;
3081
+					} else if (
3082
+						property_exists($messages_config, $property)
3083
+						&& $messages_config->{$property} !== $value
3084
+					) {
3085
+						$messages_config->{$property} = $value;
3086
+					}
3087
+				}
3088
+				//only update if the form submission was valid!
3089
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3090
+				EE_Registry::instance()->CFG->update_espresso_config();
3091
+				EE_Error::overwrite_success();
3092
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3093
+			}
3094
+		}
3095
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3096
+	}
3097
+    
3098
+    
3099
+	/**
3100
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3101
+	 *
3102
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3103
+	 *
3104
+	 * @return string            html formatted tabs
3105
+	 */
3106
+	protected function _get_mt_tabs($tab_array)
3107
+	{
3108
+		$tab_array = (array)$tab_array;
3109
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3110
+		$tabs      = '';
3111
+        
3112
+		foreach ($tab_array as $tab) {
3113
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3114
+		}
3115
+        
3116
+		return $tabs;
3117
+	}
3118
+    
3119
+    
3120
+	/**
3121
+	 * This prepares the content of the messenger meta box admin settings
3122
+	 *
3123
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3124
+	 *
3125
+	 * @return string            html formatted content
3126
+	 */
3127
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3128
+	{
3129
+        
3130
+		$fields                                         = $messenger->get_admin_settings_fields();
3131
+		$settings_template_args['template_form_fields'] = '';
3132
+        
3133
+		//is $messenger active?
3134
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3135
+        
3136
+        
3137
+		if ( ! empty($fields)) {
3138 3138
             
3139
-            $existing_settings = $messenger->get_existing_admin_settings();
3139
+			$existing_settings = $messenger->get_existing_admin_settings();
3140 3140
             
3141
-            foreach ($fields as $fldname => $fldprops) {
3142
-                $field_id                       = $messenger->name . '-' . $fldname;
3143
-                $template_form_field[$field_id] = array(
3144
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3145
-                    'label'      => $fldprops['label'],
3146
-                    'input'      => $fldprops['field_type'],
3147
-                    'type'       => $fldprops['value_type'],
3148
-                    'required'   => $fldprops['required'],
3149
-                    'validation' => $fldprops['validation'],
3150
-                    'value'      => isset($existing_settings[$field_id])
3151
-                        ? $existing_settings[$field_id]
3152
-                        : $fldprops['default'],
3153
-                    'css_class'  => '',
3154
-                    'format'     => $fldprops['format']
3155
-                );
3156
-            }
3141
+			foreach ($fields as $fldname => $fldprops) {
3142
+				$field_id                       = $messenger->name . '-' . $fldname;
3143
+				$template_form_field[$field_id] = array(
3144
+					'name'       => 'messenger_settings[' . $field_id . ']',
3145
+					'label'      => $fldprops['label'],
3146
+					'input'      => $fldprops['field_type'],
3147
+					'type'       => $fldprops['value_type'],
3148
+					'required'   => $fldprops['required'],
3149
+					'validation' => $fldprops['validation'],
3150
+					'value'      => isset($existing_settings[$field_id])
3151
+						? $existing_settings[$field_id]
3152
+						: $fldprops['default'],
3153
+					'css_class'  => '',
3154
+					'format'     => $fldprops['format']
3155
+				);
3156
+			}
3157 3157
             
3158 3158
             
3159
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3160
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3161
-                : '';
3162
-        }
3163
-        
3164
-        //we also need some hidden fields
3165
-        $settings_template_args['hidden_fields'] = array(
3166
-            'messenger_settings[messenger]' => array(
3167
-                'type'  => 'hidden',
3168
-                'value' => $messenger->name
3169
-            ),
3170
-            'type'                          => array(
3171
-                'type'  => 'hidden',
3172
-                'value' => 'messenger'
3173
-            )
3174
-        );
3175
-        
3176
-        //make sure any active message types that are existing are included in the hidden fields
3177
-        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3178
-            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3179
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3180
-                    'type'  => 'hidden',
3181
-                    'value' => $mt
3182
-                );
3183
-            }
3184
-        }
3185
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3186
-            $settings_template_args['hidden_fields'],
3187
-            'array'
3188
-        );
3189
-        $active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3190
-        
3191
-        $settings_template_args['messenger']           = $messenger->name;
3192
-        $settings_template_args['description']         = $messenger->description;
3193
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3194
-        
3195
-        
3196
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)
3197
-            ? $settings_template_args['show_hide_edit_form']
3198
-            : ' hidden';
3199
-        
3200
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3201
-            ? ' hidden'
3202
-            : $settings_template_args['show_hide_edit_form'];
3203
-        
3204
-        
3205
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3206
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3207
-        $settings_template_args['on_off_status'] = $active ? true : false;
3208
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3209
-        $content                                 = EEH_Template::display_template($template, $settings_template_args,
3210
-            true);
3211
-        
3212
-        return $content;
3213
-    }
3214
-    
3215
-    
3216
-    /**
3217
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3218
-     */
3219
-    public function activate_messenger_toggle()
3220
-    {
3221
-        $success = true;
3222
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3223
-        //let's check that we have required data
3224
-        if ( ! isset($this->_req_data['messenger'])) {
3225
-            EE_Error::add_error(
3226
-                __('Messenger name needed to toggle activation. None given', 'event_espresso'),
3227
-                __FILE__,
3228
-                __FUNCTION__,
3229
-                __LINE__
3230
-            );
3231
-            $success = false;
3232
-        }
3233
-        
3234
-        //do a nonce check here since we're not arriving via a normal route
3235
-        $nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3236
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3237
-        
3238
-        $this->_verify_nonce($nonce, $nonce_ref);
3239
-        
3240
-        
3241
-        if ( ! isset($this->_req_data['status'])) {
3242
-            EE_Error::add_error(
3243
-                __(
3244
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3245
-                    'event_espresso'
3246
-                ),
3247
-                __FILE__,
3248
-                __FUNCTION__,
3249
-                __LINE__
3250
-            );
3251
-            $success = false;
3252
-        }
3253
-        
3254
-        //do check to verify we have a valid status.
3255
-        $status = $this->_req_data['status'];
3256
-        
3257
-        if ($status != 'off' && $status != 'on') {
3258
-            EE_Error::add_error(
3259
-                sprintf(
3260
-                    __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3261
-                    $this->_req_data['status']
3262
-                ),
3263
-                __FILE__,
3264
-                __FUNCTION__,
3265
-                __LINE__
3266
-            );
3267
-            $success = false;
3268
-        }
3269
-        
3270
-        if ($success) {
3271
-            //made it here?  Stop dawdling then!!
3272
-            $success = $status == 'off'
3273
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3274
-                : $this->_activate_messenger($this->_req_data['messenger']);
3275
-        }
3276
-        
3277
-        $this->_template_args['success'] = $success;
3278
-        
3279
-        //no special instructions so let's just do the json return (which should automatically do all the special stuff).
3280
-        $this->_return_json();
3281
-        
3282
-    }
3283
-    
3284
-    
3285
-    /**
3286
-     * used by ajax from the messages settings page to activate|deactivate a message type
3287
-     *
3288
-     */
3289
-    public function activate_mt_toggle()
3290
-    {
3291
-        $success = true;
3292
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3293
-        
3294
-        //let's make sure we have the necessary data
3295
-        if ( ! isset($this->_req_data['message_type'])) {
3296
-            EE_Error::add_error(
3297
-                __('Message Type name needed to toggle activation. None given', 'event_espresso'),
3298
-                __FILE__, __FUNCTION__, __LINE__
3299
-            );
3300
-            $success = false;
3301
-        }
3302
-        
3303
-        if ( ! isset($this->_req_data['messenger'])) {
3304
-            EE_Error::add_error(
3305
-                __('Messenger name needed to toggle activation. None given', 'event_espresso'),
3306
-                __FILE__, __FUNCTION__, __LINE__
3307
-            );
3308
-            $success = false;
3309
-        }
3310
-        
3311
-        if ( ! isset($this->_req_data['status'])) {
3312
-            EE_Error::add_error(
3313
-                __('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3314
-                    'event_espresso'),
3315
-                __FILE__, __FUNCTION__, __LINE__
3316
-            );
3317
-            $success = false;
3318
-        }
3319
-        
3320
-        
3321
-        //do check to verify we have a valid status.
3322
-        $status = $this->_req_data['status'];
3323
-        
3324
-        if ($status != 'activate' && $status != 'deactivate') {
3325
-            EE_Error::add_error(
3326
-                sprintf(
3327
-                    __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3328
-                    $this->_req_data['status']
3329
-                ),
3330
-                __FILE__, __FUNCTION__, __LINE__
3331
-            );
3332
-            $success = false;
3333
-        }
3334
-        
3335
-        
3336
-        //do a nonce check here since we're not arriving via a normal route
3337
-        $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3338
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3339
-        
3340
-        $this->_verify_nonce($nonce, $nonce_ref);
3341
-        
3342
-        if ($success) {
3343
-            //made it here? um, what are you waiting for then?
3344
-            $success = $status == 'deactivate'
3345
-                ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],
3346
-                    $this->_req_data['message_type'])
3347
-                : $this->_activate_message_type_for_messenger($this->_req_data['messenger'],
3348
-                    $this->_req_data['message_type']);
3349
-        }
3350
-        
3351
-        $this->_template_args['success'] = $success;
3352
-        $this->_return_json();
3353
-    }
3354
-    
3355
-    
3356
-    /**
3357
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3358
-     *
3359
-     * @param string $messenger_name The name of the messenger being activated
3360
-     *
3361
-     * @return bool
3362
-     */
3363
-    protected function _activate_messenger($messenger_name)
3364
-    {
3365
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3366
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3367
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();
3368
-        
3369
-        //ensure is active
3370
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3371
-        
3372
-        //set response_data for reload
3373
-        foreach ($message_types_to_activate as $message_type_name) {
3374
-            /** @var EE_message_type $message_type */
3375
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3376
-            if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3377
-                    $message_type_name)
3378
-                && $message_type instanceof EE_message_type
3379
-            ) {
3380
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3381
-                if ($message_type->get_admin_settings_fields()) {
3382
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3383
-                }
3384
-            }
3385
-        }
3386
-        
3387
-        //add success message for activating messenger
3388
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3389
-        
3390
-    }
3391
-    
3392
-    
3393
-    /**
3394
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3395
-     *
3396
-     * @param string $messenger_name The name of the messenger being activated
3397
-     *
3398
-     * @return bool
3399
-     */
3400
-    protected function _deactivate_messenger($messenger_name)
3401
-    {
3402
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3403
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3404
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3405
-        
3406
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3407
-    }
3408
-    
3409
-    
3410
-    /**
3411
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3412
-     *
3413
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3414
-     * @param string $message_type_name The name of the message type being activated for the messenger
3415
-     *
3416
-     * @return bool
3417
-     */
3418
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3419
-    {
3420
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3421
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3422
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3423
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3424
-        
3425
-        //ensure is active
3426
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3427
-        
3428
-        //set response for load
3429
-        if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3430
-            $message_type_name)
3431
-        ) {
3432
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
3433
-            if ($message_type_to_activate->get_admin_settings_fields()) {
3434
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
3435
-            }
3436
-        }
3437
-        
3438
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3439
-            $message_type_to_activate);
3440
-    }
3441
-    
3442
-    
3443
-    /**
3444
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3445
-     *
3446
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3447
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
3448
-     *
3449
-     * @return bool
3450
-     */
3451
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3452
-    {
3453
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3454
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3455
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3456
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3457
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3458
-        
3459
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3460
-            $message_type_to_deactivate);
3461
-    }
3462
-    
3463
-    
3464
-    /**
3465
-     * This just initializes the defaults for activating messenger and message type responses.
3466
-     */
3467
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
3468
-    {
3469
-        $this->_template_args['data']['active_mts'] = array();
3470
-        $this->_template_args['data']['mt_reload']  = array();
3471
-    }
3472
-    
3473
-    
3474
-    /**
3475
-     * Setup appropriate response for activating a messenger and/or message types
3476
-     *
3477
-     * @param EE_messenger         $messenger
3478
-     * @param EE_message_type|null $message_type
3479
-     *
3480
-     * @return bool
3481
-     * @throws EE_Error
3482
-     */
3483
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
3484
-        $messenger,
3485
-        EE_Message_Type $message_type = null
3486
-    ) {
3487
-        //if $messenger isn't a valid messenger object then get out.
3488
-        if ( ! $messenger instanceof EE_Messenger) {
3489
-            EE_Error::add_error(
3490
-                __('The messenger being activated is not a valid messenger', 'event_espresso'),
3491
-                __FILE__,
3492
-                __FUNCTION__,
3493
-                __LINE__
3494
-            );
3159
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3160
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3161
+				: '';
3162
+		}
3163
+        
3164
+		//we also need some hidden fields
3165
+		$settings_template_args['hidden_fields'] = array(
3166
+			'messenger_settings[messenger]' => array(
3167
+				'type'  => 'hidden',
3168
+				'value' => $messenger->name
3169
+			),
3170
+			'type'                          => array(
3171
+				'type'  => 'hidden',
3172
+				'value' => 'messenger'
3173
+			)
3174
+		);
3175
+        
3176
+		//make sure any active message types that are existing are included in the hidden fields
3177
+		if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3178
+			foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3179
+				$settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3180
+					'type'  => 'hidden',
3181
+					'value' => $mt
3182
+				);
3183
+			}
3184
+		}
3185
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3186
+			$settings_template_args['hidden_fields'],
3187
+			'array'
3188
+		);
3189
+		$active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3190
+        
3191
+		$settings_template_args['messenger']           = $messenger->name;
3192
+		$settings_template_args['description']         = $messenger->description;
3193
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3194
+        
3195
+        
3196
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)
3197
+			? $settings_template_args['show_hide_edit_form']
3198
+			: ' hidden';
3199
+        
3200
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3201
+			? ' hidden'
3202
+			: $settings_template_args['show_hide_edit_form'];
3203
+        
3204
+        
3205
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3206
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3207
+		$settings_template_args['on_off_status'] = $active ? true : false;
3208
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3209
+		$content                                 = EEH_Template::display_template($template, $settings_template_args,
3210
+			true);
3211
+        
3212
+		return $content;
3213
+	}
3214
+    
3215
+    
3216
+	/**
3217
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3218
+	 */
3219
+	public function activate_messenger_toggle()
3220
+	{
3221
+		$success = true;
3222
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3223
+		//let's check that we have required data
3224
+		if ( ! isset($this->_req_data['messenger'])) {
3225
+			EE_Error::add_error(
3226
+				__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3227
+				__FILE__,
3228
+				__FUNCTION__,
3229
+				__LINE__
3230
+			);
3231
+			$success = false;
3232
+		}
3233
+        
3234
+		//do a nonce check here since we're not arriving via a normal route
3235
+		$nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3236
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3237
+        
3238
+		$this->_verify_nonce($nonce, $nonce_ref);
3239
+        
3240
+        
3241
+		if ( ! isset($this->_req_data['status'])) {
3242
+			EE_Error::add_error(
3243
+				__(
3244
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3245
+					'event_espresso'
3246
+				),
3247
+				__FILE__,
3248
+				__FUNCTION__,
3249
+				__LINE__
3250
+			);
3251
+			$success = false;
3252
+		}
3253
+        
3254
+		//do check to verify we have a valid status.
3255
+		$status = $this->_req_data['status'];
3256
+        
3257
+		if ($status != 'off' && $status != 'on') {
3258
+			EE_Error::add_error(
3259
+				sprintf(
3260
+					__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3261
+					$this->_req_data['status']
3262
+				),
3263
+				__FILE__,
3264
+				__FUNCTION__,
3265
+				__LINE__
3266
+			);
3267
+			$success = false;
3268
+		}
3269
+        
3270
+		if ($success) {
3271
+			//made it here?  Stop dawdling then!!
3272
+			$success = $status == 'off'
3273
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3274
+				: $this->_activate_messenger($this->_req_data['messenger']);
3275
+		}
3276
+        
3277
+		$this->_template_args['success'] = $success;
3278
+        
3279
+		//no special instructions so let's just do the json return (which should automatically do all the special stuff).
3280
+		$this->_return_json();
3281
+        
3282
+	}
3283
+    
3284
+    
3285
+	/**
3286
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3287
+	 *
3288
+	 */
3289
+	public function activate_mt_toggle()
3290
+	{
3291
+		$success = true;
3292
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3293
+        
3294
+		//let's make sure we have the necessary data
3295
+		if ( ! isset($this->_req_data['message_type'])) {
3296
+			EE_Error::add_error(
3297
+				__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3298
+				__FILE__, __FUNCTION__, __LINE__
3299
+			);
3300
+			$success = false;
3301
+		}
3302
+        
3303
+		if ( ! isset($this->_req_data['messenger'])) {
3304
+			EE_Error::add_error(
3305
+				__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3306
+				__FILE__, __FUNCTION__, __LINE__
3307
+			);
3308
+			$success = false;
3309
+		}
3310
+        
3311
+		if ( ! isset($this->_req_data['status'])) {
3312
+			EE_Error::add_error(
3313
+				__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3314
+					'event_espresso'),
3315
+				__FILE__, __FUNCTION__, __LINE__
3316
+			);
3317
+			$success = false;
3318
+		}
3319
+        
3320
+        
3321
+		//do check to verify we have a valid status.
3322
+		$status = $this->_req_data['status'];
3323
+        
3324
+		if ($status != 'activate' && $status != 'deactivate') {
3325
+			EE_Error::add_error(
3326
+				sprintf(
3327
+					__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3328
+					$this->_req_data['status']
3329
+				),
3330
+				__FILE__, __FUNCTION__, __LINE__
3331
+			);
3332
+			$success = false;
3333
+		}
3334
+        
3335
+        
3336
+		//do a nonce check here since we're not arriving via a normal route
3337
+		$nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3338
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3339
+        
3340
+		$this->_verify_nonce($nonce, $nonce_ref);
3341
+        
3342
+		if ($success) {
3343
+			//made it here? um, what are you waiting for then?
3344
+			$success = $status == 'deactivate'
3345
+				? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],
3346
+					$this->_req_data['message_type'])
3347
+				: $this->_activate_message_type_for_messenger($this->_req_data['messenger'],
3348
+					$this->_req_data['message_type']);
3349
+		}
3350
+        
3351
+		$this->_template_args['success'] = $success;
3352
+		$this->_return_json();
3353
+	}
3354
+    
3355
+    
3356
+	/**
3357
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3358
+	 *
3359
+	 * @param string $messenger_name The name of the messenger being activated
3360
+	 *
3361
+	 * @return bool
3362
+	 */
3363
+	protected function _activate_messenger($messenger_name)
3364
+	{
3365
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3366
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3367
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();
3368
+        
3369
+		//ensure is active
3370
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3371
+        
3372
+		//set response_data for reload
3373
+		foreach ($message_types_to_activate as $message_type_name) {
3374
+			/** @var EE_message_type $message_type */
3375
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3376
+			if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3377
+					$message_type_name)
3378
+				&& $message_type instanceof EE_message_type
3379
+			) {
3380
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3381
+				if ($message_type->get_admin_settings_fields()) {
3382
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3383
+				}
3384
+			}
3385
+		}
3386
+        
3387
+		//add success message for activating messenger
3388
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3389
+        
3390
+	}
3391
+    
3392
+    
3393
+	/**
3394
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3395
+	 *
3396
+	 * @param string $messenger_name The name of the messenger being activated
3397
+	 *
3398
+	 * @return bool
3399
+	 */
3400
+	protected function _deactivate_messenger($messenger_name)
3401
+	{
3402
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3403
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3404
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3405
+        
3406
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3407
+	}
3408
+    
3409
+    
3410
+	/**
3411
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3412
+	 *
3413
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3414
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3415
+	 *
3416
+	 * @return bool
3417
+	 */
3418
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3419
+	{
3420
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3421
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3422
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3423
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3424
+        
3425
+		//ensure is active
3426
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3427
+        
3428
+		//set response for load
3429
+		if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3430
+			$message_type_name)
3431
+		) {
3432
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
3433
+			if ($message_type_to_activate->get_admin_settings_fields()) {
3434
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
3435
+			}
3436
+		}
3437
+        
3438
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3439
+			$message_type_to_activate);
3440
+	}
3441
+    
3442
+    
3443
+	/**
3444
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3445
+	 *
3446
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3447
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
3448
+	 *
3449
+	 * @return bool
3450
+	 */
3451
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3452
+	{
3453
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3454
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3455
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3456
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3457
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3458
+        
3459
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3460
+			$message_type_to_deactivate);
3461
+	}
3462
+    
3463
+    
3464
+	/**
3465
+	 * This just initializes the defaults for activating messenger and message type responses.
3466
+	 */
3467
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
3468
+	{
3469
+		$this->_template_args['data']['active_mts'] = array();
3470
+		$this->_template_args['data']['mt_reload']  = array();
3471
+	}
3472
+    
3473
+    
3474
+	/**
3475
+	 * Setup appropriate response for activating a messenger and/or message types
3476
+	 *
3477
+	 * @param EE_messenger         $messenger
3478
+	 * @param EE_message_type|null $message_type
3479
+	 *
3480
+	 * @return bool
3481
+	 * @throws EE_Error
3482
+	 */
3483
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
3484
+		$messenger,
3485
+		EE_Message_Type $message_type = null
3486
+	) {
3487
+		//if $messenger isn't a valid messenger object then get out.
3488
+		if ( ! $messenger instanceof EE_Messenger) {
3489
+			EE_Error::add_error(
3490
+				__('The messenger being activated is not a valid messenger', 'event_espresso'),
3491
+				__FILE__,
3492
+				__FUNCTION__,
3493
+				__LINE__
3494
+			);
3495 3495
             
3496
-            return false;
3497
-        }
3498
-        //activated
3499
-        if ($this->_template_args['data']['active_mts']) {
3500
-            EE_Error::overwrite_success();
3501
-            //activated a message type with the messenger
3502
-            if ($message_type instanceof EE_message_type) {
3503
-                EE_Error::add_success(
3504
-                    sprintf(
3505
-                        __('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
3506
-                        ucwords($message_type->label['singular']),
3507
-                        ucwords($messenger->label['singular'])
3508
-                    )
3509
-                );
3496
+			return false;
3497
+		}
3498
+		//activated
3499
+		if ($this->_template_args['data']['active_mts']) {
3500
+			EE_Error::overwrite_success();
3501
+			//activated a message type with the messenger
3502
+			if ($message_type instanceof EE_message_type) {
3503
+				EE_Error::add_success(
3504
+					sprintf(
3505
+						__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
3506
+						ucwords($message_type->label['singular']),
3507
+						ucwords($messenger->label['singular'])
3508
+					)
3509
+				);
3510 3510
                 
3511
-                //if message type was invoice then let's make sure we activate the invoice payment method.
3512
-                if ($message_type->name == 'invoice') {
3513
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
3514
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3515
-                    if ($pm instanceof EE_Payment_Method) {
3516
-                        EE_Error::add_attention(__('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.',
3517
-                            'event_espresso'));
3518
-                    }
3519
-                }
3520
-                //just toggles the entire messenger
3521
-            } else {
3522
-                EE_Error::add_success(
3523
-                    sprintf(
3524
-                        __('%s messenger has been successfully activated', 'event_espresso'),
3525
-                        ucwords($messenger->label['singular'])
3526
-                    )
3527
-                );
3528
-            }
3511
+				//if message type was invoice then let's make sure we activate the invoice payment method.
3512
+				if ($message_type->name == 'invoice') {
3513
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
3514
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3515
+					if ($pm instanceof EE_Payment_Method) {
3516
+						EE_Error::add_attention(__('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.',
3517
+							'event_espresso'));
3518
+					}
3519
+				}
3520
+				//just toggles the entire messenger
3521
+			} else {
3522
+				EE_Error::add_success(
3523
+					sprintf(
3524
+						__('%s messenger has been successfully activated', 'event_espresso'),
3525
+						ucwords($messenger->label['singular'])
3526
+					)
3527
+				);
3528
+			}
3529 3529
             
3530
-            return true;
3530
+			return true;
3531 3531
             
3532
-            //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3533
-            //message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3534
-            //in which case we just give a success message for the messenger being successfully activated.
3535
-        } else {
3536
-            if ( ! $messenger->get_default_message_types()) {
3537
-                //messenger doesn't have any default message types so still a success.
3538
-                EE_Error::add_success(
3539
-                    sprintf(
3540
-                        __('%s messenger was successfully activated.', 'event_espresso'),
3541
-                        ucwords($messenger->label['singular'])
3542
-                    )
3543
-                );
3532
+			//possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3533
+			//message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3534
+			//in which case we just give a success message for the messenger being successfully activated.
3535
+		} else {
3536
+			if ( ! $messenger->get_default_message_types()) {
3537
+				//messenger doesn't have any default message types so still a success.
3538
+				EE_Error::add_success(
3539
+					sprintf(
3540
+						__('%s messenger was successfully activated.', 'event_espresso'),
3541
+						ucwords($messenger->label['singular'])
3542
+					)
3543
+				);
3544 3544
                 
3545
-                return true;
3546
-            } else {
3547
-                EE_Error::add_error(
3548
-                    $message_type instanceof EE_message_type
3549
-                        ? sprintf(
3550
-                        __('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
3551
-                        ucwords($message_type->label['singular']),
3552
-                        ucwords($messenger->label['singular'])
3553
-                    )
3554
-                        : sprintf(
3555
-                        __('%s messenger was not successfully activated', 'event_espresso'),
3556
-                        ucwords($messenger->label['singular'])
3557
-                    ),
3558
-                    __FILE__,
3559
-                    __FUNCTION__,
3560
-                    __LINE__
3561
-                );
3545
+				return true;
3546
+			} else {
3547
+				EE_Error::add_error(
3548
+					$message_type instanceof EE_message_type
3549
+						? sprintf(
3550
+						__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
3551
+						ucwords($message_type->label['singular']),
3552
+						ucwords($messenger->label['singular'])
3553
+					)
3554
+						: sprintf(
3555
+						__('%s messenger was not successfully activated', 'event_espresso'),
3556
+						ucwords($messenger->label['singular'])
3557
+					),
3558
+					__FILE__,
3559
+					__FUNCTION__,
3560
+					__LINE__
3561
+				);
3562 3562
                 
3563
-                return false;
3564
-            }
3565
-        }
3566
-    }
3567
-    
3568
-    
3569
-    /**
3570
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
3571
-     *
3572
-     * @param EE_messenger         $messenger
3573
-     * @param EE_message_type|null $message_type
3574
-     *
3575
-     * @return bool
3576
-     */
3577
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3578
-        $messenger,
3579
-        EE_message_type $message_type = null
3580
-    ) {
3581
-        EE_Error::overwrite_success();
3582
-        
3583
-        //if $messenger isn't a valid messenger object then get out.
3584
-        if ( ! $messenger instanceof EE_Messenger) {
3585
-            EE_Error::add_error(
3586
-                __('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3587
-                __FILE__,
3588
-                __FUNCTION__,
3589
-                __LINE__
3590
-            );
3563
+				return false;
3564
+			}
3565
+		}
3566
+	}
3567
+    
3568
+    
3569
+	/**
3570
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
3571
+	 *
3572
+	 * @param EE_messenger         $messenger
3573
+	 * @param EE_message_type|null $message_type
3574
+	 *
3575
+	 * @return bool
3576
+	 */
3577
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3578
+		$messenger,
3579
+		EE_message_type $message_type = null
3580
+	) {
3581
+		EE_Error::overwrite_success();
3582
+        
3583
+		//if $messenger isn't a valid messenger object then get out.
3584
+		if ( ! $messenger instanceof EE_Messenger) {
3585
+			EE_Error::add_error(
3586
+				__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3587
+				__FILE__,
3588
+				__FUNCTION__,
3589
+				__LINE__
3590
+			);
3591 3591
             
3592
-            return false;
3593
-        }
3594
-        
3595
-        if ($message_type instanceof EE_message_type) {
3596
-            $message_type_name = $message_type->name;
3597
-            EE_Error::add_success(
3598
-                sprintf(
3599
-                    __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
3600
-                    ucwords($message_type->label['singular']),
3601
-                    ucwords($messenger->label['singular'])
3602
-                )
3603
-            );
3604
-        } else {
3605
-            $message_type_name = '';
3606
-            EE_Error::add_success(
3607
-                sprintf(
3608
-                    __('%s messenger has been successfully deactivated.', 'event_espresso'),
3609
-                    ucwords($messenger->label['singular'])
3610
-                )
3611
-            );
3612
-        }
3613
-        
3614
-        //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3615
-        if ($messenger->name == 'html' || $message_type_name == 'invoice') {
3616
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
3617
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3618
-            if ($count_updated > 0) {
3619
-                $msg = $message_type_name == 'invoice'
3620
-                    ? __('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.',
3621
-                        'event_espresso')
3622
-                    : __('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.',
3623
-                        'event_espresso');
3624
-                EE_Error::add_attention($msg);
3625
-            }
3626
-        }
3627
-        
3628
-        return true;
3629
-    }
3630
-    
3631
-    
3632
-    /**
3633
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3634
-     */
3635
-    public function update_mt_form()
3636
-    {
3637
-        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
3638
-            EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__,
3639
-                __LINE__);
3640
-            $this->_return_json();
3641
-        }
3642
-        
3643
-        $message_types = $this->get_installed_message_types();
3644
-        
3645
-        $message_type = $message_types[$this->_req_data['message_type']];
3646
-        $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
3647
-        
3648
-        $content                         = $this->_message_type_settings_content($message_type, $messenger, true);
3649
-        $this->_template_args['success'] = true;
3650
-        $this->_template_args['content'] = $content;
3651
-        $this->_return_json();
3652
-    }
3653
-    
3654
-    
3655
-    /**
3656
-     * this handles saving the settings for a messenger or message type
3657
-     *
3658
-     */
3659
-    public function save_settings()
3660
-    {
3661
-        if ( ! isset($this->_req_data['type'])) {
3662
-            EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
3663
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3664
-            $this->_template_args['error'] = true;
3665
-            $this->_return_json();
3666
-        }
3667
-        
3668
-        
3669
-        if ($this->_req_data['type'] == 'messenger') {
3670
-            $settings  = $this->_req_data['messenger_settings']; //this should be an array.
3671
-            $messenger = $settings['messenger'];
3672
-            //let's setup the settings data
3673
-            foreach ($settings as $key => $value) {
3674
-                switch ($key) {
3675
-                    case 'messenger' :
3676
-                        unset($settings['messenger']);
3677
-                        break;
3678
-                    case 'message_types' :
3679
-                        unset($settings['message_types']);
3680
-                        break;
3681
-                    default :
3682
-                        $settings[$key] = $value;
3683
-                        break;
3684
-                }
3685
-            }
3686
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3687
-        } else if ($this->_req_data['type'] == 'message_type') {
3688
-            $settings     = $this->_req_data['message_type_settings'];
3689
-            $messenger    = $settings['messenger'];
3690
-            $message_type = $settings['message_type'];
3592
+			return false;
3593
+		}
3594
+        
3595
+		if ($message_type instanceof EE_message_type) {
3596
+			$message_type_name = $message_type->name;
3597
+			EE_Error::add_success(
3598
+				sprintf(
3599
+					__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
3600
+					ucwords($message_type->label['singular']),
3601
+					ucwords($messenger->label['singular'])
3602
+				)
3603
+			);
3604
+		} else {
3605
+			$message_type_name = '';
3606
+			EE_Error::add_success(
3607
+				sprintf(
3608
+					__('%s messenger has been successfully deactivated.', 'event_espresso'),
3609
+					ucwords($messenger->label['singular'])
3610
+				)
3611
+			);
3612
+		}
3613
+        
3614
+		//if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3615
+		if ($messenger->name == 'html' || $message_type_name == 'invoice') {
3616
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
3617
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3618
+			if ($count_updated > 0) {
3619
+				$msg = $message_type_name == 'invoice'
3620
+					? __('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.',
3621
+						'event_espresso')
3622
+					: __('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.',
3623
+						'event_espresso');
3624
+				EE_Error::add_attention($msg);
3625
+			}
3626
+		}
3627
+        
3628
+		return true;
3629
+	}
3630
+    
3631
+    
3632
+	/**
3633
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3634
+	 */
3635
+	public function update_mt_form()
3636
+	{
3637
+		if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
3638
+			EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__,
3639
+				__LINE__);
3640
+			$this->_return_json();
3641
+		}
3642
+        
3643
+		$message_types = $this->get_installed_message_types();
3644
+        
3645
+		$message_type = $message_types[$this->_req_data['message_type']];
3646
+		$messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
3647
+        
3648
+		$content                         = $this->_message_type_settings_content($message_type, $messenger, true);
3649
+		$this->_template_args['success'] = true;
3650
+		$this->_template_args['content'] = $content;
3651
+		$this->_return_json();
3652
+	}
3653
+    
3654
+    
3655
+	/**
3656
+	 * this handles saving the settings for a messenger or message type
3657
+	 *
3658
+	 */
3659
+	public function save_settings()
3660
+	{
3661
+		if ( ! isset($this->_req_data['type'])) {
3662
+			EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
3663
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3664
+			$this->_template_args['error'] = true;
3665
+			$this->_return_json();
3666
+		}
3667
+        
3668
+        
3669
+		if ($this->_req_data['type'] == 'messenger') {
3670
+			$settings  = $this->_req_data['messenger_settings']; //this should be an array.
3671
+			$messenger = $settings['messenger'];
3672
+			//let's setup the settings data
3673
+			foreach ($settings as $key => $value) {
3674
+				switch ($key) {
3675
+					case 'messenger' :
3676
+						unset($settings['messenger']);
3677
+						break;
3678
+					case 'message_types' :
3679
+						unset($settings['message_types']);
3680
+						break;
3681
+					default :
3682
+						$settings[$key] = $value;
3683
+						break;
3684
+				}
3685
+			}
3686
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3687
+		} else if ($this->_req_data['type'] == 'message_type') {
3688
+			$settings     = $this->_req_data['message_type_settings'];
3689
+			$messenger    = $settings['messenger'];
3690
+			$message_type = $settings['message_type'];
3691 3691
             
3692
-            foreach ($settings as $key => $value) {
3693
-                switch ($key) {
3694
-                    case 'messenger' :
3695
-                        unset($settings['messenger']);
3696
-                        break;
3697
-                    case 'message_type' :
3698
-                        unset($settings['message_type']);
3699
-                        break;
3700
-                    default :
3701
-                        $settings[$key] = $value;
3702
-                        break;
3703
-                }
3704
-            }
3692
+			foreach ($settings as $key => $value) {
3693
+				switch ($key) {
3694
+					case 'messenger' :
3695
+						unset($settings['messenger']);
3696
+						break;
3697
+					case 'message_type' :
3698
+						unset($settings['message_type']);
3699
+						break;
3700
+					default :
3701
+						$settings[$key] = $value;
3702
+						break;
3703
+				}
3704
+			}
3705 3705
             
3706
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3707
-        }
3708
-        
3709
-        //okay we should have the data all setup.  Now we just update!
3710
-        $success = $this->_message_resource_manager->update_active_messengers_option();
3711
-        
3712
-        if ($success) {
3713
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
3714
-        } else {
3715
-            EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3716
-        }
3717
-        
3718
-        $this->_template_args['success'] = $success;
3719
-        $this->_return_json();
3720
-    }
3721
-    
3722
-    
3723
-    
3724
-    
3725
-    /**  EE MESSAGE PROCESSING ACTIONS **/
3726
-    
3727
-    
3728
-    /**
3729
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
3730
-     * However, this does not send immediately, it just queues for sending.
3731
-     *
3732
-     * @since 4.9.0
3733
-     */
3734
-    protected function _generate_now()
3735
-    {
3736
-        $msg_ids = $this->_get_msg_ids_from_request();
3737
-        EED_Messages::generate_now($msg_ids);
3738
-        $this->_redirect_after_action(false, '', '', array(), true);
3739
-    }
3740
-    
3741
-    
3742
-    /**
3743
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
3744
-     * are EEM_Message::status_resend or EEM_Message::status_idle
3745
-     *
3746
-     * @since 4.9.0
3747
-     *
3748
-     */
3749
-    protected function _generate_and_send_now()
3750
-    {
3751
-        $this->_generate_now();
3752
-        $this->_send_now();
3753
-        $this->_redirect_after_action(false, '', '', array(), true);
3754
-    }
3755
-    
3756
-    
3757
-    /**
3758
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
3759
-     *
3760
-     * @since 4.9.0
3761
-     */
3762
-    protected function _queue_for_resending()
3763
-    {
3764
-        $msg_ids = $this->_get_msg_ids_from_request();
3765
-        EED_Messages::queue_for_resending($msg_ids);
3766
-        $this->_redirect_after_action(false, '', '', array(), true);
3767
-    }
3768
-    
3769
-    
3770
-    /**
3771
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
3772
-     *
3773
-     * @since 4.9.0
3774
-     */
3775
-    protected function _send_now()
3776
-    {
3777
-        $msg_ids = $this->_get_msg_ids_from_request();
3778
-        EED_Messages::send_now($msg_ids);
3779
-        $this->_redirect_after_action(false, '', '', array(), true);
3780
-    }
3781
-    
3782
-    
3783
-    /**
3784
-     * Deletes EE_messages for IDs in the request.
3785
-     *
3786
-     * @since 4.9.0
3787
-     */
3788
-    protected function _delete_ee_messages()
3789
-    {
3790
-        $msg_ids       = $this->_get_msg_ids_from_request();
3791
-        $deleted_count = 0;
3792
-        foreach ($msg_ids as $msg_id) {
3793
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
3794
-                $deleted_count++;
3795
-            }
3796
-        }
3797
-        if ($deleted_count) {
3798
-            $this->_redirect_after_action(
3799
-                true,
3800
-                _n('message', 'messages', $deleted_count, 'event_espresso'),
3801
-                __('deleted', 'event_espresso')
3802
-            );
3803
-        } else {
3804
-            EE_Error::add_error(
3805
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
3806
-                __FILE__, __FUNCTION__, __LINE__
3807
-            );
3808
-            $this->_redirect_after_action(false, '', '', array(), true);
3809
-        }
3810
-    }
3811
-    
3812
-    
3813
-    /**
3814
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
3815
-     * @since 4.9.0
3816
-     * @return array
3817
-     */
3818
-    protected function _get_msg_ids_from_request()
3819
-    {
3820
-        if ( ! isset($this->_req_data['MSG_ID'])) {
3821
-            return array();
3822
-        }
3823
-        
3824
-        return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);
3825
-    }
3706
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3707
+		}
3708
+        
3709
+		//okay we should have the data all setup.  Now we just update!
3710
+		$success = $this->_message_resource_manager->update_active_messengers_option();
3711
+        
3712
+		if ($success) {
3713
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
3714
+		} else {
3715
+			EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3716
+		}
3717
+        
3718
+		$this->_template_args['success'] = $success;
3719
+		$this->_return_json();
3720
+	}
3721
+    
3722
+    
3723
+    
3724
+    
3725
+	/**  EE MESSAGE PROCESSING ACTIONS **/
3726
+    
3727
+    
3728
+	/**
3729
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
3730
+	 * However, this does not send immediately, it just queues for sending.
3731
+	 *
3732
+	 * @since 4.9.0
3733
+	 */
3734
+	protected function _generate_now()
3735
+	{
3736
+		$msg_ids = $this->_get_msg_ids_from_request();
3737
+		EED_Messages::generate_now($msg_ids);
3738
+		$this->_redirect_after_action(false, '', '', array(), true);
3739
+	}
3740
+    
3741
+    
3742
+	/**
3743
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
3744
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
3745
+	 *
3746
+	 * @since 4.9.0
3747
+	 *
3748
+	 */
3749
+	protected function _generate_and_send_now()
3750
+	{
3751
+		$this->_generate_now();
3752
+		$this->_send_now();
3753
+		$this->_redirect_after_action(false, '', '', array(), true);
3754
+	}
3755
+    
3756
+    
3757
+	/**
3758
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
3759
+	 *
3760
+	 * @since 4.9.0
3761
+	 */
3762
+	protected function _queue_for_resending()
3763
+	{
3764
+		$msg_ids = $this->_get_msg_ids_from_request();
3765
+		EED_Messages::queue_for_resending($msg_ids);
3766
+		$this->_redirect_after_action(false, '', '', array(), true);
3767
+	}
3768
+    
3769
+    
3770
+	/**
3771
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
3772
+	 *
3773
+	 * @since 4.9.0
3774
+	 */
3775
+	protected function _send_now()
3776
+	{
3777
+		$msg_ids = $this->_get_msg_ids_from_request();
3778
+		EED_Messages::send_now($msg_ids);
3779
+		$this->_redirect_after_action(false, '', '', array(), true);
3780
+	}
3781
+    
3782
+    
3783
+	/**
3784
+	 * Deletes EE_messages for IDs in the request.
3785
+	 *
3786
+	 * @since 4.9.0
3787
+	 */
3788
+	protected function _delete_ee_messages()
3789
+	{
3790
+		$msg_ids       = $this->_get_msg_ids_from_request();
3791
+		$deleted_count = 0;
3792
+		foreach ($msg_ids as $msg_id) {
3793
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
3794
+				$deleted_count++;
3795
+			}
3796
+		}
3797
+		if ($deleted_count) {
3798
+			$this->_redirect_after_action(
3799
+				true,
3800
+				_n('message', 'messages', $deleted_count, 'event_espresso'),
3801
+				__('deleted', 'event_espresso')
3802
+			);
3803
+		} else {
3804
+			EE_Error::add_error(
3805
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
3806
+				__FILE__, __FUNCTION__, __LINE__
3807
+			);
3808
+			$this->_redirect_after_action(false, '', '', array(), true);
3809
+		}
3810
+	}
3811
+    
3812
+    
3813
+	/**
3814
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
3815
+	 * @since 4.9.0
3816
+	 * @return array
3817
+	 */
3818
+	protected function _get_msg_ids_from_request()
3819
+	{
3820
+		if ( ! isset($this->_req_data['MSG_ID'])) {
3821
+			return array();
3822
+		}
3823
+        
3824
+		return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);
3825
+	}
3826 3826
     
3827 3827
     
3828 3828
 }
Please login to merge, or discard this patch.
core/domain/DomainBase.php 2 patches
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -18,132 +18,132 @@
 block discarded – undo
18 18
 abstract class DomainBase
19 19
 {
20 20
 
21
-    /**
22
-     * Equivalent to `__FILE__` for main plugin file.
23
-     *
24
-     * @var string
25
-     */
26
-    private static $plugin_file = '';
27
-
28
-    /**
29
-     * String indicating version for plugin
30
-     *
31
-     * @var string
32
-     */
33
-    private static $version = '';
34
-
35
-    /**
36
-     * @var string $plugin_basename
37
-     */
38
-    private static $plugin_basename = '';
39
-
40
-    /**
41
-     * @var string $plugin_path
42
-     */
43
-    private static $plugin_path = '';
44
-
45
-    /**
46
-     * @var string $plugin_url
47
-     */
48
-    private static $plugin_url = '';
49
-
50
-
51
-
52
-    /**
53
-     * Initializes internal static properties.
54
-     *
55
-     * @param string $plugin_file
56
-     * @param string $version
57
-     */
58
-    public static function init($plugin_file, $version)
59
-    {
60
-        self::$plugin_file = $plugin_file;
61
-        self::$version = $version;
62
-        self::$plugin_basename = plugin_basename($plugin_file);
63
-        self::$plugin_path = plugin_dir_path($plugin_file);
64
-        self::$plugin_url = plugin_dir_url($plugin_file);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * @return string
71
-     * @throws DomainException
72
-     */
73
-    public static function pluginFile()
74
-    {
75
-        self::verifyInitialized(__METHOD__);
76
-        return self::$plugin_file;
77
-    }
78
-
79
-
80
-
81
-    /**
82
-     * @return string
83
-     * @throws DomainException
84
-     */
85
-    public static function pluginBasename()
86
-    {
87
-        self::verifyInitialized(__METHOD__);
88
-        return self::$plugin_basename;
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * @return string
95
-     * @throws DomainException
96
-     */
97
-    public static function pluginPath()
98
-    {
99
-        self::verifyInitialized(__METHOD__);
100
-        return self::$plugin_path;
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * @return string
107
-     * @throws DomainException
108
-     */
109
-    public static function pluginUrl()
110
-    {
111
-        self::verifyInitialized(__METHOD__);
112
-        return self::$plugin_url;
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     * @return string
119
-     * @throws DomainException
120
-     */
121
-    public static function version()
122
-    {
123
-        self::verifyInitialized(__METHOD__);
124
-        return self::$version;
125
-    }
126
-
127
-
128
-
129
-    /**
130
-     * @param string $method
131
-     * @throws DomainException
132
-     */
133
-    private static function verifyInitialized($method)
134
-    {
135
-        if (self::$plugin_file === '') {
136
-            throw new DomainException(
137
-                sprintf(
138
-                    esc_html__(
139
-                        '%1$s needs to be called before %2$s can return a value.',
140
-                        'event_espresso'
141
-                    ),
142
-                    get_called_class() . '::init()',
143
-                    "{$method}()"
144
-                )
145
-            );
146
-        }
147
-    }
21
+	/**
22
+	 * Equivalent to `__FILE__` for main plugin file.
23
+	 *
24
+	 * @var string
25
+	 */
26
+	private static $plugin_file = '';
27
+
28
+	/**
29
+	 * String indicating version for plugin
30
+	 *
31
+	 * @var string
32
+	 */
33
+	private static $version = '';
34
+
35
+	/**
36
+	 * @var string $plugin_basename
37
+	 */
38
+	private static $plugin_basename = '';
39
+
40
+	/**
41
+	 * @var string $plugin_path
42
+	 */
43
+	private static $plugin_path = '';
44
+
45
+	/**
46
+	 * @var string $plugin_url
47
+	 */
48
+	private static $plugin_url = '';
49
+
50
+
51
+
52
+	/**
53
+	 * Initializes internal static properties.
54
+	 *
55
+	 * @param string $plugin_file
56
+	 * @param string $version
57
+	 */
58
+	public static function init($plugin_file, $version)
59
+	{
60
+		self::$plugin_file = $plugin_file;
61
+		self::$version = $version;
62
+		self::$plugin_basename = plugin_basename($plugin_file);
63
+		self::$plugin_path = plugin_dir_path($plugin_file);
64
+		self::$plugin_url = plugin_dir_url($plugin_file);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * @return string
71
+	 * @throws DomainException
72
+	 */
73
+	public static function pluginFile()
74
+	{
75
+		self::verifyInitialized(__METHOD__);
76
+		return self::$plugin_file;
77
+	}
78
+
79
+
80
+
81
+	/**
82
+	 * @return string
83
+	 * @throws DomainException
84
+	 */
85
+	public static function pluginBasename()
86
+	{
87
+		self::verifyInitialized(__METHOD__);
88
+		return self::$plugin_basename;
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * @return string
95
+	 * @throws DomainException
96
+	 */
97
+	public static function pluginPath()
98
+	{
99
+		self::verifyInitialized(__METHOD__);
100
+		return self::$plugin_path;
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * @return string
107
+	 * @throws DomainException
108
+	 */
109
+	public static function pluginUrl()
110
+	{
111
+		self::verifyInitialized(__METHOD__);
112
+		return self::$plugin_url;
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 * @return string
119
+	 * @throws DomainException
120
+	 */
121
+	public static function version()
122
+	{
123
+		self::verifyInitialized(__METHOD__);
124
+		return self::$version;
125
+	}
126
+
127
+
128
+
129
+	/**
130
+	 * @param string $method
131
+	 * @throws DomainException
132
+	 */
133
+	private static function verifyInitialized($method)
134
+	{
135
+		if (self::$plugin_file === '') {
136
+			throw new DomainException(
137
+				sprintf(
138
+					esc_html__(
139
+						'%1$s needs to be called before %2$s can return a value.',
140
+						'event_espresso'
141
+					),
142
+					get_called_class() . '::init()',
143
+					"{$method}()"
144
+				)
145
+			);
146
+		}
147
+	}
148 148
 
149 149
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -139,7 +139,7 @@
 block discarded – undo
139 139
                         '%1$s needs to be called before %2$s can return a value.',
140 140
                         'event_espresso'
141 141
                     ),
142
-                    get_called_class() . '::init()',
142
+                    get_called_class().'::init()',
143 143
                     "{$method}()"
144 144
                 )
145 145
             );
Please login to merge, or discard this patch.
core/services/shortcodes/LegacyShortcodesManager.php 1 patch
Indentation   +423 added lines, -423 removed lines patch added patch discarded remove patch
@@ -25,429 +25,429 @@
 block discarded – undo
25 25
 class LegacyShortcodesManager
26 26
 {
27 27
 
28
-    /**
29
-     * @var EE_Registry $registry
30
-     */
31
-    private $registry;
32
-
33
-
34
-
35
-
36
-    /**
37
-     * LegacyShortcodesManager constructor.
38
-     *
39
-     * @param \EE_Registry $registry
40
-     */
41
-    public function __construct(EE_Registry $registry)
42
-    {
43
-        $this->registry = $registry;
44
-    }
45
-
46
-
47
-
48
-    /**
49
-     * @return EE_Registry
50
-     */
51
-    public function registry()
52
-    {
53
-        return $this->registry;
54
-    }
55
-
56
-
57
-
58
-    /**
59
-     * registerShortcodes
60
-     *
61
-     * @return void
62
-     */
63
-    public function registerShortcodes()
64
-    {
65
-        $this->registry->shortcodes = $this->getShortcodes();
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * getShortcodes
72
-     *
73
-     * @return array
74
-     */
75
-    public function getShortcodes()
76
-    {
77
-        // previously this method would glob the shortcodes directory
78
-        // then filter that list of shortcodes to register,
79
-        // but now we are going to just supply an empty array.
80
-        // this allows any shortcodes that have not yet been converted to the new system
81
-        // to still get loaded and processed, albeit using the same legacy logic as before
82
-        $shortcodes_to_register = apply_filters(
83
-            'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
84
-            array()
85
-        );
86
-        if ( ! empty($shortcodes_to_register)) {
87
-            // cycle thru shortcode folders
88
-            foreach ($shortcodes_to_register as $shortcode_path) {
89
-                // add to list of installed shortcode modules
90
-                $this->registerShortcode($shortcode_path);
91
-            }
92
-        }
93
-        // filter list of installed modules
94
-        return apply_filters(
95
-            'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
96
-            ! empty($this->registry->shortcodes)
97
-                ? $this->registry->shortcodes
98
-                : array()
99
-        );
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     *    register_shortcode - makes core aware of this shortcode
106
-     *
107
-     * @access    public
108
-     * @param    string $shortcode_path - full path up to and including shortcode folder
109
-     * @return    bool
110
-     */
111
-    public function registerShortcode($shortcode_path = null)
112
-    {
113
-        do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path);
114
-        $shortcode_ext = '.shortcode.php';
115
-        // make all separators match
116
-        $shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path);
117
-        // does the file path INCLUDE the actual file name as part of the path ?
118
-        if (strpos($shortcode_path, $shortcode_ext) !== false) {
119
-            // grab shortcode file name from directory name and break apart at dots
120
-            $shortcode_file = explode('.', basename($shortcode_path));
121
-            // take first segment from file name pieces and remove class prefix if it exists
122
-            $shortcode = strpos($shortcode_file[0], 'EES_') === 0
123
-                ? substr($shortcode_file[0], 4)
124
-                : $shortcode_file[0];
125
-            // sanitize shortcode directory name
126
-            $shortcode = sanitize_key($shortcode);
127
-            // now we need to rebuild the shortcode path
128
-            $shortcode_path = explode(DS, $shortcode_path);
129
-            // remove last segment
130
-            array_pop($shortcode_path);
131
-            // glue it back together
132
-            $shortcode_path = implode(DS, $shortcode_path) . DS;
133
-        } else {
134
-            // we need to generate the filename based off of the folder name
135
-            // grab and sanitize shortcode directory name
136
-            $shortcode = sanitize_key(basename($shortcode_path));
137
-            $shortcode_path = rtrim($shortcode_path, DS) . DS;
138
-        }
139
-        // create classname from shortcode directory or file name
140
-        $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
141
-        // add class prefix
142
-        $shortcode_class = 'EES_' . $shortcode;
143
-        // does the shortcode exist ?
144
-        if ( ! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) {
145
-            $msg = sprintf(
146
-                esc_html__(
147
-                    'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
148
-                    'event_espresso'
149
-                ),
150
-                $shortcode_class,
151
-                $shortcode_path . DS . $shortcode_class . $shortcode_ext
152
-            );
153
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
154
-            return false;
155
-        }
156
-        // load the shortcode class file
157
-        require_once($shortcode_path . $shortcode_class . $shortcode_ext);
158
-        // verify that class exists
159
-        if ( ! class_exists($shortcode_class)) {
160
-            $msg = sprintf(
161
-                esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'),
162
-                $shortcode_class
163
-            );
164
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
165
-            return false;
166
-        }
167
-        $shortcode = strtoupper($shortcode);
168
-        // add to array of registered shortcodes
169
-        $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
170
-        return true;
171
-    }
172
-
173
-
174
-
175
-    /**
176
-     *    _initialize_shortcodes
177
-     *    allow shortcodes to set hooks for the rest of the system
178
-     *
179
-     * @access private
180
-     * @return void
181
-     */
182
-    public function addShortcodes()
183
-    {
184
-        // cycle thru shortcode folders
185
-        foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) {
186
-            // add class prefix
187
-            $shortcode_class = 'EES_' . $shortcode;
188
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
189
-            // which set hooks ?
190
-            if (is_admin()) {
191
-                // fire immediately
192
-                call_user_func(array($shortcode_class, 'set_hooks_admin'));
193
-            } else {
194
-                // delay until other systems are online
195
-                add_action(
196
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
197
-                    array($shortcode_class, 'set_hooks')
198
-                );
199
-                // convert classname to UPPERCASE and create WP shortcode.
200
-                $shortcode_tag = strtoupper($shortcode);
201
-                // but first check if the shortcode has already
202
-                // been added before assigning 'fallback_shortcode_processor'
203
-                if ( ! shortcode_exists($shortcode_tag)) {
204
-                    // NOTE: this shortcode declaration will get overridden if the shortcode
205
-                    // is successfully detected in the post content in initializeShortcode()
206
-                    add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
207
-                }
208
-            }
209
-        }
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * callback for the WP "get_header" hook point
216
-     * checks posts for EE shortcodes, and initializes them,
217
-     * then toggles filter switch that loads core default assets
218
-     *
219
-     * @param \WP_Query $wp_query
220
-     * @return void
221
-     */
222
-    public function initializeShortcodes(WP_Query $wp_query)
223
-    {
224
-        if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) {
225
-            return;
226
-        }
227
-        global $wp;
228
-        /** @var EE_Front_controller $Front_Controller */
229
-        $Front_Controller = $this->registry->load_core('Front_Controller', array(), false);
230
-        do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller);
231
-        $Front_Controller->Request_Handler()->set_request_vars();
232
-        // grab post_name from request
233
-        $current_post = apply_filters(
234
-            'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name',
235
-            $Front_Controller->Request_Handler()->get('post_name')
236
-        );
237
-        $show_on_front = get_option('show_on_front');
238
-        // if it's not set, then check if frontpage is blog
239
-        if (empty($current_post)) {
240
-            // yup.. this is the posts page, prepare to load all shortcode modules
241
-            $current_post = 'posts';
242
-            // unless..
243
-            if ($show_on_front === 'page') {
244
-                // some other page is set as the homepage
245
-                $page_on_front = get_option('page_on_front');
246
-                if ($page_on_front) {
247
-                    // k now we need to find the post_name for this page
248
-                    global $wpdb;
249
-                    $page_on_front = $wpdb->get_var(
250
-                        $wpdb->prepare(
251
-                            "SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d",
252
-                            $page_on_front
253
-                        )
254
-                    );
255
-                    // set the current post slug to what it actually is
256
-                    $current_post = $page_on_front ? $page_on_front : $current_post;
257
-                }
258
-            }
259
-        }
260
-        // in case $current_post is hierarchical like: /parent-page/current-page
261
-        $current_post = basename($current_post);
262
-        if (
263
-            // is current page/post the "blog" page ?
264
-            $current_post === EE_Config::get_page_for_posts()
265
-            // or are we on a category page?
266
-            || (
267
-                is_array(term_exists($current_post, 'category'))
268
-                || array_key_exists('category_name', $wp->query_vars)
269
-            )
270
-        ) {
271
-            // initialize all legacy shortcodes
272
-            $load_assets = $this->parseContentForShortcodes('', true);
273
-        } else {
274
-            global $wpdb;
275
-            $post_content = $wpdb->get_var(
276
-                $wpdb->prepare(
277
-                    "SELECT post_content from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s",
278
-                    $current_post
279
-                )
280
-            );
281
-            $load_assets = $this->parseContentForShortcodes($post_content);
282
-        }
283
-        if ($load_assets) {
284
-            $this->registry->REQ->set_espresso_page(true);
285
-            add_filter('FHEE_load_css', '__return_true');
286
-            add_filter('FHEE_load_js', '__return_true');
287
-        }
288
-        do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller);
289
-    }
290
-
291
-
292
-
293
-    /**
294
-     * checks supplied content against list of legacy shortcodes,
295
-     * then initializes any found shortcodes, and returns true.
296
-     * returns false if no shortcodes found.
297
-     *
298
-     * @param string $content
299
-     * @param bool   $load_all if true, then ALL active legacy shortcodes will be initialized
300
-     * @return bool
301
-     */
302
-    public function parseContentForShortcodes($content = '', $load_all = false)
303
-    {
304
-        $has_shortcode = false;
305
-        foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) {
306
-            if ($load_all || has_shortcode($content, $shortcode_class) ) {
307
-                // load up the shortcode
308
-                $this->initializeShortcode($shortcode_class);
309
-                $has_shortcode = true;
310
-            }
311
-        }
312
-        return $has_shortcode;
313
-    }
314
-
315
-
316
-
317
-    /**
318
-     * given a shortcode name, will instantiate the shortcode and call it's run() method
319
-     *
320
-     * @param string $shortcode_class
321
-     * @param WP     $wp
322
-     */
323
-    public function initializeShortcode($shortcode_class = '', WP $wp = null)
324
-    {
325
-        // don't do anything if shortcode is already initialized
326
-        if (
327
-            empty($this->registry->shortcodes->{$shortcode_class})
328
-            || ! is_string($this->registry->shortcodes->{$shortcode_class})
329
-        ) {
330
-            return;
331
-        }
332
-        // let's pause to reflect on this...
333
-        $sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class));
334
-        // ensure that class is actually a shortcode
335
-        if (
336
-            defined('WP_DEBUG')
337
-            && WP_DEBUG === true
338
-            && ! $sc_reflector->isSubclassOf('EES_Shortcode')
339
-        ) {
340
-            EE_Error::add_error(
341
-                sprintf(
342
-                    esc_html__(
343
-                        'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
344
-                        'event_espresso'
345
-                    ),
346
-                    $shortcode_class
347
-                ),
348
-                __FILE__,
349
-                __FUNCTION__,
350
-                __LINE__
351
-            );
352
-            add_filter('FHEE_run_EE_the_content', '__return_true');
353
-            return;
354
-        }
355
-        global $wp;
356
-        // and pass the request object to the run method
357
-        $this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
358
-        // fire the shortcode class's run method, so that it can activate resources
359
-        $this->registry->shortcodes->{$shortcode_class}->run($wp);
360
-    }
361
-
362
-
363
-
364
-    /**
365
-     * get classname, remove EES_prefix, and convert to UPPERCASE
366
-     *
367
-     * @param string $class_name
368
-     * @return string
369
-     */
370
-    public static function generateShortcodeTagFromClassName($class_name)
371
-    {
372
-        return strtoupper(str_replace('EES_', '', $class_name));
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * add EES_prefix and Capitalize words
379
-     *
380
-     * @param string $tag
381
-     * @return string
382
-     */
383
-    public static function generateShortcodeClassNameFromTag($tag)
384
-    {
385
-        // order of operation runs from inside to out
386
-        // 5) maybe add prefix
387
-        return LegacyShortcodesManager::addShortcodeClassPrefix(
388
-        // 4) find spaces, replace with underscores
389
-            str_replace(
390
-                ' ',
391
-                '_',
392
-                // 3) capitalize first letter of each word
393
-                ucwords(
394
-                // 2) also change to lowercase so ucwords() will work
395
-                    strtolower(
396
-                    // 1) find underscores, replace with spaces so ucwords() will work
397
-                        str_replace(
398
-                            '_',
399
-                            ' ',
400
-                            $tag
401
-                        )
402
-                    )
403
-                )
404
-            )
405
-        );
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * maybe add EES_prefix
412
-     *
413
-     * @param string $class_name
414
-     * @return string
415
-     */
416
-    public static function addShortcodeClassPrefix($class_name)
417
-    {
418
-        return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name;
419
-    }
420
-
421
-
422
-
423
-    /**
424
-     * @return array
425
-     */
426
-    public function getEspressoShortcodeTags()
427
-    {
428
-        static $shortcode_tags = array();
429
-        if (empty($shortcode_tags)) {
430
-            $shortcode_tags = array_keys((array)$this->registry->shortcodes);
431
-        }
432
-        return $shortcode_tags;
433
-    }
434
-
435
-
436
-
437
-    /**
438
-     * @param string $content
439
-     * @return string
440
-     */
441
-    public function doShortcode($content)
442
-    {
443
-        foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) {
444
-            if (strpos($content, $shortcode_tag) !== false) {
445
-                $shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag);
446
-                $this->initializeShortcode($shortcode_class);
447
-            }
448
-        }
449
-        return do_shortcode($content);
450
-    }
28
+	/**
29
+	 * @var EE_Registry $registry
30
+	 */
31
+	private $registry;
32
+
33
+
34
+
35
+
36
+	/**
37
+	 * LegacyShortcodesManager constructor.
38
+	 *
39
+	 * @param \EE_Registry $registry
40
+	 */
41
+	public function __construct(EE_Registry $registry)
42
+	{
43
+		$this->registry = $registry;
44
+	}
45
+
46
+
47
+
48
+	/**
49
+	 * @return EE_Registry
50
+	 */
51
+	public function registry()
52
+	{
53
+		return $this->registry;
54
+	}
55
+
56
+
57
+
58
+	/**
59
+	 * registerShortcodes
60
+	 *
61
+	 * @return void
62
+	 */
63
+	public function registerShortcodes()
64
+	{
65
+		$this->registry->shortcodes = $this->getShortcodes();
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * getShortcodes
72
+	 *
73
+	 * @return array
74
+	 */
75
+	public function getShortcodes()
76
+	{
77
+		// previously this method would glob the shortcodes directory
78
+		// then filter that list of shortcodes to register,
79
+		// but now we are going to just supply an empty array.
80
+		// this allows any shortcodes that have not yet been converted to the new system
81
+		// to still get loaded and processed, albeit using the same legacy logic as before
82
+		$shortcodes_to_register = apply_filters(
83
+			'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
84
+			array()
85
+		);
86
+		if ( ! empty($shortcodes_to_register)) {
87
+			// cycle thru shortcode folders
88
+			foreach ($shortcodes_to_register as $shortcode_path) {
89
+				// add to list of installed shortcode modules
90
+				$this->registerShortcode($shortcode_path);
91
+			}
92
+		}
93
+		// filter list of installed modules
94
+		return apply_filters(
95
+			'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
96
+			! empty($this->registry->shortcodes)
97
+				? $this->registry->shortcodes
98
+				: array()
99
+		);
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 *    register_shortcode - makes core aware of this shortcode
106
+	 *
107
+	 * @access    public
108
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
109
+	 * @return    bool
110
+	 */
111
+	public function registerShortcode($shortcode_path = null)
112
+	{
113
+		do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path);
114
+		$shortcode_ext = '.shortcode.php';
115
+		// make all separators match
116
+		$shortcode_path = str_replace(array('\\', '/'), DS, $shortcode_path);
117
+		// does the file path INCLUDE the actual file name as part of the path ?
118
+		if (strpos($shortcode_path, $shortcode_ext) !== false) {
119
+			// grab shortcode file name from directory name and break apart at dots
120
+			$shortcode_file = explode('.', basename($shortcode_path));
121
+			// take first segment from file name pieces and remove class prefix if it exists
122
+			$shortcode = strpos($shortcode_file[0], 'EES_') === 0
123
+				? substr($shortcode_file[0], 4)
124
+				: $shortcode_file[0];
125
+			// sanitize shortcode directory name
126
+			$shortcode = sanitize_key($shortcode);
127
+			// now we need to rebuild the shortcode path
128
+			$shortcode_path = explode(DS, $shortcode_path);
129
+			// remove last segment
130
+			array_pop($shortcode_path);
131
+			// glue it back together
132
+			$shortcode_path = implode(DS, $shortcode_path) . DS;
133
+		} else {
134
+			// we need to generate the filename based off of the folder name
135
+			// grab and sanitize shortcode directory name
136
+			$shortcode = sanitize_key(basename($shortcode_path));
137
+			$shortcode_path = rtrim($shortcode_path, DS) . DS;
138
+		}
139
+		// create classname from shortcode directory or file name
140
+		$shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode)));
141
+		// add class prefix
142
+		$shortcode_class = 'EES_' . $shortcode;
143
+		// does the shortcode exist ?
144
+		if ( ! is_readable($shortcode_path . DS . $shortcode_class . $shortcode_ext)) {
145
+			$msg = sprintf(
146
+				esc_html__(
147
+					'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
148
+					'event_espresso'
149
+				),
150
+				$shortcode_class,
151
+				$shortcode_path . DS . $shortcode_class . $shortcode_ext
152
+			);
153
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
154
+			return false;
155
+		}
156
+		// load the shortcode class file
157
+		require_once($shortcode_path . $shortcode_class . $shortcode_ext);
158
+		// verify that class exists
159
+		if ( ! class_exists($shortcode_class)) {
160
+			$msg = sprintf(
161
+				esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'),
162
+				$shortcode_class
163
+			);
164
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
165
+			return false;
166
+		}
167
+		$shortcode = strtoupper($shortcode);
168
+		// add to array of registered shortcodes
169
+		$this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
170
+		return true;
171
+	}
172
+
173
+
174
+
175
+	/**
176
+	 *    _initialize_shortcodes
177
+	 *    allow shortcodes to set hooks for the rest of the system
178
+	 *
179
+	 * @access private
180
+	 * @return void
181
+	 */
182
+	public function addShortcodes()
183
+	{
184
+		// cycle thru shortcode folders
185
+		foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) {
186
+			// add class prefix
187
+			$shortcode_class = 'EES_' . $shortcode;
188
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
189
+			// which set hooks ?
190
+			if (is_admin()) {
191
+				// fire immediately
192
+				call_user_func(array($shortcode_class, 'set_hooks_admin'));
193
+			} else {
194
+				// delay until other systems are online
195
+				add_action(
196
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
197
+					array($shortcode_class, 'set_hooks')
198
+				);
199
+				// convert classname to UPPERCASE and create WP shortcode.
200
+				$shortcode_tag = strtoupper($shortcode);
201
+				// but first check if the shortcode has already
202
+				// been added before assigning 'fallback_shortcode_processor'
203
+				if ( ! shortcode_exists($shortcode_tag)) {
204
+					// NOTE: this shortcode declaration will get overridden if the shortcode
205
+					// is successfully detected in the post content in initializeShortcode()
206
+					add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor'));
207
+				}
208
+			}
209
+		}
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * callback for the WP "get_header" hook point
216
+	 * checks posts for EE shortcodes, and initializes them,
217
+	 * then toggles filter switch that loads core default assets
218
+	 *
219
+	 * @param \WP_Query $wp_query
220
+	 * @return void
221
+	 */
222
+	public function initializeShortcodes(WP_Query $wp_query)
223
+	{
224
+		if (empty($this->registry->shortcodes) || ! $wp_query->is_main_query() || is_admin()) {
225
+			return;
226
+		}
227
+		global $wp;
228
+		/** @var EE_Front_controller $Front_Controller */
229
+		$Front_Controller = $this->registry->load_core('Front_Controller', array(), false);
230
+		do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller);
231
+		$Front_Controller->Request_Handler()->set_request_vars();
232
+		// grab post_name from request
233
+		$current_post = apply_filters(
234
+			'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name',
235
+			$Front_Controller->Request_Handler()->get('post_name')
236
+		);
237
+		$show_on_front = get_option('show_on_front');
238
+		// if it's not set, then check if frontpage is blog
239
+		if (empty($current_post)) {
240
+			// yup.. this is the posts page, prepare to load all shortcode modules
241
+			$current_post = 'posts';
242
+			// unless..
243
+			if ($show_on_front === 'page') {
244
+				// some other page is set as the homepage
245
+				$page_on_front = get_option('page_on_front');
246
+				if ($page_on_front) {
247
+					// k now we need to find the post_name for this page
248
+					global $wpdb;
249
+					$page_on_front = $wpdb->get_var(
250
+						$wpdb->prepare(
251
+							"SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d",
252
+							$page_on_front
253
+						)
254
+					);
255
+					// set the current post slug to what it actually is
256
+					$current_post = $page_on_front ? $page_on_front : $current_post;
257
+				}
258
+			}
259
+		}
260
+		// in case $current_post is hierarchical like: /parent-page/current-page
261
+		$current_post = basename($current_post);
262
+		if (
263
+			// is current page/post the "blog" page ?
264
+			$current_post === EE_Config::get_page_for_posts()
265
+			// or are we on a category page?
266
+			|| (
267
+				is_array(term_exists($current_post, 'category'))
268
+				|| array_key_exists('category_name', $wp->query_vars)
269
+			)
270
+		) {
271
+			// initialize all legacy shortcodes
272
+			$load_assets = $this->parseContentForShortcodes('', true);
273
+		} else {
274
+			global $wpdb;
275
+			$post_content = $wpdb->get_var(
276
+				$wpdb->prepare(
277
+					"SELECT post_content from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s",
278
+					$current_post
279
+				)
280
+			);
281
+			$load_assets = $this->parseContentForShortcodes($post_content);
282
+		}
283
+		if ($load_assets) {
284
+			$this->registry->REQ->set_espresso_page(true);
285
+			add_filter('FHEE_load_css', '__return_true');
286
+			add_filter('FHEE_load_js', '__return_true');
287
+		}
288
+		do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller);
289
+	}
290
+
291
+
292
+
293
+	/**
294
+	 * checks supplied content against list of legacy shortcodes,
295
+	 * then initializes any found shortcodes, and returns true.
296
+	 * returns false if no shortcodes found.
297
+	 *
298
+	 * @param string $content
299
+	 * @param bool   $load_all if true, then ALL active legacy shortcodes will be initialized
300
+	 * @return bool
301
+	 */
302
+	public function parseContentForShortcodes($content = '', $load_all = false)
303
+	{
304
+		$has_shortcode = false;
305
+		foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) {
306
+			if ($load_all || has_shortcode($content, $shortcode_class) ) {
307
+				// load up the shortcode
308
+				$this->initializeShortcode($shortcode_class);
309
+				$has_shortcode = true;
310
+			}
311
+		}
312
+		return $has_shortcode;
313
+	}
314
+
315
+
316
+
317
+	/**
318
+	 * given a shortcode name, will instantiate the shortcode and call it's run() method
319
+	 *
320
+	 * @param string $shortcode_class
321
+	 * @param WP     $wp
322
+	 */
323
+	public function initializeShortcode($shortcode_class = '', WP $wp = null)
324
+	{
325
+		// don't do anything if shortcode is already initialized
326
+		if (
327
+			empty($this->registry->shortcodes->{$shortcode_class})
328
+			|| ! is_string($this->registry->shortcodes->{$shortcode_class})
329
+		) {
330
+			return;
331
+		}
332
+		// let's pause to reflect on this...
333
+		$sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class));
334
+		// ensure that class is actually a shortcode
335
+		if (
336
+			defined('WP_DEBUG')
337
+			&& WP_DEBUG === true
338
+			&& ! $sc_reflector->isSubclassOf('EES_Shortcode')
339
+		) {
340
+			EE_Error::add_error(
341
+				sprintf(
342
+					esc_html__(
343
+						'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.',
344
+						'event_espresso'
345
+					),
346
+					$shortcode_class
347
+				),
348
+				__FILE__,
349
+				__FUNCTION__,
350
+				__LINE__
351
+			);
352
+			add_filter('FHEE_run_EE_the_content', '__return_true');
353
+			return;
354
+		}
355
+		global $wp;
356
+		// and pass the request object to the run method
357
+		$this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance();
358
+		// fire the shortcode class's run method, so that it can activate resources
359
+		$this->registry->shortcodes->{$shortcode_class}->run($wp);
360
+	}
361
+
362
+
363
+
364
+	/**
365
+	 * get classname, remove EES_prefix, and convert to UPPERCASE
366
+	 *
367
+	 * @param string $class_name
368
+	 * @return string
369
+	 */
370
+	public static function generateShortcodeTagFromClassName($class_name)
371
+	{
372
+		return strtoupper(str_replace('EES_', '', $class_name));
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * add EES_prefix and Capitalize words
379
+	 *
380
+	 * @param string $tag
381
+	 * @return string
382
+	 */
383
+	public static function generateShortcodeClassNameFromTag($tag)
384
+	{
385
+		// order of operation runs from inside to out
386
+		// 5) maybe add prefix
387
+		return LegacyShortcodesManager::addShortcodeClassPrefix(
388
+		// 4) find spaces, replace with underscores
389
+			str_replace(
390
+				' ',
391
+				'_',
392
+				// 3) capitalize first letter of each word
393
+				ucwords(
394
+				// 2) also change to lowercase so ucwords() will work
395
+					strtolower(
396
+					// 1) find underscores, replace with spaces so ucwords() will work
397
+						str_replace(
398
+							'_',
399
+							' ',
400
+							$tag
401
+						)
402
+					)
403
+				)
404
+			)
405
+		);
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * maybe add EES_prefix
412
+	 *
413
+	 * @param string $class_name
414
+	 * @return string
415
+	 */
416
+	public static function addShortcodeClassPrefix($class_name)
417
+	{
418
+		return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name;
419
+	}
420
+
421
+
422
+
423
+	/**
424
+	 * @return array
425
+	 */
426
+	public function getEspressoShortcodeTags()
427
+	{
428
+		static $shortcode_tags = array();
429
+		if (empty($shortcode_tags)) {
430
+			$shortcode_tags = array_keys((array)$this->registry->shortcodes);
431
+		}
432
+		return $shortcode_tags;
433
+	}
434
+
435
+
436
+
437
+	/**
438
+	 * @param string $content
439
+	 * @return string
440
+	 */
441
+	public function doShortcode($content)
442
+	{
443
+		foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) {
444
+			if (strpos($content, $shortcode_tag) !== false) {
445
+				$shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag);
446
+				$this->initializeShortcode($shortcode_class);
447
+			}
448
+		}
449
+		return do_shortcode($content);
450
+	}
451 451
 
452 452
 
453 453
 
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/FormHandler.php 2 patches
Indentation   +637 added lines, -637 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 use EventEspresso\core\exceptions\InvalidFormSubmissionException;
16 16
 
17 17
 if (! defined('EVENT_ESPRESSO_VERSION')) {
18
-    exit('No direct script access allowed');
18
+	exit('No direct script access allowed');
19 19
 }
20 20
 
21 21
 
@@ -34,642 +34,642 @@  discard block
 block discarded – undo
34 34
 abstract class FormHandler implements FormHandlerInterface
35 35
 {
36 36
 
37
-    /**
38
-     * will add opening and closing HTML form tags as well as a submit button
39
-     */
40
-    const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
41
-
42
-    /**
43
-     * will add opening and closing HTML form tags but NOT a submit button
44
-     */
45
-    const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
46
-
47
-    /**
48
-     * will NOT add opening and closing HTML form tags but will add a submit button
49
-     */
50
-    const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
51
-
52
-    /**
53
-     * will NOT add opening and closing HTML form tags NOR a submit button
54
-     */
55
-    const DO_NOT_SETUP_FORM = 'do_not_setup_form';
56
-
57
-    /**
58
-     * if set to false, then this form has no displayable content,
59
-     * and will only be used for processing data sent passed via GET or POST
60
-     * defaults to true ( ie: form has displayable content )
61
-     *
62
-     * @var boolean $displayable
63
-     */
64
-    private $displayable = true;
65
-
66
-    /**
67
-     * @var string $form_name
68
-     */
69
-    private $form_name;
70
-
71
-    /**
72
-     * @var string $admin_name
73
-     */
74
-    private $admin_name;
75
-
76
-    /**
77
-     * @var string $slug
78
-     */
79
-    private $slug;
80
-
81
-    /**
82
-     * @var string $submit_btn_text
83
-     */
84
-    private $submit_btn_text;
85
-
86
-    /**
87
-     * @var string $form_action
88
-     */
89
-    private $form_action;
90
-
91
-    /**
92
-     * form params in key value pairs
93
-     * can be added to form action URL or as hidden inputs
94
-     *
95
-     * @var array $form_args
96
-     */
97
-    private $form_args = array();
98
-
99
-    /**
100
-     * value of one of the string constant above
101
-     *
102
-     * @var string $form_config
103
-     */
104
-    private $form_config;
105
-
106
-    /**
107
-     * whether or not the form was determined to be invalid
108
-     *
109
-     * @var boolean $form_has_errors
110
-     */
111
-    private $form_has_errors;
112
-
113
-    /**
114
-     * the absolute top level form section being used on the page
115
-     *
116
-     * @var EE_Form_Section_Proper $form
117
-     */
118
-    private $form;
119
-
120
-    /**
121
-     * @var EE_Registry $registry
122
-     */
123
-    protected $registry;
124
-
125
-
126
-
127
-    /**
128
-     * Form constructor.
129
-     *
130
-     * @param string      $form_name
131
-     * @param string      $admin_name
132
-     * @param string      $slug
133
-     * @param string      $form_action
134
-     * @param string      $form_config
135
-     * @param EE_Registry $registry
136
-     * @throws InvalidDataTypeException
137
-     * @throws DomainException
138
-     * @throws InvalidArgumentException
139
-     */
140
-    public function __construct(
141
-        $form_name,
142
-        $admin_name,
143
-        $slug,
144
-        $form_action = '',
145
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
146
-        EE_Registry $registry
147
-    ) {
148
-        $this->setFormName($form_name);
149
-        $this->setAdminName($admin_name);
150
-        $this->setSlug($slug);
151
-        $this->setFormAction($form_action);
152
-        $this->setFormConfig($form_config);
153
-        $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
154
-        $this->registry = $registry;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * @return array
161
-     */
162
-    public static function getFormConfigConstants()
163
-    {
164
-        return array(
165
-            FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
166
-            FormHandler::ADD_FORM_TAGS_ONLY,
167
-            FormHandler::ADD_FORM_SUBMIT_ONLY,
168
-            FormHandler::DO_NOT_SETUP_FORM,
169
-        );
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * @param bool $for_display
176
-     * @return EE_Form_Section_Proper
177
-     * @throws EE_Error
178
-     * @throws LogicException
179
-     */
180
-    public function form($for_display = false)
181
-    {
182
-        if (! $this->formIsValid()) {
183
-            return null;
184
-        }
185
-        if ($for_display) {
186
-            $form_config = $this->formConfig();
187
-            if (
188
-                $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
189
-                || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
190
-            ) {
191
-                $this->appendSubmitButton();
192
-                $this->clearFormButtonFloats();
193
-            }
194
-        }
195
-        return $this->form;
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * @return boolean
202
-     * @throws LogicException
203
-     */
204
-    public function formIsValid()
205
-    {
206
-        if (! $this->form instanceof EE_Form_Section_Proper) {
207
-            static $generated = false;
208
-            if (! $generated) {
209
-                $generated = true;
210
-                $form = apply_filters(
211
-                    'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
212
-                    $this->generate(),
213
-                    $this
214
-                );
215
-                if ($form instanceof EE_Form_Section_Proper) {
216
-                    $this->setForm($form);
217
-                }
218
-            }
219
-            return $this->verifyForm();
220
-        }
221
-        return true;
222
-    }
223
-
224
-
225
-
226
-    /**
227
-     * @return boolean
228
-     * @throws LogicException
229
-     */
230
-    public function verifyForm()
231
-    {
232
-        if ($this->form instanceof EE_Form_Section_Proper) {
233
-            return true;
234
-        }
235
-        throw new LogicException(
236
-            sprintf(
237
-                esc_html__('The "%1$s" form is invalid or missing', 'event_espresso'),
238
-                $this->form_name
239
-            )
240
-        );
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     * @param EE_Form_Section_Proper $form
247
-     */
248
-    public function setForm(EE_Form_Section_Proper $form)
249
-    {
250
-        $this->form = $form;
251
-    }
252
-
253
-
254
-
255
-    /**
256
-     * @return boolean
257
-     */
258
-    public function displayable()
259
-    {
260
-        return $this->displayable;
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * @param boolean $displayable
267
-     */
268
-    public function setDisplayable($displayable = false)
269
-    {
270
-        $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * a public name for the form that can be displayed on the frontend of a site
277
-     *
278
-     * @return string
279
-     */
280
-    public function formName()
281
-    {
282
-        return $this->form_name;
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * @param string $form_name
289
-     * @throws InvalidDataTypeException
290
-     */
291
-    public function setFormName($form_name)
292
-    {
293
-        if (! is_string($form_name)) {
294
-            throw new InvalidDataTypeException('$form_name', $form_name, 'string');
295
-        }
296
-        $this->form_name = $form_name;
297
-    }
298
-
299
-
300
-
301
-    /**
302
-     * a public name for the form that can be displayed, but only in the admin
303
-     *
304
-     * @return string
305
-     */
306
-    public function adminName()
307
-    {
308
-        return $this->admin_name;
309
-    }
310
-
311
-
312
-
313
-    /**
314
-     * @param string $admin_name
315
-     * @throws InvalidDataTypeException
316
-     */
317
-    public function setAdminName($admin_name)
318
-    {
319
-        if (! is_string($admin_name)) {
320
-            throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
321
-        }
322
-        $this->admin_name = $admin_name;
323
-    }
324
-
325
-
326
-
327
-    /**
328
-     * a URL friendly string that can be used for identifying the form
329
-     *
330
-     * @return string
331
-     */
332
-    public function slug()
333
-    {
334
-        return $this->slug;
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     * @param string $slug
341
-     * @throws InvalidDataTypeException
342
-     */
343
-    public function setSlug($slug)
344
-    {
345
-        if (! is_string($slug)) {
346
-            throw new InvalidDataTypeException('$slug', $slug, 'string');
347
-        }
348
-        $this->slug = $slug;
349
-    }
350
-
351
-
352
-
353
-    /**
354
-     * @return string
355
-     */
356
-    public function submitBtnText()
357
-    {
358
-        return $this->submit_btn_text;
359
-    }
360
-
361
-
362
-
363
-    /**
364
-     * @param string $submit_btn_text
365
-     * @throws InvalidDataTypeException
366
-     * @throws InvalidArgumentException
367
-     */
368
-    public function setSubmitBtnText($submit_btn_text)
369
-    {
370
-        if (! is_string($submit_btn_text)) {
371
-            throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
372
-        }
373
-        if (empty($submit_btn_text)) {
374
-            throw new InvalidArgumentException(
375
-                esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
376
-            );
377
-        }
378
-        $this->submit_btn_text = $submit_btn_text;
379
-    }
380
-
381
-
382
-
383
-    /**
384
-     * @return string
385
-     */
386
-    public function formAction()
387
-    {
388
-        return ! empty($this->form_args)
389
-            ? add_query_arg($this->form_args, $this->form_action)
390
-            : $this->form_action;
391
-    }
392
-
393
-
394
-
395
-    /**
396
-     * @param string $form_action
397
-     * @throws InvalidDataTypeException
398
-     */
399
-    public function setFormAction($form_action)
400
-    {
401
-        if (! is_string($form_action)) {
402
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
403
-        }
404
-        $this->form_action = $form_action;
405
-    }
406
-
407
-
408
-
409
-    /**
410
-     * @param array $form_args
411
-     * @throws InvalidDataTypeException
412
-     * @throws InvalidArgumentException
413
-     */
414
-    public function addFormActionArgs($form_args = array())
415
-    {
416
-        if (is_object($form_args)) {
417
-            throw new InvalidDataTypeException(
418
-                '$form_args',
419
-                $form_args,
420
-                'anything other than an object was expected.'
421
-            );
422
-        }
423
-        if (empty($form_args)) {
424
-            throw new InvalidArgumentException(
425
-                esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
426
-            );
427
-        }
428
-        $this->form_args = array_merge($this->form_args, $form_args);
429
-    }
430
-
431
-
432
-
433
-    /**
434
-     * @return string
435
-     */
436
-    public function formConfig()
437
-    {
438
-        return $this->form_config;
439
-    }
440
-
441
-
442
-
443
-    /**
444
-     * @param string $form_config
445
-     * @throws DomainException
446
-     */
447
-    public function setFormConfig($form_config)
448
-    {
449
-        if (
450
-        ! in_array(
451
-            $form_config,
452
-            array(
453
-                FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
454
-                FormHandler::ADD_FORM_TAGS_ONLY,
455
-                FormHandler::ADD_FORM_SUBMIT_ONLY,
456
-                FormHandler::DO_NOT_SETUP_FORM,
457
-            ),
458
-            true
459
-        )
460
-        ) {
461
-            throw new DomainException(
462
-                sprintf(
463
-                    esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
464
-                        'event_espresso'),
465
-                    $form_config
466
-                )
467
-            );
468
-        }
469
-        $this->form_config = $form_config;
470
-    }
471
-
472
-
473
-
474
-    /**
475
-     * called after the form is instantiated
476
-     * and used for performing any logic that needs to occur early
477
-     * before any of the other methods are called.
478
-     * returns true if everything is ok to proceed,
479
-     * and false if no further form logic should be implemented
480
-     *
481
-     * @return boolean
482
-     */
483
-    public function initialize()
484
-    {
485
-        $this->form_has_errors = EE_Error::has_error(true);
486
-        return true;
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     * used for setting up css and js
493
-     *
494
-     * @return void
495
-     * @throws LogicException
496
-     * @throws EE_Error
497
-     */
498
-    public function enqueueStylesAndScripts()
499
-    {
500
-        $this->form(false)->enqueue_js();
501
-    }
502
-
503
-
504
-
505
-    /**
506
-     * creates and returns the actual form
507
-     *
508
-     * @return EE_Form_Section_Proper
509
-     */
510
-    abstract public function generate();
511
-
512
-
513
-
514
-    /**
515
-     * creates and returns an EE_Submit_Input labeled "Submit"
516
-     *
517
-     * @param string $text
518
-     * @return EE_Submit_Input
519
-     */
520
-    public function generateSubmitButton($text = '')
521
-    {
522
-        $text = ! empty($text) ? $text : $this->submitBtnText();
523
-        return new EE_Submit_Input(
524
-            array(
525
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
526
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
527
-                'html_class'            => 'ee-form-submit',
528
-                'html_label'            => '&nbsp;',
529
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
530
-                'default'               => $text,
531
-            )
532
-        );
533
-    }
534
-
535
-
536
-
537
-    /**
538
-     * calls generateSubmitButton() and appends it onto the form along with a float clearing div
539
-     *
540
-     * @param string $text
541
-     * @return void
542
-     * @throws LogicException
543
-     * @throws EE_Error
544
-     */
545
-    public function appendSubmitButton($text = '')
546
-    {
547
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
548
-            return;
549
-        }
550
-        $this->form->add_subsections(
551
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
552
-            null,
553
-            false
554
-        );
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * creates and returns an EE_Submit_Input labeled "Cancel"
561
-     *
562
-     * @param string $text
563
-     * @return EE_Submit_Input
564
-     */
565
-    public function generateCancelButton($text = '')
566
-    {
567
-        $cancel_button = new EE_Submit_Input(
568
-            array(
569
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
570
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
571
-                'html_class'            => 'ee-cancel-form',
572
-                'html_label'            => '&nbsp;',
573
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
574
-                'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
575
-            )
576
-        );
577
-        $cancel_button->set_button_css_attributes(false);
578
-        return $cancel_button;
579
-    }
580
-
581
-
582
-
583
-    /**
584
-     * appends a float clearing div onto end of form
585
-     *
586
-     * @return void
587
-     * @throws EE_Error
588
-     */
589
-    public function clearFormButtonFloats()
590
-    {
591
-        $this->form->add_subsections(
592
-            array(
593
-                'clear-submit-btn-float' => new EE_Form_Section_HTML(
594
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
595
-                ),
596
-            ),
597
-            null,
598
-            false
599
-        );
600
-    }
601
-
602
-
603
-
604
-    /**
605
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
606
-     * returns a string of HTML that can be directly echoed in a template
607
-     *
608
-     * @return string
609
-     * @throws LogicException
610
-     * @throws EE_Error
611
-     */
612
-    public function display()
613
-    {
614
-        $form_html = apply_filters(
615
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
616
-            ''
617
-        );
618
-        $form_config = $this->formConfig();
619
-        if (
620
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
621
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
622
-        ) {
623
-            $form_html .= $this->form()->form_open($this->formAction());
624
-        }
625
-        $form_html .= $this->form(true)->get_html($this->form_has_errors);
626
-        if (
627
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
628
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
629
-        ) {
630
-            $form_html .= $this->form()->form_close();
631
-        }
632
-        $form_html .= apply_filters(
633
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
634
-            ''
635
-        );
636
-        return $form_html;
637
-    }
638
-
639
-
640
-
641
-    /**
642
-     * handles processing the form submission
643
-     * returns true or false depending on whether the form was processed successfully or not
644
-     *
645
-     * @param array $submitted_form_data
646
-     * @return array
647
-     * @throws EE_Error
648
-     * @throws LogicException
649
-     * @throws InvalidFormSubmissionException
650
-     */
651
-    public function process($submitted_form_data = array())
652
-    {
653
-        if (! $this->form()->was_submitted($submitted_form_data)) {
654
-            throw new InvalidFormSubmissionException($this->form_name);
655
-        }
656
-        $this->form(true)->receive_form_submission($submitted_form_data);
657
-        if (! $this->form()->is_valid()) {
658
-            throw new InvalidFormSubmissionException(
659
-                $this->form_name,
660
-                sprintf(
661
-                    esc_html__(
662
-                        'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
663
-                        'event_espresso'
664
-                    ),
665
-                    $this->form_name,
666
-                    '<br />',
667
-                    $this->form()->submission_error_message()
668
-                )
669
-            );
670
-        }
671
-        return $this->form()->valid_data();
672
-    }
37
+	/**
38
+	 * will add opening and closing HTML form tags as well as a submit button
39
+	 */
40
+	const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
41
+
42
+	/**
43
+	 * will add opening and closing HTML form tags but NOT a submit button
44
+	 */
45
+	const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
46
+
47
+	/**
48
+	 * will NOT add opening and closing HTML form tags but will add a submit button
49
+	 */
50
+	const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
51
+
52
+	/**
53
+	 * will NOT add opening and closing HTML form tags NOR a submit button
54
+	 */
55
+	const DO_NOT_SETUP_FORM = 'do_not_setup_form';
56
+
57
+	/**
58
+	 * if set to false, then this form has no displayable content,
59
+	 * and will only be used for processing data sent passed via GET or POST
60
+	 * defaults to true ( ie: form has displayable content )
61
+	 *
62
+	 * @var boolean $displayable
63
+	 */
64
+	private $displayable = true;
65
+
66
+	/**
67
+	 * @var string $form_name
68
+	 */
69
+	private $form_name;
70
+
71
+	/**
72
+	 * @var string $admin_name
73
+	 */
74
+	private $admin_name;
75
+
76
+	/**
77
+	 * @var string $slug
78
+	 */
79
+	private $slug;
80
+
81
+	/**
82
+	 * @var string $submit_btn_text
83
+	 */
84
+	private $submit_btn_text;
85
+
86
+	/**
87
+	 * @var string $form_action
88
+	 */
89
+	private $form_action;
90
+
91
+	/**
92
+	 * form params in key value pairs
93
+	 * can be added to form action URL or as hidden inputs
94
+	 *
95
+	 * @var array $form_args
96
+	 */
97
+	private $form_args = array();
98
+
99
+	/**
100
+	 * value of one of the string constant above
101
+	 *
102
+	 * @var string $form_config
103
+	 */
104
+	private $form_config;
105
+
106
+	/**
107
+	 * whether or not the form was determined to be invalid
108
+	 *
109
+	 * @var boolean $form_has_errors
110
+	 */
111
+	private $form_has_errors;
112
+
113
+	/**
114
+	 * the absolute top level form section being used on the page
115
+	 *
116
+	 * @var EE_Form_Section_Proper $form
117
+	 */
118
+	private $form;
119
+
120
+	/**
121
+	 * @var EE_Registry $registry
122
+	 */
123
+	protected $registry;
124
+
125
+
126
+
127
+	/**
128
+	 * Form constructor.
129
+	 *
130
+	 * @param string      $form_name
131
+	 * @param string      $admin_name
132
+	 * @param string      $slug
133
+	 * @param string      $form_action
134
+	 * @param string      $form_config
135
+	 * @param EE_Registry $registry
136
+	 * @throws InvalidDataTypeException
137
+	 * @throws DomainException
138
+	 * @throws InvalidArgumentException
139
+	 */
140
+	public function __construct(
141
+		$form_name,
142
+		$admin_name,
143
+		$slug,
144
+		$form_action = '',
145
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
146
+		EE_Registry $registry
147
+	) {
148
+		$this->setFormName($form_name);
149
+		$this->setAdminName($admin_name);
150
+		$this->setSlug($slug);
151
+		$this->setFormAction($form_action);
152
+		$this->setFormConfig($form_config);
153
+		$this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
154
+		$this->registry = $registry;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * @return array
161
+	 */
162
+	public static function getFormConfigConstants()
163
+	{
164
+		return array(
165
+			FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
166
+			FormHandler::ADD_FORM_TAGS_ONLY,
167
+			FormHandler::ADD_FORM_SUBMIT_ONLY,
168
+			FormHandler::DO_NOT_SETUP_FORM,
169
+		);
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * @param bool $for_display
176
+	 * @return EE_Form_Section_Proper
177
+	 * @throws EE_Error
178
+	 * @throws LogicException
179
+	 */
180
+	public function form($for_display = false)
181
+	{
182
+		if (! $this->formIsValid()) {
183
+			return null;
184
+		}
185
+		if ($for_display) {
186
+			$form_config = $this->formConfig();
187
+			if (
188
+				$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
189
+				|| $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
190
+			) {
191
+				$this->appendSubmitButton();
192
+				$this->clearFormButtonFloats();
193
+			}
194
+		}
195
+		return $this->form;
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * @return boolean
202
+	 * @throws LogicException
203
+	 */
204
+	public function formIsValid()
205
+	{
206
+		if (! $this->form instanceof EE_Form_Section_Proper) {
207
+			static $generated = false;
208
+			if (! $generated) {
209
+				$generated = true;
210
+				$form = apply_filters(
211
+					'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
212
+					$this->generate(),
213
+					$this
214
+				);
215
+				if ($form instanceof EE_Form_Section_Proper) {
216
+					$this->setForm($form);
217
+				}
218
+			}
219
+			return $this->verifyForm();
220
+		}
221
+		return true;
222
+	}
223
+
224
+
225
+
226
+	/**
227
+	 * @return boolean
228
+	 * @throws LogicException
229
+	 */
230
+	public function verifyForm()
231
+	{
232
+		if ($this->form instanceof EE_Form_Section_Proper) {
233
+			return true;
234
+		}
235
+		throw new LogicException(
236
+			sprintf(
237
+				esc_html__('The "%1$s" form is invalid or missing', 'event_espresso'),
238
+				$this->form_name
239
+			)
240
+		);
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 * @param EE_Form_Section_Proper $form
247
+	 */
248
+	public function setForm(EE_Form_Section_Proper $form)
249
+	{
250
+		$this->form = $form;
251
+	}
252
+
253
+
254
+
255
+	/**
256
+	 * @return boolean
257
+	 */
258
+	public function displayable()
259
+	{
260
+		return $this->displayable;
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * @param boolean $displayable
267
+	 */
268
+	public function setDisplayable($displayable = false)
269
+	{
270
+		$this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * a public name for the form that can be displayed on the frontend of a site
277
+	 *
278
+	 * @return string
279
+	 */
280
+	public function formName()
281
+	{
282
+		return $this->form_name;
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * @param string $form_name
289
+	 * @throws InvalidDataTypeException
290
+	 */
291
+	public function setFormName($form_name)
292
+	{
293
+		if (! is_string($form_name)) {
294
+			throw new InvalidDataTypeException('$form_name', $form_name, 'string');
295
+		}
296
+		$this->form_name = $form_name;
297
+	}
298
+
299
+
300
+
301
+	/**
302
+	 * a public name for the form that can be displayed, but only in the admin
303
+	 *
304
+	 * @return string
305
+	 */
306
+	public function adminName()
307
+	{
308
+		return $this->admin_name;
309
+	}
310
+
311
+
312
+
313
+	/**
314
+	 * @param string $admin_name
315
+	 * @throws InvalidDataTypeException
316
+	 */
317
+	public function setAdminName($admin_name)
318
+	{
319
+		if (! is_string($admin_name)) {
320
+			throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
321
+		}
322
+		$this->admin_name = $admin_name;
323
+	}
324
+
325
+
326
+
327
+	/**
328
+	 * a URL friendly string that can be used for identifying the form
329
+	 *
330
+	 * @return string
331
+	 */
332
+	public function slug()
333
+	{
334
+		return $this->slug;
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 * @param string $slug
341
+	 * @throws InvalidDataTypeException
342
+	 */
343
+	public function setSlug($slug)
344
+	{
345
+		if (! is_string($slug)) {
346
+			throw new InvalidDataTypeException('$slug', $slug, 'string');
347
+		}
348
+		$this->slug = $slug;
349
+	}
350
+
351
+
352
+
353
+	/**
354
+	 * @return string
355
+	 */
356
+	public function submitBtnText()
357
+	{
358
+		return $this->submit_btn_text;
359
+	}
360
+
361
+
362
+
363
+	/**
364
+	 * @param string $submit_btn_text
365
+	 * @throws InvalidDataTypeException
366
+	 * @throws InvalidArgumentException
367
+	 */
368
+	public function setSubmitBtnText($submit_btn_text)
369
+	{
370
+		if (! is_string($submit_btn_text)) {
371
+			throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
372
+		}
373
+		if (empty($submit_btn_text)) {
374
+			throw new InvalidArgumentException(
375
+				esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
376
+			);
377
+		}
378
+		$this->submit_btn_text = $submit_btn_text;
379
+	}
380
+
381
+
382
+
383
+	/**
384
+	 * @return string
385
+	 */
386
+	public function formAction()
387
+	{
388
+		return ! empty($this->form_args)
389
+			? add_query_arg($this->form_args, $this->form_action)
390
+			: $this->form_action;
391
+	}
392
+
393
+
394
+
395
+	/**
396
+	 * @param string $form_action
397
+	 * @throws InvalidDataTypeException
398
+	 */
399
+	public function setFormAction($form_action)
400
+	{
401
+		if (! is_string($form_action)) {
402
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
403
+		}
404
+		$this->form_action = $form_action;
405
+	}
406
+
407
+
408
+
409
+	/**
410
+	 * @param array $form_args
411
+	 * @throws InvalidDataTypeException
412
+	 * @throws InvalidArgumentException
413
+	 */
414
+	public function addFormActionArgs($form_args = array())
415
+	{
416
+		if (is_object($form_args)) {
417
+			throw new InvalidDataTypeException(
418
+				'$form_args',
419
+				$form_args,
420
+				'anything other than an object was expected.'
421
+			);
422
+		}
423
+		if (empty($form_args)) {
424
+			throw new InvalidArgumentException(
425
+				esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
426
+			);
427
+		}
428
+		$this->form_args = array_merge($this->form_args, $form_args);
429
+	}
430
+
431
+
432
+
433
+	/**
434
+	 * @return string
435
+	 */
436
+	public function formConfig()
437
+	{
438
+		return $this->form_config;
439
+	}
440
+
441
+
442
+
443
+	/**
444
+	 * @param string $form_config
445
+	 * @throws DomainException
446
+	 */
447
+	public function setFormConfig($form_config)
448
+	{
449
+		if (
450
+		! in_array(
451
+			$form_config,
452
+			array(
453
+				FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
454
+				FormHandler::ADD_FORM_TAGS_ONLY,
455
+				FormHandler::ADD_FORM_SUBMIT_ONLY,
456
+				FormHandler::DO_NOT_SETUP_FORM,
457
+			),
458
+			true
459
+		)
460
+		) {
461
+			throw new DomainException(
462
+				sprintf(
463
+					esc_html__('"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
464
+						'event_espresso'),
465
+					$form_config
466
+				)
467
+			);
468
+		}
469
+		$this->form_config = $form_config;
470
+	}
471
+
472
+
473
+
474
+	/**
475
+	 * called after the form is instantiated
476
+	 * and used for performing any logic that needs to occur early
477
+	 * before any of the other methods are called.
478
+	 * returns true if everything is ok to proceed,
479
+	 * and false if no further form logic should be implemented
480
+	 *
481
+	 * @return boolean
482
+	 */
483
+	public function initialize()
484
+	{
485
+		$this->form_has_errors = EE_Error::has_error(true);
486
+		return true;
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 * used for setting up css and js
493
+	 *
494
+	 * @return void
495
+	 * @throws LogicException
496
+	 * @throws EE_Error
497
+	 */
498
+	public function enqueueStylesAndScripts()
499
+	{
500
+		$this->form(false)->enqueue_js();
501
+	}
502
+
503
+
504
+
505
+	/**
506
+	 * creates and returns the actual form
507
+	 *
508
+	 * @return EE_Form_Section_Proper
509
+	 */
510
+	abstract public function generate();
511
+
512
+
513
+
514
+	/**
515
+	 * creates and returns an EE_Submit_Input labeled "Submit"
516
+	 *
517
+	 * @param string $text
518
+	 * @return EE_Submit_Input
519
+	 */
520
+	public function generateSubmitButton($text = '')
521
+	{
522
+		$text = ! empty($text) ? $text : $this->submitBtnText();
523
+		return new EE_Submit_Input(
524
+			array(
525
+				'html_name'             => 'ee-form-submit-' . $this->slug(),
526
+				'html_id'               => 'ee-form-submit-' . $this->slug(),
527
+				'html_class'            => 'ee-form-submit',
528
+				'html_label'            => '&nbsp;',
529
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
530
+				'default'               => $text,
531
+			)
532
+		);
533
+	}
534
+
535
+
536
+
537
+	/**
538
+	 * calls generateSubmitButton() and appends it onto the form along with a float clearing div
539
+	 *
540
+	 * @param string $text
541
+	 * @return void
542
+	 * @throws LogicException
543
+	 * @throws EE_Error
544
+	 */
545
+	public function appendSubmitButton($text = '')
546
+	{
547
+		if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
548
+			return;
549
+		}
550
+		$this->form->add_subsections(
551
+			array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
552
+			null,
553
+			false
554
+		);
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * creates and returns an EE_Submit_Input labeled "Cancel"
561
+	 *
562
+	 * @param string $text
563
+	 * @return EE_Submit_Input
564
+	 */
565
+	public function generateCancelButton($text = '')
566
+	{
567
+		$cancel_button = new EE_Submit_Input(
568
+			array(
569
+				'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
570
+				'html_id'               => 'ee-cancel-form-' . $this->slug(),
571
+				'html_class'            => 'ee-cancel-form',
572
+				'html_label'            => '&nbsp;',
573
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
574
+				'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
575
+			)
576
+		);
577
+		$cancel_button->set_button_css_attributes(false);
578
+		return $cancel_button;
579
+	}
580
+
581
+
582
+
583
+	/**
584
+	 * appends a float clearing div onto end of form
585
+	 *
586
+	 * @return void
587
+	 * @throws EE_Error
588
+	 */
589
+	public function clearFormButtonFloats()
590
+	{
591
+		$this->form->add_subsections(
592
+			array(
593
+				'clear-submit-btn-float' => new EE_Form_Section_HTML(
594
+					EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
595
+				),
596
+			),
597
+			null,
598
+			false
599
+		);
600
+	}
601
+
602
+
603
+
604
+	/**
605
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
606
+	 * returns a string of HTML that can be directly echoed in a template
607
+	 *
608
+	 * @return string
609
+	 * @throws LogicException
610
+	 * @throws EE_Error
611
+	 */
612
+	public function display()
613
+	{
614
+		$form_html = apply_filters(
615
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
616
+			''
617
+		);
618
+		$form_config = $this->formConfig();
619
+		if (
620
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
621
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
622
+		) {
623
+			$form_html .= $this->form()->form_open($this->formAction());
624
+		}
625
+		$form_html .= $this->form(true)->get_html($this->form_has_errors);
626
+		if (
627
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
628
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
629
+		) {
630
+			$form_html .= $this->form()->form_close();
631
+		}
632
+		$form_html .= apply_filters(
633
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
634
+			''
635
+		);
636
+		return $form_html;
637
+	}
638
+
639
+
640
+
641
+	/**
642
+	 * handles processing the form submission
643
+	 * returns true or false depending on whether the form was processed successfully or not
644
+	 *
645
+	 * @param array $submitted_form_data
646
+	 * @return array
647
+	 * @throws EE_Error
648
+	 * @throws LogicException
649
+	 * @throws InvalidFormSubmissionException
650
+	 */
651
+	public function process($submitted_form_data = array())
652
+	{
653
+		if (! $this->form()->was_submitted($submitted_form_data)) {
654
+			throw new InvalidFormSubmissionException($this->form_name);
655
+		}
656
+		$this->form(true)->receive_form_submission($submitted_form_data);
657
+		if (! $this->form()->is_valid()) {
658
+			throw new InvalidFormSubmissionException(
659
+				$this->form_name,
660
+				sprintf(
661
+					esc_html__(
662
+						'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
663
+						'event_espresso'
664
+					),
665
+					$this->form_name,
666
+					'<br />',
667
+					$this->form()->submission_error_message()
668
+				)
669
+			);
670
+		}
671
+		return $this->form()->valid_data();
672
+	}
673 673
 
674 674
 
675 675
 
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 use EventEspresso\core\exceptions\InvalidDataTypeException;
15 15
 use EventEspresso\core\exceptions\InvalidFormSubmissionException;
16 16
 
17
-if (! defined('EVENT_ESPRESSO_VERSION')) {
17
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
18 18
     exit('No direct script access allowed');
19 19
 }
20 20
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
      */
180 180
     public function form($for_display = false)
181 181
     {
182
-        if (! $this->formIsValid()) {
182
+        if ( ! $this->formIsValid()) {
183 183
             return null;
184 184
         }
185 185
         if ($for_display) {
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
      */
204 204
     public function formIsValid()
205 205
     {
206
-        if (! $this->form instanceof EE_Form_Section_Proper) {
206
+        if ( ! $this->form instanceof EE_Form_Section_Proper) {
207 207
             static $generated = false;
208
-            if (! $generated) {
208
+            if ( ! $generated) {
209 209
                 $generated = true;
210 210
                 $form = apply_filters(
211 211
                     'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      */
291 291
     public function setFormName($form_name)
292 292
     {
293
-        if (! is_string($form_name)) {
293
+        if ( ! is_string($form_name)) {
294 294
             throw new InvalidDataTypeException('$form_name', $form_name, 'string');
295 295
         }
296 296
         $this->form_name = $form_name;
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
      */
317 317
     public function setAdminName($admin_name)
318 318
     {
319
-        if (! is_string($admin_name)) {
319
+        if ( ! is_string($admin_name)) {
320 320
             throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
321 321
         }
322 322
         $this->admin_name = $admin_name;
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
      */
343 343
     public function setSlug($slug)
344 344
     {
345
-        if (! is_string($slug)) {
345
+        if ( ! is_string($slug)) {
346 346
             throw new InvalidDataTypeException('$slug', $slug, 'string');
347 347
         }
348 348
         $this->slug = $slug;
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
      */
368 368
     public function setSubmitBtnText($submit_btn_text)
369 369
     {
370
-        if (! is_string($submit_btn_text)) {
370
+        if ( ! is_string($submit_btn_text)) {
371 371
             throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
372 372
         }
373 373
         if (empty($submit_btn_text)) {
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
      */
399 399
     public function setFormAction($form_action)
400 400
     {
401
-        if (! is_string($form_action)) {
401
+        if ( ! is_string($form_action)) {
402 402
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
403 403
         }
404 404
         $this->form_action = $form_action;
@@ -522,11 +522,11 @@  discard block
 block discarded – undo
522 522
         $text = ! empty($text) ? $text : $this->submitBtnText();
523 523
         return new EE_Submit_Input(
524 524
             array(
525
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
526
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
525
+                'html_name'             => 'ee-form-submit-'.$this->slug(),
526
+                'html_id'               => 'ee-form-submit-'.$this->slug(),
527 527
                 'html_class'            => 'ee-form-submit',
528 528
                 'html_label'            => '&nbsp;',
529
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
529
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
530 530
                 'default'               => $text,
531 531
             )
532 532
         );
@@ -544,11 +544,11 @@  discard block
 block discarded – undo
544 544
      */
545 545
     public function appendSubmitButton($text = '')
546 546
     {
547
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
547
+        if ($this->form->subsection_exists($this->slug().'-submit-btn')) {
548 548
             return;
549 549
         }
550 550
         $this->form->add_subsections(
551
-            array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)),
551
+            array($this->slug().'-submit-btn' => $this->generateSubmitButton($text)),
552 552
             null,
553 553
             false
554 554
         );
@@ -566,11 +566,11 @@  discard block
 block discarded – undo
566 566
     {
567 567
         $cancel_button = new EE_Submit_Input(
568 568
             array(
569
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
570
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
569
+                'html_name'             => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!!
570
+                'html_id'               => 'ee-cancel-form-'.$this->slug(),
571 571
                 'html_class'            => 'ee-cancel-form',
572 572
                 'html_label'            => '&nbsp;',
573
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
573
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
574 574
                 'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
575 575
             )
576 576
         );
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
         $this->form->add_subsections(
592 592
             array(
593 593
                 'clear-submit-btn-float' => new EE_Form_Section_HTML(
594
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
594
+                    EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx()
595 595
                 ),
596 596
             ),
597 597
             null,
@@ -650,11 +650,11 @@  discard block
 block discarded – undo
650 650
      */
651 651
     public function process($submitted_form_data = array())
652 652
     {
653
-        if (! $this->form()->was_submitted($submitted_form_data)) {
653
+        if ( ! $this->form()->was_submitted($submitted_form_data)) {
654 654
             throw new InvalidFormSubmissionException($this->form_name);
655 655
         }
656 656
         $this->form(true)->receive_form_submission($submitted_form_data);
657
-        if (! $this->form()->is_valid()) {
657
+        if ( ! $this->form()->is_valid()) {
658 658
             throw new InvalidFormSubmissionException(
659 659
                 $this->form_name,
660 660
                 sprintf(
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_Payment_Method_Manager.lib.php 1 patch
Indentation   +419 added lines, -419 removed lines patch added patch discarded remove patch
@@ -19,420 +19,420 @@  discard block
 block discarded – undo
19 19
 class EE_Payment_Method_Manager implements ResettableInterface
20 20
 {
21 21
 
22
-    /**
23
-     * @var EE_Payment_Method_Manager $_instance
24
-     */
25
-    private static $_instance;
26
-
27
-    /**
28
-     * @var array keys are class names without 'EE_PMT_', values are their filepaths
29
-     */
30
-    protected $_payment_method_types = array();
31
-
32
-
33
-
34
-    /**
35
-     * @singleton method used to instantiate class object
36
-     * @return EE_Payment_Method_Manager instance
37
-     */
38
-    public static function instance()
39
-    {
40
-        // check if class object is instantiated, and instantiated properly
41
-        if (! self::$_instance instanceof EE_Payment_Method_Manager) {
42
-            self::$_instance = new self();
43
-        }
44
-        EE_Registry::instance()->load_lib('PMT_Base');
45
-        return self::$_instance;
46
-    }
47
-
48
-
49
-
50
-    /**
51
-     * Resets the instance and returns a new one
52
-     *
53
-     * @return EE_Payment_Method_Manager
54
-     */
55
-    public static function reset()
56
-    {
57
-        self::$_instance = null;
58
-        return self::instance();
59
-    }
60
-
61
-
62
-
63
-    /**
64
-     * If necessary, re-register payment methods
65
-     *
66
-     * @param boolean $force_recheck whether to recheck for payment method types,
67
-     *                               or just re-use the PMTs we found last time we checked during this request (if
68
-     *                               we have not yet checked during this request, then we need to check anyways)
69
-     */
70
-    public function maybe_register_payment_methods($force_recheck = false)
71
-    {
72
-        if (! $this->_payment_method_types || $force_recheck) {
73
-            $this->_register_payment_methods();
74
-            //if in admin lets ensure caps are set.
75
-            if (is_admin()) {
76
-                add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps'));
77
-                EE_Registry::instance()->CAP->init_caps();
78
-            }
79
-        }
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * register_payment_methods
86
-     *
87
-     * @return array
88
-     */
89
-    protected function _register_payment_methods()
90
-    {
91
-        // grab list of installed modules
92
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
93
-        // filter list of modules to register
94
-        $pm_to_register = apply_filters(
95
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
96
-            $pm_to_register
97
-        );
98
-        // loop through folders
99
-        foreach ($pm_to_register as $pm_path) {
100
-            $this->register_payment_method($pm_path);
101
-        }
102
-        do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
103
-        // filter list of installed modules
104
-        //keep them organized alphabetically by the payment method type's name
105
-        ksort($this->_payment_method_types);
106
-        return apply_filters(
107
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
108
-            $this->_payment_method_types
109
-        );
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * register_payment_method- makes core aware of this payment method
116
-     *
117
-     * @param string $payment_method_path - full path up to and including payment method folder
118
-     * @return boolean
119
-     */
120
-    public function register_payment_method($payment_method_path = '')
121
-    {
122
-        do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
123
-        $module_ext = '.pm.php';
124
-        // make all separators match
125
-        $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS);
126
-        // grab and sanitize module name
127
-        $module_dir = basename($payment_method_path);
128
-        // create classname from module directory name
129
-        $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
130
-        // add class prefix
131
-        $module_class = 'EE_PMT_' . $module;
132
-        // does the module exist ?
133
-        if (! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
134
-            $msg = sprintf(
135
-                esc_html__(
136
-                    'The requested %s payment method file could not be found or is not readable due to file permissions.',
137
-                    'event_espresso'
138
-                ), $module
139
-            );
140
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
141
-            return false;
142
-        }
143
-        // load the module class file
144
-        require_once($payment_method_path . DS . $module_class . $module_ext);
145
-        // verify that class exists
146
-        if (! class_exists($module_class)) {
147
-            $msg = sprintf(
148
-                esc_html__('The requested %s module class does not exist.', 'event_espresso'),
149
-                $module_class
150
-            );
151
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
152
-            return false;
153
-        }
154
-        // add to array of registered modules
155
-        $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
156
-        return true;
157
-    }
158
-
159
-
160
-
161
-    /**
162
-     * Checks if a payment method has been registered, and if so includes it
163
-     *
164
-     * @param string  $payment_method_name like 'PayPal_Pro', (ie classname without the prefix 'EEPM_')
165
-     * @param boolean $force_recheck       whether to force re-checking for new payment method types
166
-     * @return boolean
167
-     */
168
-    public function payment_method_type_exists($payment_method_name, $force_recheck = false)
169
-    {
170
-        if (
171
-            $force_recheck
172
-            || ! is_array($this->_payment_method_types)
173
-            || ! isset($this->_payment_method_types[$payment_method_name])
174
-        ) {
175
-            $this->maybe_register_payment_methods($force_recheck);
176
-        }
177
-        if (isset($this->_payment_method_types[$payment_method_name])) {
178
-            require_once($this->_payment_method_types[$payment_method_name]);
179
-            return true;
180
-        }
181
-        return false;
182
-    }
183
-
184
-
185
-
186
-    /**
187
-     * Returns all the class names of the various payment method types
188
-     *
189
-     * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names'
190
-     *                               (what you'd find in wp_esp_payment_method.PMD_type)
191
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
192
-     * @return array
193
-     */
194
-    public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
195
-    {
196
-        $this->maybe_register_payment_methods($force_recheck);
197
-        if ($with_prefixes) {
198
-            $classnames = array_keys($this->_payment_method_types);
199
-            $payment_methods = array();
200
-            foreach ($classnames as $classname) {
201
-                $payment_methods[] = $this->payment_method_class_from_type($classname);
202
-            }
203
-            return $payment_methods;
204
-        }
205
-        return array_keys($this->_payment_method_types);
206
-    }
207
-
208
-
209
-
210
-    /**
211
-     * Gets an object of each payment method type, none of which are bound to a
212
-     * payment method instance
213
-     *
214
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
215
-     * @return EE_PMT_Base[]
216
-     */
217
-    public function payment_method_types($force_recheck = false)
218
-    {
219
-        $this->maybe_register_payment_methods($force_recheck);
220
-        $payment_method_objects = array();
221
-        foreach ($this->payment_method_type_names(true) as $classname) {
222
-            $payment_method_objects[] = new $classname;
223
-        }
224
-        return $payment_method_objects;
225
-    }
226
-
227
-
228
-
229
-    /**
230
-     * Changes the payment method's classname into the payment method type's name
231
-     * (as used on the payment method's table's PMD_type field)
232
-     *
233
-     * @param string $classname
234
-     * @return string
235
-     */
236
-    public function payment_method_type_sans_class_prefix($classname)
237
-    {
238
-        return str_replace('EE_PMT_', '', $classname);
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * Does the opposite of payment-method_type_sans_prefix
245
-     *
246
-     * @param string $type
247
-     * @return string
248
-     */
249
-    public function payment_method_class_from_type($type)
250
-    {
251
-        $this->maybe_register_payment_methods();
252
-        return 'EE_PMT_' . $type;
253
-    }
254
-
255
-
256
-
257
-    /**
258
-     * Activates a payment method of the given type.
259
-     *
260
-     * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
261
-     * @return EE_Payment_Method
262
-     * @throws EE_Error
263
-     */
264
-    public function activate_a_payment_method_of_type($payment_method_type)
265
-    {
266
-        $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
267
-        if (! $payment_method instanceof EE_Payment_Method) {
268
-            $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
269
-            if (class_exists($pm_type_class)) {
270
-                /** @var $pm_type_obj EE_PMT_Base */
271
-                $pm_type_obj = new $pm_type_class;
272
-                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
273
-                if (! $payment_method) {
274
-                    $payment_method = $this->create_payment_method_of_type($pm_type_obj);
275
-                }
276
-                $payment_method->set_type($payment_method_type);
277
-                $this->initialize_payment_method($payment_method);
278
-            } else {
279
-                throw new EE_Error(
280
-                    sprintf(
281
-                        esc_html__(
282
-                            'There is no payment method of type %1$s, so it could not be activated',
283
-                            'event_espresso'
284
-                        ),
285
-                        $pm_type_class
286
-                    )
287
-                );
288
-            }
289
-        }
290
-        $payment_method->set_active();
291
-        $payment_method->save();
292
-        if ($payment_method->type() === 'Invoice') {
293
-            /** @type EE_Message_Resource_Manager $message_resource_manager */
294
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
295
-            $message_resource_manager->ensure_message_type_is_active('invoice', 'html');
296
-            $message_resource_manager->ensure_messenger_is_active('pdf');
297
-            EE_Error::add_persistent_admin_notice(
298
-                'invoice_pm_requirements_notice',
299
-                sprintf(
300
-                    esc_html__(
301
-                        'The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
302
-                        'event_espresso'
303
-                    ),
304
-                    '<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
305
-                    '</a>'
306
-                ),
307
-                true
308
-            );
309
-        }
310
-        return $payment_method;
311
-    }
312
-
313
-
314
-
315
-    /**
316
-     * Creates a payment method of the specified type. Does not save it.
317
-     *
318
-     * @global WP_User    $current_user
319
-     * @param EE_PMT_Base $pm_type_obj
320
-     * @return EE_Payment_Method
321
-     * @throws EE_Error
322
-     */
323
-    public function create_payment_method_of_type($pm_type_obj)
324
-    {
325
-        global $current_user;
326
-        $payment_method = EE_Payment_Method::new_instance(
327
-            array(
328
-                'PMD_type'       => $pm_type_obj->system_name(),
329
-                'PMD_name'       => $pm_type_obj->pretty_name(),
330
-                'PMD_admin_name' => $pm_type_obj->pretty_name(),
331
-                'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
332
-                'PMD_wp_user'    => $current_user->ID,
333
-                'PMD_order'      => EEM_Payment_Method::instance()->count(
334
-                        array(array('PMD_type' => array('!=', 'Admin_Only')))
335
-                    ) * 10,
336
-            )
337
-        );
338
-        return $payment_method;
339
-    }
340
-
341
-
342
-
343
-    /**
344
-     * Sets the initial payment method properties (including extra meta)
345
-     *
346
-     * @param EE_Payment_Method $payment_method
347
-     * @return EE_Payment_Method
348
-     * @throws EE_Error
349
-     */
350
-    public function initialize_payment_method($payment_method)
351
-    {
352
-        $pm_type_obj = $payment_method->type_obj();
353
-        $payment_method->set_description($pm_type_obj->default_description());
354
-        if (! $payment_method->button_url()) {
355
-            $payment_method->set_button_url($pm_type_obj->default_button_url());
356
-        }
357
-        //now add setup its default extra meta properties
358
-        $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
359
-        if (! empty($extra_metas)) {
360
-            //verify the payment method has an ID before adding extra meta
361
-            if (! $payment_method->ID()) {
362
-                $payment_method->save();
363
-            }
364
-            foreach ($extra_metas as $meta_name => $input) {
365
-                $payment_method->update_extra_meta($meta_name, $input->raw_value());
366
-            }
367
-        }
368
-        return $payment_method;
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * Makes sure the payment method is related to the specified payment method
375
-     *
376
-     * @deprecated in 4.9.40 because the currency payment method table is being deprecated
377
-     * @param EE_Payment_Method $payment_method
378
-     * @return EE_Payment_Method
379
-     * @throws EE_Error
380
-     */
381
-    public function set_usable_currencies_on_payment_method($payment_method)
382
-    {
383
-        EE_Error::doing_it_wrong(
384
-            'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method',
385
-            esc_html__(
386
-                'We no longer define what currencies are usable by payment methods. Its not used nor efficient.',
387
-                'event_espresso'
388
-            ),
389
-            '4.9.40'
390
-        );
391
-        return $payment_method;
392
-    }
393
-
394
-
395
-
396
-    /**
397
-     * Deactivates a payment method of the given payment method slug.
398
-     *
399
-     * @param string $payment_method_slug The slug for the payment method to deactivate.
400
-     * @return int count of rows updated.
401
-     * @throws EE_Error
402
-     */
403
-    public function deactivate_payment_method($payment_method_slug)
404
-    {
405
-        EE_Log::instance()->log(
406
-            __FILE__,
407
-            __FUNCTION__,
408
-            sprintf(
409
-                esc_html__(
410
-                    'Payment method with slug %1$s is being deactivated by site admin',
411
-                    'event_espresso'
412
-                ),
413
-                $payment_method_slug
414
-            ),
415
-            'payment_method_change'
416
-        );
417
-        $count_updated = EEM_Payment_Method::instance()->update(
418
-            array('PMD_scope' => array()),
419
-            array(array('PMD_slug' => $payment_method_slug))
420
-        );
421
-        return $count_updated;
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method
428
-     * access caps.
429
-     *
430
-     * @param array $caps capabilities being filtered
431
-     * @return array
432
-     */
433
-    public function add_payment_method_caps($caps)
434
-    {
435
-        /* add dynamic caps from payment methods
22
+	/**
23
+	 * @var EE_Payment_Method_Manager $_instance
24
+	 */
25
+	private static $_instance;
26
+
27
+	/**
28
+	 * @var array keys are class names without 'EE_PMT_', values are their filepaths
29
+	 */
30
+	protected $_payment_method_types = array();
31
+
32
+
33
+
34
+	/**
35
+	 * @singleton method used to instantiate class object
36
+	 * @return EE_Payment_Method_Manager instance
37
+	 */
38
+	public static function instance()
39
+	{
40
+		// check if class object is instantiated, and instantiated properly
41
+		if (! self::$_instance instanceof EE_Payment_Method_Manager) {
42
+			self::$_instance = new self();
43
+		}
44
+		EE_Registry::instance()->load_lib('PMT_Base');
45
+		return self::$_instance;
46
+	}
47
+
48
+
49
+
50
+	/**
51
+	 * Resets the instance and returns a new one
52
+	 *
53
+	 * @return EE_Payment_Method_Manager
54
+	 */
55
+	public static function reset()
56
+	{
57
+		self::$_instance = null;
58
+		return self::instance();
59
+	}
60
+
61
+
62
+
63
+	/**
64
+	 * If necessary, re-register payment methods
65
+	 *
66
+	 * @param boolean $force_recheck whether to recheck for payment method types,
67
+	 *                               or just re-use the PMTs we found last time we checked during this request (if
68
+	 *                               we have not yet checked during this request, then we need to check anyways)
69
+	 */
70
+	public function maybe_register_payment_methods($force_recheck = false)
71
+	{
72
+		if (! $this->_payment_method_types || $force_recheck) {
73
+			$this->_register_payment_methods();
74
+			//if in admin lets ensure caps are set.
75
+			if (is_admin()) {
76
+				add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps'));
77
+				EE_Registry::instance()->CAP->init_caps();
78
+			}
79
+		}
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * register_payment_methods
86
+	 *
87
+	 * @return array
88
+	 */
89
+	protected function _register_payment_methods()
90
+	{
91
+		// grab list of installed modules
92
+		$pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
93
+		// filter list of modules to register
94
+		$pm_to_register = apply_filters(
95
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
96
+			$pm_to_register
97
+		);
98
+		// loop through folders
99
+		foreach ($pm_to_register as $pm_path) {
100
+			$this->register_payment_method($pm_path);
101
+		}
102
+		do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
103
+		// filter list of installed modules
104
+		//keep them organized alphabetically by the payment method type's name
105
+		ksort($this->_payment_method_types);
106
+		return apply_filters(
107
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
108
+			$this->_payment_method_types
109
+		);
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * register_payment_method- makes core aware of this payment method
116
+	 *
117
+	 * @param string $payment_method_path - full path up to and including payment method folder
118
+	 * @return boolean
119
+	 */
120
+	public function register_payment_method($payment_method_path = '')
121
+	{
122
+		do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
123
+		$module_ext = '.pm.php';
124
+		// make all separators match
125
+		$payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS);
126
+		// grab and sanitize module name
127
+		$module_dir = basename($payment_method_path);
128
+		// create classname from module directory name
129
+		$module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
130
+		// add class prefix
131
+		$module_class = 'EE_PMT_' . $module;
132
+		// does the module exist ?
133
+		if (! is_readable($payment_method_path . DS . $module_class . $module_ext)) {
134
+			$msg = sprintf(
135
+				esc_html__(
136
+					'The requested %s payment method file could not be found or is not readable due to file permissions.',
137
+					'event_espresso'
138
+				), $module
139
+			);
140
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
141
+			return false;
142
+		}
143
+		// load the module class file
144
+		require_once($payment_method_path . DS . $module_class . $module_ext);
145
+		// verify that class exists
146
+		if (! class_exists($module_class)) {
147
+			$msg = sprintf(
148
+				esc_html__('The requested %s module class does not exist.', 'event_espresso'),
149
+				$module_class
150
+			);
151
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
152
+			return false;
153
+		}
154
+		// add to array of registered modules
155
+		$this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext;
156
+		return true;
157
+	}
158
+
159
+
160
+
161
+	/**
162
+	 * Checks if a payment method has been registered, and if so includes it
163
+	 *
164
+	 * @param string  $payment_method_name like 'PayPal_Pro', (ie classname without the prefix 'EEPM_')
165
+	 * @param boolean $force_recheck       whether to force re-checking for new payment method types
166
+	 * @return boolean
167
+	 */
168
+	public function payment_method_type_exists($payment_method_name, $force_recheck = false)
169
+	{
170
+		if (
171
+			$force_recheck
172
+			|| ! is_array($this->_payment_method_types)
173
+			|| ! isset($this->_payment_method_types[$payment_method_name])
174
+		) {
175
+			$this->maybe_register_payment_methods($force_recheck);
176
+		}
177
+		if (isset($this->_payment_method_types[$payment_method_name])) {
178
+			require_once($this->_payment_method_types[$payment_method_name]);
179
+			return true;
180
+		}
181
+		return false;
182
+	}
183
+
184
+
185
+
186
+	/**
187
+	 * Returns all the class names of the various payment method types
188
+	 *
189
+	 * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names'
190
+	 *                               (what you'd find in wp_esp_payment_method.PMD_type)
191
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
192
+	 * @return array
193
+	 */
194
+	public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
195
+	{
196
+		$this->maybe_register_payment_methods($force_recheck);
197
+		if ($with_prefixes) {
198
+			$classnames = array_keys($this->_payment_method_types);
199
+			$payment_methods = array();
200
+			foreach ($classnames as $classname) {
201
+				$payment_methods[] = $this->payment_method_class_from_type($classname);
202
+			}
203
+			return $payment_methods;
204
+		}
205
+		return array_keys($this->_payment_method_types);
206
+	}
207
+
208
+
209
+
210
+	/**
211
+	 * Gets an object of each payment method type, none of which are bound to a
212
+	 * payment method instance
213
+	 *
214
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
215
+	 * @return EE_PMT_Base[]
216
+	 */
217
+	public function payment_method_types($force_recheck = false)
218
+	{
219
+		$this->maybe_register_payment_methods($force_recheck);
220
+		$payment_method_objects = array();
221
+		foreach ($this->payment_method_type_names(true) as $classname) {
222
+			$payment_method_objects[] = new $classname;
223
+		}
224
+		return $payment_method_objects;
225
+	}
226
+
227
+
228
+
229
+	/**
230
+	 * Changes the payment method's classname into the payment method type's name
231
+	 * (as used on the payment method's table's PMD_type field)
232
+	 *
233
+	 * @param string $classname
234
+	 * @return string
235
+	 */
236
+	public function payment_method_type_sans_class_prefix($classname)
237
+	{
238
+		return str_replace('EE_PMT_', '', $classname);
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * Does the opposite of payment-method_type_sans_prefix
245
+	 *
246
+	 * @param string $type
247
+	 * @return string
248
+	 */
249
+	public function payment_method_class_from_type($type)
250
+	{
251
+		$this->maybe_register_payment_methods();
252
+		return 'EE_PMT_' . $type;
253
+	}
254
+
255
+
256
+
257
+	/**
258
+	 * Activates a payment method of the given type.
259
+	 *
260
+	 * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
261
+	 * @return EE_Payment_Method
262
+	 * @throws EE_Error
263
+	 */
264
+	public function activate_a_payment_method_of_type($payment_method_type)
265
+	{
266
+		$payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
267
+		if (! $payment_method instanceof EE_Payment_Method) {
268
+			$pm_type_class = $this->payment_method_class_from_type($payment_method_type);
269
+			if (class_exists($pm_type_class)) {
270
+				/** @var $pm_type_obj EE_PMT_Base */
271
+				$pm_type_obj = new $pm_type_class;
272
+				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
273
+				if (! $payment_method) {
274
+					$payment_method = $this->create_payment_method_of_type($pm_type_obj);
275
+				}
276
+				$payment_method->set_type($payment_method_type);
277
+				$this->initialize_payment_method($payment_method);
278
+			} else {
279
+				throw new EE_Error(
280
+					sprintf(
281
+						esc_html__(
282
+							'There is no payment method of type %1$s, so it could not be activated',
283
+							'event_espresso'
284
+						),
285
+						$pm_type_class
286
+					)
287
+				);
288
+			}
289
+		}
290
+		$payment_method->set_active();
291
+		$payment_method->save();
292
+		if ($payment_method->type() === 'Invoice') {
293
+			/** @type EE_Message_Resource_Manager $message_resource_manager */
294
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
295
+			$message_resource_manager->ensure_message_type_is_active('invoice', 'html');
296
+			$message_resource_manager->ensure_messenger_is_active('pdf');
297
+			EE_Error::add_persistent_admin_notice(
298
+				'invoice_pm_requirements_notice',
299
+				sprintf(
300
+					esc_html__(
301
+						'The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.',
302
+						'event_espresso'
303
+					),
304
+					'<a href="' . admin_url('admin.php?page=espresso_messages') . '">',
305
+					'</a>'
306
+				),
307
+				true
308
+			);
309
+		}
310
+		return $payment_method;
311
+	}
312
+
313
+
314
+
315
+	/**
316
+	 * Creates a payment method of the specified type. Does not save it.
317
+	 *
318
+	 * @global WP_User    $current_user
319
+	 * @param EE_PMT_Base $pm_type_obj
320
+	 * @return EE_Payment_Method
321
+	 * @throws EE_Error
322
+	 */
323
+	public function create_payment_method_of_type($pm_type_obj)
324
+	{
325
+		global $current_user;
326
+		$payment_method = EE_Payment_Method::new_instance(
327
+			array(
328
+				'PMD_type'       => $pm_type_obj->system_name(),
329
+				'PMD_name'       => $pm_type_obj->pretty_name(),
330
+				'PMD_admin_name' => $pm_type_obj->pretty_name(),
331
+				'PMD_slug'       => $pm_type_obj->system_name(),//automatically converted to slug
332
+				'PMD_wp_user'    => $current_user->ID,
333
+				'PMD_order'      => EEM_Payment_Method::instance()->count(
334
+						array(array('PMD_type' => array('!=', 'Admin_Only')))
335
+					) * 10,
336
+			)
337
+		);
338
+		return $payment_method;
339
+	}
340
+
341
+
342
+
343
+	/**
344
+	 * Sets the initial payment method properties (including extra meta)
345
+	 *
346
+	 * @param EE_Payment_Method $payment_method
347
+	 * @return EE_Payment_Method
348
+	 * @throws EE_Error
349
+	 */
350
+	public function initialize_payment_method($payment_method)
351
+	{
352
+		$pm_type_obj = $payment_method->type_obj();
353
+		$payment_method->set_description($pm_type_obj->default_description());
354
+		if (! $payment_method->button_url()) {
355
+			$payment_method->set_button_url($pm_type_obj->default_button_url());
356
+		}
357
+		//now add setup its default extra meta properties
358
+		$extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
359
+		if (! empty($extra_metas)) {
360
+			//verify the payment method has an ID before adding extra meta
361
+			if (! $payment_method->ID()) {
362
+				$payment_method->save();
363
+			}
364
+			foreach ($extra_metas as $meta_name => $input) {
365
+				$payment_method->update_extra_meta($meta_name, $input->raw_value());
366
+			}
367
+		}
368
+		return $payment_method;
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * Makes sure the payment method is related to the specified payment method
375
+	 *
376
+	 * @deprecated in 4.9.40 because the currency payment method table is being deprecated
377
+	 * @param EE_Payment_Method $payment_method
378
+	 * @return EE_Payment_Method
379
+	 * @throws EE_Error
380
+	 */
381
+	public function set_usable_currencies_on_payment_method($payment_method)
382
+	{
383
+		EE_Error::doing_it_wrong(
384
+			'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method',
385
+			esc_html__(
386
+				'We no longer define what currencies are usable by payment methods. Its not used nor efficient.',
387
+				'event_espresso'
388
+			),
389
+			'4.9.40'
390
+		);
391
+		return $payment_method;
392
+	}
393
+
394
+
395
+
396
+	/**
397
+	 * Deactivates a payment method of the given payment method slug.
398
+	 *
399
+	 * @param string $payment_method_slug The slug for the payment method to deactivate.
400
+	 * @return int count of rows updated.
401
+	 * @throws EE_Error
402
+	 */
403
+	public function deactivate_payment_method($payment_method_slug)
404
+	{
405
+		EE_Log::instance()->log(
406
+			__FILE__,
407
+			__FUNCTION__,
408
+			sprintf(
409
+				esc_html__(
410
+					'Payment method with slug %1$s is being deactivated by site admin',
411
+					'event_espresso'
412
+				),
413
+				$payment_method_slug
414
+			),
415
+			'payment_method_change'
416
+		);
417
+		$count_updated = EEM_Payment_Method::instance()->update(
418
+			array('PMD_scope' => array()),
419
+			array(array('PMD_slug' => $payment_method_slug))
420
+		);
421
+		return $count_updated;
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method
428
+	 * access caps.
429
+	 *
430
+	 * @param array $caps capabilities being filtered
431
+	 * @return array
432
+	 */
433
+	public function add_payment_method_caps($caps)
434
+	{
435
+		/* add dynamic caps from payment methods
436 436
          * at the time of writing, october 20 2014, these are the caps added:
437 437
          * ee_payment_method_admin_only
438 438
          * ee_payment_method_aim
@@ -446,10 +446,10 @@  discard block
 block discarded – undo
446 446
          * their related capability automatically added too, so long as they are
447 447
          * registered properly using EE_Register_Payment_Method::register()
448 448
          */
449
-        foreach ($this->payment_method_types() as $payment_method_type_obj) {
450
-            $caps['administrator'][] = $payment_method_type_obj->cap_name();
451
-        }
452
-        return $caps;
453
-    }
449
+		foreach ($this->payment_method_types() as $payment_method_type_obj) {
450
+			$caps['administrator'][] = $payment_method_type_obj->cap_name();
451
+		}
452
+		return $caps;
453
+	}
454 454
 
455 455
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 1 patch
Indentation   +1653 added lines, -1653 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\interfaces\ResettableInterface;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -17,244 +17,244 @@  discard block
 block discarded – undo
17 17
 class EEH_Activation implements ResettableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * constant used to indicate a cron task is no longer in use
22
-     */
23
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
24
-
25
-    /**
26
-     * option name that will indicate whether or not we still
27
-     * need to create EE's folders in the uploads directory
28
-     * (because if EE was installed without file system access,
29
-     * we need to request credentials before we can create them)
30
-     */
31
-    const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
32
-
33
-    /**
34
-     * WP_User->ID
35
-     *
36
-     * @var int
37
-     */
38
-    private static $_default_creator_id;
39
-
40
-    /**
41
-     * indicates whether or not we've already verified core's default data during this request,
42
-     * because after migrations are done, any addons activated while in maintenance mode
43
-     * will want to setup their own default data, and they might hook into core's default data
44
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
45
-     * This prevents doing that for EVERY single addon.
46
-     *
47
-     * @var boolean
48
-     */
49
-    protected static $_initialized_db_content_already_in_this_request = false;
50
-
51
-    /**
52
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
53
-     */
54
-    private static $table_analysis;
55
-
56
-    /**
57
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
58
-     */
59
-    private static $table_manager;
60
-
61
-
62
-    /**
63
-     * @return \EventEspresso\core\services\database\TableAnalysis
64
-     */
65
-    public static function getTableAnalysis()
66
-    {
67
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
68
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
69
-        }
70
-        return self::$table_analysis;
71
-    }
72
-
73
-
74
-    /**
75
-     * @return \EventEspresso\core\services\database\TableManager
76
-     */
77
-    public static function getTableManager()
78
-    {
79
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
80
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
81
-        }
82
-        return self::$table_manager;
83
-    }
84
-
85
-
86
-    /**
87
-     *    _ensure_table_name_has_prefix
88
-     *
89
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
90
-     * @access     public
91
-     * @static
92
-     * @param $table_name
93
-     * @return string
94
-     */
95
-    public static function ensure_table_name_has_prefix($table_name)
96
-    {
97
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
98
-    }
99
-
100
-
101
-    /**
102
-     *    system_initialization
103
-     *    ensures the EE configuration settings are loaded with at least default options set
104
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
105
-     *
106
-     * @access public
107
-     * @static
108
-     * @return void
109
-     */
110
-    public static function system_initialization()
111
-    {
112
-        EEH_Activation::reset_and_update_config();
113
-        //which is fired BEFORE activation of plugin anyways
114
-        EEH_Activation::verify_default_pages_exist();
115
-    }
116
-
117
-
118
-    /**
119
-     * Sets the database schema and creates folders. This should
120
-     * be called on plugin activation and reactivation
121
-     *
122
-     * @return boolean success, whether the database and folders are setup properly
123
-     * @throws \EE_Error
124
-     */
125
-    public static function initialize_db_and_folders()
126
-    {
127
-        $good_filesystem = EEH_Activation::create_upload_directories();
128
-        $good_db         = EEH_Activation::create_database_tables();
129
-        return $good_filesystem && $good_db;
130
-    }
131
-
132
-
133
-    /**
134
-     * assuming we have an up-to-date database schema, this will populate it
135
-     * with default and initial data. This should be called
136
-     * upon activation of a new plugin, reactivation, and at the end
137
-     * of running migration scripts
138
-     *
139
-     * @throws \EE_Error
140
-     */
141
-    public static function initialize_db_content()
142
-    {
143
-        //let's avoid doing all this logic repeatedly, especially when addons are requesting it
144
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
145
-            return;
146
-        }
147
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
148
-
149
-        EEH_Activation::initialize_system_questions();
150
-        EEH_Activation::insert_default_status_codes();
151
-        EEH_Activation::generate_default_message_templates();
152
-        EEH_Activation::create_no_ticket_prices_array();
153
-        EE_Registry::instance()->CAP->init_caps();
154
-
155
-        EEH_Activation::validate_messages_system();
156
-        EEH_Activation::insert_default_payment_methods();
157
-        //in case we've
158
-        EEH_Activation::remove_cron_tasks();
159
-        EEH_Activation::create_cron_tasks();
160
-        // remove all TXN locks since that is being done via extra meta now
161
-        delete_option('ee_locked_transactions');
162
-        //also, check for CAF default db content
163
-        do_action('AHEE__EEH_Activation__initialize_db_content');
164
-        //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
165
-        //which users really won't care about on initial activation
166
-        EE_Error::overwrite_success();
167
-    }
168
-
169
-
170
-    /**
171
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
172
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
173
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
174
-     * (null)
175
-     *
176
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
177
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
178
-     * @return array
179
-     * @throws \EE_Error
180
-     */
181
-    public static function get_cron_tasks($which_to_include)
182
-    {
183
-        $cron_tasks = apply_filters(
184
-            'FHEE__EEH_Activation__get_cron_tasks',
185
-            array(
186
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
20
+	/**
21
+	 * constant used to indicate a cron task is no longer in use
22
+	 */
23
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
24
+
25
+	/**
26
+	 * option name that will indicate whether or not we still
27
+	 * need to create EE's folders in the uploads directory
28
+	 * (because if EE was installed without file system access,
29
+	 * we need to request credentials before we can create them)
30
+	 */
31
+	const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
32
+
33
+	/**
34
+	 * WP_User->ID
35
+	 *
36
+	 * @var int
37
+	 */
38
+	private static $_default_creator_id;
39
+
40
+	/**
41
+	 * indicates whether or not we've already verified core's default data during this request,
42
+	 * because after migrations are done, any addons activated while in maintenance mode
43
+	 * will want to setup their own default data, and they might hook into core's default data
44
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
45
+	 * This prevents doing that for EVERY single addon.
46
+	 *
47
+	 * @var boolean
48
+	 */
49
+	protected static $_initialized_db_content_already_in_this_request = false;
50
+
51
+	/**
52
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
53
+	 */
54
+	private static $table_analysis;
55
+
56
+	/**
57
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
58
+	 */
59
+	private static $table_manager;
60
+
61
+
62
+	/**
63
+	 * @return \EventEspresso\core\services\database\TableAnalysis
64
+	 */
65
+	public static function getTableAnalysis()
66
+	{
67
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
68
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
69
+		}
70
+		return self::$table_analysis;
71
+	}
72
+
73
+
74
+	/**
75
+	 * @return \EventEspresso\core\services\database\TableManager
76
+	 */
77
+	public static function getTableManager()
78
+	{
79
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
80
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
81
+		}
82
+		return self::$table_manager;
83
+	}
84
+
85
+
86
+	/**
87
+	 *    _ensure_table_name_has_prefix
88
+	 *
89
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
90
+	 * @access     public
91
+	 * @static
92
+	 * @param $table_name
93
+	 * @return string
94
+	 */
95
+	public static function ensure_table_name_has_prefix($table_name)
96
+	{
97
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
98
+	}
99
+
100
+
101
+	/**
102
+	 *    system_initialization
103
+	 *    ensures the EE configuration settings are loaded with at least default options set
104
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
105
+	 *
106
+	 * @access public
107
+	 * @static
108
+	 * @return void
109
+	 */
110
+	public static function system_initialization()
111
+	{
112
+		EEH_Activation::reset_and_update_config();
113
+		//which is fired BEFORE activation of plugin anyways
114
+		EEH_Activation::verify_default_pages_exist();
115
+	}
116
+
117
+
118
+	/**
119
+	 * Sets the database schema and creates folders. This should
120
+	 * be called on plugin activation and reactivation
121
+	 *
122
+	 * @return boolean success, whether the database and folders are setup properly
123
+	 * @throws \EE_Error
124
+	 */
125
+	public static function initialize_db_and_folders()
126
+	{
127
+		$good_filesystem = EEH_Activation::create_upload_directories();
128
+		$good_db         = EEH_Activation::create_database_tables();
129
+		return $good_filesystem && $good_db;
130
+	}
131
+
132
+
133
+	/**
134
+	 * assuming we have an up-to-date database schema, this will populate it
135
+	 * with default and initial data. This should be called
136
+	 * upon activation of a new plugin, reactivation, and at the end
137
+	 * of running migration scripts
138
+	 *
139
+	 * @throws \EE_Error
140
+	 */
141
+	public static function initialize_db_content()
142
+	{
143
+		//let's avoid doing all this logic repeatedly, especially when addons are requesting it
144
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
145
+			return;
146
+		}
147
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
148
+
149
+		EEH_Activation::initialize_system_questions();
150
+		EEH_Activation::insert_default_status_codes();
151
+		EEH_Activation::generate_default_message_templates();
152
+		EEH_Activation::create_no_ticket_prices_array();
153
+		EE_Registry::instance()->CAP->init_caps();
154
+
155
+		EEH_Activation::validate_messages_system();
156
+		EEH_Activation::insert_default_payment_methods();
157
+		//in case we've
158
+		EEH_Activation::remove_cron_tasks();
159
+		EEH_Activation::create_cron_tasks();
160
+		// remove all TXN locks since that is being done via extra meta now
161
+		delete_option('ee_locked_transactions');
162
+		//also, check for CAF default db content
163
+		do_action('AHEE__EEH_Activation__initialize_db_content');
164
+		//also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
165
+		//which users really won't care about on initial activation
166
+		EE_Error::overwrite_success();
167
+	}
168
+
169
+
170
+	/**
171
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
172
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
173
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
174
+	 * (null)
175
+	 *
176
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
177
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
178
+	 * @return array
179
+	 * @throws \EE_Error
180
+	 */
181
+	public static function get_cron_tasks($which_to_include)
182
+	{
183
+		$cron_tasks = apply_filters(
184
+			'FHEE__EEH_Activation__get_cron_tasks',
185
+			array(
186
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
187 187
 //				'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
188
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
189
-                //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
190
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
191
-            )
192
-        );
193
-        if ($which_to_include === 'old') {
194
-            $cron_tasks = array_filter(
195
-                $cron_tasks,
196
-                function ($value) {
197
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
198
-                }
199
-            );
200
-        } elseif ($which_to_include === 'current') {
201
-            $cron_tasks = array_filter($cron_tasks);
202
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
203
-            throw new EE_Error(
204
-                sprintf(
205
-                    __(
206
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
207
-                        'event_espresso'
208
-                    ),
209
-                    $which_to_include
210
-                )
211
-            );
212
-        }
213
-        return $cron_tasks;
214
-    }
215
-
216
-
217
-    /**
218
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
219
-     *
220
-     * @throws \EE_Error
221
-     */
222
-    public static function create_cron_tasks()
223
-    {
224
-
225
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
226
-            if (! wp_next_scheduled($hook_name)) {
227
-                /**
228
-                 * This allows client code to define the initial start timestamp for this schedule.
229
-                 */
230
-                if (is_array($frequency)
231
-                    && count($frequency) === 2
232
-                    && isset($frequency[0], $frequency[1])
233
-                ) {
234
-                    $start_timestamp = $frequency[0];
235
-                    $frequency = $frequency[1];
236
-                } else {
237
-                    $start_timestamp = time();
238
-                }
239
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
240
-            }
241
-        }
242
-
243
-    }
244
-
245
-
246
-    /**
247
-     * Remove the currently-existing and now-removed cron tasks.
248
-     *
249
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
250
-     * @throws \EE_Error
251
-     */
252
-    public static function remove_cron_tasks($remove_all = true)
253
-    {
254
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
255
-        $crons                = _get_cron_array();
256
-        $crons                = is_array($crons) ? $crons : array();
257
-        /* reminder of what $crons look like:
188
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
189
+				//there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
190
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
191
+			)
192
+		);
193
+		if ($which_to_include === 'old') {
194
+			$cron_tasks = array_filter(
195
+				$cron_tasks,
196
+				function ($value) {
197
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
198
+				}
199
+			);
200
+		} elseif ($which_to_include === 'current') {
201
+			$cron_tasks = array_filter($cron_tasks);
202
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
203
+			throw new EE_Error(
204
+				sprintf(
205
+					__(
206
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
207
+						'event_espresso'
208
+					),
209
+					$which_to_include
210
+				)
211
+			);
212
+		}
213
+		return $cron_tasks;
214
+	}
215
+
216
+
217
+	/**
218
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
219
+	 *
220
+	 * @throws \EE_Error
221
+	 */
222
+	public static function create_cron_tasks()
223
+	{
224
+
225
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
226
+			if (! wp_next_scheduled($hook_name)) {
227
+				/**
228
+				 * This allows client code to define the initial start timestamp for this schedule.
229
+				 */
230
+				if (is_array($frequency)
231
+					&& count($frequency) === 2
232
+					&& isset($frequency[0], $frequency[1])
233
+				) {
234
+					$start_timestamp = $frequency[0];
235
+					$frequency = $frequency[1];
236
+				} else {
237
+					$start_timestamp = time();
238
+				}
239
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
240
+			}
241
+		}
242
+
243
+	}
244
+
245
+
246
+	/**
247
+	 * Remove the currently-existing and now-removed cron tasks.
248
+	 *
249
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
250
+	 * @throws \EE_Error
251
+	 */
252
+	public static function remove_cron_tasks($remove_all = true)
253
+	{
254
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
255
+		$crons                = _get_cron_array();
256
+		$crons                = is_array($crons) ? $crons : array();
257
+		/* reminder of what $crons look like:
258 258
          * Top-level keys are timestamps, and their values are arrays.
259 259
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
260 260
          * and their values are arrays.
@@ -271,912 +271,912 @@  discard block
 block discarded – undo
271 271
          *					...
272 272
          *      ...
273 273
          */
274
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
275
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
276
-            if (is_array($hooks_to_fire_at_time)) {
277
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
278
-                    if (isset($ee_cron_tasks_to_remove[$hook_name])
279
-                        && is_array($ee_cron_tasks_to_remove[$hook_name])
280
-                    ) {
281
-                        unset($crons[$timestamp][$hook_name]);
282
-                    }
283
-                }
284
-                //also take care of any empty cron timestamps.
285
-                if (empty($hooks_to_fire_at_time)) {
286
-                    unset($crons[$timestamp]);
287
-                }
288
-            }
289
-        }
290
-        _set_cron_array($crons);
291
-    }
292
-
293
-
294
-    /**
295
-     *    CPT_initialization
296
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
297
-     *
298
-     * @access public
299
-     * @static
300
-     * @return void
301
-     */
302
-    public static function CPT_initialization()
303
-    {
304
-        // register Custom Post Types
305
-        EE_Registry::instance()->load_core('Register_CPTs');
306
-        flush_rewrite_rules();
307
-    }
308
-
309
-
310
-
311
-    /**
312
-     *    reset_and_update_config
313
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
314
-     * If there is old calendar config data saved, then it will get converted on activation.
315
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
316
-     *
317
-     * @access public
318
-     * @static
319
-     * @return void
320
-     */
321
-    public static function reset_and_update_config()
322
-    {
323
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
324
-        add_filter(
325
-            'FHEE__EE_Config___load_core_config__config_settings',
326
-            array('EEH_Activation', 'migrate_old_config_data'),
327
-            10,
328
-            3
329
-        );
330
-        //EE_Config::reset();
331
-        if (! EE_Config::logging_enabled()) {
332
-            delete_option(EE_Config::LOG_NAME);
333
-        }
334
-    }
335
-
336
-
337
-    /**
338
-     *    load_calendar_config
339
-     *
340
-     * @access    public
341
-     * @return    void
342
-     */
343
-    public static function load_calendar_config()
344
-    {
345
-        // grab array of all plugin folders and loop thru it
346
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
347
-        if (empty($plugins)) {
348
-            return;
349
-        }
350
-        foreach ($plugins as $plugin_path) {
351
-            // grab plugin folder name from path
352
-            $plugin = basename($plugin_path);
353
-            // drill down to Espresso plugins
354
-            // then to calendar related plugins
355
-            if (
356
-                strpos($plugin, 'espresso') !== false
357
-                || strpos($plugin, 'Espresso') !== false
358
-                || strpos($plugin, 'ee4') !== false
359
-                || strpos($plugin, 'EE4') !== false
360
-                || strpos($plugin, 'calendar') !== false
361
-            ) {
362
-                // this is what we are looking for
363
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
364
-                // does it exist in this folder ?
365
-                if (is_readable($calendar_config)) {
366
-                    // YEAH! let's load it
367
-                    require_once($calendar_config);
368
-                }
369
-            }
370
-        }
371
-    }
372
-
373
-
374
-
375
-    /**
376
-     *    _migrate_old_config_data
377
-     *
378
-     * @access    public
379
-     * @param array|stdClass $settings
380
-     * @param string         $config
381
-     * @param \EE_Config     $EE_Config
382
-     * @return \stdClass
383
-     */
384
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
385
-    {
386
-        $convert_from_array = array('addons');
387
-        // in case old settings were saved as an array
388
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
389
-            // convert existing settings to an object
390
-            $config_array = $settings;
391
-            $settings = new stdClass();
392
-            foreach ($config_array as $key => $value) {
393
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
394
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
395
-                } else {
396
-                    $settings->{$key} = $value;
397
-                }
398
-            }
399
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
400
-        }
401
-        return $settings;
402
-    }
403
-
404
-
405
-    /**
406
-     * deactivate_event_espresso
407
-     *
408
-     * @access public
409
-     * @static
410
-     * @return void
411
-     */
412
-    public static function deactivate_event_espresso()
413
-    {
414
-        // check permissions
415
-        if (current_user_can('activate_plugins')) {
416
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
417
-        }
418
-    }
419
-
420
-
421
-
422
-
423
-
424
-    /**
425
-     * verify_default_pages_exist
426
-     *
427
-     * @access public
428
-     * @static
429
-     * @return void
430
-     */
431
-    public static function verify_default_pages_exist()
432
-    {
433
-        $critical_page_problem = false;
434
-        $critical_pages = array(
435
-            array(
436
-                'id'   => 'reg_page_id',
437
-                'name' => __('Registration Checkout', 'event_espresso'),
438
-                'post' => null,
439
-                'code' => 'ESPRESSO_CHECKOUT',
440
-            ),
441
-            array(
442
-                'id'   => 'txn_page_id',
443
-                'name' => __('Transactions', 'event_espresso'),
444
-                'post' => null,
445
-                'code' => 'ESPRESSO_TXN_PAGE',
446
-            ),
447
-            array(
448
-                'id'   => 'thank_you_page_id',
449
-                'name' => __('Thank You', 'event_espresso'),
450
-                'post' => null,
451
-                'code' => 'ESPRESSO_THANK_YOU',
452
-            ),
453
-            array(
454
-                'id'   => 'cancel_page_id',
455
-                'name' => __('Registration Cancelled', 'event_espresso'),
456
-                'post' => null,
457
-                'code' => 'ESPRESSO_CANCELLED',
458
-            ),
459
-        );
460
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
461
-        foreach ($critical_pages as $critical_page) {
462
-            // is critical page ID set in config ?
463
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
464
-                // attempt to find post by ID
465
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
466
-            }
467
-            // no dice?
468
-            if ($critical_page['post'] === null) {
469
-                // attempt to find post by title
470
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
471
-                // still nothing?
472
-                if ($critical_page['post'] === null) {
473
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
474
-                    // REALLY? Still nothing ??!?!?
475
-                    if ($critical_page['post'] === null) {
476
-                        $msg = __(
477
-                            'The Event Espresso critical page configuration settings could not be updated.',
478
-                            'event_espresso'
479
-                        );
480
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
481
-                        break;
482
-                    }
483
-                }
484
-            }
485
-            // check that Post ID matches critical page ID in config
486
-            if (
487
-                isset($critical_page['post']->ID)
488
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
489
-            ) {
490
-                //update Config with post ID
491
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
492
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
493
-                    $msg = __(
494
-                        'The Event Espresso critical page configuration settings could not be updated.',
495
-                        'event_espresso'
496
-                    );
497
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
498
-                }
499
-            }
500
-            $critical_page_problem =
501
-                ! isset($critical_page['post']->post_status)
502
-                || $critical_page['post']->post_status !== 'publish'
503
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
504
-                    ? true
505
-                    : $critical_page_problem;
506
-        }
507
-        if ($critical_page_problem) {
508
-            $msg = sprintf(
509
-                __(
510
-                    'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
511
-                    'event_espresso'
512
-                ),
513
-                '<a href="'
514
-                . admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
515
-                . '">'
516
-                . __('Event Espresso Critical Pages Settings', 'event_espresso')
517
-                . '</a>'
518
-            );
519
-            EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
520
-        }
521
-        if (EE_Error::has_notices()) {
522
-            EE_Error::get_notices(false, true, true);
523
-        }
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     * Returns the first post which uses the specified shortcode
530
-     *
531
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
532
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
533
-     *                             "[ESPRESSO_THANK_YOU"
534
-     *                             (we don't search for the closing shortcode bracket because they might have added
535
-     *                             parameter to the shortcode
536
-     * @return WP_Post or NULl
537
-     */
538
-    public static function get_page_by_ee_shortcode($ee_shortcode)
539
-    {
540
-        global $wpdb;
541
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
542
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
543
-        if ($post_id) {
544
-            return get_post($post_id);
545
-        } else {
546
-            return null;
547
-        }
548
-    }
549
-
550
-
551
-    /**
552
-     *    This function generates a post for critical espresso pages
553
-     *
554
-     * @access public
555
-     * @static
556
-     * @param array $critical_page
557
-     * @return array
558
-     */
559
-    public static function create_critical_page($critical_page)
560
-    {
561
-
562
-        $post_args = array(
563
-            'post_title'     => $critical_page['name'],
564
-            'post_status'    => 'publish',
565
-            'post_type'      => 'page',
566
-            'comment_status' => 'closed',
567
-            'post_content'   => '[' . $critical_page['code'] . ']',
568
-        );
569
-
570
-        $post_id = wp_insert_post($post_args);
571
-        if (! $post_id) {
572
-            $msg = sprintf(
573
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
574
-                $critical_page['name']
575
-            );
576
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
577
-            return $critical_page;
578
-        }
579
-        // get newly created post's details
580
-        if (! $critical_page['post'] = get_post($post_id)) {
581
-            $msg = sprintf(
582
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
583
-                $critical_page['name']
584
-            );
585
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
586
-        }
587
-
588
-        return $critical_page;
589
-
590
-    }
591
-
592
-
593
-
594
-
595
-    /**
596
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
597
-     * The role being used to check is filterable.
598
-     *
599
-     * @since  4.6.0
600
-     * @global WPDB $wpdb
601
-     * @return mixed null|int WP_user ID or NULL
602
-     */
603
-    public static function get_default_creator_id()
604
-    {
605
-        global $wpdb;
606
-        if ( ! empty(self::$_default_creator_id)) {
607
-            return self::$_default_creator_id;
608
-        }/**/
609
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
610
-        //let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
611
-        $pre_filtered_id = apply_filters(
612
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
613
-            false,
614
-            $role_to_check
615
-        );
616
-        if ($pre_filtered_id !== false) {
617
-            return (int)$pre_filtered_id;
618
-        }
619
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
620
-        $query = $wpdb->prepare(
621
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
622
-            '%' . $role_to_check . '%'
623
-        );
624
-        $user_id = $wpdb->get_var($query);
625
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
626
-        if ($user_id && (int)$user_id) {
627
-            self::$_default_creator_id = (int)$user_id;
628
-            return self::$_default_creator_id;
629
-        } else {
630
-            return null;
631
-        }
632
-    }
633
-
634
-
635
-
636
-    /**
637
-     * used by EE and EE addons during plugin activation to create tables.
638
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
639
-     * but includes extra logic regarding activations.
640
-     *
641
-     * @access public
642
-     * @static
643
-     * @param string  $table_name              without the $wpdb->prefix
644
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
645
-     *                                         table query)
646
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
647
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
648
-     *                                         and new once this function is done (ie, you really do want to CREATE a
649
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
650
-     *                                         you just want to verify the table exists and matches this definition
651
-     *                                         (and if it HAS data in it you want to leave it be)
652
-     * @return void
653
-     * @throws EE_Error if there are database errors
654
-     */
655
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
656
-    {
657
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
658
-            return;
659
-        }
660
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
661
-        if ( ! function_exists('dbDelta')) {
662
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
663
-        }
664
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
665
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
666
-        // do we need to first delete an existing version of this table ?
667
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
668
-            // ok, delete the table... but ONLY if it's empty
669
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
670
-            // table is NOT empty, are you SURE you want to delete this table ???
671
-            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
672
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
673
-            } else if ( ! $deleted_safely) {
674
-                // so we should be more cautious rather than just dropping tables so easily
675
-                error_log(
676
-                    sprintf(
677
-                        __(
678
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
679
-                            'event_espresso'
680
-                        ),
681
-                        $wp_table_name,
682
-                        '<br/>',
683
-                        'espresso_db_update'
684
-                    )
685
-                );
686
-            }
687
-        }
688
-        $engine = str_replace('ENGINE=', '', $engine);
689
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
690
-    }
691
-
692
-
693
-
694
-    /**
695
-     *    add_column_if_it_doesn't_exist
696
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
697
-     *
698
-     * @access     public
699
-     * @static
700
-     * @deprecated instead use TableManager::addColumn()
701
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
702
-     * @param string $column_name
703
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
704
-     *                            'VARCHAR(10)'
705
-     * @return bool|int
706
-     */
707
-    public static function add_column_if_it_doesnt_exist(
708
-        $table_name,
709
-        $column_name,
710
-        $column_info = 'INT UNSIGNED NOT NULL'
711
-    ) {
712
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
713
-    }
714
-
715
-
716
-    /**
717
-     * get_fields_on_table
718
-     * Gets all the fields on the database table.
719
-     *
720
-     * @access     public
721
-     * @deprecated instead use TableManager::getTableColumns()
722
-     * @static
723
-     * @param string $table_name , without prefixed $wpdb->prefix
724
-     * @return array of database column names
725
-     */
726
-    public static function get_fields_on_table($table_name = null)
727
-    {
728
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
729
-    }
730
-
731
-
732
-    /**
733
-     * db_table_is_empty
734
-     *
735
-     * @access     public\
736
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
737
-     * @static
738
-     * @param string $table_name
739
-     * @return bool
740
-     */
741
-    public static function db_table_is_empty($table_name)
742
-    {
743
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
744
-    }
745
-
746
-
747
-    /**
748
-     * delete_db_table_if_empty
749
-     *
750
-     * @access public
751
-     * @static
752
-     * @param string $table_name
753
-     * @return bool | int
754
-     */
755
-    public static function delete_db_table_if_empty($table_name)
756
-    {
757
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
758
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
759
-        }
760
-        return false;
761
-    }
762
-
763
-
764
-    /**
765
-     * delete_unused_db_table
766
-     *
767
-     * @access     public
768
-     * @static
769
-     * @deprecated instead use TableManager::dropTable()
770
-     * @param string $table_name
771
-     * @return bool | int
772
-     */
773
-    public static function delete_unused_db_table($table_name)
774
-    {
775
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
776
-    }
777
-
778
-
779
-    /**
780
-     * drop_index
781
-     *
782
-     * @access     public
783
-     * @static
784
-     * @deprecated instead use TableManager::dropIndex()
785
-     * @param string $table_name
786
-     * @param string $index_name
787
-     * @return bool | int
788
-     */
789
-    public static function drop_index($table_name, $index_name)
790
-    {
791
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
792
-    }
793
-
794
-
795
-
796
-    /**
797
-     * create_database_tables
798
-     *
799
-     * @access public
800
-     * @static
801
-     * @throws EE_Error
802
-     * @return boolean success (whether database is setup properly or not)
803
-     */
804
-    public static function create_database_tables()
805
-    {
806
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
807
-        //find the migration script that sets the database to be compatible with the code
808
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
809
-        if ($dms_name) {
810
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
811
-            $current_data_migration_script->set_migrating(false);
812
-            $current_data_migration_script->schema_changes_before_migration();
813
-            $current_data_migration_script->schema_changes_after_migration();
814
-            if ($current_data_migration_script->get_errors()) {
815
-                if (WP_DEBUG) {
816
-                    foreach ($current_data_migration_script->get_errors() as $error) {
817
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
818
-                    }
819
-                } else {
820
-                    EE_Error::add_error(
821
-                        __(
822
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
274
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
275
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
276
+			if (is_array($hooks_to_fire_at_time)) {
277
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
278
+					if (isset($ee_cron_tasks_to_remove[$hook_name])
279
+						&& is_array($ee_cron_tasks_to_remove[$hook_name])
280
+					) {
281
+						unset($crons[$timestamp][$hook_name]);
282
+					}
283
+				}
284
+				//also take care of any empty cron timestamps.
285
+				if (empty($hooks_to_fire_at_time)) {
286
+					unset($crons[$timestamp]);
287
+				}
288
+			}
289
+		}
290
+		_set_cron_array($crons);
291
+	}
292
+
293
+
294
+	/**
295
+	 *    CPT_initialization
296
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
297
+	 *
298
+	 * @access public
299
+	 * @static
300
+	 * @return void
301
+	 */
302
+	public static function CPT_initialization()
303
+	{
304
+		// register Custom Post Types
305
+		EE_Registry::instance()->load_core('Register_CPTs');
306
+		flush_rewrite_rules();
307
+	}
308
+
309
+
310
+
311
+	/**
312
+	 *    reset_and_update_config
313
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
314
+	 * If there is old calendar config data saved, then it will get converted on activation.
315
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
316
+	 *
317
+	 * @access public
318
+	 * @static
319
+	 * @return void
320
+	 */
321
+	public static function reset_and_update_config()
322
+	{
323
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
324
+		add_filter(
325
+			'FHEE__EE_Config___load_core_config__config_settings',
326
+			array('EEH_Activation', 'migrate_old_config_data'),
327
+			10,
328
+			3
329
+		);
330
+		//EE_Config::reset();
331
+		if (! EE_Config::logging_enabled()) {
332
+			delete_option(EE_Config::LOG_NAME);
333
+		}
334
+	}
335
+
336
+
337
+	/**
338
+	 *    load_calendar_config
339
+	 *
340
+	 * @access    public
341
+	 * @return    void
342
+	 */
343
+	public static function load_calendar_config()
344
+	{
345
+		// grab array of all plugin folders and loop thru it
346
+		$plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
347
+		if (empty($plugins)) {
348
+			return;
349
+		}
350
+		foreach ($plugins as $plugin_path) {
351
+			// grab plugin folder name from path
352
+			$plugin = basename($plugin_path);
353
+			// drill down to Espresso plugins
354
+			// then to calendar related plugins
355
+			if (
356
+				strpos($plugin, 'espresso') !== false
357
+				|| strpos($plugin, 'Espresso') !== false
358
+				|| strpos($plugin, 'ee4') !== false
359
+				|| strpos($plugin, 'EE4') !== false
360
+				|| strpos($plugin, 'calendar') !== false
361
+			) {
362
+				// this is what we are looking for
363
+				$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
364
+				// does it exist in this folder ?
365
+				if (is_readable($calendar_config)) {
366
+					// YEAH! let's load it
367
+					require_once($calendar_config);
368
+				}
369
+			}
370
+		}
371
+	}
372
+
373
+
374
+
375
+	/**
376
+	 *    _migrate_old_config_data
377
+	 *
378
+	 * @access    public
379
+	 * @param array|stdClass $settings
380
+	 * @param string         $config
381
+	 * @param \EE_Config     $EE_Config
382
+	 * @return \stdClass
383
+	 */
384
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
385
+	{
386
+		$convert_from_array = array('addons');
387
+		// in case old settings were saved as an array
388
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
389
+			// convert existing settings to an object
390
+			$config_array = $settings;
391
+			$settings = new stdClass();
392
+			foreach ($config_array as $key => $value) {
393
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
394
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
395
+				} else {
396
+					$settings->{$key} = $value;
397
+				}
398
+			}
399
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
400
+		}
401
+		return $settings;
402
+	}
403
+
404
+
405
+	/**
406
+	 * deactivate_event_espresso
407
+	 *
408
+	 * @access public
409
+	 * @static
410
+	 * @return void
411
+	 */
412
+	public static function deactivate_event_espresso()
413
+	{
414
+		// check permissions
415
+		if (current_user_can('activate_plugins')) {
416
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
417
+		}
418
+	}
419
+
420
+
421
+
422
+
423
+
424
+	/**
425
+	 * verify_default_pages_exist
426
+	 *
427
+	 * @access public
428
+	 * @static
429
+	 * @return void
430
+	 */
431
+	public static function verify_default_pages_exist()
432
+	{
433
+		$critical_page_problem = false;
434
+		$critical_pages = array(
435
+			array(
436
+				'id'   => 'reg_page_id',
437
+				'name' => __('Registration Checkout', 'event_espresso'),
438
+				'post' => null,
439
+				'code' => 'ESPRESSO_CHECKOUT',
440
+			),
441
+			array(
442
+				'id'   => 'txn_page_id',
443
+				'name' => __('Transactions', 'event_espresso'),
444
+				'post' => null,
445
+				'code' => 'ESPRESSO_TXN_PAGE',
446
+			),
447
+			array(
448
+				'id'   => 'thank_you_page_id',
449
+				'name' => __('Thank You', 'event_espresso'),
450
+				'post' => null,
451
+				'code' => 'ESPRESSO_THANK_YOU',
452
+			),
453
+			array(
454
+				'id'   => 'cancel_page_id',
455
+				'name' => __('Registration Cancelled', 'event_espresso'),
456
+				'post' => null,
457
+				'code' => 'ESPRESSO_CANCELLED',
458
+			),
459
+		);
460
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
461
+		foreach ($critical_pages as $critical_page) {
462
+			// is critical page ID set in config ?
463
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
464
+				// attempt to find post by ID
465
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
466
+			}
467
+			// no dice?
468
+			if ($critical_page['post'] === null) {
469
+				// attempt to find post by title
470
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
471
+				// still nothing?
472
+				if ($critical_page['post'] === null) {
473
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
474
+					// REALLY? Still nothing ??!?!?
475
+					if ($critical_page['post'] === null) {
476
+						$msg = __(
477
+							'The Event Espresso critical page configuration settings could not be updated.',
478
+							'event_espresso'
479
+						);
480
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
481
+						break;
482
+					}
483
+				}
484
+			}
485
+			// check that Post ID matches critical page ID in config
486
+			if (
487
+				isset($critical_page['post']->ID)
488
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
489
+			) {
490
+				//update Config with post ID
491
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
492
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
493
+					$msg = __(
494
+						'The Event Espresso critical page configuration settings could not be updated.',
495
+						'event_espresso'
496
+					);
497
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
498
+				}
499
+			}
500
+			$critical_page_problem =
501
+				! isset($critical_page['post']->post_status)
502
+				|| $critical_page['post']->post_status !== 'publish'
503
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
504
+					? true
505
+					: $critical_page_problem;
506
+		}
507
+		if ($critical_page_problem) {
508
+			$msg = sprintf(
509
+				__(
510
+					'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
511
+					'event_espresso'
512
+				),
513
+				'<a href="'
514
+				. admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
515
+				. '">'
516
+				. __('Event Espresso Critical Pages Settings', 'event_espresso')
517
+				. '</a>'
518
+			);
519
+			EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
520
+		}
521
+		if (EE_Error::has_notices()) {
522
+			EE_Error::get_notices(false, true, true);
523
+		}
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 * Returns the first post which uses the specified shortcode
530
+	 *
531
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
532
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
533
+	 *                             "[ESPRESSO_THANK_YOU"
534
+	 *                             (we don't search for the closing shortcode bracket because they might have added
535
+	 *                             parameter to the shortcode
536
+	 * @return WP_Post or NULl
537
+	 */
538
+	public static function get_page_by_ee_shortcode($ee_shortcode)
539
+	{
540
+		global $wpdb;
541
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
542
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
543
+		if ($post_id) {
544
+			return get_post($post_id);
545
+		} else {
546
+			return null;
547
+		}
548
+	}
549
+
550
+
551
+	/**
552
+	 *    This function generates a post for critical espresso pages
553
+	 *
554
+	 * @access public
555
+	 * @static
556
+	 * @param array $critical_page
557
+	 * @return array
558
+	 */
559
+	public static function create_critical_page($critical_page)
560
+	{
561
+
562
+		$post_args = array(
563
+			'post_title'     => $critical_page['name'],
564
+			'post_status'    => 'publish',
565
+			'post_type'      => 'page',
566
+			'comment_status' => 'closed',
567
+			'post_content'   => '[' . $critical_page['code'] . ']',
568
+		);
569
+
570
+		$post_id = wp_insert_post($post_args);
571
+		if (! $post_id) {
572
+			$msg = sprintf(
573
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
574
+				$critical_page['name']
575
+			);
576
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
577
+			return $critical_page;
578
+		}
579
+		// get newly created post's details
580
+		if (! $critical_page['post'] = get_post($post_id)) {
581
+			$msg = sprintf(
582
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
583
+				$critical_page['name']
584
+			);
585
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
586
+		}
587
+
588
+		return $critical_page;
589
+
590
+	}
591
+
592
+
593
+
594
+
595
+	/**
596
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
597
+	 * The role being used to check is filterable.
598
+	 *
599
+	 * @since  4.6.0
600
+	 * @global WPDB $wpdb
601
+	 * @return mixed null|int WP_user ID or NULL
602
+	 */
603
+	public static function get_default_creator_id()
604
+	{
605
+		global $wpdb;
606
+		if ( ! empty(self::$_default_creator_id)) {
607
+			return self::$_default_creator_id;
608
+		}/**/
609
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
610
+		//let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
611
+		$pre_filtered_id = apply_filters(
612
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
613
+			false,
614
+			$role_to_check
615
+		);
616
+		if ($pre_filtered_id !== false) {
617
+			return (int)$pre_filtered_id;
618
+		}
619
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
620
+		$query = $wpdb->prepare(
621
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
622
+			'%' . $role_to_check . '%'
623
+		);
624
+		$user_id = $wpdb->get_var($query);
625
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
626
+		if ($user_id && (int)$user_id) {
627
+			self::$_default_creator_id = (int)$user_id;
628
+			return self::$_default_creator_id;
629
+		} else {
630
+			return null;
631
+		}
632
+	}
633
+
634
+
635
+
636
+	/**
637
+	 * used by EE and EE addons during plugin activation to create tables.
638
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
639
+	 * but includes extra logic regarding activations.
640
+	 *
641
+	 * @access public
642
+	 * @static
643
+	 * @param string  $table_name              without the $wpdb->prefix
644
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
645
+	 *                                         table query)
646
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
647
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
648
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
649
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
650
+	 *                                         you just want to verify the table exists and matches this definition
651
+	 *                                         (and if it HAS data in it you want to leave it be)
652
+	 * @return void
653
+	 * @throws EE_Error if there are database errors
654
+	 */
655
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
656
+	{
657
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
658
+			return;
659
+		}
660
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
661
+		if ( ! function_exists('dbDelta')) {
662
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
663
+		}
664
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
665
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
666
+		// do we need to first delete an existing version of this table ?
667
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
668
+			// ok, delete the table... but ONLY if it's empty
669
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
670
+			// table is NOT empty, are you SURE you want to delete this table ???
671
+			if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
672
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
673
+			} else if ( ! $deleted_safely) {
674
+				// so we should be more cautious rather than just dropping tables so easily
675
+				error_log(
676
+					sprintf(
677
+						__(
678
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
679
+							'event_espresso'
680
+						),
681
+						$wp_table_name,
682
+						'<br/>',
683
+						'espresso_db_update'
684
+					)
685
+				);
686
+			}
687
+		}
688
+		$engine = str_replace('ENGINE=', '', $engine);
689
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
690
+	}
691
+
692
+
693
+
694
+	/**
695
+	 *    add_column_if_it_doesn't_exist
696
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
697
+	 *
698
+	 * @access     public
699
+	 * @static
700
+	 * @deprecated instead use TableManager::addColumn()
701
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
702
+	 * @param string $column_name
703
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
704
+	 *                            'VARCHAR(10)'
705
+	 * @return bool|int
706
+	 */
707
+	public static function add_column_if_it_doesnt_exist(
708
+		$table_name,
709
+		$column_name,
710
+		$column_info = 'INT UNSIGNED NOT NULL'
711
+	) {
712
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
713
+	}
714
+
715
+
716
+	/**
717
+	 * get_fields_on_table
718
+	 * Gets all the fields on the database table.
719
+	 *
720
+	 * @access     public
721
+	 * @deprecated instead use TableManager::getTableColumns()
722
+	 * @static
723
+	 * @param string $table_name , without prefixed $wpdb->prefix
724
+	 * @return array of database column names
725
+	 */
726
+	public static function get_fields_on_table($table_name = null)
727
+	{
728
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
729
+	}
730
+
731
+
732
+	/**
733
+	 * db_table_is_empty
734
+	 *
735
+	 * @access     public\
736
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
737
+	 * @static
738
+	 * @param string $table_name
739
+	 * @return bool
740
+	 */
741
+	public static function db_table_is_empty($table_name)
742
+	{
743
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
744
+	}
745
+
746
+
747
+	/**
748
+	 * delete_db_table_if_empty
749
+	 *
750
+	 * @access public
751
+	 * @static
752
+	 * @param string $table_name
753
+	 * @return bool | int
754
+	 */
755
+	public static function delete_db_table_if_empty($table_name)
756
+	{
757
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
758
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
759
+		}
760
+		return false;
761
+	}
762
+
763
+
764
+	/**
765
+	 * delete_unused_db_table
766
+	 *
767
+	 * @access     public
768
+	 * @static
769
+	 * @deprecated instead use TableManager::dropTable()
770
+	 * @param string $table_name
771
+	 * @return bool | int
772
+	 */
773
+	public static function delete_unused_db_table($table_name)
774
+	{
775
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
776
+	}
777
+
778
+
779
+	/**
780
+	 * drop_index
781
+	 *
782
+	 * @access     public
783
+	 * @static
784
+	 * @deprecated instead use TableManager::dropIndex()
785
+	 * @param string $table_name
786
+	 * @param string $index_name
787
+	 * @return bool | int
788
+	 */
789
+	public static function drop_index($table_name, $index_name)
790
+	{
791
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
792
+	}
793
+
794
+
795
+
796
+	/**
797
+	 * create_database_tables
798
+	 *
799
+	 * @access public
800
+	 * @static
801
+	 * @throws EE_Error
802
+	 * @return boolean success (whether database is setup properly or not)
803
+	 */
804
+	public static function create_database_tables()
805
+	{
806
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
807
+		//find the migration script that sets the database to be compatible with the code
808
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
809
+		if ($dms_name) {
810
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
811
+			$current_data_migration_script->set_migrating(false);
812
+			$current_data_migration_script->schema_changes_before_migration();
813
+			$current_data_migration_script->schema_changes_after_migration();
814
+			if ($current_data_migration_script->get_errors()) {
815
+				if (WP_DEBUG) {
816
+					foreach ($current_data_migration_script->get_errors() as $error) {
817
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
818
+					}
819
+				} else {
820
+					EE_Error::add_error(
821
+						__(
822
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
823 823
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
824
-                            'event_espresso'
825
-                        )
826
-                    );
827
-                }
828
-                return false;
829
-            }
830
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
831
-        } else {
832
-            EE_Error::add_error(
833
-                __(
834
-                    'Could not determine most up-to-date data migration script from which to pull database schema
824
+							'event_espresso'
825
+						)
826
+					);
827
+				}
828
+				return false;
829
+			}
830
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
831
+		} else {
832
+			EE_Error::add_error(
833
+				__(
834
+					'Could not determine most up-to-date data migration script from which to pull database schema
835 835
                      structure. So database is probably not setup properly',
836
-                    'event_espresso'
837
-                ),
838
-                __FILE__,
839
-                __FUNCTION__,
840
-                __LINE__
841
-            );
842
-            return false;
843
-        }
844
-        return true;
845
-    }
846
-
847
-
848
-
849
-    /**
850
-     * initialize_system_questions
851
-     *
852
-     * @access public
853
-     * @static
854
-     * @return void
855
-     */
856
-    public static function initialize_system_questions()
857
-    {
858
-        // QUESTION GROUPS
859
-        global $wpdb;
860
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
861
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
862
-        // what we have
863
-        $question_groups = $wpdb->get_col($SQL);
864
-        // check the response
865
-        $question_groups = is_array($question_groups) ? $question_groups : array();
866
-        // what we should have
867
-        $QSG_systems = array(1, 2);
868
-        // loop thru what we should have and compare to what we have
869
-        foreach ($QSG_systems as $QSG_system) {
870
-            // reset values array
871
-            $QSG_values = array();
872
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
873
-            if (! in_array("$QSG_system", $question_groups)) {
874
-                // add it
875
-                switch ($QSG_system) {
876
-                    case 1:
877
-                        $QSG_values = array(
878
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
879
-                            'QSG_identifier'      => 'personal-information-' . time(),
880
-                            'QSG_desc'            => '',
881
-                            'QSG_order'           => 1,
882
-                            'QSG_show_group_name' => 1,
883
-                            'QSG_show_group_desc' => 1,
884
-                            'QSG_system'          => EEM_Question_Group::system_personal,
885
-                            'QSG_deleted'         => 0,
886
-                        );
887
-                        break;
888
-                    case 2:
889
-                        $QSG_values = array(
890
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
891
-                            'QSG_identifier'      => 'address-information-' . time(),
892
-                            'QSG_desc'            => '',
893
-                            'QSG_order'           => 2,
894
-                            'QSG_show_group_name' => 1,
895
-                            'QSG_show_group_desc' => 1,
896
-                            'QSG_system'          => EEM_Question_Group::system_address,
897
-                            'QSG_deleted'         => 0,
898
-                        );
899
-                        break;
900
-                }
901
-                // make sure we have some values before inserting them
902
-                if (! empty($QSG_values)) {
903
-                    // insert system question
904
-                    $wpdb->insert(
905
-                        $table_name,
906
-                        $QSG_values,
907
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
908
-                    );
909
-                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
910
-                }
911
-            }
912
-        }
913
-        // QUESTIONS
914
-        global $wpdb;
915
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
916
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
917
-        // what we have
918
-        $questions = $wpdb->get_col($SQL);
919
-        // what we should have
920
-        $QST_systems = array(
921
-            'fname',
922
-            'lname',
923
-            'email',
924
-            'address',
925
-            'address2',
926
-            'city',
927
-            'country',
928
-            'state',
929
-            'zip',
930
-            'phone',
931
-        );
932
-        $order_for_group_1 = 1;
933
-        $order_for_group_2 = 1;
934
-        // loop thru what we should have and compare to what we have
935
-        foreach ($QST_systems as $QST_system) {
936
-            // reset values array
937
-            $QST_values = array();
938
-            // if we don't have what we should have
939
-            if (! in_array($QST_system, $questions)) {
940
-                // add it
941
-                switch ($QST_system) {
942
-                    case 'fname':
943
-                        $QST_values = array(
944
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
945
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
946
-                            'QST_system'        => 'fname',
947
-                            'QST_type'          => 'TEXT',
948
-                            'QST_required'      => 1,
949
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
950
-                            'QST_order'         => 1,
951
-                            'QST_admin_only'    => 0,
952
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
953
-                            'QST_wp_user'       => self::get_default_creator_id(),
954
-                            'QST_deleted'       => 0,
955
-                        );
956
-                        break;
957
-                    case 'lname':
958
-                        $QST_values = array(
959
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
960
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
961
-                            'QST_system'        => 'lname',
962
-                            'QST_type'          => 'TEXT',
963
-                            'QST_required'      => 1,
964
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
965
-                            'QST_order'         => 2,
966
-                            'QST_admin_only'    => 0,
967
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
968
-                            'QST_wp_user'       => self::get_default_creator_id(),
969
-                            'QST_deleted'       => 0,
970
-                        );
971
-                        break;
972
-                    case 'email':
973
-                        $QST_values = array(
974
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
975
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
976
-                            'QST_system'        => 'email',
977
-                            'QST_type'          => 'EMAIL',
978
-                            'QST_required'      => 1,
979
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
980
-                            'QST_order'         => 3,
981
-                            'QST_admin_only'    => 0,
982
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
983
-                            'QST_wp_user'       => self::get_default_creator_id(),
984
-                            'QST_deleted'       => 0,
985
-                        );
986
-                        break;
987
-                    case 'address':
988
-                        $QST_values = array(
989
-                            'QST_display_text'  => __('Address', 'event_espresso'),
990
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
991
-                            'QST_system'        => 'address',
992
-                            'QST_type'          => 'TEXT',
993
-                            'QST_required'      => 0,
994
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
995
-                            'QST_order'         => 4,
996
-                            'QST_admin_only'    => 0,
997
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
998
-                            'QST_wp_user'       => self::get_default_creator_id(),
999
-                            'QST_deleted'       => 0,
1000
-                        );
1001
-                        break;
1002
-                    case 'address2':
1003
-                        $QST_values = array(
1004
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
1005
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1006
-                            'QST_system'        => 'address2',
1007
-                            'QST_type'          => 'TEXT',
1008
-                            'QST_required'      => 0,
1009
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1010
-                            'QST_order'         => 5,
1011
-                            'QST_admin_only'    => 0,
1012
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1013
-                            'QST_wp_user'       => self::get_default_creator_id(),
1014
-                            'QST_deleted'       => 0,
1015
-                        );
1016
-                        break;
1017
-                    case 'city':
1018
-                        $QST_values = array(
1019
-                            'QST_display_text'  => __('City', 'event_espresso'),
1020
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1021
-                            'QST_system'        => 'city',
1022
-                            'QST_type'          => 'TEXT',
1023
-                            'QST_required'      => 0,
1024
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1025
-                            'QST_order'         => 6,
1026
-                            'QST_admin_only'    => 0,
1027
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1028
-                            'QST_wp_user'       => self::get_default_creator_id(),
1029
-                            'QST_deleted'       => 0,
1030
-                        );
1031
-                        break;
1032
-                    case 'country':
1033
-                        $QST_values = array(
1034
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1035
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1036
-                            'QST_system'        => 'country',
1037
-                            'QST_type'          => 'COUNTRY',
1038
-                            'QST_required'      => 0,
1039
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1040
-                            'QST_order'         => 7,
1041
-                            'QST_admin_only'    => 0,
1042
-                            'QST_wp_user'       => self::get_default_creator_id(),
1043
-                            'QST_deleted'       => 0,
1044
-                        );
1045
-                        break;
1046
-                    case 'state':
1047
-                        $QST_values = array(
1048
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1049
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1050
-                            'QST_system'        => 'state',
1051
-                            'QST_type'          => 'STATE',
1052
-                            'QST_required'      => 0,
1053
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1054
-                            'QST_order'         => 8,
1055
-                            'QST_admin_only'    => 0,
1056
-                            'QST_wp_user'       => self::get_default_creator_id(),
1057
-                            'QST_deleted'       => 0,
1058
-                        );
1059
-                        break;
1060
-                    case 'zip':
1061
-                        $QST_values = array(
1062
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1063
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1064
-                            'QST_system'        => 'zip',
1065
-                            'QST_type'          => 'TEXT',
1066
-                            'QST_required'      => 0,
1067
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1068
-                            'QST_order'         => 9,
1069
-                            'QST_admin_only'    => 0,
1070
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1071
-                            'QST_wp_user'       => self::get_default_creator_id(),
1072
-                            'QST_deleted'       => 0,
1073
-                        );
1074
-                        break;
1075
-                    case 'phone':
1076
-                        $QST_values = array(
1077
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1078
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1079
-                            'QST_system'        => 'phone',
1080
-                            'QST_type'          => 'TEXT',
1081
-                            'QST_required'      => 0,
1082
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1083
-                            'QST_order'         => 10,
1084
-                            'QST_admin_only'    => 0,
1085
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1086
-                            'QST_wp_user'       => self::get_default_creator_id(),
1087
-                            'QST_deleted'       => 0,
1088
-                        );
1089
-                        break;
1090
-                }
1091
-                if (! empty($QST_values)) {
1092
-                    // insert system question
1093
-                    $wpdb->insert(
1094
-                        $table_name,
1095
-                        $QST_values,
1096
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1097
-                    );
1098
-                    $QST_ID = $wpdb->insert_id;
1099
-                    // QUESTION GROUP QUESTIONS
1100
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1101
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1102
-                    } else {
1103
-                        $system_question_we_want = EEM_Question_Group::system_address;
1104
-                    }
1105
-                    if (isset($QSG_IDs[$system_question_we_want])) {
1106
-                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1107
-                    } else {
1108
-                        $id_col = EEM_Question_Group::instance()
1109
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1110
-                        if (is_array($id_col)) {
1111
-                            $QSG_ID = reset($id_col);
1112
-                        } else {
1113
-                            //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1114
-                            EE_Log::instance()->log(
1115
-                                __FILE__,
1116
-                                __FUNCTION__,
1117
-                                sprintf(
1118
-                                    __(
1119
-                                        'Could not associate question %1$s to a question group because no system question
836
+					'event_espresso'
837
+				),
838
+				__FILE__,
839
+				__FUNCTION__,
840
+				__LINE__
841
+			);
842
+			return false;
843
+		}
844
+		return true;
845
+	}
846
+
847
+
848
+
849
+	/**
850
+	 * initialize_system_questions
851
+	 *
852
+	 * @access public
853
+	 * @static
854
+	 * @return void
855
+	 */
856
+	public static function initialize_system_questions()
857
+	{
858
+		// QUESTION GROUPS
859
+		global $wpdb;
860
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
861
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
862
+		// what we have
863
+		$question_groups = $wpdb->get_col($SQL);
864
+		// check the response
865
+		$question_groups = is_array($question_groups) ? $question_groups : array();
866
+		// what we should have
867
+		$QSG_systems = array(1, 2);
868
+		// loop thru what we should have and compare to what we have
869
+		foreach ($QSG_systems as $QSG_system) {
870
+			// reset values array
871
+			$QSG_values = array();
872
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
873
+			if (! in_array("$QSG_system", $question_groups)) {
874
+				// add it
875
+				switch ($QSG_system) {
876
+					case 1:
877
+						$QSG_values = array(
878
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
879
+							'QSG_identifier'      => 'personal-information-' . time(),
880
+							'QSG_desc'            => '',
881
+							'QSG_order'           => 1,
882
+							'QSG_show_group_name' => 1,
883
+							'QSG_show_group_desc' => 1,
884
+							'QSG_system'          => EEM_Question_Group::system_personal,
885
+							'QSG_deleted'         => 0,
886
+						);
887
+						break;
888
+					case 2:
889
+						$QSG_values = array(
890
+							'QSG_name'            => __('Address Information', 'event_espresso'),
891
+							'QSG_identifier'      => 'address-information-' . time(),
892
+							'QSG_desc'            => '',
893
+							'QSG_order'           => 2,
894
+							'QSG_show_group_name' => 1,
895
+							'QSG_show_group_desc' => 1,
896
+							'QSG_system'          => EEM_Question_Group::system_address,
897
+							'QSG_deleted'         => 0,
898
+						);
899
+						break;
900
+				}
901
+				// make sure we have some values before inserting them
902
+				if (! empty($QSG_values)) {
903
+					// insert system question
904
+					$wpdb->insert(
905
+						$table_name,
906
+						$QSG_values,
907
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
908
+					);
909
+					$QSG_IDs[$QSG_system] = $wpdb->insert_id;
910
+				}
911
+			}
912
+		}
913
+		// QUESTIONS
914
+		global $wpdb;
915
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
916
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
917
+		// what we have
918
+		$questions = $wpdb->get_col($SQL);
919
+		// what we should have
920
+		$QST_systems = array(
921
+			'fname',
922
+			'lname',
923
+			'email',
924
+			'address',
925
+			'address2',
926
+			'city',
927
+			'country',
928
+			'state',
929
+			'zip',
930
+			'phone',
931
+		);
932
+		$order_for_group_1 = 1;
933
+		$order_for_group_2 = 1;
934
+		// loop thru what we should have and compare to what we have
935
+		foreach ($QST_systems as $QST_system) {
936
+			// reset values array
937
+			$QST_values = array();
938
+			// if we don't have what we should have
939
+			if (! in_array($QST_system, $questions)) {
940
+				// add it
941
+				switch ($QST_system) {
942
+					case 'fname':
943
+						$QST_values = array(
944
+							'QST_display_text'  => __('First Name', 'event_espresso'),
945
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
946
+							'QST_system'        => 'fname',
947
+							'QST_type'          => 'TEXT',
948
+							'QST_required'      => 1,
949
+							'QST_required_text' => __('This field is required', 'event_espresso'),
950
+							'QST_order'         => 1,
951
+							'QST_admin_only'    => 0,
952
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
953
+							'QST_wp_user'       => self::get_default_creator_id(),
954
+							'QST_deleted'       => 0,
955
+						);
956
+						break;
957
+					case 'lname':
958
+						$QST_values = array(
959
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
960
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
961
+							'QST_system'        => 'lname',
962
+							'QST_type'          => 'TEXT',
963
+							'QST_required'      => 1,
964
+							'QST_required_text' => __('This field is required', 'event_espresso'),
965
+							'QST_order'         => 2,
966
+							'QST_admin_only'    => 0,
967
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
968
+							'QST_wp_user'       => self::get_default_creator_id(),
969
+							'QST_deleted'       => 0,
970
+						);
971
+						break;
972
+					case 'email':
973
+						$QST_values = array(
974
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
975
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
976
+							'QST_system'        => 'email',
977
+							'QST_type'          => 'EMAIL',
978
+							'QST_required'      => 1,
979
+							'QST_required_text' => __('This field is required', 'event_espresso'),
980
+							'QST_order'         => 3,
981
+							'QST_admin_only'    => 0,
982
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
983
+							'QST_wp_user'       => self::get_default_creator_id(),
984
+							'QST_deleted'       => 0,
985
+						);
986
+						break;
987
+					case 'address':
988
+						$QST_values = array(
989
+							'QST_display_text'  => __('Address', 'event_espresso'),
990
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
991
+							'QST_system'        => 'address',
992
+							'QST_type'          => 'TEXT',
993
+							'QST_required'      => 0,
994
+							'QST_required_text' => __('This field is required', 'event_espresso'),
995
+							'QST_order'         => 4,
996
+							'QST_admin_only'    => 0,
997
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
998
+							'QST_wp_user'       => self::get_default_creator_id(),
999
+							'QST_deleted'       => 0,
1000
+						);
1001
+						break;
1002
+					case 'address2':
1003
+						$QST_values = array(
1004
+							'QST_display_text'  => __('Address2', 'event_espresso'),
1005
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1006
+							'QST_system'        => 'address2',
1007
+							'QST_type'          => 'TEXT',
1008
+							'QST_required'      => 0,
1009
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1010
+							'QST_order'         => 5,
1011
+							'QST_admin_only'    => 0,
1012
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1013
+							'QST_wp_user'       => self::get_default_creator_id(),
1014
+							'QST_deleted'       => 0,
1015
+						);
1016
+						break;
1017
+					case 'city':
1018
+						$QST_values = array(
1019
+							'QST_display_text'  => __('City', 'event_espresso'),
1020
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1021
+							'QST_system'        => 'city',
1022
+							'QST_type'          => 'TEXT',
1023
+							'QST_required'      => 0,
1024
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1025
+							'QST_order'         => 6,
1026
+							'QST_admin_only'    => 0,
1027
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1028
+							'QST_wp_user'       => self::get_default_creator_id(),
1029
+							'QST_deleted'       => 0,
1030
+						);
1031
+						break;
1032
+					case 'country':
1033
+						$QST_values = array(
1034
+							'QST_display_text'  => __('Country', 'event_espresso'),
1035
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1036
+							'QST_system'        => 'country',
1037
+							'QST_type'          => 'COUNTRY',
1038
+							'QST_required'      => 0,
1039
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1040
+							'QST_order'         => 7,
1041
+							'QST_admin_only'    => 0,
1042
+							'QST_wp_user'       => self::get_default_creator_id(),
1043
+							'QST_deleted'       => 0,
1044
+						);
1045
+						break;
1046
+					case 'state':
1047
+						$QST_values = array(
1048
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1049
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1050
+							'QST_system'        => 'state',
1051
+							'QST_type'          => 'STATE',
1052
+							'QST_required'      => 0,
1053
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1054
+							'QST_order'         => 8,
1055
+							'QST_admin_only'    => 0,
1056
+							'QST_wp_user'       => self::get_default_creator_id(),
1057
+							'QST_deleted'       => 0,
1058
+						);
1059
+						break;
1060
+					case 'zip':
1061
+						$QST_values = array(
1062
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1063
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1064
+							'QST_system'        => 'zip',
1065
+							'QST_type'          => 'TEXT',
1066
+							'QST_required'      => 0,
1067
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1068
+							'QST_order'         => 9,
1069
+							'QST_admin_only'    => 0,
1070
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1071
+							'QST_wp_user'       => self::get_default_creator_id(),
1072
+							'QST_deleted'       => 0,
1073
+						);
1074
+						break;
1075
+					case 'phone':
1076
+						$QST_values = array(
1077
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1078
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1079
+							'QST_system'        => 'phone',
1080
+							'QST_type'          => 'TEXT',
1081
+							'QST_required'      => 0,
1082
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1083
+							'QST_order'         => 10,
1084
+							'QST_admin_only'    => 0,
1085
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1086
+							'QST_wp_user'       => self::get_default_creator_id(),
1087
+							'QST_deleted'       => 0,
1088
+						);
1089
+						break;
1090
+				}
1091
+				if (! empty($QST_values)) {
1092
+					// insert system question
1093
+					$wpdb->insert(
1094
+						$table_name,
1095
+						$QST_values,
1096
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1097
+					);
1098
+					$QST_ID = $wpdb->insert_id;
1099
+					// QUESTION GROUP QUESTIONS
1100
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1101
+						$system_question_we_want = EEM_Question_Group::system_personal;
1102
+					} else {
1103
+						$system_question_we_want = EEM_Question_Group::system_address;
1104
+					}
1105
+					if (isset($QSG_IDs[$system_question_we_want])) {
1106
+						$QSG_ID = $QSG_IDs[$system_question_we_want];
1107
+					} else {
1108
+						$id_col = EEM_Question_Group::instance()
1109
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1110
+						if (is_array($id_col)) {
1111
+							$QSG_ID = reset($id_col);
1112
+						} else {
1113
+							//ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1114
+							EE_Log::instance()->log(
1115
+								__FILE__,
1116
+								__FUNCTION__,
1117
+								sprintf(
1118
+									__(
1119
+										'Could not associate question %1$s to a question group because no system question
1120 1120
                                          group existed',
1121
-                                        'event_espresso'
1122
-                                    ),
1123
-                                    $QST_ID),
1124
-                                'error');
1125
-                            continue;
1126
-                        }
1127
-                    }
1128
-                    // add system questions to groups
1129
-                    $wpdb->insert(
1130
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1131
-                        array(
1132
-                            'QSG_ID'    => $QSG_ID,
1133
-                            'QST_ID'    => $QST_ID,
1134
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1135
-                        ),
1136
-                        array('%d', '%d', '%d')
1137
-                    );
1138
-                }
1139
-            }
1140
-        }
1141
-    }
1142
-
1143
-
1144
-    /**
1145
-     * Makes sure the default payment method (Invoice) is active.
1146
-     * This used to be done automatically as part of constructing the old gateways config
1147
-     *
1148
-     * @throws \EE_Error
1149
-     */
1150
-    public static function insert_default_payment_methods()
1151
-    {
1152
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1153
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1154
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1155
-        } else {
1156
-            EEM_Payment_Method::instance()->verify_button_urls();
1157
-        }
1158
-    }
1159
-
1160
-    /**
1161
-     * insert_default_status_codes
1162
-     *
1163
-     * @access public
1164
-     * @static
1165
-     * @return void
1166
-     */
1167
-    public static function insert_default_status_codes()
1168
-    {
1169
-
1170
-        global $wpdb;
1171
-
1172
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1173
-
1174
-            $table_name = EEM_Status::instance()->table();
1175
-
1176
-            $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1177
-            $wpdb->query($SQL);
1178
-
1179
-            $SQL = "INSERT INTO $table_name
1121
+										'event_espresso'
1122
+									),
1123
+									$QST_ID),
1124
+								'error');
1125
+							continue;
1126
+						}
1127
+					}
1128
+					// add system questions to groups
1129
+					$wpdb->insert(
1130
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1131
+						array(
1132
+							'QSG_ID'    => $QSG_ID,
1133
+							'QST_ID'    => $QST_ID,
1134
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1135
+						),
1136
+						array('%d', '%d', '%d')
1137
+					);
1138
+				}
1139
+			}
1140
+		}
1141
+	}
1142
+
1143
+
1144
+	/**
1145
+	 * Makes sure the default payment method (Invoice) is active.
1146
+	 * This used to be done automatically as part of constructing the old gateways config
1147
+	 *
1148
+	 * @throws \EE_Error
1149
+	 */
1150
+	public static function insert_default_payment_methods()
1151
+	{
1152
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1153
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1154
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1155
+		} else {
1156
+			EEM_Payment_Method::instance()->verify_button_urls();
1157
+		}
1158
+	}
1159
+
1160
+	/**
1161
+	 * insert_default_status_codes
1162
+	 *
1163
+	 * @access public
1164
+	 * @static
1165
+	 * @return void
1166
+	 */
1167
+	public static function insert_default_status_codes()
1168
+	{
1169
+
1170
+		global $wpdb;
1171
+
1172
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1173
+
1174
+			$table_name = EEM_Status::instance()->table();
1175
+
1176
+			$SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1177
+			$wpdb->query($SQL);
1178
+
1179
+			$SQL = "INSERT INTO $table_name
1180 1180
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1181 1181
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1182 1182
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1216,521 +1216,521 @@  discard block
 block discarded – undo
1216 1216
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1217 1217
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1218 1218
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1219
-            $wpdb->query($SQL);
1220
-
1221
-        }
1222
-
1223
-    }
1224
-
1225
-
1226
-    /**
1227
-     * create_upload_directories
1228
-     * Creates folders in the uploads directory to facilitate addons and templates
1229
-     *
1230
-     * @access public
1231
-     * @static
1232
-     * @return boolean success of verifying upload directories exist
1233
-     */
1234
-    public static function create_upload_directories()
1235
-    {
1236
-        // Create the required folders
1237
-        $folders = array(
1238
-            EVENT_ESPRESSO_TEMPLATE_DIR,
1239
-            EVENT_ESPRESSO_GATEWAY_DIR,
1240
-            EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1241
-            EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1242
-            EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1243
-        );
1244
-        foreach ($folders as $folder) {
1245
-            try {
1246
-                EEH_File::ensure_folder_exists_and_is_writable($folder);
1247
-                @ chmod($folder, 0755);
1248
-            } catch (EE_Error $e) {
1249
-                EE_Error::add_error(
1250
-                    sprintf(
1251
-                        __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1252
-                        $folder,
1253
-                        '<br />' . $e->getMessage()
1254
-                    ),
1255
-                    __FILE__, __FUNCTION__, __LINE__
1256
-                );
1257
-                //indicate we'll need to fix this later
1258
-                update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1259
-                return false;
1260
-            }
1261
-        }
1262
-        //just add the .htaccess file to the logs directory to begin with. Even if logging
1263
-        //is disabled, there might be activation errors recorded in there
1264
-        EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1265
-        //remember EE's folders are all good
1266
-        delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1267
-        return true;
1268
-    }
1269
-
1270
-    /**
1271
-     * Whether the upload directories need to be fixed or not.
1272
-     * If EE is installed but filesystem access isn't initially available,
1273
-     * we need to get the user's filesystem credentials and THEN create them,
1274
-     * so there might be period of time when EE is installed but its
1275
-     * upload directories aren't available. This indicates such a state
1276
-     *
1277
-     * @return boolean
1278
-     */
1279
-    public static function upload_directories_incomplete()
1280
-    {
1281
-        return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1282
-    }
1283
-
1284
-
1285
-    /**
1286
-     * generate_default_message_templates
1287
-     *
1288
-     * @static
1289
-     * @throws EE_Error
1290
-     * @return bool     true means new templates were created.
1291
-     *                  false means no templates were created.
1292
-     *                  This is NOT an error flag. To check for errors you will want
1293
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1294
-     */
1295
-    public static function generate_default_message_templates()
1296
-    {
1297
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1298
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1299
-        /*
1219
+			$wpdb->query($SQL);
1220
+
1221
+		}
1222
+
1223
+	}
1224
+
1225
+
1226
+	/**
1227
+	 * create_upload_directories
1228
+	 * Creates folders in the uploads directory to facilitate addons and templates
1229
+	 *
1230
+	 * @access public
1231
+	 * @static
1232
+	 * @return boolean success of verifying upload directories exist
1233
+	 */
1234
+	public static function create_upload_directories()
1235
+	{
1236
+		// Create the required folders
1237
+		$folders = array(
1238
+			EVENT_ESPRESSO_TEMPLATE_DIR,
1239
+			EVENT_ESPRESSO_GATEWAY_DIR,
1240
+			EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1241
+			EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1242
+			EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1243
+		);
1244
+		foreach ($folders as $folder) {
1245
+			try {
1246
+				EEH_File::ensure_folder_exists_and_is_writable($folder);
1247
+				@ chmod($folder, 0755);
1248
+			} catch (EE_Error $e) {
1249
+				EE_Error::add_error(
1250
+					sprintf(
1251
+						__('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1252
+						$folder,
1253
+						'<br />' . $e->getMessage()
1254
+					),
1255
+					__FILE__, __FUNCTION__, __LINE__
1256
+				);
1257
+				//indicate we'll need to fix this later
1258
+				update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1259
+				return false;
1260
+			}
1261
+		}
1262
+		//just add the .htaccess file to the logs directory to begin with. Even if logging
1263
+		//is disabled, there might be activation errors recorded in there
1264
+		EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1265
+		//remember EE's folders are all good
1266
+		delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1267
+		return true;
1268
+	}
1269
+
1270
+	/**
1271
+	 * Whether the upload directories need to be fixed or not.
1272
+	 * If EE is installed but filesystem access isn't initially available,
1273
+	 * we need to get the user's filesystem credentials and THEN create them,
1274
+	 * so there might be period of time when EE is installed but its
1275
+	 * upload directories aren't available. This indicates such a state
1276
+	 *
1277
+	 * @return boolean
1278
+	 */
1279
+	public static function upload_directories_incomplete()
1280
+	{
1281
+		return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1282
+	}
1283
+
1284
+
1285
+	/**
1286
+	 * generate_default_message_templates
1287
+	 *
1288
+	 * @static
1289
+	 * @throws EE_Error
1290
+	 * @return bool     true means new templates were created.
1291
+	 *                  false means no templates were created.
1292
+	 *                  This is NOT an error flag. To check for errors you will want
1293
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1294
+	 */
1295
+	public static function generate_default_message_templates()
1296
+	{
1297
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1298
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1299
+		/*
1300 1300
          * This first method is taking care of ensuring any default messengers
1301 1301
          * that should be made active and have templates generated are done.
1302 1302
          */
1303
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1304
-            $message_resource_manager
1305
-        );
1306
-        /**
1307
-         * This method is verifying there are no NEW default message types
1308
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1309
-         */
1310
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1311
-            $message_resource_manager
1312
-        );
1313
-        //after all is done, let's persist these changes to the db.
1314
-        $message_resource_manager->update_has_activated_messengers_option();
1315
-        $message_resource_manager->update_active_messengers_option();
1316
-        // will return true if either of these are true.  Otherwise will return false.
1317
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1318
-    }
1319
-
1320
-
1321
-
1322
-    /**
1323
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1324
-     * @return array|bool
1325
-     * @throws \EE_Error
1326
-     */
1327
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1328
-        EE_Message_Resource_Manager $message_resource_manager
1329
-    ) {
1330
-        /** @type EE_messenger[] $active_messengers */
1331
-        $active_messengers = $message_resource_manager->active_messengers();
1332
-        $installed_message_types = $message_resource_manager->installed_message_types();
1333
-        $templates_created = false;
1334
-        foreach ($active_messengers as $active_messenger) {
1335
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1336
-            $default_message_type_names_to_activate = array();
1337
-            // looping through each default message type reported by the messenger
1338
-            // and setup the actual message types to activate.
1339
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1340
-                // if already active or has already been activated before we skip
1341
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1342
-                // we also skip if the message type is not installed.
1343
-                if (
1344
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1345
-                        $default_message_type_name_for_messenger,
1346
-                        $active_messenger->name
1347
-                    )
1348
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1349
-                        $active_messenger->name,
1350
-                        $default_message_type_name_for_messenger
1351
-                    )
1352
-                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1353
-                ) {
1354
-                    continue;
1355
-                }
1356
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1357
-            }
1358
-            //let's activate!
1359
-            $message_resource_manager->ensure_message_types_are_active(
1360
-                $default_message_type_names_to_activate,
1361
-                $active_messenger->name,
1362
-                false
1363
-            );
1364
-            //activate the templates for these message types
1365
-            if ( ! empty($default_message_type_names_to_activate)) {
1366
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1367
-                    $active_messenger->name,
1368
-                    $default_message_type_names_for_messenger,
1369
-                    '',
1370
-                    true
1371
-                );
1372
-            }
1373
-        }
1374
-        return $templates_created;
1375
-    }
1376
-
1377
-
1378
-
1379
-    /**
1380
-     * This will activate and generate default messengers and default message types for those messengers.
1381
-     *
1382
-     * @param EE_message_Resource_Manager $message_resource_manager
1383
-     * @return array|bool  True means there were default messengers and message type templates generated.
1384
-     *                     False means that there were no templates generated
1385
-     *                     (which could simply mean there are no default message types for a messenger).
1386
-     * @throws EE_Error
1387
-     */
1388
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1389
-        EE_Message_Resource_Manager $message_resource_manager
1390
-    ) {
1391
-        /** @type EE_messenger[] $messengers_to_generate */
1392
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1393
-        $installed_message_types = $message_resource_manager->installed_message_types();
1394
-        $templates_generated = false;
1395
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1396
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1397
-            //verify the default message types match an installed message type.
1398
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1399
-                if (
1400
-                    ! isset($installed_message_types[$name])
1401
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1402
-                        $name,
1403
-                        $messenger_to_generate->name
1404
-                    )
1405
-                ) {
1406
-                    unset($default_message_type_names_for_messenger[$key]);
1407
-                }
1408
-            }
1409
-            // in previous iterations, the active_messengers option in the db
1410
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1411
-            // This comment is left here just in case we discover that we _do_ need to update before
1412
-            // passing off to create templates (after the refactor is done).
1413
-            // @todo remove this comment when determined not necessary.
1414
-            $message_resource_manager->activate_messenger(
1415
-                $messenger_to_generate->name,
1416
-                $default_message_type_names_for_messenger,
1417
-                false
1418
-            );
1419
-            //create any templates needing created (or will reactivate templates already generated as necessary).
1420
-            if ( ! empty($default_message_type_names_for_messenger)) {
1421
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1422
-                    $messenger_to_generate->name,
1423
-                    $default_message_type_names_for_messenger,
1424
-                    '',
1425
-                    true
1426
-                );
1427
-            }
1428
-        }
1429
-        return $templates_generated;
1430
-    }
1431
-
1432
-
1433
-    /**
1434
-     * This returns the default messengers to generate templates for on activation of EE.
1435
-     * It considers:
1436
-     * - whether a messenger is already active in the db.
1437
-     * - whether a messenger has been made active at any time in the past.
1438
-     *
1439
-     * @static
1440
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1441
-     * @return EE_messenger[]
1442
-     */
1443
-    protected static function _get_default_messengers_to_generate_on_activation(
1444
-        EE_Message_Resource_Manager $message_resource_manager
1445
-    ) {
1446
-        $active_messengers    = $message_resource_manager->active_messengers();
1447
-        $installed_messengers = $message_resource_manager->installed_messengers();
1448
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1449
-
1450
-        $messengers_to_generate = array();
1451
-        foreach ($installed_messengers as $installed_messenger) {
1452
-            //if installed messenger is a messenger that should be activated on install
1453
-            //and is not already active
1454
-            //and has never been activated
1455
-            if (
1456
-                ! $installed_messenger->activate_on_install
1457
-                || isset($active_messengers[$installed_messenger->name])
1458
-                || isset($has_activated[$installed_messenger->name])
1459
-            ) {
1460
-                continue;
1461
-            }
1462
-            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1463
-        }
1464
-        return $messengers_to_generate;
1465
-    }
1466
-
1467
-
1468
-    /**
1469
-     * This simply validates active message types to ensure they actually match installed
1470
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1471
-     * rows are set inactive.
1472
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1473
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1474
-     * are still handled in here.
1475
-     *
1476
-     * @since 4.3.1
1477
-     * @return void
1478
-     */
1479
-    public static function validate_messages_system()
1480
-    {
1481
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1482
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1483
-        $message_resource_manager->validate_active_message_types_are_installed();
1484
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1485
-    }
1486
-
1487
-
1488
-    /**
1489
-     * create_no_ticket_prices_array
1490
-     *
1491
-     * @access public
1492
-     * @static
1493
-     * @return void
1494
-     */
1495
-    public static function create_no_ticket_prices_array()
1496
-    {
1497
-        // this creates an array for tracking events that have no active ticket prices created
1498
-        // this allows us to warn admins of the situation so that it can be corrected
1499
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1500
-        if (! $espresso_no_ticket_prices) {
1501
-            add_option('ee_no_ticket_prices', array(), '', false);
1502
-        }
1503
-    }
1504
-
1505
-
1506
-    /**
1507
-     * plugin_deactivation
1508
-     *
1509
-     * @access public
1510
-     * @static
1511
-     * @return void
1512
-     */
1513
-    public static function plugin_deactivation()
1514
-    {
1515
-    }
1516
-
1517
-
1518
-    /**
1519
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1520
-     * (like post meta or term relations)
1521
-     *
1522
-     * @global wpdb $wpdb
1523
-     * @throws \EE_Error
1524
-     */
1525
-    public static function delete_all_espresso_cpt_data()
1526
-    {
1527
-        global $wpdb;
1528
-        //get all the CPT post_types
1529
-        $ee_post_types = array();
1530
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1531
-            if (method_exists($model_name, 'instance')) {
1532
-                $model_obj = call_user_func(array($model_name, 'instance'));
1533
-                if ($model_obj instanceof EEM_CPT_Base) {
1534
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1535
-                }
1536
-            }
1537
-        }
1538
-        //get all our CPTs
1539
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1540
-        $cpt_ids = $wpdb->get_col($query);
1541
-        //delete each post meta and term relations too
1542
-        foreach ($cpt_ids as $post_id) {
1543
-            wp_delete_post($post_id, true);
1544
-        }
1545
-    }
1546
-
1547
-    /**
1548
-     * Deletes all EE custom tables
1549
-     *
1550
-     * @return array
1551
-     */
1552
-    public static function drop_espresso_tables()
1553
-    {
1554
-        $tables = array();
1555
-        // load registry
1556
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1557
-            if (method_exists($model_name, 'instance')) {
1558
-                $model_obj = call_user_func(array($model_name, 'instance'));
1559
-                if ($model_obj instanceof EEM_Base) {
1560
-                    foreach ($model_obj->get_tables() as $table) {
1561
-                        if (strpos($table->get_table_name(), 'esp_')
1562
-                            &&
1563
-                            (
1564
-                                is_main_site()//main site? nuke them all
1565
-                                || ! $table->is_global()//not main site,but not global either. nuke it
1566
-                            )
1567
-                        ) {
1568
-                            $tables[$table->get_table_name()] = $table->get_table_name();
1569
-                        }
1570
-                    }
1571
-                }
1572
-            }
1573
-        }
1574
-
1575
-        //there are some tables whose models were removed.
1576
-        //they should be removed when removing all EE core's data
1577
-        $tables_without_models = array(
1578
-            'esp_promotion',
1579
-            'esp_promotion_applied',
1580
-            'esp_promotion_object',
1581
-            'esp_promotion_rule',
1582
-            'esp_rule',
1583
-        );
1584
-        foreach ($tables_without_models as $table) {
1585
-            $tables[$table] = $table;
1586
-        }
1587
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1588
-    }
1589
-
1590
-
1591
-
1592
-    /**
1593
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1594
-     * each table name provided has a wpdb prefix attached, and that it exists.
1595
-     * Returns the list actually deleted
1596
-     *
1597
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1598
-     * @global WPDB $wpdb
1599
-     * @param array $table_names
1600
-     * @return array of table names which we deleted
1601
-     */
1602
-    public static function drop_tables($table_names)
1603
-    {
1604
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1605
-    }
1606
-
1607
-
1608
-
1609
-    /**
1610
-     * plugin_uninstall
1611
-     *
1612
-     * @access public
1613
-     * @static
1614
-     * @param bool $remove_all
1615
-     * @return void
1616
-     */
1617
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1618
-    {
1619
-        global $wpdb;
1620
-        self::drop_espresso_tables();
1621
-        $wp_options_to_delete = array(
1622
-            'ee_no_ticket_prices'                => true,
1623
-            'ee_active_messengers'               => true,
1624
-            'ee_has_activated_messenger'         => true,
1625
-            'ee_flush_rewrite_rules'             => true,
1626
-            'ee_config'                          => false,
1627
-            'ee_data_migration_current_db_state' => true,
1628
-            'ee_data_migration_mapping_'         => false,
1629
-            'ee_data_migration_script_'          => false,
1630
-            'ee_data_migrations'                 => true,
1631
-            'ee_dms_map'                         => false,
1632
-            'ee_notices'                         => true,
1633
-            'lang_file_check_'                   => false,
1634
-            'ee_maintenance_mode'                => true,
1635
-            'ee_ueip_optin'                      => true,
1636
-            'ee_ueip_has_notified'               => true,
1637
-            'ee_plugin_activation_errors'        => true,
1638
-            'ee_id_mapping_from'                 => false,
1639
-            'espresso_persistent_admin_notices'  => true,
1640
-            'ee_encryption_key'                  => true,
1641
-            'pue_force_upgrade_'                 => false,
1642
-            'pue_json_error_'                    => false,
1643
-            'pue_install_key_'                   => false,
1644
-            'pue_verification_error_'            => false,
1645
-            'pu_dismissed_upgrade_'              => false,
1646
-            'external_updates-'                  => false,
1647
-            'ee_extra_data'                      => true,
1648
-            'ee_ssn_'                            => false,
1649
-            'ee_rss_'                            => false,
1650
-            'ee_rte_n_tx_'                       => false,
1651
-            'ee_pers_admin_notices'              => true,
1652
-            'ee_job_parameters_'                 => false,
1653
-            'ee_upload_directories_incomplete'   => true,
1654
-            'ee_verified_db_collations'          => true,
1655
-        );
1656
-        if (is_main_site()) {
1657
-            $wp_options_to_delete['ee_network_config'] = true;
1658
-        }
1659
-        $undeleted_options = array();
1660
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1661
-            if ($no_wildcard) {
1662
-                if ( ! delete_option($option_name)) {
1663
-                    $undeleted_options[] = $option_name;
1664
-                }
1665
-            } else {
1666
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1667
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1668
-                    if ( ! delete_option($option_name_from_wildcard)) {
1669
-                        $undeleted_options[] = $option_name_from_wildcard;
1670
-                    }
1671
-                }
1672
-            }
1673
-        }
1674
-        //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1675
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1676
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1677
-            $db_update_sans_ee4 = array();
1678
-            foreach ($espresso_db_update as $version => $times_activated) {
1679
-                if ((string)$version[0] === '3') {//if its NON EE4
1680
-                    $db_update_sans_ee4[$version] = $times_activated;
1681
-                }
1682
-            }
1683
-            update_option('espresso_db_update', $db_update_sans_ee4);
1684
-        }
1685
-        $errors = '';
1686
-        if ( ! empty($undeleted_options)) {
1687
-            $errors .= sprintf(
1688
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1689
-                '<br/>',
1690
-                implode(',<br/>', $undeleted_options)
1691
-            );
1692
-        }
1693
-        if ( ! empty($errors)) {
1694
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1695
-        }
1696
-    }
1697
-
1698
-    /**
1699
-     * Gets the mysql error code from the last used query by wpdb
1700
-     *
1701
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1702
-     */
1703
-    public static function last_wpdb_error_code()
1704
-    {
1705
-        global $wpdb;
1706
-        if ($wpdb->use_mysqli) {
1707
-            return mysqli_errno($wpdb->dbh);
1708
-        } else {
1709
-            return mysql_errno($wpdb->dbh);
1710
-        }
1711
-    }
1712
-
1713
-    /**
1714
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1715
-     *
1716
-     * @global wpdb  $wpdb
1717
-     * @deprecated instead use TableAnalysis::tableExists()
1718
-     * @param string $table_name with or without $wpdb->prefix
1719
-     * @return boolean
1720
-     */
1721
-    public static function table_exists($table_name)
1722
-    {
1723
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1724
-    }
1725
-
1726
-    /**
1727
-     * Resets the cache on EEH_Activation
1728
-     */
1729
-    public static function reset()
1730
-    {
1731
-        self::$_default_creator_id                             = null;
1732
-        self::$_initialized_db_content_already_in_this_request = false;
1733
-    }
1303
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1304
+			$message_resource_manager
1305
+		);
1306
+		/**
1307
+		 * This method is verifying there are no NEW default message types
1308
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1309
+		 */
1310
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1311
+			$message_resource_manager
1312
+		);
1313
+		//after all is done, let's persist these changes to the db.
1314
+		$message_resource_manager->update_has_activated_messengers_option();
1315
+		$message_resource_manager->update_active_messengers_option();
1316
+		// will return true if either of these are true.  Otherwise will return false.
1317
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1318
+	}
1319
+
1320
+
1321
+
1322
+	/**
1323
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1324
+	 * @return array|bool
1325
+	 * @throws \EE_Error
1326
+	 */
1327
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1328
+		EE_Message_Resource_Manager $message_resource_manager
1329
+	) {
1330
+		/** @type EE_messenger[] $active_messengers */
1331
+		$active_messengers = $message_resource_manager->active_messengers();
1332
+		$installed_message_types = $message_resource_manager->installed_message_types();
1333
+		$templates_created = false;
1334
+		foreach ($active_messengers as $active_messenger) {
1335
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1336
+			$default_message_type_names_to_activate = array();
1337
+			// looping through each default message type reported by the messenger
1338
+			// and setup the actual message types to activate.
1339
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1340
+				// if already active or has already been activated before we skip
1341
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1342
+				// we also skip if the message type is not installed.
1343
+				if (
1344
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1345
+						$default_message_type_name_for_messenger,
1346
+						$active_messenger->name
1347
+					)
1348
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1349
+						$active_messenger->name,
1350
+						$default_message_type_name_for_messenger
1351
+					)
1352
+					|| ! isset($installed_message_types[$default_message_type_name_for_messenger])
1353
+				) {
1354
+					continue;
1355
+				}
1356
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1357
+			}
1358
+			//let's activate!
1359
+			$message_resource_manager->ensure_message_types_are_active(
1360
+				$default_message_type_names_to_activate,
1361
+				$active_messenger->name,
1362
+				false
1363
+			);
1364
+			//activate the templates for these message types
1365
+			if ( ! empty($default_message_type_names_to_activate)) {
1366
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1367
+					$active_messenger->name,
1368
+					$default_message_type_names_for_messenger,
1369
+					'',
1370
+					true
1371
+				);
1372
+			}
1373
+		}
1374
+		return $templates_created;
1375
+	}
1376
+
1377
+
1378
+
1379
+	/**
1380
+	 * This will activate and generate default messengers and default message types for those messengers.
1381
+	 *
1382
+	 * @param EE_message_Resource_Manager $message_resource_manager
1383
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1384
+	 *                     False means that there were no templates generated
1385
+	 *                     (which could simply mean there are no default message types for a messenger).
1386
+	 * @throws EE_Error
1387
+	 */
1388
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1389
+		EE_Message_Resource_Manager $message_resource_manager
1390
+	) {
1391
+		/** @type EE_messenger[] $messengers_to_generate */
1392
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1393
+		$installed_message_types = $message_resource_manager->installed_message_types();
1394
+		$templates_generated = false;
1395
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1396
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1397
+			//verify the default message types match an installed message type.
1398
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1399
+				if (
1400
+					! isset($installed_message_types[$name])
1401
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1402
+						$name,
1403
+						$messenger_to_generate->name
1404
+					)
1405
+				) {
1406
+					unset($default_message_type_names_for_messenger[$key]);
1407
+				}
1408
+			}
1409
+			// in previous iterations, the active_messengers option in the db
1410
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1411
+			// This comment is left here just in case we discover that we _do_ need to update before
1412
+			// passing off to create templates (after the refactor is done).
1413
+			// @todo remove this comment when determined not necessary.
1414
+			$message_resource_manager->activate_messenger(
1415
+				$messenger_to_generate->name,
1416
+				$default_message_type_names_for_messenger,
1417
+				false
1418
+			);
1419
+			//create any templates needing created (or will reactivate templates already generated as necessary).
1420
+			if ( ! empty($default_message_type_names_for_messenger)) {
1421
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1422
+					$messenger_to_generate->name,
1423
+					$default_message_type_names_for_messenger,
1424
+					'',
1425
+					true
1426
+				);
1427
+			}
1428
+		}
1429
+		return $templates_generated;
1430
+	}
1431
+
1432
+
1433
+	/**
1434
+	 * This returns the default messengers to generate templates for on activation of EE.
1435
+	 * It considers:
1436
+	 * - whether a messenger is already active in the db.
1437
+	 * - whether a messenger has been made active at any time in the past.
1438
+	 *
1439
+	 * @static
1440
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1441
+	 * @return EE_messenger[]
1442
+	 */
1443
+	protected static function _get_default_messengers_to_generate_on_activation(
1444
+		EE_Message_Resource_Manager $message_resource_manager
1445
+	) {
1446
+		$active_messengers    = $message_resource_manager->active_messengers();
1447
+		$installed_messengers = $message_resource_manager->installed_messengers();
1448
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1449
+
1450
+		$messengers_to_generate = array();
1451
+		foreach ($installed_messengers as $installed_messenger) {
1452
+			//if installed messenger is a messenger that should be activated on install
1453
+			//and is not already active
1454
+			//and has never been activated
1455
+			if (
1456
+				! $installed_messenger->activate_on_install
1457
+				|| isset($active_messengers[$installed_messenger->name])
1458
+				|| isset($has_activated[$installed_messenger->name])
1459
+			) {
1460
+				continue;
1461
+			}
1462
+			$messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1463
+		}
1464
+		return $messengers_to_generate;
1465
+	}
1466
+
1467
+
1468
+	/**
1469
+	 * This simply validates active message types to ensure they actually match installed
1470
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1471
+	 * rows are set inactive.
1472
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1473
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1474
+	 * are still handled in here.
1475
+	 *
1476
+	 * @since 4.3.1
1477
+	 * @return void
1478
+	 */
1479
+	public static function validate_messages_system()
1480
+	{
1481
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1482
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1483
+		$message_resource_manager->validate_active_message_types_are_installed();
1484
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1485
+	}
1486
+
1487
+
1488
+	/**
1489
+	 * create_no_ticket_prices_array
1490
+	 *
1491
+	 * @access public
1492
+	 * @static
1493
+	 * @return void
1494
+	 */
1495
+	public static function create_no_ticket_prices_array()
1496
+	{
1497
+		// this creates an array for tracking events that have no active ticket prices created
1498
+		// this allows us to warn admins of the situation so that it can be corrected
1499
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1500
+		if (! $espresso_no_ticket_prices) {
1501
+			add_option('ee_no_ticket_prices', array(), '', false);
1502
+		}
1503
+	}
1504
+
1505
+
1506
+	/**
1507
+	 * plugin_deactivation
1508
+	 *
1509
+	 * @access public
1510
+	 * @static
1511
+	 * @return void
1512
+	 */
1513
+	public static function plugin_deactivation()
1514
+	{
1515
+	}
1516
+
1517
+
1518
+	/**
1519
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1520
+	 * (like post meta or term relations)
1521
+	 *
1522
+	 * @global wpdb $wpdb
1523
+	 * @throws \EE_Error
1524
+	 */
1525
+	public static function delete_all_espresso_cpt_data()
1526
+	{
1527
+		global $wpdb;
1528
+		//get all the CPT post_types
1529
+		$ee_post_types = array();
1530
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1531
+			if (method_exists($model_name, 'instance')) {
1532
+				$model_obj = call_user_func(array($model_name, 'instance'));
1533
+				if ($model_obj instanceof EEM_CPT_Base) {
1534
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1535
+				}
1536
+			}
1537
+		}
1538
+		//get all our CPTs
1539
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1540
+		$cpt_ids = $wpdb->get_col($query);
1541
+		//delete each post meta and term relations too
1542
+		foreach ($cpt_ids as $post_id) {
1543
+			wp_delete_post($post_id, true);
1544
+		}
1545
+	}
1546
+
1547
+	/**
1548
+	 * Deletes all EE custom tables
1549
+	 *
1550
+	 * @return array
1551
+	 */
1552
+	public static function drop_espresso_tables()
1553
+	{
1554
+		$tables = array();
1555
+		// load registry
1556
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1557
+			if (method_exists($model_name, 'instance')) {
1558
+				$model_obj = call_user_func(array($model_name, 'instance'));
1559
+				if ($model_obj instanceof EEM_Base) {
1560
+					foreach ($model_obj->get_tables() as $table) {
1561
+						if (strpos($table->get_table_name(), 'esp_')
1562
+							&&
1563
+							(
1564
+								is_main_site()//main site? nuke them all
1565
+								|| ! $table->is_global()//not main site,but not global either. nuke it
1566
+							)
1567
+						) {
1568
+							$tables[$table->get_table_name()] = $table->get_table_name();
1569
+						}
1570
+					}
1571
+				}
1572
+			}
1573
+		}
1574
+
1575
+		//there are some tables whose models were removed.
1576
+		//they should be removed when removing all EE core's data
1577
+		$tables_without_models = array(
1578
+			'esp_promotion',
1579
+			'esp_promotion_applied',
1580
+			'esp_promotion_object',
1581
+			'esp_promotion_rule',
1582
+			'esp_rule',
1583
+		);
1584
+		foreach ($tables_without_models as $table) {
1585
+			$tables[$table] = $table;
1586
+		}
1587
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1588
+	}
1589
+
1590
+
1591
+
1592
+	/**
1593
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1594
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1595
+	 * Returns the list actually deleted
1596
+	 *
1597
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1598
+	 * @global WPDB $wpdb
1599
+	 * @param array $table_names
1600
+	 * @return array of table names which we deleted
1601
+	 */
1602
+	public static function drop_tables($table_names)
1603
+	{
1604
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1605
+	}
1606
+
1607
+
1608
+
1609
+	/**
1610
+	 * plugin_uninstall
1611
+	 *
1612
+	 * @access public
1613
+	 * @static
1614
+	 * @param bool $remove_all
1615
+	 * @return void
1616
+	 */
1617
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1618
+	{
1619
+		global $wpdb;
1620
+		self::drop_espresso_tables();
1621
+		$wp_options_to_delete = array(
1622
+			'ee_no_ticket_prices'                => true,
1623
+			'ee_active_messengers'               => true,
1624
+			'ee_has_activated_messenger'         => true,
1625
+			'ee_flush_rewrite_rules'             => true,
1626
+			'ee_config'                          => false,
1627
+			'ee_data_migration_current_db_state' => true,
1628
+			'ee_data_migration_mapping_'         => false,
1629
+			'ee_data_migration_script_'          => false,
1630
+			'ee_data_migrations'                 => true,
1631
+			'ee_dms_map'                         => false,
1632
+			'ee_notices'                         => true,
1633
+			'lang_file_check_'                   => false,
1634
+			'ee_maintenance_mode'                => true,
1635
+			'ee_ueip_optin'                      => true,
1636
+			'ee_ueip_has_notified'               => true,
1637
+			'ee_plugin_activation_errors'        => true,
1638
+			'ee_id_mapping_from'                 => false,
1639
+			'espresso_persistent_admin_notices'  => true,
1640
+			'ee_encryption_key'                  => true,
1641
+			'pue_force_upgrade_'                 => false,
1642
+			'pue_json_error_'                    => false,
1643
+			'pue_install_key_'                   => false,
1644
+			'pue_verification_error_'            => false,
1645
+			'pu_dismissed_upgrade_'              => false,
1646
+			'external_updates-'                  => false,
1647
+			'ee_extra_data'                      => true,
1648
+			'ee_ssn_'                            => false,
1649
+			'ee_rss_'                            => false,
1650
+			'ee_rte_n_tx_'                       => false,
1651
+			'ee_pers_admin_notices'              => true,
1652
+			'ee_job_parameters_'                 => false,
1653
+			'ee_upload_directories_incomplete'   => true,
1654
+			'ee_verified_db_collations'          => true,
1655
+		);
1656
+		if (is_main_site()) {
1657
+			$wp_options_to_delete['ee_network_config'] = true;
1658
+		}
1659
+		$undeleted_options = array();
1660
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1661
+			if ($no_wildcard) {
1662
+				if ( ! delete_option($option_name)) {
1663
+					$undeleted_options[] = $option_name;
1664
+				}
1665
+			} else {
1666
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1667
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1668
+					if ( ! delete_option($option_name_from_wildcard)) {
1669
+						$undeleted_options[] = $option_name_from_wildcard;
1670
+					}
1671
+				}
1672
+			}
1673
+		}
1674
+		//also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1675
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1676
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1677
+			$db_update_sans_ee4 = array();
1678
+			foreach ($espresso_db_update as $version => $times_activated) {
1679
+				if ((string)$version[0] === '3') {//if its NON EE4
1680
+					$db_update_sans_ee4[$version] = $times_activated;
1681
+				}
1682
+			}
1683
+			update_option('espresso_db_update', $db_update_sans_ee4);
1684
+		}
1685
+		$errors = '';
1686
+		if ( ! empty($undeleted_options)) {
1687
+			$errors .= sprintf(
1688
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1689
+				'<br/>',
1690
+				implode(',<br/>', $undeleted_options)
1691
+			);
1692
+		}
1693
+		if ( ! empty($errors)) {
1694
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1695
+		}
1696
+	}
1697
+
1698
+	/**
1699
+	 * Gets the mysql error code from the last used query by wpdb
1700
+	 *
1701
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1702
+	 */
1703
+	public static function last_wpdb_error_code()
1704
+	{
1705
+		global $wpdb;
1706
+		if ($wpdb->use_mysqli) {
1707
+			return mysqli_errno($wpdb->dbh);
1708
+		} else {
1709
+			return mysql_errno($wpdb->dbh);
1710
+		}
1711
+	}
1712
+
1713
+	/**
1714
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1715
+	 *
1716
+	 * @global wpdb  $wpdb
1717
+	 * @deprecated instead use TableAnalysis::tableExists()
1718
+	 * @param string $table_name with or without $wpdb->prefix
1719
+	 * @return boolean
1720
+	 */
1721
+	public static function table_exists($table_name)
1722
+	{
1723
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1724
+	}
1725
+
1726
+	/**
1727
+	 * Resets the cache on EEH_Activation
1728
+	 */
1729
+	public static function reset()
1730
+	{
1731
+		self::$_default_creator_id                             = null;
1732
+		self::$_initialized_db_content_already_in_this_request = false;
1733
+	}
1734 1734
 }
1735 1735
 // End of file EEH_Activation.helper.php
1736 1736
 // Location: /helpers/EEH_Activation.core.php
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +3299 added lines, -3299 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\interfaces\InterminableInterface;
2 2
 
3 3
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 /**
7 7
  * Event Espresso
@@ -30,2114 +30,2114 @@  discard block
 block discarded – undo
30 30
 {
31 31
 
32 32
 
33
-    //set in _init_page_props()
34
-    public $page_slug;
33
+	//set in _init_page_props()
34
+	public $page_slug;
35 35
 
36
-    public $page_label;
36
+	public $page_label;
37 37
 
38
-    public $page_folder;
38
+	public $page_folder;
39 39
 
40
-    //set in define_page_props()
41
-    protected $_admin_base_url;
40
+	//set in define_page_props()
41
+	protected $_admin_base_url;
42 42
 
43
-    protected $_admin_base_path;
43
+	protected $_admin_base_path;
44 44
 
45
-    protected $_admin_page_title;
45
+	protected $_admin_page_title;
46 46
 
47
-    protected $_labels;
47
+	protected $_labels;
48 48
 
49 49
 
50
-    //set early within EE_Admin_Init
51
-    protected $_wp_page_slug;
50
+	//set early within EE_Admin_Init
51
+	protected $_wp_page_slug;
52 52
 
53
-    //navtabs
54
-    protected $_nav_tabs;
53
+	//navtabs
54
+	protected $_nav_tabs;
55 55
 
56
-    protected $_default_nav_tab_name;
56
+	protected $_default_nav_tab_name;
57 57
 
58
-    //helptourstops
59
-    protected $_help_tour = array();
58
+	//helptourstops
59
+	protected $_help_tour = array();
60 60
 
61 61
 
62
-    //template variables (used by templates)
63
-    protected $_template_path;
62
+	//template variables (used by templates)
63
+	protected $_template_path;
64 64
 
65
-    protected $_column_template_path;
65
+	protected $_column_template_path;
66 66
 
67
-    /**
68
-     * @var array $_template_args
69
-     */
70
-    protected $_template_args = array();
67
+	/**
68
+	 * @var array $_template_args
69
+	 */
70
+	protected $_template_args = array();
71 71
 
72
-    /**
73
-     * this will hold the list table object for a given view.
74
-     *
75
-     * @var EE_Admin_List_Table $_list_table_object
76
-     */
77
-    protected $_list_table_object;
72
+	/**
73
+	 * this will hold the list table object for a given view.
74
+	 *
75
+	 * @var EE_Admin_List_Table $_list_table_object
76
+	 */
77
+	protected $_list_table_object;
78 78
 
79
-    //bools
80
-    protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
79
+	//bools
80
+	protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
81 81
 
82
-    protected $_routing;
82
+	protected $_routing;
83 83
 
84
-    //list table args
85
-    protected $_view;
84
+	//list table args
85
+	protected $_view;
86 86
 
87
-    protected $_views;
87
+	protected $_views;
88 88
 
89 89
 
90
-    //action => method pairs used for routing incoming requests
91
-    protected $_page_routes;
90
+	//action => method pairs used for routing incoming requests
91
+	protected $_page_routes;
92 92
 
93
-    protected $_page_config;
93
+	protected $_page_config;
94 94
 
95
-    //the current page route and route config
96
-    protected $_route;
95
+	//the current page route and route config
96
+	protected $_route;
97 97
 
98
-    protected $_route_config;
98
+	protected $_route_config;
99 99
 
100
-    /**
101
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
102
-     * actions.
103
-     *
104
-     * @since 4.6.x
105
-     * @var array.
106
-     */
107
-    protected $_default_route_query_args;
100
+	/**
101
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
102
+	 * actions.
103
+	 *
104
+	 * @since 4.6.x
105
+	 * @var array.
106
+	 */
107
+	protected $_default_route_query_args;
108 108
 
109
-    //set via request page and action args.
110
-    protected $_current_page;
109
+	//set via request page and action args.
110
+	protected $_current_page;
111 111
 
112
-    protected $_current_view;
112
+	protected $_current_view;
113 113
 
114
-    protected $_current_page_view_url;
114
+	protected $_current_page_view_url;
115 115
 
116
-    //sanitized request action (and nonce)
117
-    /**
118
-     * @var string $_req_action
119
-     */
120
-    protected $_req_action;
116
+	//sanitized request action (and nonce)
117
+	/**
118
+	 * @var string $_req_action
119
+	 */
120
+	protected $_req_action;
121 121
 
122
-    /**
123
-     * @var string $_req_nonce
124
-     */
125
-    protected $_req_nonce;
122
+	/**
123
+	 * @var string $_req_nonce
124
+	 */
125
+	protected $_req_nonce;
126 126
 
127
-    //search related
128
-    protected $_search_btn_label;
127
+	//search related
128
+	protected $_search_btn_label;
129 129
 
130
-    protected $_search_box_callback;
130
+	protected $_search_box_callback;
131 131
 
132
-    /**
133
-     * WP Current Screen object
134
-     *
135
-     * @var WP_Screen
136
-     */
137
-    protected $_current_screen;
132
+	/**
133
+	 * WP Current Screen object
134
+	 *
135
+	 * @var WP_Screen
136
+	 */
137
+	protected $_current_screen;
138 138
 
139
-    //for holding EE_Admin_Hooks object when needed (set via set_hook_object())
140
-    protected $_hook_obj;
139
+	//for holding EE_Admin_Hooks object when needed (set via set_hook_object())
140
+	protected $_hook_obj;
141 141
 
142
-    //for holding incoming request data
143
-    protected $_req_data;
142
+	//for holding incoming request data
143
+	protected $_req_data;
144 144
 
145
-    // yes / no array for admin form fields
146
-    protected $_yes_no_values = array();
147
-
148
-    //some default things shared by all child classes
149
-    protected $_default_espresso_metaboxes;
150
-
151
-    /**
152
-     *    EE_Registry Object
153
-     *
154
-     * @var    EE_Registry
155
-     * @access    protected
156
-     */
157
-    protected $EE = null;
158
-
159
-
160
-
161
-    /**
162
-     * This is just a property that flags whether the given route is a caffeinated route or not.
163
-     *
164
-     * @var boolean
165
-     */
166
-    protected $_is_caf = false;
167
-
168
-
169
-
170
-    /**
171
-     * @Constructor
172
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
173
-     * @access public
174
-     */
175
-    public function __construct($routing = true)
176
-    {
177
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
178
-            $this->_is_caf = true;
179
-        }
180
-        $this->_yes_no_values = array(
181
-                array('id' => true, 'text' => __('Yes', 'event_espresso')),
182
-                array('id' => false, 'text' => __('No', 'event_espresso')),
183
-        );
184
-        //set the _req_data property.
185
-        $this->_req_data = array_merge($_GET, $_POST);
186
-        //routing enabled?
187
-        $this->_routing = $routing;
188
-        //set initial page props (child method)
189
-        $this->_init_page_props();
190
-        //set global defaults
191
-        $this->_set_defaults();
192
-        //set early because incoming requests could be ajax related and we need to register those hooks.
193
-        $this->_global_ajax_hooks();
194
-        $this->_ajax_hooks();
195
-        //other_page_hooks have to be early too.
196
-        $this->_do_other_page_hooks();
197
-        //This just allows us to have extending classes do something specific
198
-        // before the parent constructor runs _page_setup().
199
-        if (method_exists($this, '_before_page_setup')) {
200
-            $this->_before_page_setup();
201
-        }
202
-        //set up page dependencies
203
-        $this->_page_setup();
204
-    }
205
-
206
-
207
-
208
-    /**
209
-     * _init_page_props
210
-     * Child classes use to set at least the following properties:
211
-     * $page_slug.
212
-     * $page_label.
213
-     *
214
-     * @abstract
215
-     * @access protected
216
-     * @return void
217
-     */
218
-    abstract protected function _init_page_props();
219
-
220
-
221
-
222
-    /**
223
-     * _ajax_hooks
224
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
225
-     * Note: within the ajax callback methods.
226
-     *
227
-     * @abstract
228
-     * @access protected
229
-     * @return void
230
-     */
231
-    abstract protected function _ajax_hooks();
232
-
233
-
234
-
235
-    /**
236
-     * _define_page_props
237
-     * child classes define page properties in here.  Must include at least:
238
-     * $_admin_base_url = base_url for all admin pages
239
-     * $_admin_page_title = default admin_page_title for admin pages
240
-     * $_labels = array of default labels for various automatically generated elements:
241
-     *    array(
242
-     *        'buttons' => array(
243
-     *            'add' => __('label for add new button'),
244
-     *            'edit' => __('label for edit button'),
245
-     *            'delete' => __('label for delete button')
246
-     *            )
247
-     *        )
248
-     *
249
-     * @abstract
250
-     * @access protected
251
-     * @return void
252
-     */
253
-    abstract protected function _define_page_props();
254
-
255
-
256
-
257
-    /**
258
-     * _set_page_routes
259
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
260
-     * route. Here's the format
261
-     * $this->_page_routes = array(
262
-     *        'default' => array(
263
-     *            'func' => '_default_method_handling_route',
264
-     *            'args' => array('array','of','args'),
265
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
266
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
267
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
268
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
269
-     *        ),
270
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
271
-     *        )
272
-     * )
273
-     *
274
-     * @abstract
275
-     * @access protected
276
-     * @return void
277
-     */
278
-    abstract protected function _set_page_routes();
279
-
280
-
281
-
282
-    /**
283
-     * _set_page_config
284
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
285
-     * Format:
286
-     * $this->_page_config = array(
287
-     *        'default' => array(
288
-     *            'labels' => array(
289
-     *                'buttons' => array(
290
-     *                    'add' => __('label for adding item'),
291
-     *                    'edit' => __('label for editing item'),
292
-     *                    'delete' => __('label for deleting item')
293
-     *                ),
294
-     *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
295
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
296
-     *            'nav' => array(
297
-     *                'label' => __('Label for Tab', 'event_espresso').
298
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
299
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
300
-     *                'order' => 10, //required to indicate tab position.
301
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
302
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
303
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
304
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
305
-     *            this flag to make sure the necessary js gets enqueued on page load.
306
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
307
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
308
-     *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
309
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
310
-     *                'tab_id' => array(
311
-     *                    'title' => 'tab_title',
312
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
313
-     *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
314
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
315
-     *                    ),
316
-     *                'tab2_id' => array(
317
-     *                    'title' => 'tab2 title',
318
-     *                    'filename' => 'file_name_2'
319
-     *                    'callback' => 'callback_method_for_content',
320
-     *                 ),
321
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
322
-     *            'help_tour' => array(
323
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
324
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
325
-     *            ),
326
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
327
-     *            'require_nonce' to FALSE
328
-     *            )
329
-     * )
330
-     *
331
-     * @abstract
332
-     * @access protected
333
-     * @return void
334
-     */
335
-    abstract protected function _set_page_config();
336
-
337
-
338
-
339
-
340
-
341
-    /** end sample help_tour methods **/
342
-    /**
343
-     * _add_screen_options
344
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
345
-     * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
346
-     *
347
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
348
-     *         see also WP_Screen object documents...
349
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
350
-     * @abstract
351
-     * @access protected
352
-     * @return void
353
-     */
354
-    abstract protected function _add_screen_options();
355
-
356
-
357
-
358
-    /**
359
-     * _add_feature_pointers
360
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
361
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
362
-     * Note: this is just a placeholder for now.  Implementation will come down the road
363
-     * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
364
-     *
365
-     * @link   http://eamann.com/tech/wordpress-portland/
366
-     * @abstract
367
-     * @access protected
368
-     * @return void
369
-     */
370
-    abstract protected function _add_feature_pointers();
371
-
372
-
373
-
374
-    /**
375
-     * load_scripts_styles
376
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
377
-     * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
378
-     *
379
-     * @abstract
380
-     * @access public
381
-     * @return void
382
-     */
383
-    abstract public function load_scripts_styles();
384
-
385
-
386
-
387
-    /**
388
-     * admin_init
389
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
390
-     *
391
-     * @abstract
392
-     * @access public
393
-     * @return void
394
-     */
395
-    abstract public function admin_init();
396
-
397
-
398
-
399
-    /**
400
-     * admin_notices
401
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
402
-     *
403
-     * @abstract
404
-     * @access public
405
-     * @return void
406
-     */
407
-    abstract public function admin_notices();
408
-
409
-
410
-
411
-    /**
412
-     * admin_footer_scripts
413
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
414
-     *
415
-     * @access public
416
-     * @return void
417
-     */
418
-    abstract public function admin_footer_scripts();
419
-
420
-
421
-
422
-    /**
423
-     * admin_footer
424
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
425
-     *
426
-     * @access  public
427
-     * @return void
428
-     */
429
-    public function admin_footer()
430
-    {
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * _global_ajax_hooks
437
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
438
-     * Note: within the ajax callback methods.
439
-     *
440
-     * @abstract
441
-     * @access protected
442
-     * @return void
443
-     */
444
-    protected function _global_ajax_hooks()
445
-    {
446
-        //for lazy loading of metabox content
447
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
448
-    }
449
-
450
-
451
-
452
-    public function ajax_metabox_content()
453
-    {
454
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
455
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
456
-        self::cached_rss_display($contentid, $url);
457
-        wp_die();
458
-    }
459
-
460
-
461
-
462
-    /**
463
-     * _page_setup
464
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
465
-     *
466
-     * @final
467
-     * @access protected
468
-     * @return void
469
-     */
470
-    final protected function _page_setup()
471
-    {
472
-        //requires?
473
-        //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
474
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
475
-        //next verify if we need to load anything...
476
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
477
-        $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
478
-        global $ee_menu_slugs;
479
-        $ee_menu_slugs = (array)$ee_menu_slugs;
480
-        if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
481
-            return;
482
-        }
483
-        // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
484
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
485
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
486
-        }
487
-        // then set blank or -1 action values to 'default'
488
-        $this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
489
-        //if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
490
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
-        //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
492
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
493
-        $this->_current_view = $this->_req_action;
494
-        $this->_req_nonce = $this->_req_action . '_nonce';
495
-        $this->_define_page_props();
496
-        $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
497
-        //default things
498
-        $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
499
-        //set page configs
500
-        $this->_set_page_routes();
501
-        $this->_set_page_config();
502
-        //let's include any referrer data in our default_query_args for this route for "stickiness".
503
-        if (isset($this->_req_data['wp_referer'])) {
504
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
505
-        }
506
-        //for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
507
-        if (method_exists($this, '_extend_page_config')) {
508
-            $this->_extend_page_config();
509
-        }
510
-        //for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
511
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
512
-            $this->_extend_page_config_for_cpt();
513
-        }
514
-        //filter routes and page_config so addons can add their stuff. Filtering done per class
515
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
516
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
517
-        //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
518
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
519
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
520
-        }
521
-        //next route only if routing enabled
522
-        if ($this->_routing && ! defined('DOING_AJAX')) {
523
-            $this->_verify_routes();
524
-            //next let's just check user_access and kill if no access
525
-            $this->check_user_access();
526
-            if ($this->_is_UI_request) {
527
-                //admin_init stuff - global, all views for this page class, specific view
528
-                add_action('admin_init', array($this, 'admin_init'), 10);
529
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
530
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
531
-                }
532
-            } else {
533
-                //hijack regular WP loading and route admin request immediately
534
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
535
-                $this->route_admin_request();
536
-            }
537
-        }
538
-    }
539
-
540
-
541
-
542
-    /**
543
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
544
-     *
545
-     * @access private
546
-     * @return void
547
-     */
548
-    private function _do_other_page_hooks()
549
-    {
550
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
551
-        foreach ($registered_pages as $page) {
552
-            //now let's setup the file name and class that should be present
553
-            $classname = str_replace('.class.php', '', $page);
554
-            //autoloaders should take care of loading file
555
-            if ( ! class_exists($classname)) {
556
-                $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
557
-                $error_msg[] = $error_msg[0]
558
-                               . "\r\n"
559
-                               . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
560
-                                'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
561
-                throw new EE_Error(implode('||', $error_msg));
562
-            }
563
-            $a = new ReflectionClass($classname);
564
-            //notice we are passing the instance of this class to the hook object.
565
-            $hookobj[] = $a->newInstance($this);
566
-        }
567
-    }
568
-
569
-
570
-
571
-    public function load_page_dependencies()
572
-    {
573
-        try {
574
-            $this->_load_page_dependencies();
575
-        } catch (EE_Error $e) {
576
-            $e->get_error();
577
-        }
578
-    }
579
-
580
-
581
-
582
-    /**
583
-     * load_page_dependencies
584
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
585
-     *
586
-     * @access public
587
-     * @return void
588
-     */
589
-    protected function _load_page_dependencies()
590
-    {
591
-        //let's set the current_screen and screen options to override what WP set
592
-        $this->_current_screen = get_current_screen();
593
-        //load admin_notices - global, page class, and view specific
594
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
595
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
596
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
597
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
598
-        }
599
-        //load network admin_notices - global, page class, and view specific
600
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
601
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
602
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
603
-        }
604
-        //this will save any per_page screen options if they are present
605
-        $this->_set_per_page_screen_options();
606
-        //setup list table properties
607
-        $this->_set_list_table();
608
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
609
-        $this->_add_registered_meta_boxes();
610
-        $this->_add_screen_columns();
611
-        //add screen options - global, page child class, and view specific
612
-        $this->_add_global_screen_options();
613
-        $this->_add_screen_options();
614
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
615
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
616
-        }
617
-        //add help tab(s) and tours- set via page_config and qtips.
618
-        $this->_add_help_tour();
619
-        $this->_add_help_tabs();
620
-        $this->_add_qtips();
621
-        //add feature_pointers - global, page child class, and view specific
622
-        $this->_add_feature_pointers();
623
-        $this->_add_global_feature_pointers();
624
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
625
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
626
-        }
627
-        //enqueue scripts/styles - global, page class, and view specific
628
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
629
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
630
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
631
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
632
-        }
633
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
634
-        //admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
635
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
636
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
637
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
638
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
639
-        }
640
-        //admin footer scripts
641
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
642
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
643
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
644
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
645
-        }
646
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
647
-        //targeted hook
648
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
649
-    }
650
-
651
-
652
-
653
-    /**
654
-     * _set_defaults
655
-     * This sets some global defaults for class properties.
656
-     */
657
-    private function _set_defaults()
658
-    {
659
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
660
-        $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
661
-        $this->default_nav_tab_name = 'overview';
662
-        //init template args
663
-        $this->_template_args = array(
664
-                'admin_page_header'  => '',
665
-                'admin_page_content' => '',
666
-                'post_body_content'  => '',
667
-                'before_list_table'  => '',
668
-                'after_list_table'   => '',
669
-        );
670
-    }
671
-
672
-
673
-
674
-    /**
675
-     * route_admin_request
676
-     *
677
-     * @see    _route_admin_request()
678
-     * @access public
679
-     * @return void|exception error
680
-     */
681
-    public function route_admin_request()
682
-    {
683
-        try {
684
-            $this->_route_admin_request();
685
-        } catch (EE_Error $e) {
686
-            $e->get_error();
687
-        }
688
-    }
689
-
690
-
691
-
692
-    public function set_wp_page_slug($wp_page_slug)
693
-    {
694
-        $this->_wp_page_slug = $wp_page_slug;
695
-        //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
696
-        if (is_network_admin()) {
697
-            $this->_wp_page_slug .= '-network';
698
-        }
699
-    }
700
-
701
-
702
-
703
-    /**
704
-     * _verify_routes
705
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
706
-     *
707
-     * @access protected
708
-     * @return void
709
-     */
710
-    protected function _verify_routes()
711
-    {
712
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
713
-        if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
714
-            return false;
715
-        }
716
-        $this->_route = false;
717
-        $func = false;
718
-        $args = array();
719
-        // check that the page_routes array is not empty
720
-        if (empty($this->_page_routes)) {
721
-            // user error msg
722
-            $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
723
-            // developer error msg
724
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
725
-            throw new EE_Error($error_msg);
726
-        }
727
-        // and that the requested page route exists
728
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
729
-            $this->_route = $this->_page_routes[$this->_req_action];
730
-            $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
731
-        } else {
732
-            // user error msg
733
-            $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
734
-            // developer error msg
735
-            $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
736
-            throw new EE_Error($error_msg);
737
-        }
738
-        // and that a default route exists
739
-        if ( ! array_key_exists('default', $this->_page_routes)) {
740
-            // user error msg
741
-            $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
742
-            // developer error msg
743
-            $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
744
-            throw new EE_Error($error_msg);
745
-        }
746
-        //first lets' catch if the UI request has EVER been set.
747
-        if ($this->_is_UI_request === null) {
748
-            //lets set if this is a UI request or not.
749
-            $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
750
-            //wait a minute... we might have a noheader in the route array
751
-            $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
752
-        }
753
-        $this->_set_current_labels();
754
-    }
755
-
756
-
757
-
758
-    /**
759
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
760
-     *
761
-     * @param  string $route the route name we're verifying
762
-     * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
763
-     */
764
-    protected function _verify_route($route)
765
-    {
766
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
767
-            return true;
768
-        } else {
769
-            // user error msg
770
-            $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
771
-            // developer error msg
772
-            $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
773
-            throw new EE_Error($error_msg);
774
-        }
775
-    }
776
-
777
-
778
-
779
-    /**
780
-     * perform nonce verification
781
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
782
-     *
783
-     * @param  string $nonce     The nonce sent
784
-     * @param  string $nonce_ref The nonce reference string (name0)
785
-     * @return mixed (bool|die)
786
-     */
787
-    protected function _verify_nonce($nonce, $nonce_ref)
788
-    {
789
-        // verify nonce against expected value
790
-        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
791
-            // these are not the droids you are looking for !!!
792
-            $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
793
-            if (WP_DEBUG) {
794
-                $msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
795
-            }
796
-            if ( ! defined('DOING_AJAX')) {
797
-                wp_die($msg);
798
-            } else {
799
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
800
-                $this->_return_json();
801
-            }
802
-        }
803
-    }
804
-
805
-
806
-
807
-    /**
808
-     * _route_admin_request()
809
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
810
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
811
-     * in the page routes and then will try to load the corresponding method.
812
-     *
813
-     * @access protected
814
-     * @return void
815
-     * @throws \EE_Error
816
-     */
817
-    protected function _route_admin_request()
818
-    {
819
-        if ( ! $this->_is_UI_request) {
820
-            $this->_verify_routes();
821
-        }
822
-        $nonce_check = isset($this->_route_config['require_nonce'])
823
-            ? $this->_route_config['require_nonce']
824
-            : true;
825
-        if ($this->_req_action !== 'default' && $nonce_check) {
826
-            // set nonce from post data
827
-            $nonce = isset($this->_req_data[$this->_req_nonce])
828
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce])
829
-                : '';
830
-            $this->_verify_nonce($nonce, $this->_req_nonce);
831
-        }
832
-        //set the nav_tabs array but ONLY if this is  UI_request
833
-        if ($this->_is_UI_request) {
834
-            $this->_set_nav_tabs();
835
-        }
836
-        // grab callback function
837
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
838
-        // check if callback has args
839
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
840
-        $error_msg = '';
841
-        // action right before calling route
842
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
843
-        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
844
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
845
-        }
846
-        // right before calling the route, let's remove _wp_http_referer from the
847
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
848
-        $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
849
-        if ( ! empty($func)) {
850
-            if (is_array($func)) {
851
-                list($class, $method) = $func;
852
-            } else if (strpos($func, '::') !== false) {
853
-                list($class, $method) = explode('::', $func);
854
-            } else {
855
-                $class = $this;
856
-                $method = $func;
857
-            }
858
-            if ( ! (is_object($class) && $class === $this)) {
859
-                // send along this admin page object for access by addons.
860
-                $args['admin_page_object'] = $this;
861
-            }
862
-
863
-            if (
864
-                //is it a method on a class that doesn't work?
865
-                (
866
-                    (
867
-                        method_exists($class, $method)
868
-                        && call_user_func_array(array($class, $method), $args) === false
869
-                    )
870
-                    && (
871
-                        //is it a standalone function that doesn't work?
872
-                        function_exists($method)
873
-                        && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
874
-                    )
875
-                )
876
-                || (
877
-                    //is it neither a class method NOR a standalone function?
878
-                    ! method_exists($class, $method)
879
-                    && ! function_exists($method)
880
-                )
881
-            ) {
882
-                // user error msg
883
-                $error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
884
-                // developer error msg
885
-                $error_msg .= '||';
886
-                $error_msg .= sprintf(
887
-                    __(
888
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
889
-                        'event_espresso'
890
-                    ),
891
-                    $method
892
-                );
893
-            }
894
-            if ( ! empty($error_msg)) {
895
-                throw new EE_Error($error_msg);
896
-            }
897
-        }
898
-        //if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
899
-        //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
900
-        if ($this->_is_UI_request === false
901
-            && is_array($this->_route)
902
-            && ! empty($this->_route['headers_sent_route'])
903
-        ) {
904
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
905
-        }
906
-    }
907
-
908
-
909
-
910
-    /**
911
-     * This method just allows the resetting of page properties in the case where a no headers
912
-     * route redirects to a headers route in its route config.
913
-     *
914
-     * @since   4.3.0
915
-     * @param  string $new_route New (non header) route to redirect to.
916
-     * @return   void
917
-     */
918
-    protected function _reset_routing_properties($new_route)
919
-    {
920
-        $this->_is_UI_request = true;
921
-        //now we set the current route to whatever the headers_sent_route is set at
922
-        $this->_req_data['action'] = $new_route;
923
-        //rerun page setup
924
-        $this->_page_setup();
925
-    }
926
-
927
-
928
-
929
-    /**
930
-     * _add_query_arg
931
-     * adds nonce to array of arguments then calls WP add_query_arg function
932
-     *(internally just uses EEH_URL's function with the same name)
933
-     *
934
-     * @access public
935
-     * @param array  $args
936
-     * @param string $url
937
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
938
-     *                                        url in an associative array indexed by the key 'wp_referer';
939
-     *                                        Example usage:
940
-     *                                        If the current page is:
941
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
942
-     *                                        &action=default&event_id=20&month_range=March%202015
943
-     *                                        &_wpnonce=5467821
944
-     *                                        and you call:
945
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
946
-     *                                        array(
947
-     *                                        'action' => 'resend_something',
948
-     *                                        'page=>espresso_registrations'
949
-     *                                        ),
950
-     *                                        $some_url,
951
-     *                                        true
952
-     *                                        );
953
-     *                                        It will produce a url in this structure:
954
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
955
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
956
-     *                                        month_range]=March%202015
957
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
958
-     * @return string
959
-     */
960
-    public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
961
-    {
962
-        //if there is a _wp_http_referer include the values from the request but only if sticky = true
963
-        if ($sticky) {
964
-            $request = $_REQUEST;
965
-            unset($request['_wp_http_referer']);
966
-            unset($request['wp_referer']);
967
-            foreach ($request as $key => $value) {
968
-                //do not add nonces
969
-                if (strpos($key, 'nonce') !== false) {
970
-                    continue;
971
-                }
972
-                $args['wp_referer[' . $key . ']'] = $value;
973
-            }
974
-        }
975
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
976
-    }
977
-
978
-
979
-
980
-    /**
981
-     * This returns a generated link that will load the related help tab.
982
-     *
983
-     * @param  string $help_tab_id the id for the connected help tab
984
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
985
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
986
-     * @uses EEH_Template::get_help_tab_link()
987
-     * @return string              generated link
988
-     */
989
-    protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
990
-    {
991
-        return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
992
-    }
993
-
994
-
995
-
996
-    /**
997
-     * _add_help_tabs
998
-     * Note child classes define their help tabs within the page_config array.
999
-     *
1000
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1001
-     * @access protected
1002
-     * @return void
1003
-     */
1004
-    protected function _add_help_tabs()
1005
-    {
1006
-        $tour_buttons = '';
1007
-        if (isset($this->_page_config[$this->_req_action])) {
1008
-            $config = $this->_page_config[$this->_req_action];
1009
-            //is there a help tour for the current route?  if there is let's setup the tour buttons
1010
-            if (isset($this->_help_tour[$this->_req_action])) {
1011
-                $tb = array();
1012
-                $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1013
-                foreach ($this->_help_tour['tours'] as $tour) {
1014
-                    //if this is the end tour then we don't need to setup a button
1015
-                    if ($tour instanceof EE_Help_Tour_final_stop) {
1016
-                        continue;
1017
-                    }
1018
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1019
-                }
1020
-                $tour_buttons .= implode('<br />', $tb);
1021
-                $tour_buttons .= '</div></div>';
1022
-            }
1023
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1024
-            if (is_array($config) && isset($config['help_sidebar'])) {
1025
-                //check that the callback given is valid
1026
-                if ( ! method_exists($this, $config['help_sidebar'])) {
1027
-                    throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1028
-                            'event_espresso'), $config['help_sidebar'], get_class($this)));
1029
-                }
1030
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1031
-                $content .= $tour_buttons; //add help tour buttons.
1032
-                //do we have any help tours setup?  Cause if we do we want to add the buttons
1033
-                $this->_current_screen->set_help_sidebar($content);
1034
-            }
1035
-            //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1036
-            if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1037
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1038
-            }
1039
-            //handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1040
-            if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1041
-                $_ht['id'] = $this->page_slug;
1042
-                $_ht['title'] = __('Help Tours', 'event_espresso');
1043
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1044
-                $this->_current_screen->add_help_tab($_ht);
1045
-            }/**/
1046
-            if ( ! isset($config['help_tabs'])) {
1047
-                return;
1048
-            } //no help tabs for this route
1049
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1050
-                //we're here so there ARE help tabs!
1051
-                //make sure we've got what we need
1052
-                if ( ! isset($cfg['title'])) {
1053
-                    throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1054
-                }
1055
-                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1056
-                    throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1057
-                            'event_espresso'));
1058
-                }
1059
-                //first priority goes to content.
1060
-                if ( ! empty($cfg['content'])) {
1061
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1062
-                    //second priority goes to filename
1063
-                } else if ( ! empty($cfg['filename'])) {
1064
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1065
-                    //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1066
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1067
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1068
-                    if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1069
-                        EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1070
-                                'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1071
-                        return;
1072
-                    }
1073
-                    $template_args['admin_page_obj'] = $this;
1074
-                    $content = EEH_Template::display_template($file_path, $template_args, true);
1075
-                } else {
1076
-                    $content = '';
1077
-                }
1078
-                //check if callback is valid
1079
-                if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1080
-                    EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1081
-                            'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1082
-                    return;
1083
-                }
1084
-                //setup config array for help tab method
1085
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1086
-                $_ht = array(
1087
-                        'id'       => $id,
1088
-                        'title'    => $cfg['title'],
1089
-                        'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1090
-                        'content'  => $content,
1091
-                );
1092
-                $this->_current_screen->add_help_tab($_ht);
1093
-            }
1094
-        }
1095
-    }
1096
-
1097
-
1098
-
1099
-    /**
1100
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1101
-     *
1102
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1103
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1104
-     * @access protected
1105
-     * @return void
1106
-     */
1107
-    protected function _add_help_tour()
1108
-    {
1109
-        $tours = array();
1110
-        $this->_help_tour = array();
1111
-        //exit early if help tours are turned off globally
1112
-        if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1113
-            return;
1114
-        }
1115
-        //loop through _page_config to find any help_tour defined
1116
-        foreach ($this->_page_config as $route => $config) {
1117
-            //we're only going to set things up for this route
1118
-            if ($route !== $this->_req_action) {
1119
-                continue;
1120
-            }
1121
-            if (isset($config['help_tour'])) {
1122
-                foreach ($config['help_tour'] as $tour) {
1123
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1124
-                    //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1125
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1126
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1127
-                    if ( ! is_readable($file_path)) {
1128
-                        EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
1129
-                                $file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1130
-                        return;
1131
-                    }
1132
-                    require_once $file_path;
1133
-                    if ( ! class_exists($tour)) {
1134
-                        $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1135
-                        $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1136
-                                        'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1137
-                        throw new EE_Error(implode('||', $error_msg));
1138
-                    }
1139
-                    $a = new ReflectionClass($tour);
1140
-                    $tour_obj = $a->newInstance($this->_is_caf);
1141
-                    $tours[] = $tour_obj;
1142
-                    $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1143
-                }
1144
-                //let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1145
-                $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1146
-                $tours[] = $end_stop_tour;
1147
-                $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1148
-            }
1149
-        }
1150
-        if ( ! empty($tours)) {
1151
-            $this->_help_tour['tours'] = $tours;
1152
-        }
1153
-        //thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1154
-    }
1155
-
1156
-
1157
-
1158
-    /**
1159
-     * This simply sets up any qtips that have been defined in the page config
1160
-     *
1161
-     * @access protected
1162
-     * @return void
1163
-     */
1164
-    protected function _add_qtips()
1165
-    {
1166
-        if (isset($this->_route_config['qtips'])) {
1167
-            $qtips = (array)$this->_route_config['qtips'];
1168
-            //load qtip loader
1169
-            $path = array(
1170
-                    $this->_get_dir() . '/qtips/',
1171
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1172
-            );
1173
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1174
-        }
1175
-    }
1176
-
1177
-
1178
-
1179
-    /**
1180
-     * _set_nav_tabs
1181
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1182
-     *
1183
-     * @access protected
1184
-     * @return void
1185
-     */
1186
-    protected function _set_nav_tabs()
1187
-    {
1188
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1189
-        $i = 0;
1190
-        foreach ($this->_page_config as $slug => $config) {
1191
-            if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1192
-                continue;
1193
-            } //no nav tab for this config
1194
-            //check for persistent flag
1195
-            if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1196
-                continue;
1197
-            } //nav tab is only to appear when route requested.
1198
-            if ( ! $this->check_user_access($slug, true)) {
1199
-                continue;
1200
-            } //no nav tab becasue current user does not have access.
1201
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1202
-            $this->_nav_tabs[$slug] = array(
1203
-                    'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1204
-                    'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1205
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1206
-                    'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1207
-            );
1208
-            $i++;
1209
-        }
1210
-        //if $this->_nav_tabs is empty then lets set the default
1211
-        if (empty($this->_nav_tabs)) {
1212
-            $this->_nav_tabs[$this->default_nav_tab_name] = array(
1213
-                    'url'       => $this->admin_base_url,
1214
-                    'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1215
-                    'css_class' => 'nav-tab-active',
1216
-                    'order'     => 10,
1217
-            );
1218
-        }
1219
-        //now let's sort the tabs according to order
1220
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1221
-    }
1222
-
1223
-
1224
-
1225
-    /**
1226
-     * _set_current_labels
1227
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1228
-     *
1229
-     * @access private
1230
-     * @return void
1231
-     */
1232
-    private function _set_current_labels()
1233
-    {
1234
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1235
-            foreach ($this->_route_config['labels'] as $label => $text) {
1236
-                if (is_array($text)) {
1237
-                    foreach ($text as $sublabel => $subtext) {
1238
-                        $this->_labels[$label][$sublabel] = $subtext;
1239
-                    }
1240
-                } else {
1241
-                    $this->_labels[$label] = $text;
1242
-                }
1243
-            }
1244
-        }
1245
-    }
1246
-
1247
-
1248
-
1249
-    /**
1250
-     *        verifies user access for this admin page
1251
-     *
1252
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1253
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1254
-     * @return        BOOL|wp_die()
1255
-     */
1256
-    public function check_user_access($route_to_check = '', $verify_only = false)
1257
-    {
1258
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1259
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1260
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1261
-                ? $this->_page_routes[$route_to_check]['capability'] : null;
1262
-        if (empty($capability) && empty($route_to_check)) {
1263
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1264
-        } else {
1265
-            $capability = empty($capability) ? 'manage_options' : $capability;
1266
-        }
1267
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1268
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1269
-            if ($verify_only) {
1270
-                return false;
1271
-            } else {
1272
-                if ( is_user_logged_in() ) {
1273
-                    wp_die(__('You do not have access to this route.', 'event_espresso'));
1274
-                } else {
1275
-                    return false;
1276
-                }
1277
-            }
1278
-        }
1279
-        return true;
1280
-    }
1281
-
1282
-
1283
-
1284
-    /**
1285
-     * admin_init_global
1286
-     * This runs all the code that we want executed within the WP admin_init hook.
1287
-     * This method executes for ALL EE Admin pages.
1288
-     *
1289
-     * @access public
1290
-     * @return void
1291
-     */
1292
-    public function admin_init_global()
1293
-    {
1294
-    }
1295
-
1296
-
1297
-
1298
-    /**
1299
-     * wp_loaded_global
1300
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1301
-     *
1302
-     * @access public
1303
-     * @return void
1304
-     */
1305
-    public function wp_loaded()
1306
-    {
1307
-    }
1308
-
1309
-
1310
-
1311
-    /**
1312
-     * admin_notices
1313
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1314
-     *
1315
-     * @access public
1316
-     * @return void
1317
-     */
1318
-    public function admin_notices_global()
1319
-    {
1320
-        $this->_display_no_javascript_warning();
1321
-        $this->_display_espresso_notices();
1322
-    }
1323
-
1324
-
1325
-
1326
-    public function network_admin_notices_global()
1327
-    {
1328
-        $this->_display_no_javascript_warning();
1329
-        $this->_display_espresso_notices();
1330
-    }
1331
-
1332
-
1333
-
1334
-    /**
1335
-     * admin_footer_scripts_global
1336
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1337
-     *
1338
-     * @access public
1339
-     * @return void
1340
-     */
1341
-    public function admin_footer_scripts_global()
1342
-    {
1343
-        $this->_add_admin_page_ajax_loading_img();
1344
-        $this->_add_admin_page_overlay();
1345
-        //if metaboxes are present we need to add the nonce field
1346
-        if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1347
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1348
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1349
-        }
1350
-    }
1351
-
1352
-
1353
-
1354
-    /**
1355
-     * admin_footer_global
1356
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1357
-     *
1358
-     * @access  public
1359
-     * @return  void
1360
-     */
1361
-    public function admin_footer_global()
1362
-    {
1363
-        //dialog container for dialog helper
1364
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1365
-        $d_cont .= '<div class="ee-notices"></div>';
1366
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1367
-        $d_cont .= '</div>';
1368
-        echo $d_cont;
1369
-        //help tour stuff?
1370
-        if (isset($this->_help_tour[$this->_req_action])) {
1371
-            echo implode('<br />', $this->_help_tour[$this->_req_action]);
1372
-        }
1373
-        //current set timezone for timezone js
1374
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1375
-    }
1376
-
1377
-
1378
-
1379
-    /**
1380
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1381
-     * For child classes:
1382
-     * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1383
-     * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1384
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1385
-     *    'help_trigger_id' => array(
1386
-     *        'title' => __('localized title for popup', 'event_espresso'),
1387
-     *        'content' => __('localized content for popup', 'event_espresso')
1388
-     *    )
1389
-     * );
1390
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1391
-     *
1392
-     * @access protected
1393
-     * @return string content
1394
-     */
1395
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1396
-    {
1397
-        $content = '';
1398
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1399
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1400
-        //loop through the array and setup content
1401
-        foreach ($help_array as $trigger => $help) {
1402
-            //make sure the array is setup properly
1403
-            if ( ! isset($help['title']) || ! isset($help['content'])) {
1404
-                throw new EE_Error(__('Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1405
-                        'event_espresso'));
1406
-            }
1407
-            //we're good so let'd setup the template vars and then assign parsed template content to our content.
1408
-            $template_args = array(
1409
-                    'help_popup_id'      => $trigger,
1410
-                    'help_popup_title'   => $help['title'],
1411
-                    'help_popup_content' => $help['content'],
1412
-            );
1413
-            $content .= EEH_Template::display_template($template_path, $template_args, true);
1414
-        }
1415
-        if ($display) {
1416
-            echo $content;
1417
-        } else {
1418
-            return $content;
1419
-        }
1420
-    }
1421
-
1422
-
1423
-
1424
-    /**
1425
-     * All this does is retrive the help content array if set by the EE_Admin_Page child
1426
-     *
1427
-     * @access private
1428
-     * @return array properly formatted array for help popup content
1429
-     */
1430
-    private function _get_help_content()
1431
-    {
1432
-        //what is the method we're looking for?
1433
-        $method_name = '_help_popup_content_' . $this->_req_action;
1434
-        //if method doesn't exist let's get out.
1435
-        if ( ! method_exists($this, $method_name)) {
1436
-            return array();
1437
-        }
1438
-        //k we're good to go let's retrieve the help array
1439
-        $help_array = call_user_func(array($this, $method_name));
1440
-        //make sure we've got an array!
1441
-        if ( ! is_array($help_array)) {
1442
-            throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1443
-        }
1444
-        return $help_array;
1445
-    }
1446
-
1447
-
1448
-
1449
-    /**
1450
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1451
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1452
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1453
-     *
1454
-     * @access protected
1455
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1456
-     * @param boolean $display    if false then we return the trigger string
1457
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1458
-     * @return string
1459
-     */
1460
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1461
-    {
1462
-        if (defined('DOING_AJAX')) {
1463
-            return;
1464
-        }
1465
-        //let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1466
-        $help_array = $this->_get_help_content();
1467
-        $help_content = '';
1468
-        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1469
-            $help_array[$trigger_id] = array(
1470
-                    'title'   => __('Missing Content', 'event_espresso'),
1471
-                    'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1472
-                            'event_espresso'),
1473
-            );
1474
-            $help_content = $this->_set_help_popup_content($help_array, false);
1475
-        }
1476
-        //let's setup the trigger
1477
-        $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1478
-        $content = $content . $help_content;
1479
-        if ($display) {
1480
-            echo $content;
1481
-        } else {
1482
-            return $content;
1483
-        }
1484
-    }
1485
-
1486
-
1487
-
1488
-    /**
1489
-     * _add_global_screen_options
1490
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1491
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1492
-     *
1493
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1494
-     *         see also WP_Screen object documents...
1495
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1496
-     * @abstract
1497
-     * @access private
1498
-     * @return void
1499
-     */
1500
-    private function _add_global_screen_options()
1501
-    {
1502
-    }
1503
-
1504
-
1505
-
1506
-    /**
1507
-     * _add_global_feature_pointers
1508
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1509
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1510
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1511
-     *
1512
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1513
-     * @link   http://eamann.com/tech/wordpress-portland/
1514
-     * @abstract
1515
-     * @access protected
1516
-     * @return void
1517
-     */
1518
-    private function _add_global_feature_pointers()
1519
-    {
1520
-    }
1521
-
1522
-
1523
-
1524
-    /**
1525
-     * load_global_scripts_styles
1526
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1527
-     *
1528
-     * @return void
1529
-     */
1530
-    public function load_global_scripts_styles()
1531
-    {
1532
-        /** STYLES **/
1533
-        // add debugging styles
1534
-        if (WP_DEBUG) {
1535
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1536
-        }
1537
-        // register all styles
1538
-        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1539
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1540
-        //helpers styles
1541
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1542
-        /** SCRIPTS **/
1543
-        //register all scripts
1544
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1545
-        wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1546
-        wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1547
-        add_filter('FHEE_load_joyride', '__return_true');
1548
-        //script for sorting tables
1549
-        wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1550
-        //script for parsing uri's
1551
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1552
-        //and parsing associative serialized form elements
1553
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
-        //helpers scripts
1555
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1556
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1557
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1558
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1559
-        //google charts
1560
-        wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1561
-        // ENQUEUE ALL BASICS BY DEFAULT
1562
-        wp_enqueue_style('ee-admin-css');
1563
-        wp_enqueue_script('ee_admin_js');
1564
-        wp_enqueue_script('ee-accounting');
1565
-        wp_enqueue_script('jquery-validate');
1566
-        //taking care of metaboxes
1567
-        if (
1568
-            empty($this->_cpt_route)
1569
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1570
-        ) {
1571
-            wp_enqueue_script('dashboard');
1572
-        }
1573
-        // LOCALIZED DATA
1574
-        //localize script for ajax lazy loading
1575
-        $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1576
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1577
-        /**
1578
-         * help tour stuff
1579
-         */
1580
-        if ( ! empty($this->_help_tour)) {
1581
-            //register the js for kicking things off
1582
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1583
-            //setup tours for the js tour object
1584
-            foreach ($this->_help_tour['tours'] as $tour) {
1585
-                $tours[] = array(
1586
-                        'id'      => $tour->get_slug(),
1587
-                        'options' => $tour->get_options(),
1588
-                );
1589
-            }
1590
-            wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1591
-            //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1592
-        }
1593
-    }
1594
-
1595
-
1596
-
1597
-    /**
1598
-     *        admin_footer_scripts_eei18n_js_strings
1599
-     *
1600
-     * @access        public
1601
-     * @return        void
1602
-     */
1603
-    public function admin_footer_scripts_eei18n_js_strings()
1604
-    {
1605
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1606
-        EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso');
1607
-        EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1608
-        EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1609
-        EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1610
-        EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1611
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1612
-        EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1613
-        EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1614
-        EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1615
-        EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1616
-        EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1617
-        EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1618
-        EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1619
-        EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1620
-        EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1621
-        EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1622
-        EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1623
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1624
-        EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1625
-        EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1626
-        EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1627
-        EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1628
-        EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1629
-        EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1630
-        EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1631
-        EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1632
-        EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1633
-        EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1634
-        EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1635
-        EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1636
-        EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1637
-        EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1638
-        EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1639
-        EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1640
-        EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1641
-        EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1642
-        EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1643
-        EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1644
-        EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1645
-    }
1646
-
1647
-
1648
-
1649
-    /**
1650
-     *        load enhanced xdebug styles for ppl with failing eyesight
1651
-     *
1652
-     * @access        public
1653
-     * @return        void
1654
-     */
1655
-    public function add_xdebug_style()
1656
-    {
1657
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1658
-    }
1659
-
1660
-
1661
-    /************************/
1662
-    /** LIST TABLE METHODS **/
1663
-    /************************/
1664
-    /**
1665
-     * this sets up the list table if the current view requires it.
1666
-     *
1667
-     * @access protected
1668
-     * @return void
1669
-     */
1670
-    protected function _set_list_table()
1671
-    {
1672
-        //first is this a list_table view?
1673
-        if ( ! isset($this->_route_config['list_table'])) {
1674
-            return;
1675
-        } //not a list_table view so get out.
1676
-        //list table functions are per view specific (because some admin pages might have more than one listtable!)
1677
-        if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1678
-            //user error msg
1679
-            $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1680
-            //developer error msg
1681
-            $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1682
-                            $this->_req_action, '_set_list_table_views_' . $this->_req_action);
1683
-            throw new EE_Error($error_msg);
1684
-        }
1685
-        //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1686
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1687
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1688
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1689
-        $this->_set_list_table_view();
1690
-        $this->_set_list_table_object();
1691
-    }
1692
-
1693
-
1694
-
1695
-    /**
1696
-     *        set current view for List Table
1697
-     *
1698
-     * @access public
1699
-     * @return array
1700
-     */
1701
-    protected function _set_list_table_view()
1702
-    {
1703
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1704
-        // looking at active items or dumpster diving ?
1705
-        if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1706
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1707
-        } else {
1708
-            $this->_view = sanitize_key($this->_req_data['status']);
1709
-        }
1710
-    }
1711
-
1712
-
1713
-
1714
-    /**
1715
-     * _set_list_table_object
1716
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1717
-     *
1718
-     * @throws \EE_Error
1719
-     */
1720
-    protected function _set_list_table_object()
1721
-    {
1722
-        if (isset($this->_route_config['list_table'])) {
1723
-            if ( ! class_exists($this->_route_config['list_table'])) {
1724
-                throw new EE_Error(
1725
-                        sprintf(
1726
-                                __(
1727
-                                        'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1728
-                                        'event_espresso'
1729
-                                ),
1730
-                                $this->_route_config['list_table'],
1731
-                                get_class($this)
1732
-                        )
1733
-                );
1734
-            }
1735
-            $list_table = $this->_route_config['list_table'];
1736
-            $this->_list_table_object = new $list_table($this);
1737
-        }
1738
-    }
1739
-
1740
-
1741
-
1742
-    /**
1743
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1744
-     *
1745
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1746
-     *                                                    urls.  The array should be indexed by the view it is being
1747
-     *                                                    added to.
1748
-     * @return array
1749
-     */
1750
-    public function get_list_table_view_RLs($extra_query_args = array())
1751
-    {
1752
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1753
-        if (empty($this->_views)) {
1754
-            $this->_views = array();
1755
-        }
1756
-        // cycle thru views
1757
-        foreach ($this->_views as $key => $view) {
1758
-            $query_args = array();
1759
-            // check for current view
1760
-            $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1761
-            $query_args['action'] = $this->_req_action;
1762
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1763
-            $query_args['status'] = $view['slug'];
1764
-            //merge any other arguments sent in.
1765
-            if (isset($extra_query_args[$view['slug']])) {
1766
-                $query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1767
-            }
1768
-            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1769
-        }
1770
-        return $this->_views;
1771
-    }
1772
-
1773
-
1774
-
1775
-    /**
1776
-     * _entries_per_page_dropdown
1777
-     * generates a drop down box for selecting the number of visiable rows in an admin page list table
1778
-     *
1779
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1780
-     * @access protected
1781
-     * @param int $max_entries total number of rows in the table
1782
-     * @return string
1783
-     */
1784
-    protected function _entries_per_page_dropdown($max_entries = false)
1785
-    {
1786
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1787
-        $values = array(10, 25, 50, 100);
1788
-        $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1789
-        if ($max_entries) {
1790
-            $values[] = $max_entries;
1791
-            sort($values);
1792
-        }
1793
-        $entries_per_page_dropdown = '
145
+	// yes / no array for admin form fields
146
+	protected $_yes_no_values = array();
147
+
148
+	//some default things shared by all child classes
149
+	protected $_default_espresso_metaboxes;
150
+
151
+	/**
152
+	 *    EE_Registry Object
153
+	 *
154
+	 * @var    EE_Registry
155
+	 * @access    protected
156
+	 */
157
+	protected $EE = null;
158
+
159
+
160
+
161
+	/**
162
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
163
+	 *
164
+	 * @var boolean
165
+	 */
166
+	protected $_is_caf = false;
167
+
168
+
169
+
170
+	/**
171
+	 * @Constructor
172
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
173
+	 * @access public
174
+	 */
175
+	public function __construct($routing = true)
176
+	{
177
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
178
+			$this->_is_caf = true;
179
+		}
180
+		$this->_yes_no_values = array(
181
+				array('id' => true, 'text' => __('Yes', 'event_espresso')),
182
+				array('id' => false, 'text' => __('No', 'event_espresso')),
183
+		);
184
+		//set the _req_data property.
185
+		$this->_req_data = array_merge($_GET, $_POST);
186
+		//routing enabled?
187
+		$this->_routing = $routing;
188
+		//set initial page props (child method)
189
+		$this->_init_page_props();
190
+		//set global defaults
191
+		$this->_set_defaults();
192
+		//set early because incoming requests could be ajax related and we need to register those hooks.
193
+		$this->_global_ajax_hooks();
194
+		$this->_ajax_hooks();
195
+		//other_page_hooks have to be early too.
196
+		$this->_do_other_page_hooks();
197
+		//This just allows us to have extending classes do something specific
198
+		// before the parent constructor runs _page_setup().
199
+		if (method_exists($this, '_before_page_setup')) {
200
+			$this->_before_page_setup();
201
+		}
202
+		//set up page dependencies
203
+		$this->_page_setup();
204
+	}
205
+
206
+
207
+
208
+	/**
209
+	 * _init_page_props
210
+	 * Child classes use to set at least the following properties:
211
+	 * $page_slug.
212
+	 * $page_label.
213
+	 *
214
+	 * @abstract
215
+	 * @access protected
216
+	 * @return void
217
+	 */
218
+	abstract protected function _init_page_props();
219
+
220
+
221
+
222
+	/**
223
+	 * _ajax_hooks
224
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
225
+	 * Note: within the ajax callback methods.
226
+	 *
227
+	 * @abstract
228
+	 * @access protected
229
+	 * @return void
230
+	 */
231
+	abstract protected function _ajax_hooks();
232
+
233
+
234
+
235
+	/**
236
+	 * _define_page_props
237
+	 * child classes define page properties in here.  Must include at least:
238
+	 * $_admin_base_url = base_url for all admin pages
239
+	 * $_admin_page_title = default admin_page_title for admin pages
240
+	 * $_labels = array of default labels for various automatically generated elements:
241
+	 *    array(
242
+	 *        'buttons' => array(
243
+	 *            'add' => __('label for add new button'),
244
+	 *            'edit' => __('label for edit button'),
245
+	 *            'delete' => __('label for delete button')
246
+	 *            )
247
+	 *        )
248
+	 *
249
+	 * @abstract
250
+	 * @access protected
251
+	 * @return void
252
+	 */
253
+	abstract protected function _define_page_props();
254
+
255
+
256
+
257
+	/**
258
+	 * _set_page_routes
259
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
260
+	 * route. Here's the format
261
+	 * $this->_page_routes = array(
262
+	 *        'default' => array(
263
+	 *            'func' => '_default_method_handling_route',
264
+	 *            'args' => array('array','of','args'),
265
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
266
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
267
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
268
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
269
+	 *        ),
270
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
271
+	 *        )
272
+	 * )
273
+	 *
274
+	 * @abstract
275
+	 * @access protected
276
+	 * @return void
277
+	 */
278
+	abstract protected function _set_page_routes();
279
+
280
+
281
+
282
+	/**
283
+	 * _set_page_config
284
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
285
+	 * Format:
286
+	 * $this->_page_config = array(
287
+	 *        'default' => array(
288
+	 *            'labels' => array(
289
+	 *                'buttons' => array(
290
+	 *                    'add' => __('label for adding item'),
291
+	 *                    'edit' => __('label for editing item'),
292
+	 *                    'delete' => __('label for deleting item')
293
+	 *                ),
294
+	 *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
295
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
296
+	 *            'nav' => array(
297
+	 *                'label' => __('Label for Tab', 'event_espresso').
298
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
299
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
300
+	 *                'order' => 10, //required to indicate tab position.
301
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
302
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
303
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
304
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
305
+	 *            this flag to make sure the necessary js gets enqueued on page load.
306
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
307
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
308
+	 *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
309
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
310
+	 *                'tab_id' => array(
311
+	 *                    'title' => 'tab_title',
312
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
313
+	 *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
314
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
315
+	 *                    ),
316
+	 *                'tab2_id' => array(
317
+	 *                    'title' => 'tab2 title',
318
+	 *                    'filename' => 'file_name_2'
319
+	 *                    'callback' => 'callback_method_for_content',
320
+	 *                 ),
321
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
322
+	 *            'help_tour' => array(
323
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
324
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
325
+	 *            ),
326
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
327
+	 *            'require_nonce' to FALSE
328
+	 *            )
329
+	 * )
330
+	 *
331
+	 * @abstract
332
+	 * @access protected
333
+	 * @return void
334
+	 */
335
+	abstract protected function _set_page_config();
336
+
337
+
338
+
339
+
340
+
341
+	/** end sample help_tour methods **/
342
+	/**
343
+	 * _add_screen_options
344
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
345
+	 * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
346
+	 *
347
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
348
+	 *         see also WP_Screen object documents...
349
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
350
+	 * @abstract
351
+	 * @access protected
352
+	 * @return void
353
+	 */
354
+	abstract protected function _add_screen_options();
355
+
356
+
357
+
358
+	/**
359
+	 * _add_feature_pointers
360
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
361
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
362
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
363
+	 * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
364
+	 *
365
+	 * @link   http://eamann.com/tech/wordpress-portland/
366
+	 * @abstract
367
+	 * @access protected
368
+	 * @return void
369
+	 */
370
+	abstract protected function _add_feature_pointers();
371
+
372
+
373
+
374
+	/**
375
+	 * load_scripts_styles
376
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
377
+	 * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
378
+	 *
379
+	 * @abstract
380
+	 * @access public
381
+	 * @return void
382
+	 */
383
+	abstract public function load_scripts_styles();
384
+
385
+
386
+
387
+	/**
388
+	 * admin_init
389
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
390
+	 *
391
+	 * @abstract
392
+	 * @access public
393
+	 * @return void
394
+	 */
395
+	abstract public function admin_init();
396
+
397
+
398
+
399
+	/**
400
+	 * admin_notices
401
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
402
+	 *
403
+	 * @abstract
404
+	 * @access public
405
+	 * @return void
406
+	 */
407
+	abstract public function admin_notices();
408
+
409
+
410
+
411
+	/**
412
+	 * admin_footer_scripts
413
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
414
+	 *
415
+	 * @access public
416
+	 * @return void
417
+	 */
418
+	abstract public function admin_footer_scripts();
419
+
420
+
421
+
422
+	/**
423
+	 * admin_footer
424
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
425
+	 *
426
+	 * @access  public
427
+	 * @return void
428
+	 */
429
+	public function admin_footer()
430
+	{
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * _global_ajax_hooks
437
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
438
+	 * Note: within the ajax callback methods.
439
+	 *
440
+	 * @abstract
441
+	 * @access protected
442
+	 * @return void
443
+	 */
444
+	protected function _global_ajax_hooks()
445
+	{
446
+		//for lazy loading of metabox content
447
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
448
+	}
449
+
450
+
451
+
452
+	public function ajax_metabox_content()
453
+	{
454
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
455
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
456
+		self::cached_rss_display($contentid, $url);
457
+		wp_die();
458
+	}
459
+
460
+
461
+
462
+	/**
463
+	 * _page_setup
464
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
465
+	 *
466
+	 * @final
467
+	 * @access protected
468
+	 * @return void
469
+	 */
470
+	final protected function _page_setup()
471
+	{
472
+		//requires?
473
+		//admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
474
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
475
+		//next verify if we need to load anything...
476
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
477
+		$this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
478
+		global $ee_menu_slugs;
479
+		$ee_menu_slugs = (array)$ee_menu_slugs;
480
+		if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
481
+			return;
482
+		}
483
+		// becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
484
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
485
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
486
+		}
487
+		// then set blank or -1 action values to 'default'
488
+		$this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
489
+		//if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
490
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
+		//however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
492
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
493
+		$this->_current_view = $this->_req_action;
494
+		$this->_req_nonce = $this->_req_action . '_nonce';
495
+		$this->_define_page_props();
496
+		$this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
497
+		//default things
498
+		$this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
499
+		//set page configs
500
+		$this->_set_page_routes();
501
+		$this->_set_page_config();
502
+		//let's include any referrer data in our default_query_args for this route for "stickiness".
503
+		if (isset($this->_req_data['wp_referer'])) {
504
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
505
+		}
506
+		//for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
507
+		if (method_exists($this, '_extend_page_config')) {
508
+			$this->_extend_page_config();
509
+		}
510
+		//for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
511
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
512
+			$this->_extend_page_config_for_cpt();
513
+		}
514
+		//filter routes and page_config so addons can add their stuff. Filtering done per class
515
+		$this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
516
+		$this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
517
+		//if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
518
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
519
+			add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
520
+		}
521
+		//next route only if routing enabled
522
+		if ($this->_routing && ! defined('DOING_AJAX')) {
523
+			$this->_verify_routes();
524
+			//next let's just check user_access and kill if no access
525
+			$this->check_user_access();
526
+			if ($this->_is_UI_request) {
527
+				//admin_init stuff - global, all views for this page class, specific view
528
+				add_action('admin_init', array($this, 'admin_init'), 10);
529
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
530
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
531
+				}
532
+			} else {
533
+				//hijack regular WP loading and route admin request immediately
534
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
535
+				$this->route_admin_request();
536
+			}
537
+		}
538
+	}
539
+
540
+
541
+
542
+	/**
543
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
544
+	 *
545
+	 * @access private
546
+	 * @return void
547
+	 */
548
+	private function _do_other_page_hooks()
549
+	{
550
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
551
+		foreach ($registered_pages as $page) {
552
+			//now let's setup the file name and class that should be present
553
+			$classname = str_replace('.class.php', '', $page);
554
+			//autoloaders should take care of loading file
555
+			if ( ! class_exists($classname)) {
556
+				$error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
557
+				$error_msg[] = $error_msg[0]
558
+							   . "\r\n"
559
+							   . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
560
+								'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
561
+				throw new EE_Error(implode('||', $error_msg));
562
+			}
563
+			$a = new ReflectionClass($classname);
564
+			//notice we are passing the instance of this class to the hook object.
565
+			$hookobj[] = $a->newInstance($this);
566
+		}
567
+	}
568
+
569
+
570
+
571
+	public function load_page_dependencies()
572
+	{
573
+		try {
574
+			$this->_load_page_dependencies();
575
+		} catch (EE_Error $e) {
576
+			$e->get_error();
577
+		}
578
+	}
579
+
580
+
581
+
582
+	/**
583
+	 * load_page_dependencies
584
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
585
+	 *
586
+	 * @access public
587
+	 * @return void
588
+	 */
589
+	protected function _load_page_dependencies()
590
+	{
591
+		//let's set the current_screen and screen options to override what WP set
592
+		$this->_current_screen = get_current_screen();
593
+		//load admin_notices - global, page class, and view specific
594
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
595
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
596
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
597
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
598
+		}
599
+		//load network admin_notices - global, page class, and view specific
600
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
601
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
602
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
603
+		}
604
+		//this will save any per_page screen options if they are present
605
+		$this->_set_per_page_screen_options();
606
+		//setup list table properties
607
+		$this->_set_list_table();
608
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
609
+		$this->_add_registered_meta_boxes();
610
+		$this->_add_screen_columns();
611
+		//add screen options - global, page child class, and view specific
612
+		$this->_add_global_screen_options();
613
+		$this->_add_screen_options();
614
+		if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
615
+			call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
616
+		}
617
+		//add help tab(s) and tours- set via page_config and qtips.
618
+		$this->_add_help_tour();
619
+		$this->_add_help_tabs();
620
+		$this->_add_qtips();
621
+		//add feature_pointers - global, page child class, and view specific
622
+		$this->_add_feature_pointers();
623
+		$this->_add_global_feature_pointers();
624
+		if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
625
+			call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
626
+		}
627
+		//enqueue scripts/styles - global, page class, and view specific
628
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
629
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
630
+		if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
631
+			add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
632
+		}
633
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
634
+		//admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
635
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
636
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
637
+		if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
638
+			add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
639
+		}
640
+		//admin footer scripts
641
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
642
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
643
+		if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
644
+			add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
645
+		}
646
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
647
+		//targeted hook
648
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
649
+	}
650
+
651
+
652
+
653
+	/**
654
+	 * _set_defaults
655
+	 * This sets some global defaults for class properties.
656
+	 */
657
+	private function _set_defaults()
658
+	{
659
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
660
+		$this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
661
+		$this->default_nav_tab_name = 'overview';
662
+		//init template args
663
+		$this->_template_args = array(
664
+				'admin_page_header'  => '',
665
+				'admin_page_content' => '',
666
+				'post_body_content'  => '',
667
+				'before_list_table'  => '',
668
+				'after_list_table'   => '',
669
+		);
670
+	}
671
+
672
+
673
+
674
+	/**
675
+	 * route_admin_request
676
+	 *
677
+	 * @see    _route_admin_request()
678
+	 * @access public
679
+	 * @return void|exception error
680
+	 */
681
+	public function route_admin_request()
682
+	{
683
+		try {
684
+			$this->_route_admin_request();
685
+		} catch (EE_Error $e) {
686
+			$e->get_error();
687
+		}
688
+	}
689
+
690
+
691
+
692
+	public function set_wp_page_slug($wp_page_slug)
693
+	{
694
+		$this->_wp_page_slug = $wp_page_slug;
695
+		//if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
696
+		if (is_network_admin()) {
697
+			$this->_wp_page_slug .= '-network';
698
+		}
699
+	}
700
+
701
+
702
+
703
+	/**
704
+	 * _verify_routes
705
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
706
+	 *
707
+	 * @access protected
708
+	 * @return void
709
+	 */
710
+	protected function _verify_routes()
711
+	{
712
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
713
+		if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
714
+			return false;
715
+		}
716
+		$this->_route = false;
717
+		$func = false;
718
+		$args = array();
719
+		// check that the page_routes array is not empty
720
+		if (empty($this->_page_routes)) {
721
+			// user error msg
722
+			$error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
723
+			// developer error msg
724
+			$error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
725
+			throw new EE_Error($error_msg);
726
+		}
727
+		// and that the requested page route exists
728
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
729
+			$this->_route = $this->_page_routes[$this->_req_action];
730
+			$this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
731
+		} else {
732
+			// user error msg
733
+			$error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
734
+			// developer error msg
735
+			$error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
736
+			throw new EE_Error($error_msg);
737
+		}
738
+		// and that a default route exists
739
+		if ( ! array_key_exists('default', $this->_page_routes)) {
740
+			// user error msg
741
+			$error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
742
+			// developer error msg
743
+			$error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
744
+			throw new EE_Error($error_msg);
745
+		}
746
+		//first lets' catch if the UI request has EVER been set.
747
+		if ($this->_is_UI_request === null) {
748
+			//lets set if this is a UI request or not.
749
+			$this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
750
+			//wait a minute... we might have a noheader in the route array
751
+			$this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
752
+		}
753
+		$this->_set_current_labels();
754
+	}
755
+
756
+
757
+
758
+	/**
759
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
760
+	 *
761
+	 * @param  string $route the route name we're verifying
762
+	 * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
763
+	 */
764
+	protected function _verify_route($route)
765
+	{
766
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
767
+			return true;
768
+		} else {
769
+			// user error msg
770
+			$error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
771
+			// developer error msg
772
+			$error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
773
+			throw new EE_Error($error_msg);
774
+		}
775
+	}
776
+
777
+
778
+
779
+	/**
780
+	 * perform nonce verification
781
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
782
+	 *
783
+	 * @param  string $nonce     The nonce sent
784
+	 * @param  string $nonce_ref The nonce reference string (name0)
785
+	 * @return mixed (bool|die)
786
+	 */
787
+	protected function _verify_nonce($nonce, $nonce_ref)
788
+	{
789
+		// verify nonce against expected value
790
+		if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
791
+			// these are not the droids you are looking for !!!
792
+			$msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
793
+			if (WP_DEBUG) {
794
+				$msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
795
+			}
796
+			if ( ! defined('DOING_AJAX')) {
797
+				wp_die($msg);
798
+			} else {
799
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
800
+				$this->_return_json();
801
+			}
802
+		}
803
+	}
804
+
805
+
806
+
807
+	/**
808
+	 * _route_admin_request()
809
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
810
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
811
+	 * in the page routes and then will try to load the corresponding method.
812
+	 *
813
+	 * @access protected
814
+	 * @return void
815
+	 * @throws \EE_Error
816
+	 */
817
+	protected function _route_admin_request()
818
+	{
819
+		if ( ! $this->_is_UI_request) {
820
+			$this->_verify_routes();
821
+		}
822
+		$nonce_check = isset($this->_route_config['require_nonce'])
823
+			? $this->_route_config['require_nonce']
824
+			: true;
825
+		if ($this->_req_action !== 'default' && $nonce_check) {
826
+			// set nonce from post data
827
+			$nonce = isset($this->_req_data[$this->_req_nonce])
828
+				? sanitize_text_field($this->_req_data[$this->_req_nonce])
829
+				: '';
830
+			$this->_verify_nonce($nonce, $this->_req_nonce);
831
+		}
832
+		//set the nav_tabs array but ONLY if this is  UI_request
833
+		if ($this->_is_UI_request) {
834
+			$this->_set_nav_tabs();
835
+		}
836
+		// grab callback function
837
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
838
+		// check if callback has args
839
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
840
+		$error_msg = '';
841
+		// action right before calling route
842
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
843
+		if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
844
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
845
+		}
846
+		// right before calling the route, let's remove _wp_http_referer from the
847
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
848
+		$_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
849
+		if ( ! empty($func)) {
850
+			if (is_array($func)) {
851
+				list($class, $method) = $func;
852
+			} else if (strpos($func, '::') !== false) {
853
+				list($class, $method) = explode('::', $func);
854
+			} else {
855
+				$class = $this;
856
+				$method = $func;
857
+			}
858
+			if ( ! (is_object($class) && $class === $this)) {
859
+				// send along this admin page object for access by addons.
860
+				$args['admin_page_object'] = $this;
861
+			}
862
+
863
+			if (
864
+				//is it a method on a class that doesn't work?
865
+				(
866
+					(
867
+						method_exists($class, $method)
868
+						&& call_user_func_array(array($class, $method), $args) === false
869
+					)
870
+					&& (
871
+						//is it a standalone function that doesn't work?
872
+						function_exists($method)
873
+						&& call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
874
+					)
875
+				)
876
+				|| (
877
+					//is it neither a class method NOR a standalone function?
878
+					! method_exists($class, $method)
879
+					&& ! function_exists($method)
880
+				)
881
+			) {
882
+				// user error msg
883
+				$error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
884
+				// developer error msg
885
+				$error_msg .= '||';
886
+				$error_msg .= sprintf(
887
+					__(
888
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
889
+						'event_espresso'
890
+					),
891
+					$method
892
+				);
893
+			}
894
+			if ( ! empty($error_msg)) {
895
+				throw new EE_Error($error_msg);
896
+			}
897
+		}
898
+		//if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
899
+		//now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
900
+		if ($this->_is_UI_request === false
901
+			&& is_array($this->_route)
902
+			&& ! empty($this->_route['headers_sent_route'])
903
+		) {
904
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
905
+		}
906
+	}
907
+
908
+
909
+
910
+	/**
911
+	 * This method just allows the resetting of page properties in the case where a no headers
912
+	 * route redirects to a headers route in its route config.
913
+	 *
914
+	 * @since   4.3.0
915
+	 * @param  string $new_route New (non header) route to redirect to.
916
+	 * @return   void
917
+	 */
918
+	protected function _reset_routing_properties($new_route)
919
+	{
920
+		$this->_is_UI_request = true;
921
+		//now we set the current route to whatever the headers_sent_route is set at
922
+		$this->_req_data['action'] = $new_route;
923
+		//rerun page setup
924
+		$this->_page_setup();
925
+	}
926
+
927
+
928
+
929
+	/**
930
+	 * _add_query_arg
931
+	 * adds nonce to array of arguments then calls WP add_query_arg function
932
+	 *(internally just uses EEH_URL's function with the same name)
933
+	 *
934
+	 * @access public
935
+	 * @param array  $args
936
+	 * @param string $url
937
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
938
+	 *                                        url in an associative array indexed by the key 'wp_referer';
939
+	 *                                        Example usage:
940
+	 *                                        If the current page is:
941
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
942
+	 *                                        &action=default&event_id=20&month_range=March%202015
943
+	 *                                        &_wpnonce=5467821
944
+	 *                                        and you call:
945
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
946
+	 *                                        array(
947
+	 *                                        'action' => 'resend_something',
948
+	 *                                        'page=>espresso_registrations'
949
+	 *                                        ),
950
+	 *                                        $some_url,
951
+	 *                                        true
952
+	 *                                        );
953
+	 *                                        It will produce a url in this structure:
954
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
955
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
956
+	 *                                        month_range]=March%202015
957
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
958
+	 * @return string
959
+	 */
960
+	public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
961
+	{
962
+		//if there is a _wp_http_referer include the values from the request but only if sticky = true
963
+		if ($sticky) {
964
+			$request = $_REQUEST;
965
+			unset($request['_wp_http_referer']);
966
+			unset($request['wp_referer']);
967
+			foreach ($request as $key => $value) {
968
+				//do not add nonces
969
+				if (strpos($key, 'nonce') !== false) {
970
+					continue;
971
+				}
972
+				$args['wp_referer[' . $key . ']'] = $value;
973
+			}
974
+		}
975
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
976
+	}
977
+
978
+
979
+
980
+	/**
981
+	 * This returns a generated link that will load the related help tab.
982
+	 *
983
+	 * @param  string $help_tab_id the id for the connected help tab
984
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
985
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
986
+	 * @uses EEH_Template::get_help_tab_link()
987
+	 * @return string              generated link
988
+	 */
989
+	protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
990
+	{
991
+		return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
992
+	}
993
+
994
+
995
+
996
+	/**
997
+	 * _add_help_tabs
998
+	 * Note child classes define their help tabs within the page_config array.
999
+	 *
1000
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1001
+	 * @access protected
1002
+	 * @return void
1003
+	 */
1004
+	protected function _add_help_tabs()
1005
+	{
1006
+		$tour_buttons = '';
1007
+		if (isset($this->_page_config[$this->_req_action])) {
1008
+			$config = $this->_page_config[$this->_req_action];
1009
+			//is there a help tour for the current route?  if there is let's setup the tour buttons
1010
+			if (isset($this->_help_tour[$this->_req_action])) {
1011
+				$tb = array();
1012
+				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1013
+				foreach ($this->_help_tour['tours'] as $tour) {
1014
+					//if this is the end tour then we don't need to setup a button
1015
+					if ($tour instanceof EE_Help_Tour_final_stop) {
1016
+						continue;
1017
+					}
1018
+					$tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1019
+				}
1020
+				$tour_buttons .= implode('<br />', $tb);
1021
+				$tour_buttons .= '</div></div>';
1022
+			}
1023
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1024
+			if (is_array($config) && isset($config['help_sidebar'])) {
1025
+				//check that the callback given is valid
1026
+				if ( ! method_exists($this, $config['help_sidebar'])) {
1027
+					throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1028
+							'event_espresso'), $config['help_sidebar'], get_class($this)));
1029
+				}
1030
+				$content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1031
+				$content .= $tour_buttons; //add help tour buttons.
1032
+				//do we have any help tours setup?  Cause if we do we want to add the buttons
1033
+				$this->_current_screen->set_help_sidebar($content);
1034
+			}
1035
+			//if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1036
+			if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1037
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1038
+			}
1039
+			//handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1040
+			if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1041
+				$_ht['id'] = $this->page_slug;
1042
+				$_ht['title'] = __('Help Tours', 'event_espresso');
1043
+				$_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1044
+				$this->_current_screen->add_help_tab($_ht);
1045
+			}/**/
1046
+			if ( ! isset($config['help_tabs'])) {
1047
+				return;
1048
+			} //no help tabs for this route
1049
+			foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1050
+				//we're here so there ARE help tabs!
1051
+				//make sure we've got what we need
1052
+				if ( ! isset($cfg['title'])) {
1053
+					throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1054
+				}
1055
+				if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1056
+					throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1057
+							'event_espresso'));
1058
+				}
1059
+				//first priority goes to content.
1060
+				if ( ! empty($cfg['content'])) {
1061
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1062
+					//second priority goes to filename
1063
+				} else if ( ! empty($cfg['filename'])) {
1064
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1065
+					//it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1066
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1067
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1068
+					if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1069
+						EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1070
+								'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1071
+						return;
1072
+					}
1073
+					$template_args['admin_page_obj'] = $this;
1074
+					$content = EEH_Template::display_template($file_path, $template_args, true);
1075
+				} else {
1076
+					$content = '';
1077
+				}
1078
+				//check if callback is valid
1079
+				if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1080
+					EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1081
+							'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1082
+					return;
1083
+				}
1084
+				//setup config array for help tab method
1085
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1086
+				$_ht = array(
1087
+						'id'       => $id,
1088
+						'title'    => $cfg['title'],
1089
+						'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1090
+						'content'  => $content,
1091
+				);
1092
+				$this->_current_screen->add_help_tab($_ht);
1093
+			}
1094
+		}
1095
+	}
1096
+
1097
+
1098
+
1099
+	/**
1100
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1101
+	 *
1102
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1103
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1104
+	 * @access protected
1105
+	 * @return void
1106
+	 */
1107
+	protected function _add_help_tour()
1108
+	{
1109
+		$tours = array();
1110
+		$this->_help_tour = array();
1111
+		//exit early if help tours are turned off globally
1112
+		if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1113
+			return;
1114
+		}
1115
+		//loop through _page_config to find any help_tour defined
1116
+		foreach ($this->_page_config as $route => $config) {
1117
+			//we're only going to set things up for this route
1118
+			if ($route !== $this->_req_action) {
1119
+				continue;
1120
+			}
1121
+			if (isset($config['help_tour'])) {
1122
+				foreach ($config['help_tour'] as $tour) {
1123
+					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1124
+					//let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1125
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1126
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1127
+					if ( ! is_readable($file_path)) {
1128
+						EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
1129
+								$file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1130
+						return;
1131
+					}
1132
+					require_once $file_path;
1133
+					if ( ! class_exists($tour)) {
1134
+						$error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1135
+						$error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1136
+										'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1137
+						throw new EE_Error(implode('||', $error_msg));
1138
+					}
1139
+					$a = new ReflectionClass($tour);
1140
+					$tour_obj = $a->newInstance($this->_is_caf);
1141
+					$tours[] = $tour_obj;
1142
+					$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1143
+				}
1144
+				//let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1145
+				$end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1146
+				$tours[] = $end_stop_tour;
1147
+				$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1148
+			}
1149
+		}
1150
+		if ( ! empty($tours)) {
1151
+			$this->_help_tour['tours'] = $tours;
1152
+		}
1153
+		//thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1154
+	}
1155
+
1156
+
1157
+
1158
+	/**
1159
+	 * This simply sets up any qtips that have been defined in the page config
1160
+	 *
1161
+	 * @access protected
1162
+	 * @return void
1163
+	 */
1164
+	protected function _add_qtips()
1165
+	{
1166
+		if (isset($this->_route_config['qtips'])) {
1167
+			$qtips = (array)$this->_route_config['qtips'];
1168
+			//load qtip loader
1169
+			$path = array(
1170
+					$this->_get_dir() . '/qtips/',
1171
+					EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1172
+			);
1173
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1174
+		}
1175
+	}
1176
+
1177
+
1178
+
1179
+	/**
1180
+	 * _set_nav_tabs
1181
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1182
+	 *
1183
+	 * @access protected
1184
+	 * @return void
1185
+	 */
1186
+	protected function _set_nav_tabs()
1187
+	{
1188
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1189
+		$i = 0;
1190
+		foreach ($this->_page_config as $slug => $config) {
1191
+			if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1192
+				continue;
1193
+			} //no nav tab for this config
1194
+			//check for persistent flag
1195
+			if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1196
+				continue;
1197
+			} //nav tab is only to appear when route requested.
1198
+			if ( ! $this->check_user_access($slug, true)) {
1199
+				continue;
1200
+			} //no nav tab becasue current user does not have access.
1201
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1202
+			$this->_nav_tabs[$slug] = array(
1203
+					'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1204
+					'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1205
+					'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1206
+					'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1207
+			);
1208
+			$i++;
1209
+		}
1210
+		//if $this->_nav_tabs is empty then lets set the default
1211
+		if (empty($this->_nav_tabs)) {
1212
+			$this->_nav_tabs[$this->default_nav_tab_name] = array(
1213
+					'url'       => $this->admin_base_url,
1214
+					'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1215
+					'css_class' => 'nav-tab-active',
1216
+					'order'     => 10,
1217
+			);
1218
+		}
1219
+		//now let's sort the tabs according to order
1220
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1221
+	}
1222
+
1223
+
1224
+
1225
+	/**
1226
+	 * _set_current_labels
1227
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1228
+	 *
1229
+	 * @access private
1230
+	 * @return void
1231
+	 */
1232
+	private function _set_current_labels()
1233
+	{
1234
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1235
+			foreach ($this->_route_config['labels'] as $label => $text) {
1236
+				if (is_array($text)) {
1237
+					foreach ($text as $sublabel => $subtext) {
1238
+						$this->_labels[$label][$sublabel] = $subtext;
1239
+					}
1240
+				} else {
1241
+					$this->_labels[$label] = $text;
1242
+				}
1243
+			}
1244
+		}
1245
+	}
1246
+
1247
+
1248
+
1249
+	/**
1250
+	 *        verifies user access for this admin page
1251
+	 *
1252
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1253
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1254
+	 * @return        BOOL|wp_die()
1255
+	 */
1256
+	public function check_user_access($route_to_check = '', $verify_only = false)
1257
+	{
1258
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1259
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1260
+		$capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1261
+				? $this->_page_routes[$route_to_check]['capability'] : null;
1262
+		if (empty($capability) && empty($route_to_check)) {
1263
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1264
+		} else {
1265
+			$capability = empty($capability) ? 'manage_options' : $capability;
1266
+		}
1267
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1268
+		if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1269
+			if ($verify_only) {
1270
+				return false;
1271
+			} else {
1272
+				if ( is_user_logged_in() ) {
1273
+					wp_die(__('You do not have access to this route.', 'event_espresso'));
1274
+				} else {
1275
+					return false;
1276
+				}
1277
+			}
1278
+		}
1279
+		return true;
1280
+	}
1281
+
1282
+
1283
+
1284
+	/**
1285
+	 * admin_init_global
1286
+	 * This runs all the code that we want executed within the WP admin_init hook.
1287
+	 * This method executes for ALL EE Admin pages.
1288
+	 *
1289
+	 * @access public
1290
+	 * @return void
1291
+	 */
1292
+	public function admin_init_global()
1293
+	{
1294
+	}
1295
+
1296
+
1297
+
1298
+	/**
1299
+	 * wp_loaded_global
1300
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1301
+	 *
1302
+	 * @access public
1303
+	 * @return void
1304
+	 */
1305
+	public function wp_loaded()
1306
+	{
1307
+	}
1308
+
1309
+
1310
+
1311
+	/**
1312
+	 * admin_notices
1313
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1314
+	 *
1315
+	 * @access public
1316
+	 * @return void
1317
+	 */
1318
+	public function admin_notices_global()
1319
+	{
1320
+		$this->_display_no_javascript_warning();
1321
+		$this->_display_espresso_notices();
1322
+	}
1323
+
1324
+
1325
+
1326
+	public function network_admin_notices_global()
1327
+	{
1328
+		$this->_display_no_javascript_warning();
1329
+		$this->_display_espresso_notices();
1330
+	}
1331
+
1332
+
1333
+
1334
+	/**
1335
+	 * admin_footer_scripts_global
1336
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1337
+	 *
1338
+	 * @access public
1339
+	 * @return void
1340
+	 */
1341
+	public function admin_footer_scripts_global()
1342
+	{
1343
+		$this->_add_admin_page_ajax_loading_img();
1344
+		$this->_add_admin_page_overlay();
1345
+		//if metaboxes are present we need to add the nonce field
1346
+		if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1347
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1348
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1349
+		}
1350
+	}
1351
+
1352
+
1353
+
1354
+	/**
1355
+	 * admin_footer_global
1356
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1357
+	 *
1358
+	 * @access  public
1359
+	 * @return  void
1360
+	 */
1361
+	public function admin_footer_global()
1362
+	{
1363
+		//dialog container for dialog helper
1364
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1365
+		$d_cont .= '<div class="ee-notices"></div>';
1366
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1367
+		$d_cont .= '</div>';
1368
+		echo $d_cont;
1369
+		//help tour stuff?
1370
+		if (isset($this->_help_tour[$this->_req_action])) {
1371
+			echo implode('<br />', $this->_help_tour[$this->_req_action]);
1372
+		}
1373
+		//current set timezone for timezone js
1374
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1375
+	}
1376
+
1377
+
1378
+
1379
+	/**
1380
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1381
+	 * For child classes:
1382
+	 * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1383
+	 * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1384
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1385
+	 *    'help_trigger_id' => array(
1386
+	 *        'title' => __('localized title for popup', 'event_espresso'),
1387
+	 *        'content' => __('localized content for popup', 'event_espresso')
1388
+	 *    )
1389
+	 * );
1390
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1391
+	 *
1392
+	 * @access protected
1393
+	 * @return string content
1394
+	 */
1395
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1396
+	{
1397
+		$content = '';
1398
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1399
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1400
+		//loop through the array and setup content
1401
+		foreach ($help_array as $trigger => $help) {
1402
+			//make sure the array is setup properly
1403
+			if ( ! isset($help['title']) || ! isset($help['content'])) {
1404
+				throw new EE_Error(__('Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1405
+						'event_espresso'));
1406
+			}
1407
+			//we're good so let'd setup the template vars and then assign parsed template content to our content.
1408
+			$template_args = array(
1409
+					'help_popup_id'      => $trigger,
1410
+					'help_popup_title'   => $help['title'],
1411
+					'help_popup_content' => $help['content'],
1412
+			);
1413
+			$content .= EEH_Template::display_template($template_path, $template_args, true);
1414
+		}
1415
+		if ($display) {
1416
+			echo $content;
1417
+		} else {
1418
+			return $content;
1419
+		}
1420
+	}
1421
+
1422
+
1423
+
1424
+	/**
1425
+	 * All this does is retrive the help content array if set by the EE_Admin_Page child
1426
+	 *
1427
+	 * @access private
1428
+	 * @return array properly formatted array for help popup content
1429
+	 */
1430
+	private function _get_help_content()
1431
+	{
1432
+		//what is the method we're looking for?
1433
+		$method_name = '_help_popup_content_' . $this->_req_action;
1434
+		//if method doesn't exist let's get out.
1435
+		if ( ! method_exists($this, $method_name)) {
1436
+			return array();
1437
+		}
1438
+		//k we're good to go let's retrieve the help array
1439
+		$help_array = call_user_func(array($this, $method_name));
1440
+		//make sure we've got an array!
1441
+		if ( ! is_array($help_array)) {
1442
+			throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1443
+		}
1444
+		return $help_array;
1445
+	}
1446
+
1447
+
1448
+
1449
+	/**
1450
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1451
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1452
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1453
+	 *
1454
+	 * @access protected
1455
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1456
+	 * @param boolean $display    if false then we return the trigger string
1457
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1458
+	 * @return string
1459
+	 */
1460
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1461
+	{
1462
+		if (defined('DOING_AJAX')) {
1463
+			return;
1464
+		}
1465
+		//let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1466
+		$help_array = $this->_get_help_content();
1467
+		$help_content = '';
1468
+		if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1469
+			$help_array[$trigger_id] = array(
1470
+					'title'   => __('Missing Content', 'event_espresso'),
1471
+					'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1472
+							'event_espresso'),
1473
+			);
1474
+			$help_content = $this->_set_help_popup_content($help_array, false);
1475
+		}
1476
+		//let's setup the trigger
1477
+		$content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1478
+		$content = $content . $help_content;
1479
+		if ($display) {
1480
+			echo $content;
1481
+		} else {
1482
+			return $content;
1483
+		}
1484
+	}
1485
+
1486
+
1487
+
1488
+	/**
1489
+	 * _add_global_screen_options
1490
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1491
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1492
+	 *
1493
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1494
+	 *         see also WP_Screen object documents...
1495
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1496
+	 * @abstract
1497
+	 * @access private
1498
+	 * @return void
1499
+	 */
1500
+	private function _add_global_screen_options()
1501
+	{
1502
+	}
1503
+
1504
+
1505
+
1506
+	/**
1507
+	 * _add_global_feature_pointers
1508
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1509
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1510
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1511
+	 *
1512
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1513
+	 * @link   http://eamann.com/tech/wordpress-portland/
1514
+	 * @abstract
1515
+	 * @access protected
1516
+	 * @return void
1517
+	 */
1518
+	private function _add_global_feature_pointers()
1519
+	{
1520
+	}
1521
+
1522
+
1523
+
1524
+	/**
1525
+	 * load_global_scripts_styles
1526
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1527
+	 *
1528
+	 * @return void
1529
+	 */
1530
+	public function load_global_scripts_styles()
1531
+	{
1532
+		/** STYLES **/
1533
+		// add debugging styles
1534
+		if (WP_DEBUG) {
1535
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1536
+		}
1537
+		// register all styles
1538
+		wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1539
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1540
+		//helpers styles
1541
+		wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1542
+		/** SCRIPTS **/
1543
+		//register all scripts
1544
+		wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1545
+		wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1546
+		wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1547
+		add_filter('FHEE_load_joyride', '__return_true');
1548
+		//script for sorting tables
1549
+		wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1550
+		//script for parsing uri's
1551
+		wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1552
+		//and parsing associative serialized form elements
1553
+		wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
+		//helpers scripts
1555
+		wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1556
+		wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1557
+		wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1558
+		wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1559
+		//google charts
1560
+		wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1561
+		// ENQUEUE ALL BASICS BY DEFAULT
1562
+		wp_enqueue_style('ee-admin-css');
1563
+		wp_enqueue_script('ee_admin_js');
1564
+		wp_enqueue_script('ee-accounting');
1565
+		wp_enqueue_script('jquery-validate');
1566
+		//taking care of metaboxes
1567
+		if (
1568
+			empty($this->_cpt_route)
1569
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1570
+		) {
1571
+			wp_enqueue_script('dashboard');
1572
+		}
1573
+		// LOCALIZED DATA
1574
+		//localize script for ajax lazy loading
1575
+		$lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1576
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1577
+		/**
1578
+		 * help tour stuff
1579
+		 */
1580
+		if ( ! empty($this->_help_tour)) {
1581
+			//register the js for kicking things off
1582
+			wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1583
+			//setup tours for the js tour object
1584
+			foreach ($this->_help_tour['tours'] as $tour) {
1585
+				$tours[] = array(
1586
+						'id'      => $tour->get_slug(),
1587
+						'options' => $tour->get_options(),
1588
+				);
1589
+			}
1590
+			wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1591
+			//admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1592
+		}
1593
+	}
1594
+
1595
+
1596
+
1597
+	/**
1598
+	 *        admin_footer_scripts_eei18n_js_strings
1599
+	 *
1600
+	 * @access        public
1601
+	 * @return        void
1602
+	 */
1603
+	public function admin_footer_scripts_eei18n_js_strings()
1604
+	{
1605
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1606
+		EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso');
1607
+		EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1608
+		EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1609
+		EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1610
+		EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1611
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1612
+		EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1613
+		EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1614
+		EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1615
+		EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1616
+		EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1617
+		EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1618
+		EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1619
+		EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1620
+		EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1621
+		EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1622
+		EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1623
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1624
+		EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1625
+		EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1626
+		EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1627
+		EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1628
+		EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1629
+		EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1630
+		EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1631
+		EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1632
+		EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1633
+		EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1634
+		EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1635
+		EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1636
+		EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1637
+		EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1638
+		EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1639
+		EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1640
+		EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1641
+		EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1642
+		EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1643
+		EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1644
+		EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1645
+	}
1646
+
1647
+
1648
+
1649
+	/**
1650
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1651
+	 *
1652
+	 * @access        public
1653
+	 * @return        void
1654
+	 */
1655
+	public function add_xdebug_style()
1656
+	{
1657
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1658
+	}
1659
+
1660
+
1661
+	/************************/
1662
+	/** LIST TABLE METHODS **/
1663
+	/************************/
1664
+	/**
1665
+	 * this sets up the list table if the current view requires it.
1666
+	 *
1667
+	 * @access protected
1668
+	 * @return void
1669
+	 */
1670
+	protected function _set_list_table()
1671
+	{
1672
+		//first is this a list_table view?
1673
+		if ( ! isset($this->_route_config['list_table'])) {
1674
+			return;
1675
+		} //not a list_table view so get out.
1676
+		//list table functions are per view specific (because some admin pages might have more than one listtable!)
1677
+		if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1678
+			//user error msg
1679
+			$error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1680
+			//developer error msg
1681
+			$error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1682
+							$this->_req_action, '_set_list_table_views_' . $this->_req_action);
1683
+			throw new EE_Error($error_msg);
1684
+		}
1685
+		//let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1686
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1687
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1688
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1689
+		$this->_set_list_table_view();
1690
+		$this->_set_list_table_object();
1691
+	}
1692
+
1693
+
1694
+
1695
+	/**
1696
+	 *        set current view for List Table
1697
+	 *
1698
+	 * @access public
1699
+	 * @return array
1700
+	 */
1701
+	protected function _set_list_table_view()
1702
+	{
1703
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1704
+		// looking at active items or dumpster diving ?
1705
+		if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1706
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1707
+		} else {
1708
+			$this->_view = sanitize_key($this->_req_data['status']);
1709
+		}
1710
+	}
1711
+
1712
+
1713
+
1714
+	/**
1715
+	 * _set_list_table_object
1716
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1717
+	 *
1718
+	 * @throws \EE_Error
1719
+	 */
1720
+	protected function _set_list_table_object()
1721
+	{
1722
+		if (isset($this->_route_config['list_table'])) {
1723
+			if ( ! class_exists($this->_route_config['list_table'])) {
1724
+				throw new EE_Error(
1725
+						sprintf(
1726
+								__(
1727
+										'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1728
+										'event_espresso'
1729
+								),
1730
+								$this->_route_config['list_table'],
1731
+								get_class($this)
1732
+						)
1733
+				);
1734
+			}
1735
+			$list_table = $this->_route_config['list_table'];
1736
+			$this->_list_table_object = new $list_table($this);
1737
+		}
1738
+	}
1739
+
1740
+
1741
+
1742
+	/**
1743
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1744
+	 *
1745
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1746
+	 *                                                    urls.  The array should be indexed by the view it is being
1747
+	 *                                                    added to.
1748
+	 * @return array
1749
+	 */
1750
+	public function get_list_table_view_RLs($extra_query_args = array())
1751
+	{
1752
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1753
+		if (empty($this->_views)) {
1754
+			$this->_views = array();
1755
+		}
1756
+		// cycle thru views
1757
+		foreach ($this->_views as $key => $view) {
1758
+			$query_args = array();
1759
+			// check for current view
1760
+			$this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1761
+			$query_args['action'] = $this->_req_action;
1762
+			$query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1763
+			$query_args['status'] = $view['slug'];
1764
+			//merge any other arguments sent in.
1765
+			if (isset($extra_query_args[$view['slug']])) {
1766
+				$query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1767
+			}
1768
+			$this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1769
+		}
1770
+		return $this->_views;
1771
+	}
1772
+
1773
+
1774
+
1775
+	/**
1776
+	 * _entries_per_page_dropdown
1777
+	 * generates a drop down box for selecting the number of visiable rows in an admin page list table
1778
+	 *
1779
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1780
+	 * @access protected
1781
+	 * @param int $max_entries total number of rows in the table
1782
+	 * @return string
1783
+	 */
1784
+	protected function _entries_per_page_dropdown($max_entries = false)
1785
+	{
1786
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1787
+		$values = array(10, 25, 50, 100);
1788
+		$per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1789
+		if ($max_entries) {
1790
+			$values[] = $max_entries;
1791
+			sort($values);
1792
+		}
1793
+		$entries_per_page_dropdown = '
1794 1794
 			<div id="entries-per-page-dv" class="alignleft actions">
1795 1795
 				<label class="hide-if-no-js">
1796 1796
 					Show
1797 1797
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1798
-        foreach ($values as $value) {
1799
-            if ($value < $max_entries) {
1800
-                $selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1801
-                $entries_per_page_dropdown .= '
1798
+		foreach ($values as $value) {
1799
+			if ($value < $max_entries) {
1800
+				$selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1801
+				$entries_per_page_dropdown .= '
1802 1802
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
1803
-            }
1804
-        }
1805
-        $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1806
-        $entries_per_page_dropdown .= '
1803
+			}
1804
+		}
1805
+		$selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1806
+		$entries_per_page_dropdown .= '
1807 1807
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
1808
-        $entries_per_page_dropdown .= '
1808
+		$entries_per_page_dropdown .= '
1809 1809
 					</select>
1810 1810
 					entries
1811 1811
 				</label>
1812 1812
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
1813 1813
 			</div>
1814 1814
 		';
1815
-        return $entries_per_page_dropdown;
1816
-    }
1817
-
1818
-
1819
-
1820
-    /**
1821
-     *        _set_search_attributes
1822
-     *
1823
-     * @access        protected
1824
-     * @return        void
1825
-     */
1826
-    public function _set_search_attributes()
1827
-    {
1828
-        $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1829
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1830
-    }
1831
-
1832
-    /*** END LIST TABLE METHODS **/
1833
-    /*****************************/
1834
-    /**
1835
-     *        _add_registered_metaboxes
1836
-     *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1837
-     *
1838
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1839
-     * @access private
1840
-     * @return void
1841
-     */
1842
-    private function _add_registered_meta_boxes()
1843
-    {
1844
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1845
-        //we only add meta boxes if the page_route calls for it
1846
-        if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1847
-            && is_array(
1848
-                    $this->_route_config['metaboxes']
1849
-            )
1850
-        ) {
1851
-            // this simply loops through the callbacks provided
1852
-            // and checks if there is a corresponding callback registered by the child
1853
-            // if there is then we go ahead and process the metabox loader.
1854
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1855
-                // first check for Closures
1856
-                if ($metabox_callback instanceof Closure) {
1857
-                    $result = $metabox_callback();
1858
-                } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1859
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1860
-                } else {
1861
-                    $result = call_user_func(array($this, &$metabox_callback));
1862
-                }
1863
-                if ($result === false) {
1864
-                    // user error msg
1865
-                    $error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1866
-                    // developer error msg
1867
-                    $error_msg .= '||' . sprintf(
1868
-                                    __(
1869
-                                            'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1870
-                                            'event_espresso'
1871
-                                    ),
1872
-                                    $metabox_callback
1873
-                            );
1874
-                    throw new EE_Error($error_msg);
1875
-                }
1876
-            }
1877
-        }
1878
-    }
1879
-
1880
-
1881
-
1882
-    /**
1883
-     * _add_screen_columns
1884
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1885
-     *
1886
-     * @access private
1887
-     * @return void
1888
-     */
1889
-    private function _add_screen_columns()
1890
-    {
1891
-        if (
1892
-                is_array($this->_route_config)
1893
-                && isset($this->_route_config['columns'])
1894
-                && is_array($this->_route_config['columns'])
1895
-                && count($this->_route_config['columns']) === 2
1896
-        ) {
1897
-            add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1898
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1899
-            $screen_id = $this->_current_screen->id;
1900
-            $screen_columns = (int)get_user_option("screen_layout_$screen_id");
1901
-            $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1902
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1903
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
1904
-            $this->_template_args['screen'] = $this->_current_screen;
1905
-            $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1906
-            //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1907
-            $this->_route_config['has_metaboxes'] = true;
1908
-        }
1909
-    }
1910
-
1911
-
1912
-
1913
-    /**********************************/
1914
-    /** GLOBALLY AVAILABLE METABOXES **/
1915
-    /**
1916
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1917
-     * loaded on.
1918
-     */
1919
-    private function _espresso_news_post_box()
1920
-    {
1921
-        $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1922
-        add_meta_box('espresso_news_post_box', $news_box_title, array(
1923
-                $this,
1924
-                'espresso_news_post_box',
1925
-        ), $this->_wp_page_slug, 'side');
1926
-    }
1927
-
1928
-
1929
-
1930
-    /**
1931
-     * Code for setting up espresso ratings request metabox.
1932
-     */
1933
-    protected function _espresso_ratings_request()
1934
-    {
1935
-        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1936
-            return '';
1937
-        }
1938
-        $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1939
-        add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1940
-                $this,
1941
-                'espresso_ratings_request',
1942
-        ), $this->_wp_page_slug, 'side');
1943
-    }
1944
-
1945
-
1946
-
1947
-    /**
1948
-     * Code for setting up espresso ratings request metabox content.
1949
-     */
1950
-    public function espresso_ratings_request()
1951
-    {
1952
-        $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1953
-        EEH_Template::display_template($template_path, array());
1954
-    }
1955
-
1956
-
1957
-
1958
-    public static function cached_rss_display($rss_id, $url)
1959
-    {
1960
-        $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1961
-        $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1962
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
1963
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1964
-        $post = '</div>' . "\n";
1965
-        $cache_key = 'ee_rss_' . md5($rss_id);
1966
-        if (false != ($output = get_transient($cache_key))) {
1967
-            echo $pre . $output . $post;
1968
-            return true;
1969
-        }
1970
-        if ( ! $doing_ajax) {
1971
-            echo $pre . $loading . $post;
1972
-            return false;
1973
-        }
1974
-        ob_start();
1975
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1976
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1977
-        return true;
1978
-    }
1979
-
1980
-
1981
-
1982
-    public function espresso_news_post_box()
1983
-    {
1984
-        ?>
1815
+		return $entries_per_page_dropdown;
1816
+	}
1817
+
1818
+
1819
+
1820
+	/**
1821
+	 *        _set_search_attributes
1822
+	 *
1823
+	 * @access        protected
1824
+	 * @return        void
1825
+	 */
1826
+	public function _set_search_attributes()
1827
+	{
1828
+		$this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1829
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1830
+	}
1831
+
1832
+	/*** END LIST TABLE METHODS **/
1833
+	/*****************************/
1834
+	/**
1835
+	 *        _add_registered_metaboxes
1836
+	 *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1837
+	 *
1838
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1839
+	 * @access private
1840
+	 * @return void
1841
+	 */
1842
+	private function _add_registered_meta_boxes()
1843
+	{
1844
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1845
+		//we only add meta boxes if the page_route calls for it
1846
+		if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1847
+			&& is_array(
1848
+					$this->_route_config['metaboxes']
1849
+			)
1850
+		) {
1851
+			// this simply loops through the callbacks provided
1852
+			// and checks if there is a corresponding callback registered by the child
1853
+			// if there is then we go ahead and process the metabox loader.
1854
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1855
+				// first check for Closures
1856
+				if ($metabox_callback instanceof Closure) {
1857
+					$result = $metabox_callback();
1858
+				} else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1859
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1860
+				} else {
1861
+					$result = call_user_func(array($this, &$metabox_callback));
1862
+				}
1863
+				if ($result === false) {
1864
+					// user error msg
1865
+					$error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1866
+					// developer error msg
1867
+					$error_msg .= '||' . sprintf(
1868
+									__(
1869
+											'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1870
+											'event_espresso'
1871
+									),
1872
+									$metabox_callback
1873
+							);
1874
+					throw new EE_Error($error_msg);
1875
+				}
1876
+			}
1877
+		}
1878
+	}
1879
+
1880
+
1881
+
1882
+	/**
1883
+	 * _add_screen_columns
1884
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1885
+	 *
1886
+	 * @access private
1887
+	 * @return void
1888
+	 */
1889
+	private function _add_screen_columns()
1890
+	{
1891
+		if (
1892
+				is_array($this->_route_config)
1893
+				&& isset($this->_route_config['columns'])
1894
+				&& is_array($this->_route_config['columns'])
1895
+				&& count($this->_route_config['columns']) === 2
1896
+		) {
1897
+			add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1898
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1899
+			$screen_id = $this->_current_screen->id;
1900
+			$screen_columns = (int)get_user_option("screen_layout_$screen_id");
1901
+			$total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1902
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1903
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
1904
+			$this->_template_args['screen'] = $this->_current_screen;
1905
+			$this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1906
+			//finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1907
+			$this->_route_config['has_metaboxes'] = true;
1908
+		}
1909
+	}
1910
+
1911
+
1912
+
1913
+	/**********************************/
1914
+	/** GLOBALLY AVAILABLE METABOXES **/
1915
+	/**
1916
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1917
+	 * loaded on.
1918
+	 */
1919
+	private function _espresso_news_post_box()
1920
+	{
1921
+		$news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1922
+		add_meta_box('espresso_news_post_box', $news_box_title, array(
1923
+				$this,
1924
+				'espresso_news_post_box',
1925
+		), $this->_wp_page_slug, 'side');
1926
+	}
1927
+
1928
+
1929
+
1930
+	/**
1931
+	 * Code for setting up espresso ratings request metabox.
1932
+	 */
1933
+	protected function _espresso_ratings_request()
1934
+	{
1935
+		if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1936
+			return '';
1937
+		}
1938
+		$ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1939
+		add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1940
+				$this,
1941
+				'espresso_ratings_request',
1942
+		), $this->_wp_page_slug, 'side');
1943
+	}
1944
+
1945
+
1946
+
1947
+	/**
1948
+	 * Code for setting up espresso ratings request metabox content.
1949
+	 */
1950
+	public function espresso_ratings_request()
1951
+	{
1952
+		$template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1953
+		EEH_Template::display_template($template_path, array());
1954
+	}
1955
+
1956
+
1957
+
1958
+	public static function cached_rss_display($rss_id, $url)
1959
+	{
1960
+		$loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1961
+		$doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1962
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
1963
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1964
+		$post = '</div>' . "\n";
1965
+		$cache_key = 'ee_rss_' . md5($rss_id);
1966
+		if (false != ($output = get_transient($cache_key))) {
1967
+			echo $pre . $output . $post;
1968
+			return true;
1969
+		}
1970
+		if ( ! $doing_ajax) {
1971
+			echo $pre . $loading . $post;
1972
+			return false;
1973
+		}
1974
+		ob_start();
1975
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1976
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1977
+		return true;
1978
+	}
1979
+
1980
+
1981
+
1982
+	public function espresso_news_post_box()
1983
+	{
1984
+		?>
1985 1985
         <div class="padding">
1986 1986
             <div id="espresso_news_post_box_content" class="infolinks">
1987 1987
                 <?php
1988
-                // Get RSS Feed(s)
1989
-                $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1990
-                $url = urlencode($feed_url);
1991
-                self::cached_rss_display('espresso_news_post_box_content', $url);
1992
-                ?>
1988
+				// Get RSS Feed(s)
1989
+				$feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1990
+				$url = urlencode($feed_url);
1991
+				self::cached_rss_display('espresso_news_post_box_content', $url);
1992
+				?>
1993 1993
             </div>
1994 1994
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
1995 1995
         </div>
1996 1996
         <?php
1997
-    }
1998
-
1999
-
2000
-
2001
-    private function _espresso_links_post_box()
2002
-    {
2003
-        //Hiding until we actually have content to put in here...
2004
-        //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2005
-    }
2006
-
2007
-
2008
-
2009
-    public function espresso_links_post_box()
2010
-    {
2011
-        //Hiding until we actually have content to put in here...
2012
-        //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2013
-        //EEH_Template::display_template( $templatepath );
2014
-    }
2015
-
2016
-
2017
-
2018
-    protected function _espresso_sponsors_post_box()
2019
-    {
2020
-        $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2021
-        if ($show_sponsors) {
2022
-            add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2023
-        }
2024
-    }
2025
-
2026
-
2027
-
2028
-    public function espresso_sponsors_post_box()
2029
-    {
2030
-        $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2031
-        EEH_Template::display_template($templatepath);
2032
-    }
2033
-
2034
-
2035
-
2036
-    private function _publish_post_box()
2037
-    {
2038
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2039
-        //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2040
-        if ( ! empty($this->_labels['publishbox'])) {
2041
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2042
-        } else {
2043
-            $box_label = __('Publish', 'event_espresso');
2044
-        }
2045
-        $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2046
-        add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2047
-    }
2048
-
2049
-
2050
-
2051
-    public function editor_overview()
2052
-    {
2053
-        //if we have extra content set let's add it in if not make sure its empty
2054
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2055
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2056
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2057
-    }
2058
-
2059
-
2060
-    /** end of globally available metaboxes section **/
2061
-    /*************************************************/
2062
-    /**
2063
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2064
-     * protected method.
2065
-     *
2066
-     * @see   $this->_set_publish_post_box_vars for param details
2067
-     * @since 4.6.0
2068
-     */
2069
-    public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2070
-    {
2071
-        $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2072
-    }
2073
-
2074
-
2075
-
2076
-    /**
2077
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2078
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2079
-     * save, and save and close buttons to work properly, then you will want to include a
2080
-     * values for the name and id arguments.
2081
-     *
2082
-     * @todo  Add in validation for name/id arguments.
2083
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2084
-     * @param    int     $id                      id attached to the item published
2085
-     * @param    string  $delete                  page route callback for the delete action
2086
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2087
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2088
-     * @throws \EE_Error
2089
-     */
2090
-    protected function _set_publish_post_box_vars(
2091
-            $name = '',
2092
-            $id = 0,
2093
-            $delete = '',
2094
-            $save_close_redirect_URL = '',
2095
-            $both_btns = true
2096
-    ) {
2097
-        // if Save & Close, use a custom redirect URL or default to the main page?
2098
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2099
-        // create the Save & Close and Save buttons
2100
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2101
-        //if we have extra content set let's add it in if not make sure its empty
2102
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2103
-        if ($delete && ! empty($id)) {
2104
-            //make sure we have a default if just true is sent.
2105
-            $delete = ! empty($delete) ? $delete : 'delete';
2106
-            $delete_link_args = array($name => $id);
2107
-            $delete = $this->get_action_link_or_button(
2108
-                    $delete,
2109
-                    $delete,
2110
-                    $delete_link_args,
2111
-                    'submitdelete deletion',
2112
-                    '',
2113
-                    false
2114
-            );
2115
-        }
2116
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2117
-        if ( ! empty($name) && ! empty($id)) {
2118
-            $hidden_field_arr[$name] = array(
2119
-                    'type'  => 'hidden',
2120
-                    'value' => $id,
2121
-            );
2122
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2123
-        } else {
2124
-            $hf = '';
2125
-        }
2126
-        // add hidden field
2127
-        $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2128
-    }
2129
-
2130
-
2131
-
2132
-    /**
2133
-     *        displays an error message to ppl who have javascript disabled
2134
-     *
2135
-     * @access        private
2136
-     * @return        string
2137
-     */
2138
-    private function _display_no_javascript_warning()
2139
-    {
2140
-        ?>
1997
+	}
1998
+
1999
+
2000
+
2001
+	private function _espresso_links_post_box()
2002
+	{
2003
+		//Hiding until we actually have content to put in here...
2004
+		//add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2005
+	}
2006
+
2007
+
2008
+
2009
+	public function espresso_links_post_box()
2010
+	{
2011
+		//Hiding until we actually have content to put in here...
2012
+		//$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2013
+		//EEH_Template::display_template( $templatepath );
2014
+	}
2015
+
2016
+
2017
+
2018
+	protected function _espresso_sponsors_post_box()
2019
+	{
2020
+		$show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2021
+		if ($show_sponsors) {
2022
+			add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2023
+		}
2024
+	}
2025
+
2026
+
2027
+
2028
+	public function espresso_sponsors_post_box()
2029
+	{
2030
+		$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2031
+		EEH_Template::display_template($templatepath);
2032
+	}
2033
+
2034
+
2035
+
2036
+	private function _publish_post_box()
2037
+	{
2038
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2039
+		//if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2040
+		if ( ! empty($this->_labels['publishbox'])) {
2041
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2042
+		} else {
2043
+			$box_label = __('Publish', 'event_espresso');
2044
+		}
2045
+		$box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2046
+		add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2047
+	}
2048
+
2049
+
2050
+
2051
+	public function editor_overview()
2052
+	{
2053
+		//if we have extra content set let's add it in if not make sure its empty
2054
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2055
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2056
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2057
+	}
2058
+
2059
+
2060
+	/** end of globally available metaboxes section **/
2061
+	/*************************************************/
2062
+	/**
2063
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2064
+	 * protected method.
2065
+	 *
2066
+	 * @see   $this->_set_publish_post_box_vars for param details
2067
+	 * @since 4.6.0
2068
+	 */
2069
+	public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2070
+	{
2071
+		$this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2072
+	}
2073
+
2074
+
2075
+
2076
+	/**
2077
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2078
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2079
+	 * save, and save and close buttons to work properly, then you will want to include a
2080
+	 * values for the name and id arguments.
2081
+	 *
2082
+	 * @todo  Add in validation for name/id arguments.
2083
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2084
+	 * @param    int     $id                      id attached to the item published
2085
+	 * @param    string  $delete                  page route callback for the delete action
2086
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2087
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2088
+	 * @throws \EE_Error
2089
+	 */
2090
+	protected function _set_publish_post_box_vars(
2091
+			$name = '',
2092
+			$id = 0,
2093
+			$delete = '',
2094
+			$save_close_redirect_URL = '',
2095
+			$both_btns = true
2096
+	) {
2097
+		// if Save & Close, use a custom redirect URL or default to the main page?
2098
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2099
+		// create the Save & Close and Save buttons
2100
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2101
+		//if we have extra content set let's add it in if not make sure its empty
2102
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2103
+		if ($delete && ! empty($id)) {
2104
+			//make sure we have a default if just true is sent.
2105
+			$delete = ! empty($delete) ? $delete : 'delete';
2106
+			$delete_link_args = array($name => $id);
2107
+			$delete = $this->get_action_link_or_button(
2108
+					$delete,
2109
+					$delete,
2110
+					$delete_link_args,
2111
+					'submitdelete deletion',
2112
+					'',
2113
+					false
2114
+			);
2115
+		}
2116
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2117
+		if ( ! empty($name) && ! empty($id)) {
2118
+			$hidden_field_arr[$name] = array(
2119
+					'type'  => 'hidden',
2120
+					'value' => $id,
2121
+			);
2122
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2123
+		} else {
2124
+			$hf = '';
2125
+		}
2126
+		// add hidden field
2127
+		$this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2128
+	}
2129
+
2130
+
2131
+
2132
+	/**
2133
+	 *        displays an error message to ppl who have javascript disabled
2134
+	 *
2135
+	 * @access        private
2136
+	 * @return        string
2137
+	 */
2138
+	private function _display_no_javascript_warning()
2139
+	{
2140
+		?>
2141 2141
         <noscript>
2142 2142
             <div id="no-js-message" class="error">
2143 2143
                 <p style="font-size:1.3em;">
@@ -2147,1267 +2147,1267 @@  discard block
 block discarded – undo
2147 2147
             </div>
2148 2148
         </noscript>
2149 2149
         <?php
2150
-    }
2150
+	}
2151 2151
 
2152 2152
 
2153 2153
 
2154
-    /**
2155
-     *        displays espresso success and/or error notices
2156
-     *
2157
-     * @access        private
2158
-     * @return        string
2159
-     */
2160
-    private function _display_espresso_notices()
2161
-    {
2162
-        $notices = $this->_get_transient(true);
2163
-        echo stripslashes($notices);
2164
-    }
2154
+	/**
2155
+	 *        displays espresso success and/or error notices
2156
+	 *
2157
+	 * @access        private
2158
+	 * @return        string
2159
+	 */
2160
+	private function _display_espresso_notices()
2161
+	{
2162
+		$notices = $this->_get_transient(true);
2163
+		echo stripslashes($notices);
2164
+	}
2165 2165
 
2166 2166
 
2167 2167
 
2168
-    /**
2169
-     *        spinny things pacify the masses
2170
-     *
2171
-     * @access private
2172
-     * @return string
2173
-     */
2174
-    protected function _add_admin_page_ajax_loading_img()
2175
-    {
2176
-        ?>
2168
+	/**
2169
+	 *        spinny things pacify the masses
2170
+	 *
2171
+	 * @access private
2172
+	 * @return string
2173
+	 */
2174
+	protected function _add_admin_page_ajax_loading_img()
2175
+	{
2176
+		?>
2177 2177
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2178 2178
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e('loading...', 'event_espresso'); ?></span>
2179 2179
         </div>
2180 2180
         <?php
2181
-    }
2181
+	}
2182 2182
 
2183 2183
 
2184 2184
 
2185
-    /**
2186
-     *        add admin page overlay for modal boxes
2187
-     *
2188
-     * @access private
2189
-     * @return string
2190
-     */
2191
-    protected function _add_admin_page_overlay()
2192
-    {
2193
-        ?>
2185
+	/**
2186
+	 *        add admin page overlay for modal boxes
2187
+	 *
2188
+	 * @access private
2189
+	 * @return string
2190
+	 */
2191
+	protected function _add_admin_page_overlay()
2192
+	{
2193
+		?>
2194 2194
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2195 2195
         <?php
2196
-    }
2197
-
2198
-
2199
-
2200
-    /**
2201
-     * facade for add_meta_box
2202
-     *
2203
-     * @param string  $action        where the metabox get's displayed
2204
-     * @param string  $title         Title of Metabox (output in metabox header)
2205
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2206
-     * @param array   $callback_args an array of args supplied for the metabox
2207
-     * @param string  $column        what metabox column
2208
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2209
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2210
-     */
2211
-    public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2212
-    {
2213
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2214
-        //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2215
-        if (empty($callback_args) && $create_func) {
2216
-            $callback_args = array(
2217
-                    'template_path' => $this->_template_path,
2218
-                    'template_args' => $this->_template_args,
2219
-            );
2220
-        }
2221
-        //if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2222
-        $call_back_func = $create_func ? create_function('$post, $metabox',
2223
-                'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2224
-        add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2225
-    }
2226
-
2227
-
2228
-
2229
-    /**
2230
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2231
-     *
2232
-     * @return [type] [description]
2233
-     */
2234
-    public function display_admin_page_with_metabox_columns()
2235
-    {
2236
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2237
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2238
-        //the final wrapper
2239
-        $this->admin_page_wrapper();
2240
-    }
2241
-
2242
-
2243
-
2244
-    /**
2245
-     *        generates  HTML wrapper for an admin details page
2246
-     *
2247
-     * @access public
2248
-     * @return void
2249
-     */
2250
-    public function display_admin_page_with_sidebar()
2251
-    {
2252
-        $this->_display_admin_page(true);
2253
-    }
2254
-
2255
-
2256
-
2257
-    /**
2258
-     *        generates  HTML wrapper for an admin details page (except no sidebar)
2259
-     *
2260
-     * @access public
2261
-     * @return void
2262
-     */
2263
-    public function display_admin_page_with_no_sidebar()
2264
-    {
2265
-        $this->_display_admin_page();
2266
-    }
2267
-
2268
-
2269
-
2270
-    /**
2271
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2272
-     *
2273
-     * @access public
2274
-     * @return void
2275
-     */
2276
-    public function display_about_admin_page()
2277
-    {
2278
-        $this->_display_admin_page(false, true);
2279
-    }
2280
-
2281
-
2282
-
2283
-    /**
2284
-     * display_admin_page
2285
-     * contains the code for actually displaying an admin page
2286
-     *
2287
-     * @access private
2288
-     * @param  boolean $sidebar true with sidebar, false without
2289
-     * @param  boolean $about   use the about admin wrapper instead of the default.
2290
-     * @return void
2291
-     */
2292
-    private function _display_admin_page($sidebar = false, $about = false)
2293
-    {
2294
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2295
-        //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2296
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2297
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2298
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2299
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2300
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2301
-                ? 'poststuff'
2302
-                : 'espresso-default-admin';
2303
-        $template_path = $sidebar
2304
-                ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2305
-                : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2306
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2307
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2308
-        }
2309
-        $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2310
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2311
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2312
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2313
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2314
-        // the final template wrapper
2315
-        $this->admin_page_wrapper($about);
2316
-    }
2317
-
2318
-
2319
-
2320
-    /**
2321
-     * This is used to display caf preview pages.
2322
-     *
2323
-     * @since 4.3.2
2324
-     * @param string $utm_campaign_source what is the key used for google analytics link
2325
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2326
-     * @return void
2327
-     * @throws \EE_Error
2328
-     */
2329
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2330
-    {
2331
-        //let's generate a default preview action button if there isn't one already present.
2332
-        $this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2333
-        $buy_now_url = add_query_arg(
2334
-                array(
2335
-                        'ee_ver'       => 'ee4',
2336
-                        'utm_source'   => 'ee4_plugin_admin',
2337
-                        'utm_medium'   => 'link',
2338
-                        'utm_campaign' => $utm_campaign_source,
2339
-                        'utm_content'  => 'buy_now_button',
2340
-                ),
2341
-                'http://eventespresso.com/pricing/'
2342
-        );
2343
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2344
-                ? $this->get_action_link_or_button(
2345
-                        '',
2346
-                        'buy_now',
2347
-                        array(),
2348
-                        'button-primary button-large',
2349
-                        $buy_now_url,
2350
-                        true
2351
-                )
2352
-                : $this->_template_args['preview_action_button'];
2353
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2354
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2355
-                $template_path,
2356
-                $this->_template_args,
2357
-                true
2358
-        );
2359
-        $this->_display_admin_page($display_sidebar);
2360
-    }
2361
-
2362
-
2363
-
2364
-    /**
2365
-     * display_admin_list_table_page_with_sidebar
2366
-     * generates HTML wrapper for an admin_page with list_table
2367
-     *
2368
-     * @access public
2369
-     * @return void
2370
-     */
2371
-    public function display_admin_list_table_page_with_sidebar()
2372
-    {
2373
-        $this->_display_admin_list_table_page(true);
2374
-    }
2375
-
2376
-
2377
-
2378
-    /**
2379
-     * display_admin_list_table_page_with_no_sidebar
2380
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2381
-     *
2382
-     * @access public
2383
-     * @return void
2384
-     */
2385
-    public function display_admin_list_table_page_with_no_sidebar()
2386
-    {
2387
-        $this->_display_admin_list_table_page();
2388
-    }
2389
-
2390
-
2391
-
2392
-    /**
2393
-     * generates html wrapper for an admin_list_table page
2394
-     *
2395
-     * @access private
2396
-     * @param boolean $sidebar whether to display with sidebar or not.
2397
-     * @return void
2398
-     */
2399
-    private function _display_admin_list_table_page($sidebar = false)
2400
-    {
2401
-        //setup search attributes
2402
-        $this->_set_search_attributes();
2403
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2404
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2405
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
2406
-                ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2407
-                : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2408
-        $this->_template_args['list_table'] = $this->_list_table_object;
2409
-        $this->_template_args['current_route'] = $this->_req_action;
2410
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2411
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2412
-        if ( ! empty($ajax_sorting_callback)) {
2413
-            $sortable_list_table_form_fields = wp_nonce_field(
2414
-                    $ajax_sorting_callback . '_nonce',
2415
-                    $ajax_sorting_callback . '_nonce',
2416
-                    false,
2417
-                    false
2418
-            );
2419
-            //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2420
-            //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2421
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2422
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2423
-        } else {
2424
-            $sortable_list_table_form_fields = '';
2425
-        }
2426
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2427
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2428
-        $nonce_ref = $this->_req_action . '_nonce';
2429
-        $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2430
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2431
-        //display message about search results?
2432
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2433
-                ? '<p class="ee-search-results">' . sprintf(
2434
-                        esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2435
-                        trim($this->_req_data['s'], '%')
2436
-                ) . '</p>'
2437
-                : '';
2438
-        // filter before_list_table template arg
2439
-        $this->_template_args['before_list_table'] = apply_filters(
2440
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2441
-            $this->_template_args['before_list_table'],
2442
-            $this->page_slug,
2443
-            $this->_req_data,
2444
-            $this->_req_action
2445
-        );
2446
-        // convert to array and filter again
2447
-        // arrays are easier to inject new items in a specific location,
2448
-        // but would not be backwards compatible, so we have to add a new filter
2449
-        $this->_template_args['before_list_table'] = implode(
2450
-            " \n",
2451
-            (array) apply_filters(
2452
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2453
-                (array) $this->_template_args['before_list_table'],
2454
-                $this->page_slug,
2455
-                $this->_req_data,
2456
-                $this->_req_action
2457
-            )
2458
-        );
2459
-        // filter after_list_table template arg
2460
-        $this->_template_args['after_list_table'] = apply_filters(
2461
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2462
-            $this->_template_args['after_list_table'],
2463
-            $this->page_slug,
2464
-            $this->_req_data,
2465
-            $this->_req_action
2466
-        );
2467
-        // convert to array and filter again
2468
-        // arrays are easier to inject new items in a specific location,
2469
-        // but would not be backwards compatible, so we have to add a new filter
2470
-        $this->_template_args['after_list_table'] = implode(
2471
-            " \n",
2472
-            (array) apply_filters(
2473
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2474
-                (array) $this->_template_args['after_list_table'],
2475
-                $this->page_slug,
2476
-                $this->_req_data,
2477
-                $this->_req_action
2478
-            )
2479
-        );
2480
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2481
-                $template_path,
2482
-                $this->_template_args,
2483
-                true
2484
-        );
2485
-        // the final template wrapper
2486
-        if ($sidebar) {
2487
-            $this->display_admin_page_with_sidebar();
2488
-        } else {
2489
-            $this->display_admin_page_with_no_sidebar();
2490
-        }
2491
-    }
2492
-
2493
-
2494
-
2495
-    /**
2496
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2497
-     * $items are expected in an array in the following format:
2498
-     * $legend_items = array(
2499
-     *        'item_id' => array(
2500
-     *            'icon' => 'http://url_to_icon_being_described.png',
2501
-     *            'desc' => __('localized description of item');
2502
-     *        )
2503
-     * );
2504
-     *
2505
-     * @param  array $items see above for format of array
2506
-     * @return string        html string of legend
2507
-     */
2508
-    protected function _display_legend($items)
2509
-    {
2510
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2511
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2512
-        return EEH_Template::display_template($legend_template, $this->_template_args, true);
2513
-    }
2514
-
2515
-
2516
-    /**
2517
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2518
-     * The returned json object is created from an array in the following format:
2519
-     * array(
2520
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2521
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
2522
-     *  'notices' => '', // - contains any EE_Error formatted notices
2523
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2524
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2525
-     *  specific template args that might be included in here)
2526
-     * )
2527
-     * The json object is populated by whatever is set in the $_template_args property.
2528
-     *
2529
-     * @param bool  $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2530
-     * @param array $notices_arguments  Use this to pass any additional args on to the _process_notices.
2531
-     * @return void
2532
-     */
2533
-    protected function _return_json($sticky_notices = false, $notices_arguments = array())
2534
-    {
2535
-        //make sure any EE_Error notices have been handled.
2536
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
2537
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2538
-        unset($this->_template_args['data']);
2539
-        $json = array(
2540
-                'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2541
-                'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2542
-                'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2543
-                'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2544
-                'notices'   => EE_Error::get_notices(),
2545
-                'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2546
-                'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2547
-                'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2548
-        );
2549
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
2550
-        if (null === error_get_last() || ! headers_sent()) {
2551
-            header('Content-Type: application/json; charset=UTF-8');
2552
-        }
2553
-        echo wp_json_encode($json);
2554
-
2555
-        exit();
2556
-    }
2557
-
2558
-
2559
-
2560
-    /**
2561
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2562
-     *
2563
-     * @return void
2564
-     * @throws EE_Error
2565
-     */
2566
-    public function return_json()
2567
-    {
2568
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2569
-            $this->_return_json();
2570
-        } else {
2571
-            throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2572
-        }
2573
-    }
2574
-
2575
-
2576
-
2577
-    /**
2578
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2579
-     *
2580
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2581
-     * @access   public
2582
-     */
2583
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
2584
-    {
2585
-        $this->_hook_obj = $hook_obj;
2586
-    }
2587
-
2588
-
2589
-
2590
-    /**
2591
-     *        generates  HTML wrapper with Tabbed nav for an admin page
2592
-     *
2593
-     * @access public
2594
-     * @param  boolean $about whether to use the special about page wrapper or default.
2595
-     * @return void
2596
-     */
2597
-    public function admin_page_wrapper($about = false)
2598
-    {
2599
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2600
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
2601
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2602
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2603
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2604
-                isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2605
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2606
-                isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2607
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2608
-        // load settings page wrapper template
2609
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2610
-        //about page?
2611
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2612
-        if (defined('DOING_AJAX')) {
2613
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2614
-            $this->_return_json();
2615
-        } else {
2616
-            EEH_Template::display_template($template_path, $this->_template_args);
2617
-        }
2618
-    }
2619
-
2620
-
2621
-
2622
-    /**
2623
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2624
-     *
2625
-     * @return string html
2626
-     */
2627
-    protected function _get_main_nav_tabs()
2628
-    {
2629
-        //let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2630
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2631
-    }
2632
-
2633
-
2634
-
2635
-    /**
2636
-     *        sort nav tabs
2637
-     *
2638
-     * @access public
2639
-     * @param $a
2640
-     * @param $b
2641
-     * @return int
2642
-     */
2643
-    private function _sort_nav_tabs($a, $b)
2644
-    {
2645
-        if ($a['order'] == $b['order']) {
2646
-            return 0;
2647
-        }
2648
-        return ($a['order'] < $b['order']) ? -1 : 1;
2649
-    }
2650
-
2651
-
2652
-
2653
-    /**
2654
-     *    generates HTML for the forms used on admin pages
2655
-     *
2656
-     * @access protected
2657
-     * @param    array $input_vars - array of input field details
2658
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2659
-     * @return string
2660
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2661
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2662
-     */
2663
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2664
-    {
2665
-        $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2666
-        return $content;
2667
-    }
2668
-
2669
-
2670
-
2671
-    /**
2672
-     * generates the "Save" and "Save & Close" buttons for edit forms
2673
-     *
2674
-     * @access protected
2675
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2676
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2677
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2678
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2679
-     */
2680
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2681
-    {
2682
-        //make sure $text and $actions are in an array
2683
-        $text = (array)$text;
2684
-        $actions = (array)$actions;
2685
-        $referrer_url = empty($referrer) ? '' : $referrer;
2686
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2687
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2688
-        $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2689
-        $default_names = array('save', 'save_and_close');
2690
-        //add in a hidden index for the current page (so save and close redirects properly)
2691
-        $this->_template_args['save_buttons'] = $referrer_url;
2692
-        foreach ($button_text as $key => $button) {
2693
-            $ref = $default_names[$key];
2694
-            $id = $this->_current_view . '_' . $ref;
2695
-            $name = ! empty($actions) ? $actions[$key] : $ref;
2696
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2697
-            if ( ! $both) {
2698
-                break;
2699
-            }
2700
-        }
2701
-    }
2702
-
2703
-
2704
-
2705
-    /**
2706
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2707
-     *
2708
-     * @see   $this->_set_add_edit_form_tags() for details on params
2709
-     * @since 4.6.0
2710
-     * @param string $route
2711
-     * @param array  $additional_hidden_fields
2712
-     */
2713
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2714
-    {
2715
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2716
-    }
2717
-
2718
-
2719
-
2720
-    /**
2721
-     * set form open and close tags on add/edit pages.
2722
-     *
2723
-     * @access protected
2724
-     * @param string $route                    the route you want the form to direct to
2725
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2726
-     * @return void
2727
-     */
2728
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2729
-    {
2730
-        if (empty($route)) {
2731
-            $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2732
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2733
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2734
-        }
2735
-        // open form
2736
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2737
-        // add nonce
2738
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2739
-        //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2740
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2741
-        // add REQUIRED form action
2742
-        $hidden_fields = array(
2743
-                'action' => array('type' => 'hidden', 'value' => $route),
2744
-        );
2745
-        // merge arrays
2746
-        $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2747
-        // generate form fields
2748
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2749
-        // add fields to form
2750
-        foreach ((array)$form_fields as $field_name => $form_field) {
2751
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2752
-        }
2753
-        // close form
2754
-        $this->_template_args['after_admin_page_content'] = '</form>';
2755
-    }
2756
-
2757
-
2758
-
2759
-    /**
2760
-     * Public Wrapper for _redirect_after_action() method since its
2761
-     * discovered it would be useful for external code to have access.
2762
-     *
2763
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
2764
-     * @since 4.5.0
2765
-     */
2766
-    public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2767
-    {
2768
-        $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2769
-    }
2770
-
2771
-
2772
-
2773
-    /**
2774
-     *    _redirect_after_action
2775
-     *
2776
-     * @param int    $success            - whether success was for two or more records, or just one, or none
2777
-     * @param string $what               - what the action was performed on
2778
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
2779
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2780
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2781
-     * @access protected
2782
-     * @return void
2783
-     */
2784
-    protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2785
-    {
2786
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2787
-        //class name for actions/filters.
2788
-        $classname = get_class($this);
2789
-        //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2790
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2791
-        $notices = EE_Error::get_notices(false);
2792
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
2793
-        if ( ! $override_overwrite || ! empty($notices['errors'])) {
2794
-            EE_Error::overwrite_success();
2795
-        }
2796
-        if ( ! empty($what) && ! empty($action_desc)) {
2797
-            // how many records affected ? more than one record ? or just one ?
2798
-            if ($success > 1 && empty($notices['errors'])) {
2799
-                // set plural msg
2800
-                EE_Error::add_success(
2801
-                        sprintf(
2802
-                                __('The "%s" have been successfully %s.', 'event_espresso'),
2803
-                                $what,
2804
-                                $action_desc
2805
-                        ),
2806
-                        __FILE__, __FUNCTION__, __LINE__
2807
-                );
2808
-            } else if ($success == 1 && empty($notices['errors'])) {
2809
-                // set singular msg
2810
-                EE_Error::add_success(
2811
-                        sprintf(
2812
-                                __('The "%s" has been successfully %s.', 'event_espresso'),
2813
-                                $what,
2814
-                                $action_desc
2815
-                        ),
2816
-                        __FILE__, __FUNCTION__, __LINE__
2817
-                );
2818
-            }
2819
-        }
2820
-        // check that $query_args isn't something crazy
2821
-        if ( ! is_array($query_args)) {
2822
-            $query_args = array();
2823
-        }
2824
-        /**
2825
-         * Allow injecting actions before the query_args are modified for possible different
2826
-         * redirections on save and close actions
2827
-         *
2828
-         * @since 4.2.0
2829
-         * @param array $query_args       The original query_args array coming into the
2830
-         *                                method.
2831
-         */
2832
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2833
-        //calculate where we're going (if we have a "save and close" button pushed)
2834
-        if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2835
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2836
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2837
-            // regenerate query args array from referrer URL
2838
-            parse_str($parsed_url['query'], $query_args);
2839
-            // correct page and action will be in the query args now
2840
-            $redirect_url = admin_url('admin.php');
2841
-        }
2842
-        //merge any default query_args set in _default_route_query_args property
2843
-        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2844
-            $args_to_merge = array();
2845
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
2846
-                //is there a wp_referer array in our _default_route_query_args property?
2847
-                if ($query_param == 'wp_referer') {
2848
-                    $query_value = (array)$query_value;
2849
-                    foreach ($query_value as $reference => $value) {
2850
-                        if (strpos($reference, 'nonce') !== false) {
2851
-                            continue;
2852
-                        }
2853
-                        //finally we will override any arguments in the referer with
2854
-                        //what might be set on the _default_route_query_args array.
2855
-                        if (isset($this->_default_route_query_args[$reference])) {
2856
-                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2857
-                        } else {
2858
-                            $args_to_merge[$reference] = urlencode($value);
2859
-                        }
2860
-                    }
2861
-                    continue;
2862
-                }
2863
-                $args_to_merge[$query_param] = $query_value;
2864
-            }
2865
-            //now let's merge these arguments but override with what was specifically sent in to the
2866
-            //redirect.
2867
-            $query_args = array_merge($args_to_merge, $query_args);
2868
-        }
2869
-        $this->_process_notices($query_args);
2870
-        // generate redirect url
2871
-        // if redirecting to anything other than the main page, add a nonce
2872
-        if (isset($query_args['action'])) {
2873
-            // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2874
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2875
-        }
2876
-        //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2877
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2878
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2879
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2880
-        if (defined('DOING_AJAX')) {
2881
-            $default_data = array(
2882
-                    'close'        => true,
2883
-                    'redirect_url' => $redirect_url,
2884
-                    'where'        => 'main',
2885
-                    'what'         => 'append',
2886
-            );
2887
-            $this->_template_args['success'] = $success;
2888
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2889
-            $this->_return_json();
2890
-        }
2891
-        wp_safe_redirect($redirect_url);
2892
-        exit();
2893
-    }
2894
-
2895
-
2896
-
2897
-    /**
2898
-     * process any notices before redirecting (or returning ajax request)
2899
-     * This method sets the $this->_template_args['notices'] attribute;
2900
-     *
2901
-     * @param  array $query_args        any query args that need to be used for notice transient ('action')
2902
-     * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2903
-     * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2904
-     * @return void
2905
-     */
2906
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2907
-    {
2908
-        //first let's set individual error properties if doing_ajax and the properties aren't already set.
2909
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2910
-            $notices = EE_Error::get_notices(false);
2911
-            if (empty($this->_template_args['success'])) {
2912
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2913
-            }
2914
-            if (empty($this->_template_args['errors'])) {
2915
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2916
-            }
2917
-            if (empty($this->_template_args['attention'])) {
2918
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2919
-            }
2920
-        }
2921
-        $this->_template_args['notices'] = EE_Error::get_notices();
2922
-        //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2923
-        if ( ! defined('DOING_AJAX') || $sticky_notices) {
2924
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
2925
-            $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2926
-        }
2927
-    }
2928
-
2929
-
2930
-
2931
-    /**
2932
-     * get_action_link_or_button
2933
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
2934
-     *
2935
-     * @param string $action        use this to indicate which action the url is generated with.
2936
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2937
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2938
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2939
-     * @param string $base_url      If this is not provided
2940
-     *                              the _admin_base_url will be used as the default for the button base_url.
2941
-     *                              Otherwise this value will be used.
2942
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2943
-     * @return string
2944
-     * @throws \EE_Error
2945
-     */
2946
-    public function get_action_link_or_button(
2947
-            $action,
2948
-            $type = 'add',
2949
-            $extra_request = array(),
2950
-            $class = 'button-primary',
2951
-            $base_url = '',
2952
-            $exclude_nonce = false
2953
-    ) {
2954
-        //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2955
-        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2956
-            throw new EE_Error(
2957
-                    sprintf(
2958
-                            __(
2959
-                                    'There is no page route for given action for the button.  This action was given: %s',
2960
-                                    'event_espresso'
2961
-                            ),
2962
-                            $action
2963
-                    )
2964
-            );
2965
-        }
2966
-        if ( ! isset($this->_labels['buttons'][$type])) {
2967
-            throw new EE_Error(
2968
-                    sprintf(
2969
-                            __(
2970
-                                    'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2971
-                                    'event_espresso'
2972
-                            ),
2973
-                            $type
2974
-                    )
2975
-            );
2976
-        }
2977
-        //finally check user access for this button.
2978
-        $has_access = $this->check_user_access($action, true);
2979
-        if ( ! $has_access) {
2980
-            return '';
2981
-        }
2982
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2983
-        $query_args = array(
2984
-                'action' => $action,
2985
-        );
2986
-        //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2987
-        if ( ! empty($extra_request)) {
2988
-            $query_args = array_merge($extra_request, $query_args);
2989
-        }
2990
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2991
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2992
-    }
2993
-
2994
-
2995
-
2996
-    /**
2997
-     * _per_page_screen_option
2998
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
2999
-     *
3000
-     * @return void
3001
-     */
3002
-    protected function _per_page_screen_option()
3003
-    {
3004
-        $option = 'per_page';
3005
-        $args = array(
3006
-                'label'   => $this->_admin_page_title,
3007
-                'default' => 10,
3008
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3009
-        );
3010
-        //ONLY add the screen option if the user has access to it.
3011
-        if ($this->check_user_access($this->_current_view, true)) {
3012
-            add_screen_option($option, $args);
3013
-        }
3014
-    }
3015
-
3016
-
3017
-
3018
-    /**
3019
-     * set_per_page_screen_option
3020
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3021
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3022
-     *
3023
-     * @access private
3024
-     * @return void
3025
-     */
3026
-    private function _set_per_page_screen_options()
3027
-    {
3028
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3029
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3030
-            if ( ! $user = wp_get_current_user()) {
3031
-                return;
3032
-            }
3033
-            $option = $_POST['wp_screen_options']['option'];
3034
-            $value = $_POST['wp_screen_options']['value'];
3035
-            if ($option != sanitize_key($option)) {
3036
-                return;
3037
-            }
3038
-            $map_option = $option;
3039
-            $option = str_replace('-', '_', $option);
3040
-            switch ($map_option) {
3041
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3042
-                    $value = (int)$value;
3043
-                    if ($value < 1 || $value > 999) {
3044
-                        return;
3045
-                    }
3046
-                    break;
3047
-                default:
3048
-                    $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3049
-                    if (false === $value) {
3050
-                        return;
3051
-                    }
3052
-                    break;
3053
-            }
3054
-            update_user_meta($user->ID, $option, $value);
3055
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3056
-            exit;
3057
-        }
3058
-    }
3059
-
3060
-
3061
-
3062
-    /**
3063
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3064
-     *
3065
-     * @param array $data array that will be assigned to template args.
3066
-     */
3067
-    public function set_template_args($data)
3068
-    {
3069
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3070
-    }
3071
-
3072
-
3073
-
3074
-    /**
3075
-     * This makes available the WP transient system for temporarily moving data between routes
3076
-     *
3077
-     * @access protected
3078
-     * @param string $route             the route that should receive the transient
3079
-     * @param array  $data              the data that gets sent
3080
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3081
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3082
-     * @return void
3083
-     */
3084
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3085
-    {
3086
-        $user_id = get_current_user_id();
3087
-        if ( ! $skip_route_verify) {
3088
-            $this->_verify_route($route);
3089
-        }
3090
-        //now let's set the string for what kind of transient we're setting
3091
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3092
-        $data = $notices ? array('notices' => $data) : $data;
3093
-        //is there already a transient for this route?  If there is then let's ADD to that transient
3094
-        $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3095
-        if ($existing) {
3096
-            $data = array_merge((array)$data, (array)$existing);
3097
-        }
3098
-        if (is_multisite() && is_network_admin()) {
3099
-            set_site_transient($transient, $data, 8);
3100
-        } else {
3101
-            set_transient($transient, $data, 8);
3102
-        }
3103
-    }
3104
-
3105
-
3106
-
3107
-    /**
3108
-     * this retrieves the temporary transient that has been set for moving data between routes.
3109
-     *
3110
-     * @param bool $notices true we get notices transient. False we just return normal route transient
3111
-     * @return mixed data
3112
-     */
3113
-    protected function _get_transient($notices = false, $route = false)
3114
-    {
3115
-        $user_id = get_current_user_id();
3116
-        $route = ! $route ? $this->_req_action : $route;
3117
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3118
-        $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3119
-        //delete transient after retrieval (just in case it hasn't expired);
3120
-        if (is_multisite() && is_network_admin()) {
3121
-            delete_site_transient($transient);
3122
-        } else {
3123
-            delete_transient($transient);
3124
-        }
3125
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3126
-    }
3127
-
3128
-
3129
-
3130
-    /**
3131
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3132
-     * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3133
-     *
3134
-     * @return void
3135
-     */
3136
-    protected function _transient_garbage_collection()
3137
-    {
3138
-        global $wpdb;
3139
-        //retrieve all existing transients
3140
-        $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3141
-        if ($results = $wpdb->get_results($query)) {
3142
-            foreach ($results as $result) {
3143
-                $transient = str_replace('_transient_', '', $result->option_name);
3144
-                get_transient($transient);
3145
-                if (is_multisite() && is_network_admin()) {
3146
-                    get_site_transient($transient);
3147
-                }
3148
-            }
3149
-        }
3150
-    }
3151
-
3152
-
3153
-
3154
-    /**
3155
-     * get_view
3156
-     *
3157
-     * @access public
3158
-     * @return string content of _view property
3159
-     */
3160
-    public function get_view()
3161
-    {
3162
-        return $this->_view;
3163
-    }
3164
-
3165
-
3166
-
3167
-    /**
3168
-     * getter for the protected $_views property
3169
-     *
3170
-     * @return array
3171
-     */
3172
-    public function get_views()
3173
-    {
3174
-        return $this->_views;
3175
-    }
3176
-
3177
-
3178
-
3179
-    /**
3180
-     * get_current_page
3181
-     *
3182
-     * @access public
3183
-     * @return string _current_page property value
3184
-     */
3185
-    public function get_current_page()
3186
-    {
3187
-        return $this->_current_page;
3188
-    }
3189
-
3190
-
3191
-
3192
-    /**
3193
-     * get_current_view
3194
-     *
3195
-     * @access public
3196
-     * @return string _current_view property value
3197
-     */
3198
-    public function get_current_view()
3199
-    {
3200
-        return $this->_current_view;
3201
-    }
3202
-
3203
-
3204
-
3205
-    /**
3206
-     * get_current_screen
3207
-     *
3208
-     * @access public
3209
-     * @return object The current WP_Screen object
3210
-     */
3211
-    public function get_current_screen()
3212
-    {
3213
-        return $this->_current_screen;
3214
-    }
3215
-
3216
-
3217
-
3218
-    /**
3219
-     * get_current_page_view_url
3220
-     *
3221
-     * @access public
3222
-     * @return string This returns the url for the current_page_view.
3223
-     */
3224
-    public function get_current_page_view_url()
3225
-    {
3226
-        return $this->_current_page_view_url;
3227
-    }
3228
-
3229
-
3230
-
3231
-    /**
3232
-     * just returns the _req_data property
3233
-     *
3234
-     * @return array
3235
-     */
3236
-    public function get_request_data()
3237
-    {
3238
-        return $this->_req_data;
3239
-    }
3240
-
3241
-
3242
-
3243
-    /**
3244
-     * returns the _req_data protected property
3245
-     *
3246
-     * @return string
3247
-     */
3248
-    public function get_req_action()
3249
-    {
3250
-        return $this->_req_action;
3251
-    }
3252
-
3253
-
3254
-
3255
-    /**
3256
-     * @return bool  value of $_is_caf property
3257
-     */
3258
-    public function is_caf()
3259
-    {
3260
-        return $this->_is_caf;
3261
-    }
3262
-
3263
-
3264
-
3265
-    /**
3266
-     * @return mixed
3267
-     */
3268
-    public function default_espresso_metaboxes()
3269
-    {
3270
-        return $this->_default_espresso_metaboxes;
3271
-    }
3272
-
3273
-
3274
-
3275
-    /**
3276
-     * @return mixed
3277
-     */
3278
-    public function admin_base_url()
3279
-    {
3280
-        return $this->_admin_base_url;
3281
-    }
3282
-
3283
-
3284
-
3285
-    /**
3286
-     * @return mixed
3287
-     */
3288
-    public function wp_page_slug()
3289
-    {
3290
-        return $this->_wp_page_slug;
3291
-    }
3292
-
3293
-
3294
-
3295
-    /**
3296
-     * updates  espresso configuration settings
3297
-     *
3298
-     * @access    protected
3299
-     * @param string                   $tab
3300
-     * @param EE_Config_Base|EE_Config $config
3301
-     * @param string                   $file file where error occurred
3302
-     * @param string                   $func function  where error occurred
3303
-     * @param string                   $line line no where error occurred
3304
-     * @return boolean
3305
-     */
3306
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3307
-    {
3308
-        //remove any options that are NOT going to be saved with the config settings.
3309
-        if (isset($config->core->ee_ueip_optin)) {
3310
-            $config->core->ee_ueip_has_notified = true;
3311
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3312
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3313
-            update_option('ee_ueip_has_notified', true);
3314
-        }
3315
-        // and save it (note we're also doing the network save here)
3316
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3317
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3318
-        if ($config_saved && $net_saved) {
3319
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3320
-            return true;
3321
-        } else {
3322
-            EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3323
-            return false;
3324
-        }
3325
-    }
3326
-
3327
-
3328
-
3329
-    /**
3330
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3331
-     *
3332
-     * @return array
3333
-     */
3334
-    public function get_yes_no_values()
3335
-    {
3336
-        return $this->_yes_no_values;
3337
-    }
3338
-
3339
-
3340
-
3341
-    protected function _get_dir()
3342
-    {
3343
-        $reflector = new ReflectionClass(get_class($this));
3344
-        return dirname($reflector->getFileName());
3345
-    }
3346
-
3347
-
3348
-
3349
-    /**
3350
-     * A helper for getting a "next link".
3351
-     *
3352
-     * @param string $url   The url to link to
3353
-     * @param string $class The class to use.
3354
-     * @return string
3355
-     */
3356
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3357
-    {
3358
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3359
-    }
3360
-
3361
-
3362
-
3363
-    /**
3364
-     * A helper for getting a "previous link".
3365
-     *
3366
-     * @param string $url   The url to link to
3367
-     * @param string $class The class to use.
3368
-     * @return string
3369
-     */
3370
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3371
-    {
3372
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3373
-    }
3374
-
3375
-
3376
-
3377
-
3378
-
3379
-
3380
-
3381
-    //below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3382
-    /**
3383
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data
3384
-     * array.
3385
-     *
3386
-     * @return bool success/fail
3387
-     */
3388
-    protected function _process_resend_registration()
3389
-    {
3390
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3391
-        do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3392
-        return $this->_template_args['success'];
3393
-    }
3394
-
3395
-
3396
-
3397
-    /**
3398
-     * This automatically processes any payment message notifications when manual payment has been applied.
3399
-     *
3400
-     * @access protected
3401
-     * @param \EE_Payment $payment
3402
-     * @return bool success/fail
3403
-     */
3404
-    protected function _process_payment_notification(EE_Payment $payment)
3405
-    {
3406
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3407
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3408
-        $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3409
-        return $this->_template_args['success'];
3410
-    }
2196
+	}
2197
+
2198
+
2199
+
2200
+	/**
2201
+	 * facade for add_meta_box
2202
+	 *
2203
+	 * @param string  $action        where the metabox get's displayed
2204
+	 * @param string  $title         Title of Metabox (output in metabox header)
2205
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2206
+	 * @param array   $callback_args an array of args supplied for the metabox
2207
+	 * @param string  $column        what metabox column
2208
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2209
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2210
+	 */
2211
+	public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2212
+	{
2213
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2214
+		//if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2215
+		if (empty($callback_args) && $create_func) {
2216
+			$callback_args = array(
2217
+					'template_path' => $this->_template_path,
2218
+					'template_args' => $this->_template_args,
2219
+			);
2220
+		}
2221
+		//if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2222
+		$call_back_func = $create_func ? create_function('$post, $metabox',
2223
+				'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2224
+		add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2225
+	}
2226
+
2227
+
2228
+
2229
+	/**
2230
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2231
+	 *
2232
+	 * @return [type] [description]
2233
+	 */
2234
+	public function display_admin_page_with_metabox_columns()
2235
+	{
2236
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2237
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2238
+		//the final wrapper
2239
+		$this->admin_page_wrapper();
2240
+	}
2241
+
2242
+
2243
+
2244
+	/**
2245
+	 *        generates  HTML wrapper for an admin details page
2246
+	 *
2247
+	 * @access public
2248
+	 * @return void
2249
+	 */
2250
+	public function display_admin_page_with_sidebar()
2251
+	{
2252
+		$this->_display_admin_page(true);
2253
+	}
2254
+
2255
+
2256
+
2257
+	/**
2258
+	 *        generates  HTML wrapper for an admin details page (except no sidebar)
2259
+	 *
2260
+	 * @access public
2261
+	 * @return void
2262
+	 */
2263
+	public function display_admin_page_with_no_sidebar()
2264
+	{
2265
+		$this->_display_admin_page();
2266
+	}
2267
+
2268
+
2269
+
2270
+	/**
2271
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2272
+	 *
2273
+	 * @access public
2274
+	 * @return void
2275
+	 */
2276
+	public function display_about_admin_page()
2277
+	{
2278
+		$this->_display_admin_page(false, true);
2279
+	}
2280
+
2281
+
2282
+
2283
+	/**
2284
+	 * display_admin_page
2285
+	 * contains the code for actually displaying an admin page
2286
+	 *
2287
+	 * @access private
2288
+	 * @param  boolean $sidebar true with sidebar, false without
2289
+	 * @param  boolean $about   use the about admin wrapper instead of the default.
2290
+	 * @return void
2291
+	 */
2292
+	private function _display_admin_page($sidebar = false, $about = false)
2293
+	{
2294
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2295
+		//custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2296
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2297
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2298
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2299
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2300
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2301
+				? 'poststuff'
2302
+				: 'espresso-default-admin';
2303
+		$template_path = $sidebar
2304
+				? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2305
+				: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2306
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2307
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2308
+		}
2309
+		$template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2310
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2311
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2312
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2313
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2314
+		// the final template wrapper
2315
+		$this->admin_page_wrapper($about);
2316
+	}
2317
+
2318
+
2319
+
2320
+	/**
2321
+	 * This is used to display caf preview pages.
2322
+	 *
2323
+	 * @since 4.3.2
2324
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2325
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2326
+	 * @return void
2327
+	 * @throws \EE_Error
2328
+	 */
2329
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2330
+	{
2331
+		//let's generate a default preview action button if there isn't one already present.
2332
+		$this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2333
+		$buy_now_url = add_query_arg(
2334
+				array(
2335
+						'ee_ver'       => 'ee4',
2336
+						'utm_source'   => 'ee4_plugin_admin',
2337
+						'utm_medium'   => 'link',
2338
+						'utm_campaign' => $utm_campaign_source,
2339
+						'utm_content'  => 'buy_now_button',
2340
+				),
2341
+				'http://eventespresso.com/pricing/'
2342
+		);
2343
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2344
+				? $this->get_action_link_or_button(
2345
+						'',
2346
+						'buy_now',
2347
+						array(),
2348
+						'button-primary button-large',
2349
+						$buy_now_url,
2350
+						true
2351
+				)
2352
+				: $this->_template_args['preview_action_button'];
2353
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2354
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2355
+				$template_path,
2356
+				$this->_template_args,
2357
+				true
2358
+		);
2359
+		$this->_display_admin_page($display_sidebar);
2360
+	}
2361
+
2362
+
2363
+
2364
+	/**
2365
+	 * display_admin_list_table_page_with_sidebar
2366
+	 * generates HTML wrapper for an admin_page with list_table
2367
+	 *
2368
+	 * @access public
2369
+	 * @return void
2370
+	 */
2371
+	public function display_admin_list_table_page_with_sidebar()
2372
+	{
2373
+		$this->_display_admin_list_table_page(true);
2374
+	}
2375
+
2376
+
2377
+
2378
+	/**
2379
+	 * display_admin_list_table_page_with_no_sidebar
2380
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2381
+	 *
2382
+	 * @access public
2383
+	 * @return void
2384
+	 */
2385
+	public function display_admin_list_table_page_with_no_sidebar()
2386
+	{
2387
+		$this->_display_admin_list_table_page();
2388
+	}
2389
+
2390
+
2391
+
2392
+	/**
2393
+	 * generates html wrapper for an admin_list_table page
2394
+	 *
2395
+	 * @access private
2396
+	 * @param boolean $sidebar whether to display with sidebar or not.
2397
+	 * @return void
2398
+	 */
2399
+	private function _display_admin_list_table_page($sidebar = false)
2400
+	{
2401
+		//setup search attributes
2402
+		$this->_set_search_attributes();
2403
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2404
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2405
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
2406
+				? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2407
+				: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2408
+		$this->_template_args['list_table'] = $this->_list_table_object;
2409
+		$this->_template_args['current_route'] = $this->_req_action;
2410
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2411
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2412
+		if ( ! empty($ajax_sorting_callback)) {
2413
+			$sortable_list_table_form_fields = wp_nonce_field(
2414
+					$ajax_sorting_callback . '_nonce',
2415
+					$ajax_sorting_callback . '_nonce',
2416
+					false,
2417
+					false
2418
+			);
2419
+			//			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2420
+			//			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2421
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2422
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2423
+		} else {
2424
+			$sortable_list_table_form_fields = '';
2425
+		}
2426
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2427
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2428
+		$nonce_ref = $this->_req_action . '_nonce';
2429
+		$hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2430
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2431
+		//display message about search results?
2432
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2433
+				? '<p class="ee-search-results">' . sprintf(
2434
+						esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2435
+						trim($this->_req_data['s'], '%')
2436
+				) . '</p>'
2437
+				: '';
2438
+		// filter before_list_table template arg
2439
+		$this->_template_args['before_list_table'] = apply_filters(
2440
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2441
+			$this->_template_args['before_list_table'],
2442
+			$this->page_slug,
2443
+			$this->_req_data,
2444
+			$this->_req_action
2445
+		);
2446
+		// convert to array and filter again
2447
+		// arrays are easier to inject new items in a specific location,
2448
+		// but would not be backwards compatible, so we have to add a new filter
2449
+		$this->_template_args['before_list_table'] = implode(
2450
+			" \n",
2451
+			(array) apply_filters(
2452
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2453
+				(array) $this->_template_args['before_list_table'],
2454
+				$this->page_slug,
2455
+				$this->_req_data,
2456
+				$this->_req_action
2457
+			)
2458
+		);
2459
+		// filter after_list_table template arg
2460
+		$this->_template_args['after_list_table'] = apply_filters(
2461
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2462
+			$this->_template_args['after_list_table'],
2463
+			$this->page_slug,
2464
+			$this->_req_data,
2465
+			$this->_req_action
2466
+		);
2467
+		// convert to array and filter again
2468
+		// arrays are easier to inject new items in a specific location,
2469
+		// but would not be backwards compatible, so we have to add a new filter
2470
+		$this->_template_args['after_list_table'] = implode(
2471
+			" \n",
2472
+			(array) apply_filters(
2473
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2474
+				(array) $this->_template_args['after_list_table'],
2475
+				$this->page_slug,
2476
+				$this->_req_data,
2477
+				$this->_req_action
2478
+			)
2479
+		);
2480
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2481
+				$template_path,
2482
+				$this->_template_args,
2483
+				true
2484
+		);
2485
+		// the final template wrapper
2486
+		if ($sidebar) {
2487
+			$this->display_admin_page_with_sidebar();
2488
+		} else {
2489
+			$this->display_admin_page_with_no_sidebar();
2490
+		}
2491
+	}
2492
+
2493
+
2494
+
2495
+	/**
2496
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2497
+	 * $items are expected in an array in the following format:
2498
+	 * $legend_items = array(
2499
+	 *        'item_id' => array(
2500
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2501
+	 *            'desc' => __('localized description of item');
2502
+	 *        )
2503
+	 * );
2504
+	 *
2505
+	 * @param  array $items see above for format of array
2506
+	 * @return string        html string of legend
2507
+	 */
2508
+	protected function _display_legend($items)
2509
+	{
2510
+		$this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2511
+		$legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2512
+		return EEH_Template::display_template($legend_template, $this->_template_args, true);
2513
+	}
2514
+
2515
+
2516
+	/**
2517
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2518
+	 * The returned json object is created from an array in the following format:
2519
+	 * array(
2520
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2521
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
2522
+	 *  'notices' => '', // - contains any EE_Error formatted notices
2523
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2524
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2525
+	 *  specific template args that might be included in here)
2526
+	 * )
2527
+	 * The json object is populated by whatever is set in the $_template_args property.
2528
+	 *
2529
+	 * @param bool  $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2530
+	 * @param array $notices_arguments  Use this to pass any additional args on to the _process_notices.
2531
+	 * @return void
2532
+	 */
2533
+	protected function _return_json($sticky_notices = false, $notices_arguments = array())
2534
+	{
2535
+		//make sure any EE_Error notices have been handled.
2536
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
2537
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2538
+		unset($this->_template_args['data']);
2539
+		$json = array(
2540
+				'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2541
+				'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2542
+				'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2543
+				'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2544
+				'notices'   => EE_Error::get_notices(),
2545
+				'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2546
+				'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2547
+				'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2548
+		);
2549
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2550
+		if (null === error_get_last() || ! headers_sent()) {
2551
+			header('Content-Type: application/json; charset=UTF-8');
2552
+		}
2553
+		echo wp_json_encode($json);
2554
+
2555
+		exit();
2556
+	}
2557
+
2558
+
2559
+
2560
+	/**
2561
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2562
+	 *
2563
+	 * @return void
2564
+	 * @throws EE_Error
2565
+	 */
2566
+	public function return_json()
2567
+	{
2568
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2569
+			$this->_return_json();
2570
+		} else {
2571
+			throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2572
+		}
2573
+	}
2574
+
2575
+
2576
+
2577
+	/**
2578
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2579
+	 *
2580
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2581
+	 * @access   public
2582
+	 */
2583
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
2584
+	{
2585
+		$this->_hook_obj = $hook_obj;
2586
+	}
2587
+
2588
+
2589
+
2590
+	/**
2591
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
2592
+	 *
2593
+	 * @access public
2594
+	 * @param  boolean $about whether to use the special about page wrapper or default.
2595
+	 * @return void
2596
+	 */
2597
+	public function admin_page_wrapper($about = false)
2598
+	{
2599
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2600
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
2601
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
2602
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
2603
+		$this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2604
+				isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2605
+		$this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2606
+				isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2607
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2608
+		// load settings page wrapper template
2609
+		$template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2610
+		//about page?
2611
+		$template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2612
+		if (defined('DOING_AJAX')) {
2613
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2614
+			$this->_return_json();
2615
+		} else {
2616
+			EEH_Template::display_template($template_path, $this->_template_args);
2617
+		}
2618
+	}
2619
+
2620
+
2621
+
2622
+	/**
2623
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2624
+	 *
2625
+	 * @return string html
2626
+	 */
2627
+	protected function _get_main_nav_tabs()
2628
+	{
2629
+		//let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2630
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2631
+	}
2632
+
2633
+
2634
+
2635
+	/**
2636
+	 *        sort nav tabs
2637
+	 *
2638
+	 * @access public
2639
+	 * @param $a
2640
+	 * @param $b
2641
+	 * @return int
2642
+	 */
2643
+	private function _sort_nav_tabs($a, $b)
2644
+	{
2645
+		if ($a['order'] == $b['order']) {
2646
+			return 0;
2647
+		}
2648
+		return ($a['order'] < $b['order']) ? -1 : 1;
2649
+	}
2650
+
2651
+
2652
+
2653
+	/**
2654
+	 *    generates HTML for the forms used on admin pages
2655
+	 *
2656
+	 * @access protected
2657
+	 * @param    array $input_vars - array of input field details
2658
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2659
+	 * @return string
2660
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2661
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2662
+	 */
2663
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2664
+	{
2665
+		$content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2666
+		return $content;
2667
+	}
2668
+
2669
+
2670
+
2671
+	/**
2672
+	 * generates the "Save" and "Save & Close" buttons for edit forms
2673
+	 *
2674
+	 * @access protected
2675
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2676
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2677
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2678
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2679
+	 */
2680
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2681
+	{
2682
+		//make sure $text and $actions are in an array
2683
+		$text = (array)$text;
2684
+		$actions = (array)$actions;
2685
+		$referrer_url = empty($referrer) ? '' : $referrer;
2686
+		$referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2687
+				: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2688
+		$button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2689
+		$default_names = array('save', 'save_and_close');
2690
+		//add in a hidden index for the current page (so save and close redirects properly)
2691
+		$this->_template_args['save_buttons'] = $referrer_url;
2692
+		foreach ($button_text as $key => $button) {
2693
+			$ref = $default_names[$key];
2694
+			$id = $this->_current_view . '_' . $ref;
2695
+			$name = ! empty($actions) ? $actions[$key] : $ref;
2696
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2697
+			if ( ! $both) {
2698
+				break;
2699
+			}
2700
+		}
2701
+	}
2702
+
2703
+
2704
+
2705
+	/**
2706
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2707
+	 *
2708
+	 * @see   $this->_set_add_edit_form_tags() for details on params
2709
+	 * @since 4.6.0
2710
+	 * @param string $route
2711
+	 * @param array  $additional_hidden_fields
2712
+	 */
2713
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2714
+	{
2715
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2716
+	}
2717
+
2718
+
2719
+
2720
+	/**
2721
+	 * set form open and close tags on add/edit pages.
2722
+	 *
2723
+	 * @access protected
2724
+	 * @param string $route                    the route you want the form to direct to
2725
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2726
+	 * @return void
2727
+	 */
2728
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2729
+	{
2730
+		if (empty($route)) {
2731
+			$user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2732
+			$dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2733
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2734
+		}
2735
+		// open form
2736
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2737
+		// add nonce
2738
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2739
+		//		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2740
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2741
+		// add REQUIRED form action
2742
+		$hidden_fields = array(
2743
+				'action' => array('type' => 'hidden', 'value' => $route),
2744
+		);
2745
+		// merge arrays
2746
+		$hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2747
+		// generate form fields
2748
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2749
+		// add fields to form
2750
+		foreach ((array)$form_fields as $field_name => $form_field) {
2751
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2752
+		}
2753
+		// close form
2754
+		$this->_template_args['after_admin_page_content'] = '</form>';
2755
+	}
2756
+
2757
+
2758
+
2759
+	/**
2760
+	 * Public Wrapper for _redirect_after_action() method since its
2761
+	 * discovered it would be useful for external code to have access.
2762
+	 *
2763
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
2764
+	 * @since 4.5.0
2765
+	 */
2766
+	public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2767
+	{
2768
+		$this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2769
+	}
2770
+
2771
+
2772
+
2773
+	/**
2774
+	 *    _redirect_after_action
2775
+	 *
2776
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
2777
+	 * @param string $what               - what the action was performed on
2778
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
2779
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2780
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2781
+	 * @access protected
2782
+	 * @return void
2783
+	 */
2784
+	protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2785
+	{
2786
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2787
+		//class name for actions/filters.
2788
+		$classname = get_class($this);
2789
+		//set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2790
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2791
+		$notices = EE_Error::get_notices(false);
2792
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
2793
+		if ( ! $override_overwrite || ! empty($notices['errors'])) {
2794
+			EE_Error::overwrite_success();
2795
+		}
2796
+		if ( ! empty($what) && ! empty($action_desc)) {
2797
+			// how many records affected ? more than one record ? or just one ?
2798
+			if ($success > 1 && empty($notices['errors'])) {
2799
+				// set plural msg
2800
+				EE_Error::add_success(
2801
+						sprintf(
2802
+								__('The "%s" have been successfully %s.', 'event_espresso'),
2803
+								$what,
2804
+								$action_desc
2805
+						),
2806
+						__FILE__, __FUNCTION__, __LINE__
2807
+				);
2808
+			} else if ($success == 1 && empty($notices['errors'])) {
2809
+				// set singular msg
2810
+				EE_Error::add_success(
2811
+						sprintf(
2812
+								__('The "%s" has been successfully %s.', 'event_espresso'),
2813
+								$what,
2814
+								$action_desc
2815
+						),
2816
+						__FILE__, __FUNCTION__, __LINE__
2817
+				);
2818
+			}
2819
+		}
2820
+		// check that $query_args isn't something crazy
2821
+		if ( ! is_array($query_args)) {
2822
+			$query_args = array();
2823
+		}
2824
+		/**
2825
+		 * Allow injecting actions before the query_args are modified for possible different
2826
+		 * redirections on save and close actions
2827
+		 *
2828
+		 * @since 4.2.0
2829
+		 * @param array $query_args       The original query_args array coming into the
2830
+		 *                                method.
2831
+		 */
2832
+		do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2833
+		//calculate where we're going (if we have a "save and close" button pushed)
2834
+		if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2835
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2836
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2837
+			// regenerate query args array from referrer URL
2838
+			parse_str($parsed_url['query'], $query_args);
2839
+			// correct page and action will be in the query args now
2840
+			$redirect_url = admin_url('admin.php');
2841
+		}
2842
+		//merge any default query_args set in _default_route_query_args property
2843
+		if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2844
+			$args_to_merge = array();
2845
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
2846
+				//is there a wp_referer array in our _default_route_query_args property?
2847
+				if ($query_param == 'wp_referer') {
2848
+					$query_value = (array)$query_value;
2849
+					foreach ($query_value as $reference => $value) {
2850
+						if (strpos($reference, 'nonce') !== false) {
2851
+							continue;
2852
+						}
2853
+						//finally we will override any arguments in the referer with
2854
+						//what might be set on the _default_route_query_args array.
2855
+						if (isset($this->_default_route_query_args[$reference])) {
2856
+							$args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2857
+						} else {
2858
+							$args_to_merge[$reference] = urlencode($value);
2859
+						}
2860
+					}
2861
+					continue;
2862
+				}
2863
+				$args_to_merge[$query_param] = $query_value;
2864
+			}
2865
+			//now let's merge these arguments but override with what was specifically sent in to the
2866
+			//redirect.
2867
+			$query_args = array_merge($args_to_merge, $query_args);
2868
+		}
2869
+		$this->_process_notices($query_args);
2870
+		// generate redirect url
2871
+		// if redirecting to anything other than the main page, add a nonce
2872
+		if (isset($query_args['action'])) {
2873
+			// manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2874
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2875
+		}
2876
+		//we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2877
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2878
+		$redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2879
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2880
+		if (defined('DOING_AJAX')) {
2881
+			$default_data = array(
2882
+					'close'        => true,
2883
+					'redirect_url' => $redirect_url,
2884
+					'where'        => 'main',
2885
+					'what'         => 'append',
2886
+			);
2887
+			$this->_template_args['success'] = $success;
2888
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2889
+			$this->_return_json();
2890
+		}
2891
+		wp_safe_redirect($redirect_url);
2892
+		exit();
2893
+	}
2894
+
2895
+
2896
+
2897
+	/**
2898
+	 * process any notices before redirecting (or returning ajax request)
2899
+	 * This method sets the $this->_template_args['notices'] attribute;
2900
+	 *
2901
+	 * @param  array $query_args        any query args that need to be used for notice transient ('action')
2902
+	 * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2903
+	 * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2904
+	 * @return void
2905
+	 */
2906
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2907
+	{
2908
+		//first let's set individual error properties if doing_ajax and the properties aren't already set.
2909
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2910
+			$notices = EE_Error::get_notices(false);
2911
+			if (empty($this->_template_args['success'])) {
2912
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2913
+			}
2914
+			if (empty($this->_template_args['errors'])) {
2915
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2916
+			}
2917
+			if (empty($this->_template_args['attention'])) {
2918
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2919
+			}
2920
+		}
2921
+		$this->_template_args['notices'] = EE_Error::get_notices();
2922
+		//IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2923
+		if ( ! defined('DOING_AJAX') || $sticky_notices) {
2924
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
2925
+			$this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2926
+		}
2927
+	}
2928
+
2929
+
2930
+
2931
+	/**
2932
+	 * get_action_link_or_button
2933
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
2934
+	 *
2935
+	 * @param string $action        use this to indicate which action the url is generated with.
2936
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2937
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2938
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2939
+	 * @param string $base_url      If this is not provided
2940
+	 *                              the _admin_base_url will be used as the default for the button base_url.
2941
+	 *                              Otherwise this value will be used.
2942
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2943
+	 * @return string
2944
+	 * @throws \EE_Error
2945
+	 */
2946
+	public function get_action_link_or_button(
2947
+			$action,
2948
+			$type = 'add',
2949
+			$extra_request = array(),
2950
+			$class = 'button-primary',
2951
+			$base_url = '',
2952
+			$exclude_nonce = false
2953
+	) {
2954
+		//first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2955
+		if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2956
+			throw new EE_Error(
2957
+					sprintf(
2958
+							__(
2959
+									'There is no page route for given action for the button.  This action was given: %s',
2960
+									'event_espresso'
2961
+							),
2962
+							$action
2963
+					)
2964
+			);
2965
+		}
2966
+		if ( ! isset($this->_labels['buttons'][$type])) {
2967
+			throw new EE_Error(
2968
+					sprintf(
2969
+							__(
2970
+									'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2971
+									'event_espresso'
2972
+							),
2973
+							$type
2974
+					)
2975
+			);
2976
+		}
2977
+		//finally check user access for this button.
2978
+		$has_access = $this->check_user_access($action, true);
2979
+		if ( ! $has_access) {
2980
+			return '';
2981
+		}
2982
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2983
+		$query_args = array(
2984
+				'action' => $action,
2985
+		);
2986
+		//merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2987
+		if ( ! empty($extra_request)) {
2988
+			$query_args = array_merge($extra_request, $query_args);
2989
+		}
2990
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2991
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2992
+	}
2993
+
2994
+
2995
+
2996
+	/**
2997
+	 * _per_page_screen_option
2998
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
2999
+	 *
3000
+	 * @return void
3001
+	 */
3002
+	protected function _per_page_screen_option()
3003
+	{
3004
+		$option = 'per_page';
3005
+		$args = array(
3006
+				'label'   => $this->_admin_page_title,
3007
+				'default' => 10,
3008
+				'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3009
+		);
3010
+		//ONLY add the screen option if the user has access to it.
3011
+		if ($this->check_user_access($this->_current_view, true)) {
3012
+			add_screen_option($option, $args);
3013
+		}
3014
+	}
3015
+
3016
+
3017
+
3018
+	/**
3019
+	 * set_per_page_screen_option
3020
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3021
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3022
+	 *
3023
+	 * @access private
3024
+	 * @return void
3025
+	 */
3026
+	private function _set_per_page_screen_options()
3027
+	{
3028
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3029
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3030
+			if ( ! $user = wp_get_current_user()) {
3031
+				return;
3032
+			}
3033
+			$option = $_POST['wp_screen_options']['option'];
3034
+			$value = $_POST['wp_screen_options']['value'];
3035
+			if ($option != sanitize_key($option)) {
3036
+				return;
3037
+			}
3038
+			$map_option = $option;
3039
+			$option = str_replace('-', '_', $option);
3040
+			switch ($map_option) {
3041
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3042
+					$value = (int)$value;
3043
+					if ($value < 1 || $value > 999) {
3044
+						return;
3045
+					}
3046
+					break;
3047
+				default:
3048
+					$value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3049
+					if (false === $value) {
3050
+						return;
3051
+					}
3052
+					break;
3053
+			}
3054
+			update_user_meta($user->ID, $option, $value);
3055
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3056
+			exit;
3057
+		}
3058
+	}
3059
+
3060
+
3061
+
3062
+	/**
3063
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3064
+	 *
3065
+	 * @param array $data array that will be assigned to template args.
3066
+	 */
3067
+	public function set_template_args($data)
3068
+	{
3069
+		$this->_template_args = array_merge($this->_template_args, (array)$data);
3070
+	}
3071
+
3072
+
3073
+
3074
+	/**
3075
+	 * This makes available the WP transient system for temporarily moving data between routes
3076
+	 *
3077
+	 * @access protected
3078
+	 * @param string $route             the route that should receive the transient
3079
+	 * @param array  $data              the data that gets sent
3080
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3081
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3082
+	 * @return void
3083
+	 */
3084
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3085
+	{
3086
+		$user_id = get_current_user_id();
3087
+		if ( ! $skip_route_verify) {
3088
+			$this->_verify_route($route);
3089
+		}
3090
+		//now let's set the string for what kind of transient we're setting
3091
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3092
+		$data = $notices ? array('notices' => $data) : $data;
3093
+		//is there already a transient for this route?  If there is then let's ADD to that transient
3094
+		$existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3095
+		if ($existing) {
3096
+			$data = array_merge((array)$data, (array)$existing);
3097
+		}
3098
+		if (is_multisite() && is_network_admin()) {
3099
+			set_site_transient($transient, $data, 8);
3100
+		} else {
3101
+			set_transient($transient, $data, 8);
3102
+		}
3103
+	}
3104
+
3105
+
3106
+
3107
+	/**
3108
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3109
+	 *
3110
+	 * @param bool $notices true we get notices transient. False we just return normal route transient
3111
+	 * @return mixed data
3112
+	 */
3113
+	protected function _get_transient($notices = false, $route = false)
3114
+	{
3115
+		$user_id = get_current_user_id();
3116
+		$route = ! $route ? $this->_req_action : $route;
3117
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3118
+		$data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3119
+		//delete transient after retrieval (just in case it hasn't expired);
3120
+		if (is_multisite() && is_network_admin()) {
3121
+			delete_site_transient($transient);
3122
+		} else {
3123
+			delete_transient($transient);
3124
+		}
3125
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3126
+	}
3127
+
3128
+
3129
+
3130
+	/**
3131
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3132
+	 * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3133
+	 *
3134
+	 * @return void
3135
+	 */
3136
+	protected function _transient_garbage_collection()
3137
+	{
3138
+		global $wpdb;
3139
+		//retrieve all existing transients
3140
+		$query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3141
+		if ($results = $wpdb->get_results($query)) {
3142
+			foreach ($results as $result) {
3143
+				$transient = str_replace('_transient_', '', $result->option_name);
3144
+				get_transient($transient);
3145
+				if (is_multisite() && is_network_admin()) {
3146
+					get_site_transient($transient);
3147
+				}
3148
+			}
3149
+		}
3150
+	}
3151
+
3152
+
3153
+
3154
+	/**
3155
+	 * get_view
3156
+	 *
3157
+	 * @access public
3158
+	 * @return string content of _view property
3159
+	 */
3160
+	public function get_view()
3161
+	{
3162
+		return $this->_view;
3163
+	}
3164
+
3165
+
3166
+
3167
+	/**
3168
+	 * getter for the protected $_views property
3169
+	 *
3170
+	 * @return array
3171
+	 */
3172
+	public function get_views()
3173
+	{
3174
+		return $this->_views;
3175
+	}
3176
+
3177
+
3178
+
3179
+	/**
3180
+	 * get_current_page
3181
+	 *
3182
+	 * @access public
3183
+	 * @return string _current_page property value
3184
+	 */
3185
+	public function get_current_page()
3186
+	{
3187
+		return $this->_current_page;
3188
+	}
3189
+
3190
+
3191
+
3192
+	/**
3193
+	 * get_current_view
3194
+	 *
3195
+	 * @access public
3196
+	 * @return string _current_view property value
3197
+	 */
3198
+	public function get_current_view()
3199
+	{
3200
+		return $this->_current_view;
3201
+	}
3202
+
3203
+
3204
+
3205
+	/**
3206
+	 * get_current_screen
3207
+	 *
3208
+	 * @access public
3209
+	 * @return object The current WP_Screen object
3210
+	 */
3211
+	public function get_current_screen()
3212
+	{
3213
+		return $this->_current_screen;
3214
+	}
3215
+
3216
+
3217
+
3218
+	/**
3219
+	 * get_current_page_view_url
3220
+	 *
3221
+	 * @access public
3222
+	 * @return string This returns the url for the current_page_view.
3223
+	 */
3224
+	public function get_current_page_view_url()
3225
+	{
3226
+		return $this->_current_page_view_url;
3227
+	}
3228
+
3229
+
3230
+
3231
+	/**
3232
+	 * just returns the _req_data property
3233
+	 *
3234
+	 * @return array
3235
+	 */
3236
+	public function get_request_data()
3237
+	{
3238
+		return $this->_req_data;
3239
+	}
3240
+
3241
+
3242
+
3243
+	/**
3244
+	 * returns the _req_data protected property
3245
+	 *
3246
+	 * @return string
3247
+	 */
3248
+	public function get_req_action()
3249
+	{
3250
+		return $this->_req_action;
3251
+	}
3252
+
3253
+
3254
+
3255
+	/**
3256
+	 * @return bool  value of $_is_caf property
3257
+	 */
3258
+	public function is_caf()
3259
+	{
3260
+		return $this->_is_caf;
3261
+	}
3262
+
3263
+
3264
+
3265
+	/**
3266
+	 * @return mixed
3267
+	 */
3268
+	public function default_espresso_metaboxes()
3269
+	{
3270
+		return $this->_default_espresso_metaboxes;
3271
+	}
3272
+
3273
+
3274
+
3275
+	/**
3276
+	 * @return mixed
3277
+	 */
3278
+	public function admin_base_url()
3279
+	{
3280
+		return $this->_admin_base_url;
3281
+	}
3282
+
3283
+
3284
+
3285
+	/**
3286
+	 * @return mixed
3287
+	 */
3288
+	public function wp_page_slug()
3289
+	{
3290
+		return $this->_wp_page_slug;
3291
+	}
3292
+
3293
+
3294
+
3295
+	/**
3296
+	 * updates  espresso configuration settings
3297
+	 *
3298
+	 * @access    protected
3299
+	 * @param string                   $tab
3300
+	 * @param EE_Config_Base|EE_Config $config
3301
+	 * @param string                   $file file where error occurred
3302
+	 * @param string                   $func function  where error occurred
3303
+	 * @param string                   $line line no where error occurred
3304
+	 * @return boolean
3305
+	 */
3306
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3307
+	{
3308
+		//remove any options that are NOT going to be saved with the config settings.
3309
+		if (isset($config->core->ee_ueip_optin)) {
3310
+			$config->core->ee_ueip_has_notified = true;
3311
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3312
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3313
+			update_option('ee_ueip_has_notified', true);
3314
+		}
3315
+		// and save it (note we're also doing the network save here)
3316
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3317
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3318
+		if ($config_saved && $net_saved) {
3319
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3320
+			return true;
3321
+		} else {
3322
+			EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3323
+			return false;
3324
+		}
3325
+	}
3326
+
3327
+
3328
+
3329
+	/**
3330
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3331
+	 *
3332
+	 * @return array
3333
+	 */
3334
+	public function get_yes_no_values()
3335
+	{
3336
+		return $this->_yes_no_values;
3337
+	}
3338
+
3339
+
3340
+
3341
+	protected function _get_dir()
3342
+	{
3343
+		$reflector = new ReflectionClass(get_class($this));
3344
+		return dirname($reflector->getFileName());
3345
+	}
3346
+
3347
+
3348
+
3349
+	/**
3350
+	 * A helper for getting a "next link".
3351
+	 *
3352
+	 * @param string $url   The url to link to
3353
+	 * @param string $class The class to use.
3354
+	 * @return string
3355
+	 */
3356
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3357
+	{
3358
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3359
+	}
3360
+
3361
+
3362
+
3363
+	/**
3364
+	 * A helper for getting a "previous link".
3365
+	 *
3366
+	 * @param string $url   The url to link to
3367
+	 * @param string $class The class to use.
3368
+	 * @return string
3369
+	 */
3370
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3371
+	{
3372
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3373
+	}
3374
+
3375
+
3376
+
3377
+
3378
+
3379
+
3380
+
3381
+	//below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3382
+	/**
3383
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data
3384
+	 * array.
3385
+	 *
3386
+	 * @return bool success/fail
3387
+	 */
3388
+	protected function _process_resend_registration()
3389
+	{
3390
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3391
+		do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3392
+		return $this->_template_args['success'];
3393
+	}
3394
+
3395
+
3396
+
3397
+	/**
3398
+	 * This automatically processes any payment message notifications when manual payment has been applied.
3399
+	 *
3400
+	 * @access protected
3401
+	 * @param \EE_Payment $payment
3402
+	 * @return bool success/fail
3403
+	 */
3404
+	protected function _process_payment_notification(EE_Payment $payment)
3405
+	{
3406
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3407
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3408
+		$this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3409
+		return $this->_template_args['success'];
3410
+	}
3411 3411
 
3412 3412
 
3413 3413
 }
Please login to merge, or discard this patch.