Completed
Branch master (b348a7)
by
unknown
18:00 queued 15:50
created
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.31.rc.000');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.31.rc.000');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.
core/EE_Front_Controller.core.php 1 patch
Indentation   +509 added lines, -509 removed lines patch added patch discarded remove patch
@@ -18,513 +18,513 @@
 block discarded – undo
18 18
 final class EE_Front_Controller
19 19
 {
20 20
 
21
-    /**
22
-     * @var string
23
-     */
24
-    private $_template_path;
25
-
26
-    /**
27
-     * @var string
28
-     */
29
-    private $_template;
30
-
31
-    /**
32
-     * @type EE_Registry
33
-     */
34
-    protected $Registry;
35
-
36
-    /**
37
-     * @type EE_Request_Handler
38
-     */
39
-    protected $Request_Handler;
40
-
41
-    /**
42
-     * @type EE_Module_Request_Router
43
-     */
44
-    protected $Module_Request_Router;
45
-
46
-    /**
47
-     * @type CurrentPage
48
-     */
49
-    protected $current_page;
50
-
51
-
52
-    /**
53
-     *    class constructor
54
-     *    should fire after shortcode, module, addon, or other plugin's default priority init phases have run
55
-     *
56
-     * @access    public
57
-     * @param EE_Registry              $Registry
58
-     * @param CurrentPage              $EspressoPage
59
-     * @param EE_Module_Request_Router $Module_Request_Router
60
-     */
61
-    public function __construct(
62
-        EE_Registry $Registry,
63
-        CurrentPage $EspressoPage,
64
-        EE_Module_Request_Router $Module_Request_Router
65
-    ) {
66
-        $this->Registry              = $Registry;
67
-        $this->current_page          = $EspressoPage;
68
-        $this->Module_Request_Router = $Module_Request_Router;
69
-        // load other resources and begin to actually run shortcodes and modules
70
-        // analyse the incoming WP request
71
-        add_action('parse_request', array($this, 'get_request'), 1, 1);
72
-        // process request with module factory
73
-        add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1);
74
-        // before headers sent
75
-        add_action('wp', array($this, 'wp'), 5);
76
-        // primarily used to process any content shortcodes
77
-        add_action('template_redirect', array($this, 'templateRedirect'), 999);
78
-        // header
79
-        add_action('wp_head', array($this, 'header_meta_tag'), 5);
80
-        add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10);
81
-        add_filter('template_include', array($this, 'template_include'), 1);
82
-        // display errors
83
-        add_action('loop_start', array($this, 'display_errors'), 2);
84
-        // the content
85
-        // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 );
86
-        // exclude our private cpt comments
87
-        add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1);
88
-        // make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://)
89
-        add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1);
90
-        // action hook EE
91
-        do_action('AHEE__EE_Front_Controller__construct__done', $this);
92
-    }
93
-
94
-
95
-    /**
96
-     * @return EE_Request_Handler
97
-     * @deprecated 4.10.14.p
98
-     */
99
-    public function Request_Handler()
100
-    {
101
-        if (! $this->Request_Handler instanceof EE_Request_Handler) {
102
-            $this->Request_Handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler');
103
-        }
104
-        return $this->Request_Handler;
105
-    }
106
-
107
-
108
-    /**
109
-     * @return EE_Module_Request_Router
110
-     */
111
-    public function Module_Request_Router()
112
-    {
113
-        return $this->Module_Request_Router;
114
-    }
115
-
116
-
117
-    /**
118
-     * @return LegacyShortcodesManager
119
-     * @deprecated 4.10.14.p
120
-     */
121
-    public function getLegacyShortcodesManager()
122
-    {
123
-        return EE_Config::getLegacyShortcodesManager();
124
-    }
125
-
126
-
127
-
128
-
129
-
130
-    /***********************************************        INIT ACTION HOOK         ***********************************************/
131
-    /**
132
-     * filter_wp_comments
133
-     * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment
134
-     * widgets/queries done on frontend
135
-     *
136
-     * @param  array $clauses array of comment clauses setup by WP_Comment_Query
137
-     * @return array array of comment clauses with modifications.
138
-     * @throws InvalidArgumentException
139
-     * @throws InvalidDataTypeException
140
-     * @throws InvalidInterfaceException
141
-     */
142
-    public function filter_wp_comments($clauses)
143
-    {
144
-        global $wpdb;
145
-        if (strpos($clauses['join'], $wpdb->posts) !== false) {
146
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
147
-            $custom_post_types = LoaderFactory::getLoader()->getShared(
148
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
149
-            );
150
-            $cpts = $custom_post_types->getPrivateCustomPostTypes();
151
-            foreach ($cpts as $cpt => $details) {
152
-                $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt);
153
-            }
154
-        }
155
-        return $clauses;
156
-    }
157
-
158
-
159
-    /**
160
-     * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend
161
-     *
162
-     * @param  string $url incoming url
163
-     * @return string         final assembled url
164
-     */
165
-    public function maybe_force_admin_ajax_ssl($url)
166
-    {
167
-        if (is_ssl() && preg_match('/admin-ajax.php/', $url)) {
168
-            $url = str_replace('http://', 'https://', $url);
169
-        }
170
-        return $url;
171
-    }
172
-
173
-
174
-
175
-
176
-
177
-
178
-    /***********************************************        WP_LOADED ACTION HOOK         ***********************************************/
179
-
180
-
181
-    /**
182
-     *    wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their
183
-     *    default priority init phases have run
184
-     *
185
-     * @access    public
186
-     * @return    void
187
-     */
188
-    public function wp_loaded()
189
-    {
190
-    }
191
-
192
-
193
-
194
-
195
-
196
-    /***********************************************        PARSE_REQUEST HOOK         ***********************************************/
197
-    /**
198
-     *    _get_request
199
-     *
200
-     * @access public
201
-     * @param WP $WP
202
-     * @return void
203
-     */
204
-    public function get_request(WP $WP)
205
-    {
206
-        do_action('AHEE__EE_Front_Controller__get_request__start');
207
-        $this->current_page->parseQueryVars($WP);
208
-        do_action('AHEE__EE_Front_Controller__get_request__complete');
209
-        remove_action('parse_request', [$this, 'get_request'], 1);
210
-    }
211
-
212
-
213
-    /**
214
-     *    pre_get_posts - basically a module factory for instantiating modules and selecting the final view template
215
-     *
216
-     * @access    public
217
-     * @param WP_Query $WP_Query
218
-     * @return    void
219
-     * @throws EE_Error
220
-     * @throws ReflectionException
221
-     */
222
-    public function pre_get_posts($WP_Query)
223
-    {
224
-        // only load Module_Request_Router if this is the main query
225
-        if (
226
-            $this->Module_Request_Router instanceof EE_Module_Request_Router
227
-            && $WP_Query->is_main_query()
228
-        ) {
229
-            // cycle thru module routes
230
-            while ($route = $this->Module_Request_Router->get_route($WP_Query)) {
231
-                // determine module and method for route
232
-                $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]);
233
-                if ($module instanceof EED_Module) {
234
-                    // get registered view for route
235
-                    $this->_template_path = $this->Module_Request_Router->get_view($route);
236
-                    // grab module name
237
-                    $module_name = $module->module_name();
238
-                    // map the module to the module objects
239
-                    $this->Registry->modules->{$module_name} = $module;
240
-                }
241
-            }
242
-        }
243
-    }
244
-
245
-
246
-
247
-
248
-
249
-    /***********************************************        WP HOOK         ***********************************************/
250
-
251
-
252
-    /**
253
-     *    wp - basically last chance to do stuff before headers sent
254
-     *
255
-     * @access    public
256
-     * @return    void
257
-     */
258
-    public function wp()
259
-    {
260
-    }
261
-
262
-
263
-
264
-    /***********************     GET_HEADER && WP_HEAD HOOK     ***********************/
265
-
266
-
267
-    /**
268
-     * callback for the "template_redirect" hook point
269
-     * checks sidebars for EE widgets
270
-     * loads resources and assets accordingly
271
-     *
272
-     * @return void
273
-     */
274
-    public function templateRedirect()
275
-    {
276
-        global $wp_query;
277
-        if (empty($wp_query->posts)) {
278
-            return;
279
-        }
280
-        // if we already know this is an espresso page, then load assets
281
-        $load_assets = $this->current_page->isEspressoPage();
282
-        // if we are already loading assets then just move along, otherwise check for widgets
283
-        $load_assets = $load_assets || $this->espresso_widgets_in_active_sidebars();
284
-        if ($load_assets) {
285
-            add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10);
286
-            add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10);
287
-        }
288
-    }
289
-
290
-
291
-    /**
292
-     * builds list of active widgets then scans active sidebars looking for them
293
-     * returns true is an EE widget is found in an active sidebar
294
-     * Please Note: this does NOT mean that the sidebar or widget
295
-     * is actually in use in a given template, as that is unfortunately not known
296
-     * until a sidebar and it's widgets are actually loaded
297
-     *
298
-     * @return boolean
299
-     */
300
-    private function espresso_widgets_in_active_sidebars()
301
-    {
302
-        $espresso_widgets = array();
303
-        foreach ($this->Registry->widgets as $widget_class => $widget) {
304
-            $id_base = EspressoWidget::getIdBase($widget_class);
305
-            if (is_active_widget(false, false, $id_base)) {
306
-                $espresso_widgets[] = $id_base;
307
-            }
308
-        }
309
-        $all_sidebar_widgets = wp_get_sidebars_widgets();
310
-        foreach ($all_sidebar_widgets as $sidebar_widgets) {
311
-            if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) {
312
-                foreach ($sidebar_widgets as $sidebar_widget) {
313
-                    foreach ($espresso_widgets as $espresso_widget) {
314
-                        if (strpos($sidebar_widget, $espresso_widget) !== false) {
315
-                            return true;
316
-                        }
317
-                    }
318
-                }
319
-            }
320
-        }
321
-        return false;
322
-    }
323
-
324
-
325
-    /**
326
-     *    header_meta_tag
327
-     *
328
-     * @access    public
329
-     * @return    void
330
-     */
331
-    public function header_meta_tag()
332
-    {
333
-        print(
334
-        apply_filters(
335
-            'FHEE__EE_Front_Controller__header_meta_tag',
336
-            '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n"
337
-        )
338
-        );
339
-
340
-        // let's exclude all event type taxonomy term archive pages from search engine indexing
341
-        // @see https://events.codebasehq.com/projects/event-espresso/tickets/10249
342
-        // also exclude all critical pages from indexing
343
-        if (
344
-            (
345
-                is_tax('espresso_event_type')
346
-                && get_option('blog_public') !== '0'
347
-            )
348
-            || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array())
349
-        ) {
350
-            print(
351
-            apply_filters(
352
-                'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
353
-                '<meta name="robots" content="noindex,follow" />' . "\n"
354
-            )
355
-            );
356
-        }
357
-    }
358
-
359
-
360
-    /**
361
-     * wp_print_scripts
362
-     *
363
-     * @return void
364
-     * @throws EE_Error
365
-     */
366
-    public function wp_print_scripts()
367
-    {
368
-        global $post;
369
-        if (
370
-            isset($post->EE_Event)
371
-            && $post->EE_Event instanceof EE_Event
372
-            && get_post_type() === 'espresso_events'
373
-            && is_singular()
374
-        ) {
375
-            EEH_Schema::add_json_linked_data_for_event($post->EE_Event);
376
-        }
377
-    }
378
-
379
-
380
-    public function enqueueStyle()
381
-    {
382
-        wp_enqueue_style('espresso_default');
383
-        wp_enqueue_style('espresso_custom_css');
384
-    }
385
-
386
-
387
-
388
-    /***********************************************        WP_FOOTER         ***********************************************/
389
-
390
-
391
-    public function enqueueScripts()
392
-    {
393
-        wp_enqueue_script('espresso_core');
394
-    }
395
-
396
-
397
-    /**
398
-     * display_errors
399
-     *
400
-     * @access public
401
-     * @return void
402
-     * @throws DomainException
403
-     */
404
-    public function display_errors()
405
-    {
406
-        static $shown_already = false;
407
-        do_action('AHEE__EE_Front_Controller__display_errors__begin');
408
-        if (
409
-            ! $shown_already
410
-            && apply_filters('FHEE__EE_Front_Controller__display_errors', true)
411
-            && is_main_query()
412
-            && ! is_feed()
413
-            && in_the_loop()
414
-            && $this->current_page->isEspressoPage()
415
-        ) {
416
-            $shown_already = true;
417
-            if (did_action('wp_head')) {
418
-                $this->printNotices();
419
-            } else {
420
-                // block enabled themes run their query loop before headers are sent
421
-                // so we need to add our notices onto the beginning of the content
422
-                add_filter('the_content', [$this, 'prependNotices'], 1, 1);
423
-            }
424
-        }
425
-        do_action('AHEE__EE_Front_Controller__display_errors__end');
426
-    }
427
-
428
-
429
-    /**
430
-     * @param string $the_content
431
-     * @return string
432
-     * @since 4.10.30.p
433
-     */
434
-    public function prependNotices($the_content)
435
-    {
436
-        $notices = $this->printNotices();
437
-        return $notices ? $notices . $the_content : $the_content;
438
-    }
439
-
440
-
441
-    /**
442
-     * @return false|string
443
-     * @since 4.10.30.p
444
-     */
445
-    public function printNotices()
446
-    {
447
-        ob_start();
448
-        echo wp_kses(EE_Error::get_notices(), AllowedTags::getWithFormTags());
449
-        EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
450
-        return ob_get_clean();
451
-    }
452
-
453
-
454
-
455
-    /***********************************************        UTILITIES         ***********************************************/
456
-
457
-
458
-    /**
459
-     * @param string $template_include_path
460
-     * @return string
461
-     * @throws EE_Error
462
-     * @throws ReflectionException
463
-     */
464
-    public function template_include($template_include_path = null)
465
-    {
466
-        if ($this->current_page->isEspressoPage()) {
467
-            // despite all helpers having autoloaders set, we need to manually load the template loader
468
-            // because there are some side effects in that class for triggering template tag functions
469
-            $this->Registry->load_helper('EEH_Template');
470
-            $this->_template_path = ! empty($this->_template_path)
471
-                ? basename($this->_template_path)
472
-                : basename(
473
-                    $template_include_path
474
-                );
475
-            $template_path = EEH_Template::locate_template($this->_template_path, array(), false);
476
-            $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path;
477
-            $this->_template = basename($this->_template_path);
478
-            return $this->_template_path;
479
-        }
480
-        return $template_include_path;
481
-    }
482
-
483
-
484
-    /**
485
-     * @param bool $with_path
486
-     * @return    string
487
-     */
488
-    public function get_selected_template($with_path = false)
489
-    {
490
-        return $with_path ? $this->_template_path : $this->_template;
491
-    }
492
-
493
-
494
-    /**
495
-     * @param string $shortcode_class
496
-     * @param WP     $wp
497
-     * @throws ReflectionException
498
-     * @deprecated 4.9.26
499
-     */
500
-    public function initialize_shortcode($shortcode_class = '', WP $wp = null)
501
-    {
502
-        EE_Error::doing_it_wrong(
503
-            __METHOD__,
504
-            esc_html__(
505
-                'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.',
506
-                'event_espresso'
507
-            ),
508
-            '4.9.26'
509
-        );
510
-        $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp);
511
-    }
512
-
513
-
514
-    /**
515
-     * @return void
516
-     * @deprecated 4.9.57.p
517
-     */
518
-    public function loadPersistentAdminNoticeManager()
519
-    {
520
-    }
521
-
522
-
523
-    /**
524
-     * @return void
525
-     * @deprecated 4.9.64.p
526
-     */
527
-    public function employ_CPT_Strategy()
528
-    {
529
-    }
21
+	/**
22
+	 * @var string
23
+	 */
24
+	private $_template_path;
25
+
26
+	/**
27
+	 * @var string
28
+	 */
29
+	private $_template;
30
+
31
+	/**
32
+	 * @type EE_Registry
33
+	 */
34
+	protected $Registry;
35
+
36
+	/**
37
+	 * @type EE_Request_Handler
38
+	 */
39
+	protected $Request_Handler;
40
+
41
+	/**
42
+	 * @type EE_Module_Request_Router
43
+	 */
44
+	protected $Module_Request_Router;
45
+
46
+	/**
47
+	 * @type CurrentPage
48
+	 */
49
+	protected $current_page;
50
+
51
+
52
+	/**
53
+	 *    class constructor
54
+	 *    should fire after shortcode, module, addon, or other plugin's default priority init phases have run
55
+	 *
56
+	 * @access    public
57
+	 * @param EE_Registry              $Registry
58
+	 * @param CurrentPage              $EspressoPage
59
+	 * @param EE_Module_Request_Router $Module_Request_Router
60
+	 */
61
+	public function __construct(
62
+		EE_Registry $Registry,
63
+		CurrentPage $EspressoPage,
64
+		EE_Module_Request_Router $Module_Request_Router
65
+	) {
66
+		$this->Registry              = $Registry;
67
+		$this->current_page          = $EspressoPage;
68
+		$this->Module_Request_Router = $Module_Request_Router;
69
+		// load other resources and begin to actually run shortcodes and modules
70
+		// analyse the incoming WP request
71
+		add_action('parse_request', array($this, 'get_request'), 1, 1);
72
+		// process request with module factory
73
+		add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1);
74
+		// before headers sent
75
+		add_action('wp', array($this, 'wp'), 5);
76
+		// primarily used to process any content shortcodes
77
+		add_action('template_redirect', array($this, 'templateRedirect'), 999);
78
+		// header
79
+		add_action('wp_head', array($this, 'header_meta_tag'), 5);
80
+		add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10);
81
+		add_filter('template_include', array($this, 'template_include'), 1);
82
+		// display errors
83
+		add_action('loop_start', array($this, 'display_errors'), 2);
84
+		// the content
85
+		// add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 );
86
+		// exclude our private cpt comments
87
+		add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1);
88
+		// make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://)
89
+		add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1);
90
+		// action hook EE
91
+		do_action('AHEE__EE_Front_Controller__construct__done', $this);
92
+	}
93
+
94
+
95
+	/**
96
+	 * @return EE_Request_Handler
97
+	 * @deprecated 4.10.14.p
98
+	 */
99
+	public function Request_Handler()
100
+	{
101
+		if (! $this->Request_Handler instanceof EE_Request_Handler) {
102
+			$this->Request_Handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler');
103
+		}
104
+		return $this->Request_Handler;
105
+	}
106
+
107
+
108
+	/**
109
+	 * @return EE_Module_Request_Router
110
+	 */
111
+	public function Module_Request_Router()
112
+	{
113
+		return $this->Module_Request_Router;
114
+	}
115
+
116
+
117
+	/**
118
+	 * @return LegacyShortcodesManager
119
+	 * @deprecated 4.10.14.p
120
+	 */
121
+	public function getLegacyShortcodesManager()
122
+	{
123
+		return EE_Config::getLegacyShortcodesManager();
124
+	}
125
+
126
+
127
+
128
+
129
+
130
+	/***********************************************        INIT ACTION HOOK         ***********************************************/
131
+	/**
132
+	 * filter_wp_comments
133
+	 * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment
134
+	 * widgets/queries done on frontend
135
+	 *
136
+	 * @param  array $clauses array of comment clauses setup by WP_Comment_Query
137
+	 * @return array array of comment clauses with modifications.
138
+	 * @throws InvalidArgumentException
139
+	 * @throws InvalidDataTypeException
140
+	 * @throws InvalidInterfaceException
141
+	 */
142
+	public function filter_wp_comments($clauses)
143
+	{
144
+		global $wpdb;
145
+		if (strpos($clauses['join'], $wpdb->posts) !== false) {
146
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
147
+			$custom_post_types = LoaderFactory::getLoader()->getShared(
148
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
149
+			);
150
+			$cpts = $custom_post_types->getPrivateCustomPostTypes();
151
+			foreach ($cpts as $cpt => $details) {
152
+				$clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt);
153
+			}
154
+		}
155
+		return $clauses;
156
+	}
157
+
158
+
159
+	/**
160
+	 * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend
161
+	 *
162
+	 * @param  string $url incoming url
163
+	 * @return string         final assembled url
164
+	 */
165
+	public function maybe_force_admin_ajax_ssl($url)
166
+	{
167
+		if (is_ssl() && preg_match('/admin-ajax.php/', $url)) {
168
+			$url = str_replace('http://', 'https://', $url);
169
+		}
170
+		return $url;
171
+	}
172
+
173
+
174
+
175
+
176
+
177
+
178
+	/***********************************************        WP_LOADED ACTION HOOK         ***********************************************/
179
+
180
+
181
+	/**
182
+	 *    wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their
183
+	 *    default priority init phases have run
184
+	 *
185
+	 * @access    public
186
+	 * @return    void
187
+	 */
188
+	public function wp_loaded()
189
+	{
190
+	}
191
+
192
+
193
+
194
+
195
+
196
+	/***********************************************        PARSE_REQUEST HOOK         ***********************************************/
197
+	/**
198
+	 *    _get_request
199
+	 *
200
+	 * @access public
201
+	 * @param WP $WP
202
+	 * @return void
203
+	 */
204
+	public function get_request(WP $WP)
205
+	{
206
+		do_action('AHEE__EE_Front_Controller__get_request__start');
207
+		$this->current_page->parseQueryVars($WP);
208
+		do_action('AHEE__EE_Front_Controller__get_request__complete');
209
+		remove_action('parse_request', [$this, 'get_request'], 1);
210
+	}
211
+
212
+
213
+	/**
214
+	 *    pre_get_posts - basically a module factory for instantiating modules and selecting the final view template
215
+	 *
216
+	 * @access    public
217
+	 * @param WP_Query $WP_Query
218
+	 * @return    void
219
+	 * @throws EE_Error
220
+	 * @throws ReflectionException
221
+	 */
222
+	public function pre_get_posts($WP_Query)
223
+	{
224
+		// only load Module_Request_Router if this is the main query
225
+		if (
226
+			$this->Module_Request_Router instanceof EE_Module_Request_Router
227
+			&& $WP_Query->is_main_query()
228
+		) {
229
+			// cycle thru module routes
230
+			while ($route = $this->Module_Request_Router->get_route($WP_Query)) {
231
+				// determine module and method for route
232
+				$module = $this->Module_Request_Router->resolve_route($route[0], $route[1]);
233
+				if ($module instanceof EED_Module) {
234
+					// get registered view for route
235
+					$this->_template_path = $this->Module_Request_Router->get_view($route);
236
+					// grab module name
237
+					$module_name = $module->module_name();
238
+					// map the module to the module objects
239
+					$this->Registry->modules->{$module_name} = $module;
240
+				}
241
+			}
242
+		}
243
+	}
244
+
245
+
246
+
247
+
248
+
249
+	/***********************************************        WP HOOK         ***********************************************/
250
+
251
+
252
+	/**
253
+	 *    wp - basically last chance to do stuff before headers sent
254
+	 *
255
+	 * @access    public
256
+	 * @return    void
257
+	 */
258
+	public function wp()
259
+	{
260
+	}
261
+
262
+
263
+
264
+	/***********************     GET_HEADER && WP_HEAD HOOK     ***********************/
265
+
266
+
267
+	/**
268
+	 * callback for the "template_redirect" hook point
269
+	 * checks sidebars for EE widgets
270
+	 * loads resources and assets accordingly
271
+	 *
272
+	 * @return void
273
+	 */
274
+	public function templateRedirect()
275
+	{
276
+		global $wp_query;
277
+		if (empty($wp_query->posts)) {
278
+			return;
279
+		}
280
+		// if we already know this is an espresso page, then load assets
281
+		$load_assets = $this->current_page->isEspressoPage();
282
+		// if we are already loading assets then just move along, otherwise check for widgets
283
+		$load_assets = $load_assets || $this->espresso_widgets_in_active_sidebars();
284
+		if ($load_assets) {
285
+			add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10);
286
+			add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10);
287
+		}
288
+	}
289
+
290
+
291
+	/**
292
+	 * builds list of active widgets then scans active sidebars looking for them
293
+	 * returns true is an EE widget is found in an active sidebar
294
+	 * Please Note: this does NOT mean that the sidebar or widget
295
+	 * is actually in use in a given template, as that is unfortunately not known
296
+	 * until a sidebar and it's widgets are actually loaded
297
+	 *
298
+	 * @return boolean
299
+	 */
300
+	private function espresso_widgets_in_active_sidebars()
301
+	{
302
+		$espresso_widgets = array();
303
+		foreach ($this->Registry->widgets as $widget_class => $widget) {
304
+			$id_base = EspressoWidget::getIdBase($widget_class);
305
+			if (is_active_widget(false, false, $id_base)) {
306
+				$espresso_widgets[] = $id_base;
307
+			}
308
+		}
309
+		$all_sidebar_widgets = wp_get_sidebars_widgets();
310
+		foreach ($all_sidebar_widgets as $sidebar_widgets) {
311
+			if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) {
312
+				foreach ($sidebar_widgets as $sidebar_widget) {
313
+					foreach ($espresso_widgets as $espresso_widget) {
314
+						if (strpos($sidebar_widget, $espresso_widget) !== false) {
315
+							return true;
316
+						}
317
+					}
318
+				}
319
+			}
320
+		}
321
+		return false;
322
+	}
323
+
324
+
325
+	/**
326
+	 *    header_meta_tag
327
+	 *
328
+	 * @access    public
329
+	 * @return    void
330
+	 */
331
+	public function header_meta_tag()
332
+	{
333
+		print(
334
+		apply_filters(
335
+			'FHEE__EE_Front_Controller__header_meta_tag',
336
+			'<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n"
337
+		)
338
+		);
339
+
340
+		// let's exclude all event type taxonomy term archive pages from search engine indexing
341
+		// @see https://events.codebasehq.com/projects/event-espresso/tickets/10249
342
+		// also exclude all critical pages from indexing
343
+		if (
344
+			(
345
+				is_tax('espresso_event_type')
346
+				&& get_option('blog_public') !== '0'
347
+			)
348
+			|| is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array())
349
+		) {
350
+			print(
351
+			apply_filters(
352
+				'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
353
+				'<meta name="robots" content="noindex,follow" />' . "\n"
354
+			)
355
+			);
356
+		}
357
+	}
358
+
359
+
360
+	/**
361
+	 * wp_print_scripts
362
+	 *
363
+	 * @return void
364
+	 * @throws EE_Error
365
+	 */
366
+	public function wp_print_scripts()
367
+	{
368
+		global $post;
369
+		if (
370
+			isset($post->EE_Event)
371
+			&& $post->EE_Event instanceof EE_Event
372
+			&& get_post_type() === 'espresso_events'
373
+			&& is_singular()
374
+		) {
375
+			EEH_Schema::add_json_linked_data_for_event($post->EE_Event);
376
+		}
377
+	}
378
+
379
+
380
+	public function enqueueStyle()
381
+	{
382
+		wp_enqueue_style('espresso_default');
383
+		wp_enqueue_style('espresso_custom_css');
384
+	}
385
+
386
+
387
+
388
+	/***********************************************        WP_FOOTER         ***********************************************/
389
+
390
+
391
+	public function enqueueScripts()
392
+	{
393
+		wp_enqueue_script('espresso_core');
394
+	}
395
+
396
+
397
+	/**
398
+	 * display_errors
399
+	 *
400
+	 * @access public
401
+	 * @return void
402
+	 * @throws DomainException
403
+	 */
404
+	public function display_errors()
405
+	{
406
+		static $shown_already = false;
407
+		do_action('AHEE__EE_Front_Controller__display_errors__begin');
408
+		if (
409
+			! $shown_already
410
+			&& apply_filters('FHEE__EE_Front_Controller__display_errors', true)
411
+			&& is_main_query()
412
+			&& ! is_feed()
413
+			&& in_the_loop()
414
+			&& $this->current_page->isEspressoPage()
415
+		) {
416
+			$shown_already = true;
417
+			if (did_action('wp_head')) {
418
+				$this->printNotices();
419
+			} else {
420
+				// block enabled themes run their query loop before headers are sent
421
+				// so we need to add our notices onto the beginning of the content
422
+				add_filter('the_content', [$this, 'prependNotices'], 1, 1);
423
+			}
424
+		}
425
+		do_action('AHEE__EE_Front_Controller__display_errors__end');
426
+	}
427
+
428
+
429
+	/**
430
+	 * @param string $the_content
431
+	 * @return string
432
+	 * @since 4.10.30.p
433
+	 */
434
+	public function prependNotices($the_content)
435
+	{
436
+		$notices = $this->printNotices();
437
+		return $notices ? $notices . $the_content : $the_content;
438
+	}
439
+
440
+
441
+	/**
442
+	 * @return false|string
443
+	 * @since 4.10.30.p
444
+	 */
445
+	public function printNotices()
446
+	{
447
+		ob_start();
448
+		echo wp_kses(EE_Error::get_notices(), AllowedTags::getWithFormTags());
449
+		EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
450
+		return ob_get_clean();
451
+	}
452
+
453
+
454
+
455
+	/***********************************************        UTILITIES         ***********************************************/
456
+
457
+
458
+	/**
459
+	 * @param string $template_include_path
460
+	 * @return string
461
+	 * @throws EE_Error
462
+	 * @throws ReflectionException
463
+	 */
464
+	public function template_include($template_include_path = null)
465
+	{
466
+		if ($this->current_page->isEspressoPage()) {
467
+			// despite all helpers having autoloaders set, we need to manually load the template loader
468
+			// because there are some side effects in that class for triggering template tag functions
469
+			$this->Registry->load_helper('EEH_Template');
470
+			$this->_template_path = ! empty($this->_template_path)
471
+				? basename($this->_template_path)
472
+				: basename(
473
+					$template_include_path
474
+				);
475
+			$template_path = EEH_Template::locate_template($this->_template_path, array(), false);
476
+			$this->_template_path = ! empty($template_path) ? $template_path : $template_include_path;
477
+			$this->_template = basename($this->_template_path);
478
+			return $this->_template_path;
479
+		}
480
+		return $template_include_path;
481
+	}
482
+
483
+
484
+	/**
485
+	 * @param bool $with_path
486
+	 * @return    string
487
+	 */
488
+	public function get_selected_template($with_path = false)
489
+	{
490
+		return $with_path ? $this->_template_path : $this->_template;
491
+	}
492
+
493
+
494
+	/**
495
+	 * @param string $shortcode_class
496
+	 * @param WP     $wp
497
+	 * @throws ReflectionException
498
+	 * @deprecated 4.9.26
499
+	 */
500
+	public function initialize_shortcode($shortcode_class = '', WP $wp = null)
501
+	{
502
+		EE_Error::doing_it_wrong(
503
+			__METHOD__,
504
+			esc_html__(
505
+				'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.',
506
+				'event_espresso'
507
+			),
508
+			'4.9.26'
509
+		);
510
+		$this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp);
511
+	}
512
+
513
+
514
+	/**
515
+	 * @return void
516
+	 * @deprecated 4.9.57.p
517
+	 */
518
+	public function loadPersistentAdminNoticeManager()
519
+	{
520
+	}
521
+
522
+
523
+	/**
524
+	 * @return void
525
+	 * @deprecated 4.9.64.p
526
+	 */
527
+	public function employ_CPT_Strategy()
528
+	{
529
+	}
530 530
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +4093 added lines, -4093 removed lines patch added patch discarded remove patch
@@ -19,4167 +19,4167 @@
 block discarded – undo
19 19
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
20 20
 {
21 21
 
22
-    /**
23
-     * @var LoaderInterface
24
-     */
25
-    protected $loader;
22
+	/**
23
+	 * @var LoaderInterface
24
+	 */
25
+	protected $loader;
26 26
 
27
-    /**
28
-     * @var RequestInterface
29
-     */
30
-    protected $request;
27
+	/**
28
+	 * @var RequestInterface
29
+	 */
30
+	protected $request;
31 31
 
32
-    // set in _init_page_props()
33
-    public $page_slug;
32
+	// set in _init_page_props()
33
+	public $page_slug;
34 34
 
35
-    public $page_label;
35
+	public $page_label;
36 36
 
37
-    public $page_folder;
37
+	public $page_folder;
38 38
 
39
-    // set in define_page_props()
40
-    protected $_admin_base_url;
39
+	// set in define_page_props()
40
+	protected $_admin_base_url;
41 41
 
42
-    protected $_admin_base_path;
42
+	protected $_admin_base_path;
43 43
 
44
-    protected $_admin_page_title;
44
+	protected $_admin_page_title;
45 45
 
46
-    protected $_labels;
46
+	protected $_labels;
47 47
 
48 48
 
49
-    // set early within EE_Admin_Init
50
-    protected $_wp_page_slug;
49
+	// set early within EE_Admin_Init
50
+	protected $_wp_page_slug;
51 51
 
52
-    // navtabs
53
-    protected $_nav_tabs;
52
+	// navtabs
53
+	protected $_nav_tabs;
54 54
 
55
-    protected $_default_nav_tab_name;
55
+	protected $_default_nav_tab_name;
56 56
 
57 57
 
58
-    // template variables (used by templates)
59
-    protected $_template_path;
58
+	// template variables (used by templates)
59
+	protected $_template_path;
60 60
 
61
-    protected $_column_template_path;
61
+	protected $_column_template_path;
62 62
 
63
-    /**
64
-     * @var array $_template_args
65
-     */
66
-    protected $_template_args = [];
63
+	/**
64
+	 * @var array $_template_args
65
+	 */
66
+	protected $_template_args = [];
67 67
 
68
-    /**
69
-     * this will hold the list table object for a given view.
70
-     *
71
-     * @var EE_Admin_List_Table $_list_table_object
72
-     */
73
-    protected $_list_table_object;
68
+	/**
69
+	 * this will hold the list table object for a given view.
70
+	 *
71
+	 * @var EE_Admin_List_Table $_list_table_object
72
+	 */
73
+	protected $_list_table_object;
74 74
 
75
-    // bools
76
-    protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
75
+	// bools
76
+	protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
77 77
 
78
-    protected $_routing;
78
+	protected $_routing;
79 79
 
80
-    // list table args
81
-    protected $_view;
80
+	// list table args
81
+	protected $_view;
82 82
 
83
-    protected $_views;
83
+	protected $_views;
84 84
 
85 85
 
86
-    // action => method pairs used for routing incoming requests
87
-    protected $_page_routes;
86
+	// action => method pairs used for routing incoming requests
87
+	protected $_page_routes;
88 88
 
89
-    /**
90
-     * @var array $_page_config
91
-     */
92
-    protected $_page_config;
89
+	/**
90
+	 * @var array $_page_config
91
+	 */
92
+	protected $_page_config;
93 93
 
94
-    /**
95
-     * the current page route and route config
96
-     *
97
-     * @var string $_route
98
-     */
99
-    protected $_route;
94
+	/**
95
+	 * the current page route and route config
96
+	 *
97
+	 * @var string $_route
98
+	 */
99
+	protected $_route;
100 100
 
101
-    /**
102
-     * @var string $_cpt_route
103
-     */
104
-    protected $_cpt_route;
101
+	/**
102
+	 * @var string $_cpt_route
103
+	 */
104
+	protected $_cpt_route;
105 105
 
106
-    /**
107
-     * @var array $_route_config
108
-     */
109
-    protected $_route_config;
106
+	/**
107
+	 * @var array $_route_config
108
+	 */
109
+	protected $_route_config;
110 110
 
111
-    /**
112
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
113
-     * actions.
114
-     *
115
-     * @since 4.6.x
116
-     * @var array.
117
-     */
118
-    protected $_default_route_query_args;
119
-
120
-    // set via request page and action args.
121
-    protected $_current_page;
122
-
123
-    protected $_current_view;
124
-
125
-    protected $_current_page_view_url;
126
-
127
-    /**
128
-     * unprocessed value for the 'action' request param (default '')
129
-     *
130
-     * @var string
131
-     */
132
-    protected $raw_req_action = '';
133
-
134
-    /**
135
-     * unprocessed value for the 'page' request param (default '')
136
-     *
137
-     * @var string
138
-     */
139
-    protected $raw_req_page = '';
140
-
141
-    /**
142
-     * sanitized request action (and nonce)
143
-     *
144
-     * @var string
145
-     */
146
-    protected $_req_action = '';
147
-
148
-    /**
149
-     * sanitized request action nonce
150
-     *
151
-     * @var string
152
-     */
153
-    protected $_req_nonce = '';
154
-
155
-    /**
156
-     * @var string
157
-     */
158
-    protected $_search_btn_label = '';
159
-
160
-    /**
161
-     * @var string
162
-     */
163
-    protected $_search_box_callback = '';
164
-
165
-    /**
166
-     * @var WP_Screen
167
-     */
168
-    protected $_current_screen;
169
-
170
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
171
-    protected $_hook_obj;
172
-
173
-    // for holding incoming request data
174
-    protected $_req_data = [];
175
-
176
-    // yes / no array for admin form fields
177
-    protected $_yes_no_values = [];
178
-
179
-    // some default things shared by all child classes
180
-    protected $_default_espresso_metaboxes;
181
-
182
-    /**
183
-     * @var EE_Registry
184
-     */
185
-    protected $EE = null;
186
-
187
-
188
-    /**
189
-     * This is just a property that flags whether the given route is a caffeinated route or not.
190
-     *
191
-     * @var boolean
192
-     */
193
-    protected $_is_caf = false;
194
-
195
-
196
-    /**
197
-     * @Constructor
198
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
199
-     * @throws EE_Error
200
-     * @throws InvalidArgumentException
201
-     * @throws ReflectionException
202
-     * @throws InvalidDataTypeException
203
-     * @throws InvalidInterfaceException
204
-     */
205
-    public function __construct($routing = true)
206
-    {
207
-        $this->loader  = LoaderFactory::getLoader();
208
-        $this->request = $this->loader->getShared(RequestInterface::class);
209
-        $this->_routing = $routing;
210
-
211
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
212
-            $this->_is_caf = true;
213
-        }
214
-        $this->_yes_no_values = [
215
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
216
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
217
-        ];
218
-        // set the _req_data property.
219
-        $this->_req_data = $this->request->requestParams();
220
-        // set initial page props (child method)
221
-        $this->_init_page_props();
222
-        // set global defaults
223
-        $this->_set_defaults();
224
-        // set early because incoming requests could be ajax related and we need to register those hooks.
225
-        $this->_global_ajax_hooks();
226
-        $this->_ajax_hooks();
227
-        // other_page_hooks have to be early too.
228
-        $this->_do_other_page_hooks();
229
-        // set up page dependencies
230
-        $this->_before_page_setup();
231
-        $this->_page_setup();
232
-        // die();
233
-    }
234
-
235
-
236
-    /**
237
-     * _init_page_props
238
-     * Child classes use to set at least the following properties:
239
-     * $page_slug.
240
-     * $page_label.
241
-     *
242
-     * @abstract
243
-     * @return void
244
-     */
245
-    abstract protected function _init_page_props();
246
-
247
-
248
-    /**
249
-     * _ajax_hooks
250
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
251
-     * Note: within the ajax callback methods.
252
-     *
253
-     * @abstract
254
-     * @return void
255
-     */
256
-    abstract protected function _ajax_hooks();
257
-
258
-
259
-    /**
260
-     * _define_page_props
261
-     * child classes define page properties in here.  Must include at least:
262
-     * $_admin_base_url = base_url for all admin pages
263
-     * $_admin_page_title = default admin_page_title for admin pages
264
-     * $_labels = array of default labels for various automatically generated elements:
265
-     *    array(
266
-     *        'buttons' => array(
267
-     *            'add' => esc_html__('label for add new button'),
268
-     *            'edit' => esc_html__('label for edit button'),
269
-     *            'delete' => esc_html__('label for delete button')
270
-     *            )
271
-     *        )
272
-     *
273
-     * @abstract
274
-     * @return void
275
-     */
276
-    abstract protected function _define_page_props();
277
-
278
-
279
-    /**
280
-     * _set_page_routes
281
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
282
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
283
-     * have a 'default' route. Here's the format
284
-     * $this->_page_routes = array(
285
-     *        'default' => array(
286
-     *            'func' => '_default_method_handling_route',
287
-     *            'args' => array('array','of','args'),
288
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
289
-     *            ajax request, backend processing)
290
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
291
-     *            headers route after.  The string you enter here should match the defined route reference for a
292
-     *            headers sent route.
293
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
294
-     *            this route.
295
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
296
-     *            checks).
297
-     *        ),
298
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
299
-     *        handling method.
300
-     *        )
301
-     * )
302
-     *
303
-     * @abstract
304
-     * @return void
305
-     */
306
-    abstract protected function _set_page_routes();
307
-
308
-
309
-    /**
310
-     * _set_page_config
311
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
312
-     * array corresponds to the page_route for the loaded page. Format:
313
-     * $this->_page_config = array(
314
-     *        'default' => array(
315
-     *            'labels' => array(
316
-     *                'buttons' => array(
317
-     *                    'add' => esc_html__('label for adding item'),
318
-     *                    'edit' => esc_html__('label for editing item'),
319
-     *                    'delete' => esc_html__('label for deleting item')
320
-     *                ),
321
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
322
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
323
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
324
-     *            _define_page_props() method
325
-     *            'nav' => array(
326
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
327
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
328
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
329
-     *                'order' => 10, //required to indicate tab position.
330
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
331
-     *                displayed then add this parameter.
332
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
333
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
334
-     *            metaboxes set for eventespresso admin pages.
335
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
336
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
337
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
338
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
339
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
340
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
341
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
342
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
343
-     *            want to display.
344
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
345
-     *                'tab_id' => array(
346
-     *                    'title' => 'tab_title',
347
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
348
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
349
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
350
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
351
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
352
-     *                    attempt to use the callback which should match the name of a method in the class
353
-     *                    ),
354
-     *                'tab2_id' => array(
355
-     *                    'title' => 'tab2 title',
356
-     *                    'filename' => 'file_name_2'
357
-     *                    'callback' => 'callback_method_for_content',
358
-     *                 ),
359
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
360
-     *            help tab area on an admin page. @return void
361
-     *
362
-     * @abstract
363
-     */
364
-    abstract protected function _set_page_config();
365
-
366
-
367
-    /**
368
-     * _add_screen_options
369
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
370
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
371
-     * to a particular view.
372
-     *
373
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
374
-     *         see also WP_Screen object documents...
375
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
376
-     * @abstract
377
-     * @return void
378
-     */
379
-    abstract protected function _add_screen_options();
380
-
381
-
382
-    /**
383
-     * _add_feature_pointers
384
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
385
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
386
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
387
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
388
-     * extended) also see:
389
-     *
390
-     * @link   http://eamann.com/tech/wordpress-portland/
391
-     * @abstract
392
-     * @return void
393
-     */
394
-    abstract protected function _add_feature_pointers();
395
-
396
-
397
-    /**
398
-     * load_scripts_styles
399
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
400
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
401
-     * scripts/styles per view by putting them in a dynamic function in this format
402
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
403
-     *
404
-     * @abstract
405
-     * @return void
406
-     */
407
-    abstract public function load_scripts_styles();
408
-
409
-
410
-    /**
411
-     * admin_init
412
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
413
-     * all pages/views loaded by child class.
414
-     *
415
-     * @abstract
416
-     * @return void
417
-     */
418
-    abstract public function admin_init();
419
-
420
-
421
-    /**
422
-     * admin_notices
423
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
424
-     * all pages/views loaded by child class.
425
-     *
426
-     * @abstract
427
-     * @return void
428
-     */
429
-    abstract public function admin_notices();
430
-
431
-
432
-    /**
433
-     * admin_footer_scripts
434
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
435
-     * will apply to all pages/views loaded by child class.
436
-     *
437
-     * @return void
438
-     */
439
-    abstract public function admin_footer_scripts();
440
-
441
-
442
-    /**
443
-     * admin_footer
444
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
445
-     * apply to all pages/views loaded by child class.
446
-     *
447
-     * @return void
448
-     */
449
-    public function admin_footer()
450
-    {
451
-    }
452
-
453
-
454
-    /**
455
-     * _global_ajax_hooks
456
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
457
-     * Note: within the ajax callback methods.
458
-     *
459
-     * @abstract
460
-     * @return void
461
-     */
462
-    protected function _global_ajax_hooks()
463
-    {
464
-        // for lazy loading of metabox content
465
-        add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
466
-    }
467
-
468
-
469
-    public function ajax_metabox_content()
470
-    {
471
-        $content_id  = $this->request->getRequestParam('contentid', '');
472
-        $content_url = $this->request->getRequestParam('contenturl', '', 'url');
473
-        self::cached_rss_display($content_id, $content_url);
474
-        wp_die();
475
-    }
476
-
477
-
478
-    /**
479
-     * allows extending classes do something specific before the parent constructor runs _page_setup().
480
-     *
481
-     * @return void
482
-     */
483
-    protected function _before_page_setup()
484
-    {
485
-        // default is to do nothing
486
-    }
487
-
488
-
489
-    /**
490
-     * Makes sure any things that need to be loaded early get handled.
491
-     * We also escape early here if the page requested doesn't match the object.
492
-     *
493
-     * @final
494
-     * @return void
495
-     * @throws EE_Error
496
-     * @throws InvalidArgumentException
497
-     * @throws ReflectionException
498
-     * @throws InvalidDataTypeException
499
-     * @throws InvalidInterfaceException
500
-     */
501
-    final protected function _page_setup()
502
-    {
503
-        // requires?
504
-        // admin_init stuff - global - we're setting this REALLY early
505
-        // so if EE_Admin pages have to hook into other WP pages they can.
506
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
507
-        add_action('admin_init', [$this, 'admin_init_global'], 5);
508
-        // next verify if we need to load anything...
509
-        $this->_current_page = $this->request->getRequestParam('page', '', 'key');
510
-        $this->page_folder   = strtolower(
511
-            str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
512
-        );
513
-        global $ee_menu_slugs;
514
-        $ee_menu_slugs = (array) $ee_menu_slugs;
515
-        if (
516
-            ! $this->request->isAjax()
517
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
518
-        ) {
519
-            return;
520
-        }
521
-        // because WP List tables have two duplicate select inputs for choosing bulk actions,
522
-        // we need to copy the action from the second to the first
523
-        $action     = $this->request->getRequestParam('action', '-1', 'key');
524
-        $action2    = $this->request->getRequestParam('action2', '-1', 'key');
525
-        $action     = $action !== '-1' ? $action : $action2;
526
-        $req_action = $action !== '-1' ? $action : 'default';
527
-
528
-        // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
529
-        // then let's use the route as the action.
530
-        // This covers cases where we're coming in from a list table that isn't on the default route.
531
-        $route = $this->request->getRequestParam('route');
532
-        $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
533
-            ? $route
534
-            : $req_action;
535
-
536
-        $this->_current_view = $this->_req_action;
537
-        $this->_req_nonce    = $this->_req_action . '_nonce';
538
-        $this->_define_page_props();
539
-        $this->_current_page_view_url = add_query_arg(
540
-            ['page' => $this->_current_page, 'action' => $this->_current_view],
541
-            $this->_admin_base_url
542
-        );
543
-        // default things
544
-        $this->_default_espresso_metaboxes = [
545
-            '_espresso_news_post_box',
546
-            '_espresso_links_post_box',
547
-            '_espresso_ratings_request',
548
-            '_espresso_sponsors_post_box',
549
-        ];
550
-        // set page configs
551
-        $this->_set_page_routes();
552
-        $this->_set_page_config();
553
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
554
-        if ($this->request->requestParamIsSet('wp_referer')) {
555
-            $wp_referer = $this->request->getRequestParam('wp_referer');
556
-            if ($wp_referer) {
557
-                $this->_default_route_query_args['wp_referer'] = $wp_referer;
558
-            }
559
-        }
560
-        // for caffeinated and other extended functionality.
561
-        //  If there is a _extend_page_config method
562
-        // then let's run that to modify the all the various page configuration arrays
563
-        if (method_exists($this, '_extend_page_config')) {
564
-            $this->_extend_page_config();
565
-        }
566
-        // for CPT and other extended functionality.
567
-        // If there is an _extend_page_config_for_cpt
568
-        // then let's run that to modify all the various page configuration arrays.
569
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
570
-            $this->_extend_page_config_for_cpt();
571
-        }
572
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
573
-        $this->_page_routes = apply_filters(
574
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
575
-            $this->_page_routes,
576
-            $this
577
-        );
578
-        $this->_page_config = apply_filters(
579
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
580
-            $this->_page_config,
581
-            $this
582
-        );
583
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
584
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
585
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
586
-            add_action(
587
-                'AHEE__EE_Admin_Page__route_admin_request',
588
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
589
-                10,
590
-                2
591
-            );
592
-        }
593
-        // next route only if routing enabled
594
-        if ($this->_routing && ! $this->request->isAjax()) {
595
-            $this->_verify_routes();
596
-            // next let's just check user_access and kill if no access
597
-            $this->check_user_access();
598
-            if ($this->_is_UI_request) {
599
-                // admin_init stuff - global, all views for this page class, specific view
600
-                add_action('admin_init', [$this, 'admin_init'], 10);
601
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
602
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
603
-                }
604
-            } else {
605
-                // hijack regular WP loading and route admin request immediately
606
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
607
-                $this->route_admin_request();
608
-            }
609
-        }
610
-    }
611
-
612
-
613
-    /**
614
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
615
-     *
616
-     * @return void
617
-     * @throws EE_Error
618
-     */
619
-    private function _do_other_page_hooks()
620
-    {
621
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
622
-        foreach ($registered_pages as $page) {
623
-            // now let's setup the file name and class that should be present
624
-            $classname = str_replace('.class.php', '', $page);
625
-            // autoloaders should take care of loading file
626
-            if (! class_exists($classname)) {
627
-                $error_msg[] = sprintf(
628
-                    esc_html__(
629
-                        'Something went wrong with loading the %s admin hooks page.',
630
-                        'event_espresso'
631
-                    ),
632
-                    $page
633
-                );
634
-                $error_msg[] = $error_msg[0]
635
-                               . "\r\n"
636
-                               . sprintf(
637
-                                   esc_html__(
638
-                                       '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',
639
-                                       'event_espresso'
640
-                                   ),
641
-                                   $page,
642
-                                   '<br />',
643
-                                   '<strong>' . $classname . '</strong>'
644
-                               );
645
-                throw new EE_Error(implode('||', $error_msg));
646
-            }
647
-            // notice we are passing the instance of this class to the hook object.
648
-            $this->loader->getShared($classname, [$this]);
649
-        }
650
-    }
651
-
652
-
653
-    /**
654
-     * @throws ReflectionException
655
-     * @throws EE_Error
656
-     */
657
-    public function load_page_dependencies()
658
-    {
659
-        try {
660
-            $this->_load_page_dependencies();
661
-        } catch (EE_Error $e) {
662
-            $e->get_error();
663
-        }
664
-    }
665
-
666
-
667
-    /**
668
-     * load_page_dependencies
669
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
670
-     *
671
-     * @return void
672
-     * @throws DomainException
673
-     * @throws EE_Error
674
-     * @throws InvalidArgumentException
675
-     * @throws InvalidDataTypeException
676
-     * @throws InvalidInterfaceException
677
-     */
678
-    protected function _load_page_dependencies()
679
-    {
680
-        // let's set the current_screen and screen options to override what WP set
681
-        $this->_current_screen = get_current_screen();
682
-        // load admin_notices - global, page class, and view specific
683
-        add_action('admin_notices', [$this, 'admin_notices_global'], 5);
684
-        add_action('admin_notices', [$this, 'admin_notices'], 10);
685
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
686
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
687
-        }
688
-        // load network admin_notices - global, page class, and view specific
689
-        add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
690
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
691
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
692
-        }
693
-        // this will save any per_page screen options if they are present
694
-        $this->_set_per_page_screen_options();
695
-        // setup list table properties
696
-        $this->_set_list_table();
697
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
698
-        // However in some cases the metaboxes will need to be added within a route handling callback.
699
-        $this->_add_registered_meta_boxes();
700
-        $this->_add_screen_columns();
701
-        // add screen options - global, page child class, and view specific
702
-        $this->_add_global_screen_options();
703
-        $this->_add_screen_options();
704
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
705
-        if (method_exists($this, $add_screen_options)) {
706
-            $this->{$add_screen_options}();
707
-        }
708
-        // add help tab(s) - set via page_config and qtips.
709
-        $this->_add_help_tabs();
710
-        $this->_add_qtips();
711
-        // add feature_pointers - global, page child class, and view specific
712
-        $this->_add_feature_pointers();
713
-        $this->_add_global_feature_pointers();
714
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
715
-        if (method_exists($this, $add_feature_pointer)) {
716
-            $this->{$add_feature_pointer}();
717
-        }
718
-        // enqueue scripts/styles - global, page class, and view specific
719
-        add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
720
-        add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
721
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
722
-            add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
723
-        }
724
-        add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
725
-        // admin_print_footer_scripts - global, page child class, and view specific.
726
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
727
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
728
-        // is a good use case. Notice the late priority we're giving these
729
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
730
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
731
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
732
-            add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
733
-        }
734
-        // admin footer scripts
735
-        add_action('admin_footer', [$this, 'admin_footer_global'], 99);
736
-        add_action('admin_footer', [$this, 'admin_footer'], 100);
737
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
738
-            add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
739
-        }
740
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
741
-        // targeted hook
742
-        do_action(
743
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
744
-        );
745
-    }
746
-
747
-
748
-    /**
749
-     * _set_defaults
750
-     * This sets some global defaults for class properties.
751
-     */
752
-    private function _set_defaults()
753
-    {
754
-        $this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
755
-        $this->_event                = $this->_template_path = $this->_column_template_path = null;
756
-        $this->_nav_tabs             = $this->_views = $this->_page_routes = [];
757
-        $this->_page_config          = $this->_default_route_query_args = [];
758
-        $this->_default_nav_tab_name = 'overview';
759
-        // init template args
760
-        $this->_template_args = [
761
-            'admin_page_header'  => '',
762
-            'admin_page_content' => '',
763
-            'post_body_content'  => '',
764
-            'before_list_table'  => '',
765
-            'after_list_table'   => '',
766
-        ];
767
-    }
768
-
769
-
770
-    /**
771
-     * route_admin_request
772
-     *
773
-     * @return void
774
-     * @throws InvalidArgumentException
775
-     * @throws InvalidInterfaceException
776
-     * @throws InvalidDataTypeException
777
-     * @throws EE_Error
778
-     * @throws ReflectionException
779
-     * @see    _route_admin_request()
780
-     */
781
-    public function route_admin_request()
782
-    {
783
-        try {
784
-            $this->_route_admin_request();
785
-        } catch (EE_Error $e) {
786
-            $e->get_error();
787
-        }
788
-    }
789
-
790
-
791
-    public function set_wp_page_slug($wp_page_slug)
792
-    {
793
-        $this->_wp_page_slug = $wp_page_slug;
794
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
795
-        if (is_network_admin()) {
796
-            $this->_wp_page_slug .= '-network';
797
-        }
798
-    }
799
-
800
-
801
-    /**
802
-     * _verify_routes
803
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
804
-     * we know if we need to drop out.
805
-     *
806
-     * @return bool
807
-     * @throws EE_Error
808
-     */
809
-    protected function _verify_routes()
810
-    {
811
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
812
-        if (! $this->_current_page && ! $this->request->isAjax()) {
813
-            return false;
814
-        }
815
-        $this->_route = false;
816
-        // check that the page_routes array is not empty
817
-        if (empty($this->_page_routes)) {
818
-            // user error msg
819
-            $error_msg = sprintf(
820
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
821
-                $this->_admin_page_title
822
-            );
823
-            // developer error msg
824
-            $error_msg .= '||' . $error_msg
825
-                          . esc_html__(
826
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
827
-                              'event_espresso'
828
-                          );
829
-            throw new EE_Error($error_msg);
830
-        }
831
-        // and that the requested page route exists
832
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
833
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
834
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
835
-                ? $this->_page_config[ $this->_req_action ]
836
-                : [];
837
-        } else {
838
-            // user error msg
839
-            $error_msg = sprintf(
840
-                esc_html__(
841
-                    'The requested page route does not exist for the %s admin page.',
842
-                    'event_espresso'
843
-                ),
844
-                $this->_admin_page_title
845
-            );
846
-            // developer error msg
847
-            $error_msg .= '||' . $error_msg
848
-                          . sprintf(
849
-                              esc_html__(
850
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
851
-                                  'event_espresso'
852
-                              ),
853
-                              $this->_req_action
854
-                          );
855
-            throw new EE_Error($error_msg);
856
-        }
857
-        // and that a default route exists
858
-        if (! array_key_exists('default', $this->_page_routes)) {
859
-            // user error msg
860
-            $error_msg = sprintf(
861
-                esc_html__(
862
-                    'A default page route has not been set for the % admin page.',
863
-                    'event_espresso'
864
-                ),
865
-                $this->_admin_page_title
866
-            );
867
-            // developer error msg
868
-            $error_msg .= '||' . $error_msg
869
-                          . esc_html__(
870
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
871
-                              'event_espresso'
872
-                          );
873
-            throw new EE_Error($error_msg);
874
-        }
875
-        // first lets' catch if the UI request has EVER been set.
876
-        if ($this->_is_UI_request === null) {
877
-            // lets set if this is a UI request or not.
878
-            $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
879
-            // wait a minute... we might have a noheader in the route array
880
-            $this->_is_UI_request = ! (
881
-                is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
882
-            )
883
-                ? $this->_is_UI_request
884
-                : false;
885
-        }
886
-        $this->_set_current_labels();
887
-        return true;
888
-    }
889
-
890
-
891
-    /**
892
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
893
-     *
894
-     * @param string $route the route name we're verifying
895
-     * @return bool we'll throw an exception if this isn't a valid route.
896
-     * @throws EE_Error
897
-     */
898
-    protected function _verify_route($route)
899
-    {
900
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
901
-            return true;
902
-        }
903
-        // user error msg
904
-        $error_msg = sprintf(
905
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
906
-            $this->_admin_page_title
907
-        );
908
-        // developer error msg
909
-        $error_msg .= '||' . $error_msg
910
-                      . sprintf(
911
-                          esc_html__(
912
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
913
-                              'event_espresso'
914
-                          ),
915
-                          $route
916
-                      );
917
-        throw new EE_Error($error_msg);
918
-    }
919
-
920
-
921
-    /**
922
-     * perform nonce verification
923
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
924
-     * using this method (and save retyping!)
925
-     *
926
-     * @param string $nonce     The nonce sent
927
-     * @param string $nonce_ref The nonce reference string (name0)
928
-     * @return void
929
-     * @throws EE_Error
930
-     */
931
-    protected function _verify_nonce($nonce, $nonce_ref)
932
-    {
933
-        // verify nonce against expected value
934
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
935
-            // these are not the droids you are looking for !!!
936
-            $msg = sprintf(
937
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
938
-                '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
939
-                '</a>'
940
-            );
941
-            if (WP_DEBUG) {
942
-                $msg .= "\n  ";
943
-                $msg .= sprintf(
944
-                    esc_html__(
945
-                        'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
946
-                        'event_espresso'
947
-                    ),
948
-                    __CLASS__
949
-                );
950
-            }
951
-            if (! $this->request->isAjax()) {
952
-                wp_die($msg);
953
-            }
954
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
955
-            $this->_return_json();
956
-        }
957
-    }
958
-
959
-
960
-    /**
961
-     * _route_admin_request()
962
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
963
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
964
-     * in the page routes and then will try to load the corresponding method.
965
-     *
966
-     * @return void
967
-     * @throws EE_Error
968
-     * @throws InvalidArgumentException
969
-     * @throws InvalidDataTypeException
970
-     * @throws InvalidInterfaceException
971
-     * @throws ReflectionException
972
-     */
973
-    protected function _route_admin_request()
974
-    {
975
-        if (! $this->_is_UI_request) {
976
-            $this->_verify_routes();
977
-        }
978
-        $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
979
-        if ($this->_req_action !== 'default' && $nonce_check) {
980
-            // set nonce from post data
981
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
982
-            $this->_verify_nonce($nonce, $this->_req_nonce);
983
-        }
984
-        // set the nav_tabs array but ONLY if this is  UI_request
985
-        if ($this->_is_UI_request) {
986
-            $this->_set_nav_tabs();
987
-        }
988
-        // grab callback function
989
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
990
-        // check if callback has args
991
-        $args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
992
-        $error_msg = '';
993
-        // action right before calling route
994
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
995
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
996
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
997
-        }
998
-        // right before calling the route, let's clean the _wp_http_referer
999
-        $this->request->setServerParam(
1000
-            'REQUEST_URI',
1001
-            remove_query_arg(
1002
-                '_wp_http_referer',
1003
-                wp_unslash($this->request->getServerParam('REQUEST_URI'))
1004
-            )
1005
-        );
1006
-        if (! empty($func)) {
1007
-            if (is_array($func)) {
1008
-                list($class, $method) = $func;
1009
-            } elseif (strpos($func, '::') !== false) {
1010
-                list($class, $method) = explode('::', $func);
1011
-            } else {
1012
-                $class  = $this;
1013
-                $method = $func;
1014
-            }
1015
-            if (! (is_object($class) && $class === $this)) {
1016
-                // send along this admin page object for access by addons.
1017
-                $args['admin_page_object'] = $this;
1018
-            }
1019
-            if (
1020
-                // is it a method on a class that doesn't work?
1021
-                (
1022
-                    (
1023
-                        method_exists($class, $method)
1024
-                        && call_user_func_array([$class, $method], $args) === false
1025
-                    )
1026
-                    && (
1027
-                        // is it a standalone function that doesn't work?
1028
-                        function_exists($method)
1029
-                        && call_user_func_array(
1030
-                            $func,
1031
-                            array_merge(['admin_page_object' => $this], $args)
1032
-                        ) === false
1033
-                    )
1034
-                )
1035
-                || (
1036
-                    // is it neither a class method NOR a standalone function?
1037
-                    ! method_exists($class, $method)
1038
-                    && ! function_exists($method)
1039
-                )
1040
-            ) {
1041
-                // user error msg
1042
-                $error_msg = esc_html__(
1043
-                    'An error occurred. The  requested page route could not be found.',
1044
-                    'event_espresso'
1045
-                );
1046
-                // developer error msg
1047
-                $error_msg .= '||';
1048
-                $error_msg .= sprintf(
1049
-                    esc_html__(
1050
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1051
-                        'event_espresso'
1052
-                    ),
1053
-                    $method
1054
-                );
1055
-            }
1056
-            if (! empty($error_msg)) {
1057
-                throw new EE_Error($error_msg);
1058
-            }
1059
-        }
1060
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1061
-        // then we need to reset the routing properties to the new route.
1062
-        // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1063
-        if (
1064
-            $this->_is_UI_request === false
1065
-            && is_array($this->_route)
1066
-            && ! empty($this->_route['headers_sent_route'])
1067
-        ) {
1068
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1069
-        }
1070
-    }
1071
-
1072
-
1073
-    /**
1074
-     * This method just allows the resetting of page properties in the case where a no headers
1075
-     * route redirects to a headers route in its route config.
1076
-     *
1077
-     * @param string $new_route New (non header) route to redirect to.
1078
-     * @return   void
1079
-     * @throws ReflectionException
1080
-     * @throws InvalidArgumentException
1081
-     * @throws InvalidInterfaceException
1082
-     * @throws InvalidDataTypeException
1083
-     * @throws EE_Error
1084
-     * @since   4.3.0
1085
-     */
1086
-    protected function _reset_routing_properties($new_route)
1087
-    {
1088
-        $this->_is_UI_request = true;
1089
-        // now we set the current route to whatever the headers_sent_route is set at
1090
-        $this->request->setRequestParam('action', $new_route);
1091
-        // rerun page setup
1092
-        $this->_page_setup();
1093
-    }
1094
-
1095
-
1096
-    /**
1097
-     * _add_query_arg
1098
-     * adds nonce to array of arguments then calls WP add_query_arg function
1099
-     *(internally just uses EEH_URL's function with the same name)
1100
-     *
1101
-     * @param array  $args
1102
-     * @param string $url
1103
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1104
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1105
-     *                                        Example usage: If the current page is:
1106
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1107
-     *                                        &action=default&event_id=20&month_range=March%202015
1108
-     *                                        &_wpnonce=5467821
1109
-     *                                        and you call:
1110
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1111
-     *                                        array(
1112
-     *                                        'action' => 'resend_something',
1113
-     *                                        'page=>espresso_registrations'
1114
-     *                                        ),
1115
-     *                                        $some_url,
1116
-     *                                        true
1117
-     *                                        );
1118
-     *                                        It will produce a url in this structure:
1119
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1120
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1121
-     *                                        month_range]=March%202015
1122
-     * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1123
-     * @return string
1124
-     */
1125
-    public static function add_query_args_and_nonce(
1126
-        $args = [],
1127
-        $url = false,
1128
-        $sticky = false,
1129
-        $exclude_nonce = false
1130
-    ) {
1131
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1132
-        if ($sticky) {
1133
-            /** @var RequestInterface $request */
1134
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1135
-            $request->unSetRequestParams(['_wp_http_referer', 'wp_referer']);
1136
-            foreach ($request->requestParams() as $key => $value) {
1137
-                // do not add nonces
1138
-                if (strpos($key, 'nonce') !== false) {
1139
-                    continue;
1140
-                }
1141
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1142
-            }
1143
-        }
1144
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1145
-    }
1146
-
1147
-
1148
-    /**
1149
-     * This returns a generated link that will load the related help tab.
1150
-     *
1151
-     * @param string $help_tab_id the id for the connected help tab
1152
-     * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1153
-     * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1154
-     * @return string              generated link
1155
-     * @uses EEH_Template::get_help_tab_link()
1156
-     */
1157
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1158
-    {
1159
-        return EEH_Template::get_help_tab_link(
1160
-            $help_tab_id,
1161
-            $this->page_slug,
1162
-            $this->_req_action,
1163
-            $icon_style,
1164
-            $help_text
1165
-        );
1166
-    }
1167
-
1168
-
1169
-    /**
1170
-     * _add_help_tabs
1171
-     * Note child classes define their help tabs within the page_config array.
1172
-     *
1173
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1174
-     * @return void
1175
-     * @throws DomainException
1176
-     * @throws EE_Error
1177
-     */
1178
-    protected function _add_help_tabs()
1179
-    {
1180
-        if (isset($this->_page_config[ $this->_req_action ])) {
1181
-            $config = $this->_page_config[ $this->_req_action ];
1182
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1183
-            if (is_array($config) && isset($config['help_sidebar'])) {
1184
-                // check that the callback given is valid
1185
-                if (! method_exists($this, $config['help_sidebar'])) {
1186
-                    throw new EE_Error(
1187
-                        sprintf(
1188
-                            esc_html__(
1189
-                                'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1190
-                                'event_espresso'
1191
-                            ),
1192
-                            $config['help_sidebar'],
1193
-                            get_class($this)
1194
-                        )
1195
-                    );
1196
-                }
1197
-                $content = apply_filters(
1198
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1199
-                    $this->{$config['help_sidebar']}()
1200
-                );
1201
-                $this->_current_screen->set_help_sidebar($content);
1202
-            }
1203
-            if (! isset($config['help_tabs'])) {
1204
-                return;
1205
-            } //no help tabs for this route
1206
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1207
-                // we're here so there ARE help tabs!
1208
-                // make sure we've got what we need
1209
-                if (! isset($cfg['title'])) {
1210
-                    throw new EE_Error(
1211
-                        esc_html__(
1212
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1213
-                            'event_espresso'
1214
-                        )
1215
-                    );
1216
-                }
1217
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1218
-                    throw new EE_Error(
1219
-                        esc_html__(
1220
-                            'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1221
-                            'event_espresso'
1222
-                        )
1223
-                    );
1224
-                }
1225
-                // first priority goes to content.
1226
-                if (! empty($cfg['content'])) {
1227
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1228
-                    // second priority goes to filename
1229
-                } elseif (! empty($cfg['filename'])) {
1230
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1231
-                    // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1232
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1233
-                                                             . basename($this->_get_dir())
1234
-                                                             . '/help_tabs/'
1235
-                                                             . $cfg['filename']
1236
-                                                             . '.help_tab.php' : $file_path;
1237
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1238
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1239
-                        EE_Error::add_error(
1240
-                            sprintf(
1241
-                                esc_html__(
1242
-                                    'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1243
-                                    'event_espresso'
1244
-                                ),
1245
-                                $tab_id,
1246
-                                key($config),
1247
-                                $file_path
1248
-                            ),
1249
-                            __FILE__,
1250
-                            __FUNCTION__,
1251
-                            __LINE__
1252
-                        );
1253
-                        return;
1254
-                    }
1255
-                    $template_args['admin_page_obj'] = $this;
1256
-                    $content                         = EEH_Template::display_template(
1257
-                        $file_path,
1258
-                        $template_args,
1259
-                        true
1260
-                    );
1261
-                } else {
1262
-                    $content = '';
1263
-                }
1264
-                // check if callback is valid
1265
-                if (
1266
-                    empty($content)
1267
-                    && (
1268
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1269
-                    )
1270
-                ) {
1271
-                    EE_Error::add_error(
1272
-                        sprintf(
1273
-                            esc_html__(
1274
-                                'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1275
-                                'event_espresso'
1276
-                            ),
1277
-                            $cfg['title']
1278
-                        ),
1279
-                        __FILE__,
1280
-                        __FUNCTION__,
1281
-                        __LINE__
1282
-                    );
1283
-                    return;
1284
-                }
1285
-                // setup config array for help tab method
1286
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1287
-                $_ht = [
1288
-                    'id'       => $id,
1289
-                    'title'    => $cfg['title'],
1290
-                    'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1291
-                    'content'  => $content,
1292
-                ];
1293
-                $this->_current_screen->add_help_tab($_ht);
1294
-            }
1295
-        }
1296
-    }
1297
-
1298
-
1299
-    /**
1300
-     * This simply sets up any qtips that have been defined in the page config
1301
-     *
1302
-     * @return void
1303
-     */
1304
-    protected function _add_qtips()
1305
-    {
1306
-        if (isset($this->_route_config['qtips'])) {
1307
-            $qtips = (array) $this->_route_config['qtips'];
1308
-            // load qtip loader
1309
-            $path = [
1310
-                $this->_get_dir() . '/qtips/',
1311
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1312
-            ];
1313
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1314
-        }
1315
-    }
1316
-
1317
-
1318
-    /**
1319
-     * _set_nav_tabs
1320
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1321
-     * wish to add additional tabs or modify accordingly.
1322
-     *
1323
-     * @return void
1324
-     * @throws InvalidArgumentException
1325
-     * @throws InvalidInterfaceException
1326
-     * @throws InvalidDataTypeException
1327
-     */
1328
-    protected function _set_nav_tabs()
1329
-    {
1330
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1331
-        $i = 0;
1332
-        foreach ($this->_page_config as $slug => $config) {
1333
-            if (! is_array($config) || empty($config['nav'])) {
1334
-                continue;
1335
-            }
1336
-            // no nav tab for this config
1337
-            // check for persistent flag
1338
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1339
-                // nav tab is only to appear when route requested.
1340
-                continue;
1341
-            }
1342
-            if (! $this->check_user_access($slug, true)) {
1343
-                // no nav tab because current user does not have access.
1344
-                continue;
1345
-            }
1346
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1347
-            $this->_nav_tabs[ $slug ] = [
1348
-                'url'       => isset($config['nav']['url'])
1349
-                    ? $config['nav']['url']
1350
-                    : self::add_query_args_and_nonce(
1351
-                        ['action' => $slug],
1352
-                        $this->_admin_base_url
1353
-                    ),
1354
-                'link_text' => isset($config['nav']['label'])
1355
-                    ? $config['nav']['label']
1356
-                    : ucwords(
1357
-                        str_replace('_', ' ', $slug)
1358
-                    ),
1359
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1360
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1361
-            ];
1362
-            $i++;
1363
-        }
1364
-        // if $this->_nav_tabs is empty then lets set the default
1365
-        if (empty($this->_nav_tabs)) {
1366
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1367
-                'url'       => $this->_admin_base_url,
1368
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1369
-                'css_class' => 'nav-tab-active',
1370
-                'order'     => 10,
1371
-            ];
1372
-        }
1373
-        // now let's sort the tabs according to order
1374
-        usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1375
-    }
1376
-
1377
-
1378
-    /**
1379
-     * _set_current_labels
1380
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1381
-     * property array
1382
-     *
1383
-     * @return void
1384
-     */
1385
-    private function _set_current_labels()
1386
-    {
1387
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1388
-            foreach ($this->_route_config['labels'] as $label => $text) {
1389
-                if (is_array($text)) {
1390
-                    foreach ($text as $sublabel => $subtext) {
1391
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1392
-                    }
1393
-                } else {
1394
-                    $this->_labels[ $label ] = $text;
1395
-                }
1396
-            }
1397
-        }
1398
-    }
1399
-
1400
-
1401
-    /**
1402
-     *        verifies user access for this admin page
1403
-     *
1404
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1405
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1406
-     *                               return false if verify fail.
1407
-     * @return bool
1408
-     * @throws InvalidArgumentException
1409
-     * @throws InvalidDataTypeException
1410
-     * @throws InvalidInterfaceException
1411
-     */
1412
-    public function check_user_access($route_to_check = '', $verify_only = false)
1413
-    {
1414
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1415
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1416
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1417
-                          && is_array(
1418
-                              $this->_page_routes[ $route_to_check ]
1419
-                          )
1420
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1421
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1422
-        if (empty($capability) && empty($route_to_check)) {
1423
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1424
-                : $this->_route['capability'];
1425
-        } else {
1426
-            $capability = empty($capability) ? 'manage_options' : $capability;
1427
-        }
1428
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1429
-        if (
1430
-            ! $this->request->isAjax()
1431
-            && (
1432
-                ! function_exists('is_admin')
1433
-                || ! EE_Registry::instance()->CAP->current_user_can(
1434
-                    $capability,
1435
-                    $this->page_slug
1436
-                    . '_'
1437
-                    . $route_to_check,
1438
-                    $id
1439
-                )
1440
-            )
1441
-        ) {
1442
-            if ($verify_only) {
1443
-                return false;
1444
-            }
1445
-            if (is_user_logged_in()) {
1446
-                wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1447
-            } else {
1448
-                return false;
1449
-            }
1450
-        }
1451
-        return true;
1452
-    }
1453
-
1454
-
1455
-    /**
1456
-     * admin_init_global
1457
-     * This runs all the code that we want executed within the WP admin_init hook.
1458
-     * This method executes for ALL EE Admin pages.
1459
-     *
1460
-     * @return void
1461
-     */
1462
-    public function admin_init_global()
1463
-    {
1464
-    }
1465
-
1466
-
1467
-    /**
1468
-     * wp_loaded_global
1469
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1470
-     * EE_Admin page and will execute on every EE Admin Page load
1471
-     *
1472
-     * @return void
1473
-     */
1474
-    public function wp_loaded()
1475
-    {
1476
-    }
1477
-
1478
-
1479
-    /**
1480
-     * admin_notices
1481
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1482
-     * ALL EE_Admin pages.
1483
-     *
1484
-     * @return void
1485
-     */
1486
-    public function admin_notices_global()
1487
-    {
1488
-        $this->_display_no_javascript_warning();
1489
-        $this->_display_espresso_notices();
1490
-    }
1491
-
1492
-
1493
-    public function network_admin_notices_global()
1494
-    {
1495
-        $this->_display_no_javascript_warning();
1496
-        $this->_display_espresso_notices();
1497
-    }
1498
-
1499
-
1500
-    /**
1501
-     * admin_footer_scripts_global
1502
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1503
-     * will apply on ALL EE_Admin pages.
1504
-     *
1505
-     * @return void
1506
-     */
1507
-    public function admin_footer_scripts_global()
1508
-    {
1509
-        $this->_add_admin_page_ajax_loading_img();
1510
-        $this->_add_admin_page_overlay();
1511
-        // if metaboxes are present we need to add the nonce field
1512
-        if (
1513
-            isset($this->_route_config['metaboxes'])
1514
-            || isset($this->_route_config['list_table'])
1515
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1516
-        ) {
1517
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1518
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1519
-        }
1520
-    }
1521
-
1522
-
1523
-    /**
1524
-     * admin_footer_global
1525
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1526
-     * ALL EE_Admin Pages.
1527
-     *
1528
-     * @return void
1529
-     */
1530
-    public function admin_footer_global()
1531
-    {
1532
-        // dialog container for dialog helper
1533
-        echo '
111
+	/**
112
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
113
+	 * actions.
114
+	 *
115
+	 * @since 4.6.x
116
+	 * @var array.
117
+	 */
118
+	protected $_default_route_query_args;
119
+
120
+	// set via request page and action args.
121
+	protected $_current_page;
122
+
123
+	protected $_current_view;
124
+
125
+	protected $_current_page_view_url;
126
+
127
+	/**
128
+	 * unprocessed value for the 'action' request param (default '')
129
+	 *
130
+	 * @var string
131
+	 */
132
+	protected $raw_req_action = '';
133
+
134
+	/**
135
+	 * unprocessed value for the 'page' request param (default '')
136
+	 *
137
+	 * @var string
138
+	 */
139
+	protected $raw_req_page = '';
140
+
141
+	/**
142
+	 * sanitized request action (and nonce)
143
+	 *
144
+	 * @var string
145
+	 */
146
+	protected $_req_action = '';
147
+
148
+	/**
149
+	 * sanitized request action nonce
150
+	 *
151
+	 * @var string
152
+	 */
153
+	protected $_req_nonce = '';
154
+
155
+	/**
156
+	 * @var string
157
+	 */
158
+	protected $_search_btn_label = '';
159
+
160
+	/**
161
+	 * @var string
162
+	 */
163
+	protected $_search_box_callback = '';
164
+
165
+	/**
166
+	 * @var WP_Screen
167
+	 */
168
+	protected $_current_screen;
169
+
170
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
171
+	protected $_hook_obj;
172
+
173
+	// for holding incoming request data
174
+	protected $_req_data = [];
175
+
176
+	// yes / no array for admin form fields
177
+	protected $_yes_no_values = [];
178
+
179
+	// some default things shared by all child classes
180
+	protected $_default_espresso_metaboxes;
181
+
182
+	/**
183
+	 * @var EE_Registry
184
+	 */
185
+	protected $EE = null;
186
+
187
+
188
+	/**
189
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
190
+	 *
191
+	 * @var boolean
192
+	 */
193
+	protected $_is_caf = false;
194
+
195
+
196
+	/**
197
+	 * @Constructor
198
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
199
+	 * @throws EE_Error
200
+	 * @throws InvalidArgumentException
201
+	 * @throws ReflectionException
202
+	 * @throws InvalidDataTypeException
203
+	 * @throws InvalidInterfaceException
204
+	 */
205
+	public function __construct($routing = true)
206
+	{
207
+		$this->loader  = LoaderFactory::getLoader();
208
+		$this->request = $this->loader->getShared(RequestInterface::class);
209
+		$this->_routing = $routing;
210
+
211
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
212
+			$this->_is_caf = true;
213
+		}
214
+		$this->_yes_no_values = [
215
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
216
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
217
+		];
218
+		// set the _req_data property.
219
+		$this->_req_data = $this->request->requestParams();
220
+		// set initial page props (child method)
221
+		$this->_init_page_props();
222
+		// set global defaults
223
+		$this->_set_defaults();
224
+		// set early because incoming requests could be ajax related and we need to register those hooks.
225
+		$this->_global_ajax_hooks();
226
+		$this->_ajax_hooks();
227
+		// other_page_hooks have to be early too.
228
+		$this->_do_other_page_hooks();
229
+		// set up page dependencies
230
+		$this->_before_page_setup();
231
+		$this->_page_setup();
232
+		// die();
233
+	}
234
+
235
+
236
+	/**
237
+	 * _init_page_props
238
+	 * Child classes use to set at least the following properties:
239
+	 * $page_slug.
240
+	 * $page_label.
241
+	 *
242
+	 * @abstract
243
+	 * @return void
244
+	 */
245
+	abstract protected function _init_page_props();
246
+
247
+
248
+	/**
249
+	 * _ajax_hooks
250
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
251
+	 * Note: within the ajax callback methods.
252
+	 *
253
+	 * @abstract
254
+	 * @return void
255
+	 */
256
+	abstract protected function _ajax_hooks();
257
+
258
+
259
+	/**
260
+	 * _define_page_props
261
+	 * child classes define page properties in here.  Must include at least:
262
+	 * $_admin_base_url = base_url for all admin pages
263
+	 * $_admin_page_title = default admin_page_title for admin pages
264
+	 * $_labels = array of default labels for various automatically generated elements:
265
+	 *    array(
266
+	 *        'buttons' => array(
267
+	 *            'add' => esc_html__('label for add new button'),
268
+	 *            'edit' => esc_html__('label for edit button'),
269
+	 *            'delete' => esc_html__('label for delete button')
270
+	 *            )
271
+	 *        )
272
+	 *
273
+	 * @abstract
274
+	 * @return void
275
+	 */
276
+	abstract protected function _define_page_props();
277
+
278
+
279
+	/**
280
+	 * _set_page_routes
281
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
282
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
283
+	 * have a 'default' route. Here's the format
284
+	 * $this->_page_routes = array(
285
+	 *        'default' => array(
286
+	 *            'func' => '_default_method_handling_route',
287
+	 *            'args' => array('array','of','args'),
288
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
289
+	 *            ajax request, backend processing)
290
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
291
+	 *            headers route after.  The string you enter here should match the defined route reference for a
292
+	 *            headers sent route.
293
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
294
+	 *            this route.
295
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
296
+	 *            checks).
297
+	 *        ),
298
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
299
+	 *        handling method.
300
+	 *        )
301
+	 * )
302
+	 *
303
+	 * @abstract
304
+	 * @return void
305
+	 */
306
+	abstract protected function _set_page_routes();
307
+
308
+
309
+	/**
310
+	 * _set_page_config
311
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
312
+	 * array corresponds to the page_route for the loaded page. Format:
313
+	 * $this->_page_config = array(
314
+	 *        'default' => array(
315
+	 *            'labels' => array(
316
+	 *                'buttons' => array(
317
+	 *                    'add' => esc_html__('label for adding item'),
318
+	 *                    'edit' => esc_html__('label for editing item'),
319
+	 *                    'delete' => esc_html__('label for deleting item')
320
+	 *                ),
321
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
322
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
323
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
324
+	 *            _define_page_props() method
325
+	 *            'nav' => array(
326
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
327
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
328
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
329
+	 *                'order' => 10, //required to indicate tab position.
330
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
331
+	 *                displayed then add this parameter.
332
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
333
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
334
+	 *            metaboxes set for eventespresso admin pages.
335
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
336
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
337
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
338
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
339
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
340
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
341
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
342
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
343
+	 *            want to display.
344
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
345
+	 *                'tab_id' => array(
346
+	 *                    'title' => 'tab_title',
347
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
348
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
349
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
350
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
351
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
352
+	 *                    attempt to use the callback which should match the name of a method in the class
353
+	 *                    ),
354
+	 *                'tab2_id' => array(
355
+	 *                    'title' => 'tab2 title',
356
+	 *                    'filename' => 'file_name_2'
357
+	 *                    'callback' => 'callback_method_for_content',
358
+	 *                 ),
359
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
360
+	 *            help tab area on an admin page. @return void
361
+	 *
362
+	 * @abstract
363
+	 */
364
+	abstract protected function _set_page_config();
365
+
366
+
367
+	/**
368
+	 * _add_screen_options
369
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
370
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
371
+	 * to a particular view.
372
+	 *
373
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
374
+	 *         see also WP_Screen object documents...
375
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
376
+	 * @abstract
377
+	 * @return void
378
+	 */
379
+	abstract protected function _add_screen_options();
380
+
381
+
382
+	/**
383
+	 * _add_feature_pointers
384
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
385
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
386
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
387
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
388
+	 * extended) also see:
389
+	 *
390
+	 * @link   http://eamann.com/tech/wordpress-portland/
391
+	 * @abstract
392
+	 * @return void
393
+	 */
394
+	abstract protected function _add_feature_pointers();
395
+
396
+
397
+	/**
398
+	 * load_scripts_styles
399
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
400
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
401
+	 * scripts/styles per view by putting them in a dynamic function in this format
402
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
403
+	 *
404
+	 * @abstract
405
+	 * @return void
406
+	 */
407
+	abstract public function load_scripts_styles();
408
+
409
+
410
+	/**
411
+	 * admin_init
412
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
413
+	 * all pages/views loaded by child class.
414
+	 *
415
+	 * @abstract
416
+	 * @return void
417
+	 */
418
+	abstract public function admin_init();
419
+
420
+
421
+	/**
422
+	 * admin_notices
423
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
424
+	 * all pages/views loaded by child class.
425
+	 *
426
+	 * @abstract
427
+	 * @return void
428
+	 */
429
+	abstract public function admin_notices();
430
+
431
+
432
+	/**
433
+	 * admin_footer_scripts
434
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
435
+	 * will apply to all pages/views loaded by child class.
436
+	 *
437
+	 * @return void
438
+	 */
439
+	abstract public function admin_footer_scripts();
440
+
441
+
442
+	/**
443
+	 * admin_footer
444
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
445
+	 * apply to all pages/views loaded by child class.
446
+	 *
447
+	 * @return void
448
+	 */
449
+	public function admin_footer()
450
+	{
451
+	}
452
+
453
+
454
+	/**
455
+	 * _global_ajax_hooks
456
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
457
+	 * Note: within the ajax callback methods.
458
+	 *
459
+	 * @abstract
460
+	 * @return void
461
+	 */
462
+	protected function _global_ajax_hooks()
463
+	{
464
+		// for lazy loading of metabox content
465
+		add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
466
+	}
467
+
468
+
469
+	public function ajax_metabox_content()
470
+	{
471
+		$content_id  = $this->request->getRequestParam('contentid', '');
472
+		$content_url = $this->request->getRequestParam('contenturl', '', 'url');
473
+		self::cached_rss_display($content_id, $content_url);
474
+		wp_die();
475
+	}
476
+
477
+
478
+	/**
479
+	 * allows extending classes do something specific before the parent constructor runs _page_setup().
480
+	 *
481
+	 * @return void
482
+	 */
483
+	protected function _before_page_setup()
484
+	{
485
+		// default is to do nothing
486
+	}
487
+
488
+
489
+	/**
490
+	 * Makes sure any things that need to be loaded early get handled.
491
+	 * We also escape early here if the page requested doesn't match the object.
492
+	 *
493
+	 * @final
494
+	 * @return void
495
+	 * @throws EE_Error
496
+	 * @throws InvalidArgumentException
497
+	 * @throws ReflectionException
498
+	 * @throws InvalidDataTypeException
499
+	 * @throws InvalidInterfaceException
500
+	 */
501
+	final protected function _page_setup()
502
+	{
503
+		// requires?
504
+		// admin_init stuff - global - we're setting this REALLY early
505
+		// so if EE_Admin pages have to hook into other WP pages they can.
506
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
507
+		add_action('admin_init', [$this, 'admin_init_global'], 5);
508
+		// next verify if we need to load anything...
509
+		$this->_current_page = $this->request->getRequestParam('page', '', 'key');
510
+		$this->page_folder   = strtolower(
511
+			str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
512
+		);
513
+		global $ee_menu_slugs;
514
+		$ee_menu_slugs = (array) $ee_menu_slugs;
515
+		if (
516
+			! $this->request->isAjax()
517
+			&& (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
518
+		) {
519
+			return;
520
+		}
521
+		// because WP List tables have two duplicate select inputs for choosing bulk actions,
522
+		// we need to copy the action from the second to the first
523
+		$action     = $this->request->getRequestParam('action', '-1', 'key');
524
+		$action2    = $this->request->getRequestParam('action2', '-1', 'key');
525
+		$action     = $action !== '-1' ? $action : $action2;
526
+		$req_action = $action !== '-1' ? $action : 'default';
527
+
528
+		// if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
529
+		// then let's use the route as the action.
530
+		// This covers cases where we're coming in from a list table that isn't on the default route.
531
+		$route = $this->request->getRequestParam('route');
532
+		$this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
533
+			? $route
534
+			: $req_action;
535
+
536
+		$this->_current_view = $this->_req_action;
537
+		$this->_req_nonce    = $this->_req_action . '_nonce';
538
+		$this->_define_page_props();
539
+		$this->_current_page_view_url = add_query_arg(
540
+			['page' => $this->_current_page, 'action' => $this->_current_view],
541
+			$this->_admin_base_url
542
+		);
543
+		// default things
544
+		$this->_default_espresso_metaboxes = [
545
+			'_espresso_news_post_box',
546
+			'_espresso_links_post_box',
547
+			'_espresso_ratings_request',
548
+			'_espresso_sponsors_post_box',
549
+		];
550
+		// set page configs
551
+		$this->_set_page_routes();
552
+		$this->_set_page_config();
553
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
554
+		if ($this->request->requestParamIsSet('wp_referer')) {
555
+			$wp_referer = $this->request->getRequestParam('wp_referer');
556
+			if ($wp_referer) {
557
+				$this->_default_route_query_args['wp_referer'] = $wp_referer;
558
+			}
559
+		}
560
+		// for caffeinated and other extended functionality.
561
+		//  If there is a _extend_page_config method
562
+		// then let's run that to modify the all the various page configuration arrays
563
+		if (method_exists($this, '_extend_page_config')) {
564
+			$this->_extend_page_config();
565
+		}
566
+		// for CPT and other extended functionality.
567
+		// If there is an _extend_page_config_for_cpt
568
+		// then let's run that to modify all the various page configuration arrays.
569
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
570
+			$this->_extend_page_config_for_cpt();
571
+		}
572
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
573
+		$this->_page_routes = apply_filters(
574
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
575
+			$this->_page_routes,
576
+			$this
577
+		);
578
+		$this->_page_config = apply_filters(
579
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
580
+			$this->_page_config,
581
+			$this
582
+		);
583
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
584
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
585
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
586
+			add_action(
587
+				'AHEE__EE_Admin_Page__route_admin_request',
588
+				[$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
589
+				10,
590
+				2
591
+			);
592
+		}
593
+		// next route only if routing enabled
594
+		if ($this->_routing && ! $this->request->isAjax()) {
595
+			$this->_verify_routes();
596
+			// next let's just check user_access and kill if no access
597
+			$this->check_user_access();
598
+			if ($this->_is_UI_request) {
599
+				// admin_init stuff - global, all views for this page class, specific view
600
+				add_action('admin_init', [$this, 'admin_init'], 10);
601
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
602
+					add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
603
+				}
604
+			} else {
605
+				// hijack regular WP loading and route admin request immediately
606
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
607
+				$this->route_admin_request();
608
+			}
609
+		}
610
+	}
611
+
612
+
613
+	/**
614
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
615
+	 *
616
+	 * @return void
617
+	 * @throws EE_Error
618
+	 */
619
+	private function _do_other_page_hooks()
620
+	{
621
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
622
+		foreach ($registered_pages as $page) {
623
+			// now let's setup the file name and class that should be present
624
+			$classname = str_replace('.class.php', '', $page);
625
+			// autoloaders should take care of loading file
626
+			if (! class_exists($classname)) {
627
+				$error_msg[] = sprintf(
628
+					esc_html__(
629
+						'Something went wrong with loading the %s admin hooks page.',
630
+						'event_espresso'
631
+					),
632
+					$page
633
+				);
634
+				$error_msg[] = $error_msg[0]
635
+							   . "\r\n"
636
+							   . sprintf(
637
+								   esc_html__(
638
+									   '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',
639
+									   'event_espresso'
640
+								   ),
641
+								   $page,
642
+								   '<br />',
643
+								   '<strong>' . $classname . '</strong>'
644
+							   );
645
+				throw new EE_Error(implode('||', $error_msg));
646
+			}
647
+			// notice we are passing the instance of this class to the hook object.
648
+			$this->loader->getShared($classname, [$this]);
649
+		}
650
+	}
651
+
652
+
653
+	/**
654
+	 * @throws ReflectionException
655
+	 * @throws EE_Error
656
+	 */
657
+	public function load_page_dependencies()
658
+	{
659
+		try {
660
+			$this->_load_page_dependencies();
661
+		} catch (EE_Error $e) {
662
+			$e->get_error();
663
+		}
664
+	}
665
+
666
+
667
+	/**
668
+	 * load_page_dependencies
669
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
670
+	 *
671
+	 * @return void
672
+	 * @throws DomainException
673
+	 * @throws EE_Error
674
+	 * @throws InvalidArgumentException
675
+	 * @throws InvalidDataTypeException
676
+	 * @throws InvalidInterfaceException
677
+	 */
678
+	protected function _load_page_dependencies()
679
+	{
680
+		// let's set the current_screen and screen options to override what WP set
681
+		$this->_current_screen = get_current_screen();
682
+		// load admin_notices - global, page class, and view specific
683
+		add_action('admin_notices', [$this, 'admin_notices_global'], 5);
684
+		add_action('admin_notices', [$this, 'admin_notices'], 10);
685
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
686
+			add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
687
+		}
688
+		// load network admin_notices - global, page class, and view specific
689
+		add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
690
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
691
+			add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
692
+		}
693
+		// this will save any per_page screen options if they are present
694
+		$this->_set_per_page_screen_options();
695
+		// setup list table properties
696
+		$this->_set_list_table();
697
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
698
+		// However in some cases the metaboxes will need to be added within a route handling callback.
699
+		$this->_add_registered_meta_boxes();
700
+		$this->_add_screen_columns();
701
+		// add screen options - global, page child class, and view specific
702
+		$this->_add_global_screen_options();
703
+		$this->_add_screen_options();
704
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
705
+		if (method_exists($this, $add_screen_options)) {
706
+			$this->{$add_screen_options}();
707
+		}
708
+		// add help tab(s) - set via page_config and qtips.
709
+		$this->_add_help_tabs();
710
+		$this->_add_qtips();
711
+		// add feature_pointers - global, page child class, and view specific
712
+		$this->_add_feature_pointers();
713
+		$this->_add_global_feature_pointers();
714
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
715
+		if (method_exists($this, $add_feature_pointer)) {
716
+			$this->{$add_feature_pointer}();
717
+		}
718
+		// enqueue scripts/styles - global, page class, and view specific
719
+		add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
720
+		add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
721
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
722
+			add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
723
+		}
724
+		add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
725
+		// admin_print_footer_scripts - global, page child class, and view specific.
726
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
727
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
728
+		// is a good use case. Notice the late priority we're giving these
729
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
730
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
731
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
732
+			add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
733
+		}
734
+		// admin footer scripts
735
+		add_action('admin_footer', [$this, 'admin_footer_global'], 99);
736
+		add_action('admin_footer', [$this, 'admin_footer'], 100);
737
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
738
+			add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
739
+		}
740
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
741
+		// targeted hook
742
+		do_action(
743
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
744
+		);
745
+	}
746
+
747
+
748
+	/**
749
+	 * _set_defaults
750
+	 * This sets some global defaults for class properties.
751
+	 */
752
+	private function _set_defaults()
753
+	{
754
+		$this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
755
+		$this->_event                = $this->_template_path = $this->_column_template_path = null;
756
+		$this->_nav_tabs             = $this->_views = $this->_page_routes = [];
757
+		$this->_page_config          = $this->_default_route_query_args = [];
758
+		$this->_default_nav_tab_name = 'overview';
759
+		// init template args
760
+		$this->_template_args = [
761
+			'admin_page_header'  => '',
762
+			'admin_page_content' => '',
763
+			'post_body_content'  => '',
764
+			'before_list_table'  => '',
765
+			'after_list_table'   => '',
766
+		];
767
+	}
768
+
769
+
770
+	/**
771
+	 * route_admin_request
772
+	 *
773
+	 * @return void
774
+	 * @throws InvalidArgumentException
775
+	 * @throws InvalidInterfaceException
776
+	 * @throws InvalidDataTypeException
777
+	 * @throws EE_Error
778
+	 * @throws ReflectionException
779
+	 * @see    _route_admin_request()
780
+	 */
781
+	public function route_admin_request()
782
+	{
783
+		try {
784
+			$this->_route_admin_request();
785
+		} catch (EE_Error $e) {
786
+			$e->get_error();
787
+		}
788
+	}
789
+
790
+
791
+	public function set_wp_page_slug($wp_page_slug)
792
+	{
793
+		$this->_wp_page_slug = $wp_page_slug;
794
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
795
+		if (is_network_admin()) {
796
+			$this->_wp_page_slug .= '-network';
797
+		}
798
+	}
799
+
800
+
801
+	/**
802
+	 * _verify_routes
803
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
804
+	 * we know if we need to drop out.
805
+	 *
806
+	 * @return bool
807
+	 * @throws EE_Error
808
+	 */
809
+	protected function _verify_routes()
810
+	{
811
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
812
+		if (! $this->_current_page && ! $this->request->isAjax()) {
813
+			return false;
814
+		}
815
+		$this->_route = false;
816
+		// check that the page_routes array is not empty
817
+		if (empty($this->_page_routes)) {
818
+			// user error msg
819
+			$error_msg = sprintf(
820
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
821
+				$this->_admin_page_title
822
+			);
823
+			// developer error msg
824
+			$error_msg .= '||' . $error_msg
825
+						  . esc_html__(
826
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
827
+							  'event_espresso'
828
+						  );
829
+			throw new EE_Error($error_msg);
830
+		}
831
+		// and that the requested page route exists
832
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
833
+			$this->_route        = $this->_page_routes[ $this->_req_action ];
834
+			$this->_route_config = isset($this->_page_config[ $this->_req_action ])
835
+				? $this->_page_config[ $this->_req_action ]
836
+				: [];
837
+		} else {
838
+			// user error msg
839
+			$error_msg = sprintf(
840
+				esc_html__(
841
+					'The requested page route does not exist for the %s admin page.',
842
+					'event_espresso'
843
+				),
844
+				$this->_admin_page_title
845
+			);
846
+			// developer error msg
847
+			$error_msg .= '||' . $error_msg
848
+						  . sprintf(
849
+							  esc_html__(
850
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
851
+								  'event_espresso'
852
+							  ),
853
+							  $this->_req_action
854
+						  );
855
+			throw new EE_Error($error_msg);
856
+		}
857
+		// and that a default route exists
858
+		if (! array_key_exists('default', $this->_page_routes)) {
859
+			// user error msg
860
+			$error_msg = sprintf(
861
+				esc_html__(
862
+					'A default page route has not been set for the % admin page.',
863
+					'event_espresso'
864
+				),
865
+				$this->_admin_page_title
866
+			);
867
+			// developer error msg
868
+			$error_msg .= '||' . $error_msg
869
+						  . esc_html__(
870
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
871
+							  'event_espresso'
872
+						  );
873
+			throw new EE_Error($error_msg);
874
+		}
875
+		// first lets' catch if the UI request has EVER been set.
876
+		if ($this->_is_UI_request === null) {
877
+			// lets set if this is a UI request or not.
878
+			$this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
879
+			// wait a minute... we might have a noheader in the route array
880
+			$this->_is_UI_request = ! (
881
+				is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
882
+			)
883
+				? $this->_is_UI_request
884
+				: false;
885
+		}
886
+		$this->_set_current_labels();
887
+		return true;
888
+	}
889
+
890
+
891
+	/**
892
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
893
+	 *
894
+	 * @param string $route the route name we're verifying
895
+	 * @return bool we'll throw an exception if this isn't a valid route.
896
+	 * @throws EE_Error
897
+	 */
898
+	protected function _verify_route($route)
899
+	{
900
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
901
+			return true;
902
+		}
903
+		// user error msg
904
+		$error_msg = sprintf(
905
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
906
+			$this->_admin_page_title
907
+		);
908
+		// developer error msg
909
+		$error_msg .= '||' . $error_msg
910
+					  . sprintf(
911
+						  esc_html__(
912
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
913
+							  'event_espresso'
914
+						  ),
915
+						  $route
916
+					  );
917
+		throw new EE_Error($error_msg);
918
+	}
919
+
920
+
921
+	/**
922
+	 * perform nonce verification
923
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
924
+	 * using this method (and save retyping!)
925
+	 *
926
+	 * @param string $nonce     The nonce sent
927
+	 * @param string $nonce_ref The nonce reference string (name0)
928
+	 * @return void
929
+	 * @throws EE_Error
930
+	 */
931
+	protected function _verify_nonce($nonce, $nonce_ref)
932
+	{
933
+		// verify nonce against expected value
934
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
935
+			// these are not the droids you are looking for !!!
936
+			$msg = sprintf(
937
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
938
+				'<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
939
+				'</a>'
940
+			);
941
+			if (WP_DEBUG) {
942
+				$msg .= "\n  ";
943
+				$msg .= sprintf(
944
+					esc_html__(
945
+						'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
946
+						'event_espresso'
947
+					),
948
+					__CLASS__
949
+				);
950
+			}
951
+			if (! $this->request->isAjax()) {
952
+				wp_die($msg);
953
+			}
954
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
955
+			$this->_return_json();
956
+		}
957
+	}
958
+
959
+
960
+	/**
961
+	 * _route_admin_request()
962
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
963
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
964
+	 * in the page routes and then will try to load the corresponding method.
965
+	 *
966
+	 * @return void
967
+	 * @throws EE_Error
968
+	 * @throws InvalidArgumentException
969
+	 * @throws InvalidDataTypeException
970
+	 * @throws InvalidInterfaceException
971
+	 * @throws ReflectionException
972
+	 */
973
+	protected function _route_admin_request()
974
+	{
975
+		if (! $this->_is_UI_request) {
976
+			$this->_verify_routes();
977
+		}
978
+		$nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
979
+		if ($this->_req_action !== 'default' && $nonce_check) {
980
+			// set nonce from post data
981
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
982
+			$this->_verify_nonce($nonce, $this->_req_nonce);
983
+		}
984
+		// set the nav_tabs array but ONLY if this is  UI_request
985
+		if ($this->_is_UI_request) {
986
+			$this->_set_nav_tabs();
987
+		}
988
+		// grab callback function
989
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
990
+		// check if callback has args
991
+		$args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
992
+		$error_msg = '';
993
+		// action right before calling route
994
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
995
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
996
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
997
+		}
998
+		// right before calling the route, let's clean the _wp_http_referer
999
+		$this->request->setServerParam(
1000
+			'REQUEST_URI',
1001
+			remove_query_arg(
1002
+				'_wp_http_referer',
1003
+				wp_unslash($this->request->getServerParam('REQUEST_URI'))
1004
+			)
1005
+		);
1006
+		if (! empty($func)) {
1007
+			if (is_array($func)) {
1008
+				list($class, $method) = $func;
1009
+			} elseif (strpos($func, '::') !== false) {
1010
+				list($class, $method) = explode('::', $func);
1011
+			} else {
1012
+				$class  = $this;
1013
+				$method = $func;
1014
+			}
1015
+			if (! (is_object($class) && $class === $this)) {
1016
+				// send along this admin page object for access by addons.
1017
+				$args['admin_page_object'] = $this;
1018
+			}
1019
+			if (
1020
+				// is it a method on a class that doesn't work?
1021
+				(
1022
+					(
1023
+						method_exists($class, $method)
1024
+						&& call_user_func_array([$class, $method], $args) === false
1025
+					)
1026
+					&& (
1027
+						// is it a standalone function that doesn't work?
1028
+						function_exists($method)
1029
+						&& call_user_func_array(
1030
+							$func,
1031
+							array_merge(['admin_page_object' => $this], $args)
1032
+						) === false
1033
+					)
1034
+				)
1035
+				|| (
1036
+					// is it neither a class method NOR a standalone function?
1037
+					! method_exists($class, $method)
1038
+					&& ! function_exists($method)
1039
+				)
1040
+			) {
1041
+				// user error msg
1042
+				$error_msg = esc_html__(
1043
+					'An error occurred. The  requested page route could not be found.',
1044
+					'event_espresso'
1045
+				);
1046
+				// developer error msg
1047
+				$error_msg .= '||';
1048
+				$error_msg .= sprintf(
1049
+					esc_html__(
1050
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1051
+						'event_espresso'
1052
+					),
1053
+					$method
1054
+				);
1055
+			}
1056
+			if (! empty($error_msg)) {
1057
+				throw new EE_Error($error_msg);
1058
+			}
1059
+		}
1060
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1061
+		// then we need to reset the routing properties to the new route.
1062
+		// now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1063
+		if (
1064
+			$this->_is_UI_request === false
1065
+			&& is_array($this->_route)
1066
+			&& ! empty($this->_route['headers_sent_route'])
1067
+		) {
1068
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1069
+		}
1070
+	}
1071
+
1072
+
1073
+	/**
1074
+	 * This method just allows the resetting of page properties in the case where a no headers
1075
+	 * route redirects to a headers route in its route config.
1076
+	 *
1077
+	 * @param string $new_route New (non header) route to redirect to.
1078
+	 * @return   void
1079
+	 * @throws ReflectionException
1080
+	 * @throws InvalidArgumentException
1081
+	 * @throws InvalidInterfaceException
1082
+	 * @throws InvalidDataTypeException
1083
+	 * @throws EE_Error
1084
+	 * @since   4.3.0
1085
+	 */
1086
+	protected function _reset_routing_properties($new_route)
1087
+	{
1088
+		$this->_is_UI_request = true;
1089
+		// now we set the current route to whatever the headers_sent_route is set at
1090
+		$this->request->setRequestParam('action', $new_route);
1091
+		// rerun page setup
1092
+		$this->_page_setup();
1093
+	}
1094
+
1095
+
1096
+	/**
1097
+	 * _add_query_arg
1098
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1099
+	 *(internally just uses EEH_URL's function with the same name)
1100
+	 *
1101
+	 * @param array  $args
1102
+	 * @param string $url
1103
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1104
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1105
+	 *                                        Example usage: If the current page is:
1106
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1107
+	 *                                        &action=default&event_id=20&month_range=March%202015
1108
+	 *                                        &_wpnonce=5467821
1109
+	 *                                        and you call:
1110
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1111
+	 *                                        array(
1112
+	 *                                        'action' => 'resend_something',
1113
+	 *                                        'page=>espresso_registrations'
1114
+	 *                                        ),
1115
+	 *                                        $some_url,
1116
+	 *                                        true
1117
+	 *                                        );
1118
+	 *                                        It will produce a url in this structure:
1119
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1120
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1121
+	 *                                        month_range]=March%202015
1122
+	 * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1123
+	 * @return string
1124
+	 */
1125
+	public static function add_query_args_and_nonce(
1126
+		$args = [],
1127
+		$url = false,
1128
+		$sticky = false,
1129
+		$exclude_nonce = false
1130
+	) {
1131
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1132
+		if ($sticky) {
1133
+			/** @var RequestInterface $request */
1134
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1135
+			$request->unSetRequestParams(['_wp_http_referer', 'wp_referer']);
1136
+			foreach ($request->requestParams() as $key => $value) {
1137
+				// do not add nonces
1138
+				if (strpos($key, 'nonce') !== false) {
1139
+					continue;
1140
+				}
1141
+				$args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1142
+			}
1143
+		}
1144
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1145
+	}
1146
+
1147
+
1148
+	/**
1149
+	 * This returns a generated link that will load the related help tab.
1150
+	 *
1151
+	 * @param string $help_tab_id the id for the connected help tab
1152
+	 * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1153
+	 * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1154
+	 * @return string              generated link
1155
+	 * @uses EEH_Template::get_help_tab_link()
1156
+	 */
1157
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1158
+	{
1159
+		return EEH_Template::get_help_tab_link(
1160
+			$help_tab_id,
1161
+			$this->page_slug,
1162
+			$this->_req_action,
1163
+			$icon_style,
1164
+			$help_text
1165
+		);
1166
+	}
1167
+
1168
+
1169
+	/**
1170
+	 * _add_help_tabs
1171
+	 * Note child classes define their help tabs within the page_config array.
1172
+	 *
1173
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1174
+	 * @return void
1175
+	 * @throws DomainException
1176
+	 * @throws EE_Error
1177
+	 */
1178
+	protected function _add_help_tabs()
1179
+	{
1180
+		if (isset($this->_page_config[ $this->_req_action ])) {
1181
+			$config = $this->_page_config[ $this->_req_action ];
1182
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1183
+			if (is_array($config) && isset($config['help_sidebar'])) {
1184
+				// check that the callback given is valid
1185
+				if (! method_exists($this, $config['help_sidebar'])) {
1186
+					throw new EE_Error(
1187
+						sprintf(
1188
+							esc_html__(
1189
+								'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1190
+								'event_espresso'
1191
+							),
1192
+							$config['help_sidebar'],
1193
+							get_class($this)
1194
+						)
1195
+					);
1196
+				}
1197
+				$content = apply_filters(
1198
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1199
+					$this->{$config['help_sidebar']}()
1200
+				);
1201
+				$this->_current_screen->set_help_sidebar($content);
1202
+			}
1203
+			if (! isset($config['help_tabs'])) {
1204
+				return;
1205
+			} //no help tabs for this route
1206
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1207
+				// we're here so there ARE help tabs!
1208
+				// make sure we've got what we need
1209
+				if (! isset($cfg['title'])) {
1210
+					throw new EE_Error(
1211
+						esc_html__(
1212
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1213
+							'event_espresso'
1214
+						)
1215
+					);
1216
+				}
1217
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1218
+					throw new EE_Error(
1219
+						esc_html__(
1220
+							'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1221
+							'event_espresso'
1222
+						)
1223
+					);
1224
+				}
1225
+				// first priority goes to content.
1226
+				if (! empty($cfg['content'])) {
1227
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1228
+					// second priority goes to filename
1229
+				} elseif (! empty($cfg['filename'])) {
1230
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1231
+					// it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1232
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1233
+															 . basename($this->_get_dir())
1234
+															 . '/help_tabs/'
1235
+															 . $cfg['filename']
1236
+															 . '.help_tab.php' : $file_path;
1237
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1238
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1239
+						EE_Error::add_error(
1240
+							sprintf(
1241
+								esc_html__(
1242
+									'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1243
+									'event_espresso'
1244
+								),
1245
+								$tab_id,
1246
+								key($config),
1247
+								$file_path
1248
+							),
1249
+							__FILE__,
1250
+							__FUNCTION__,
1251
+							__LINE__
1252
+						);
1253
+						return;
1254
+					}
1255
+					$template_args['admin_page_obj'] = $this;
1256
+					$content                         = EEH_Template::display_template(
1257
+						$file_path,
1258
+						$template_args,
1259
+						true
1260
+					);
1261
+				} else {
1262
+					$content = '';
1263
+				}
1264
+				// check if callback is valid
1265
+				if (
1266
+					empty($content)
1267
+					&& (
1268
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1269
+					)
1270
+				) {
1271
+					EE_Error::add_error(
1272
+						sprintf(
1273
+							esc_html__(
1274
+								'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1275
+								'event_espresso'
1276
+							),
1277
+							$cfg['title']
1278
+						),
1279
+						__FILE__,
1280
+						__FUNCTION__,
1281
+						__LINE__
1282
+					);
1283
+					return;
1284
+				}
1285
+				// setup config array for help tab method
1286
+				$id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1287
+				$_ht = [
1288
+					'id'       => $id,
1289
+					'title'    => $cfg['title'],
1290
+					'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1291
+					'content'  => $content,
1292
+				];
1293
+				$this->_current_screen->add_help_tab($_ht);
1294
+			}
1295
+		}
1296
+	}
1297
+
1298
+
1299
+	/**
1300
+	 * This simply sets up any qtips that have been defined in the page config
1301
+	 *
1302
+	 * @return void
1303
+	 */
1304
+	protected function _add_qtips()
1305
+	{
1306
+		if (isset($this->_route_config['qtips'])) {
1307
+			$qtips = (array) $this->_route_config['qtips'];
1308
+			// load qtip loader
1309
+			$path = [
1310
+				$this->_get_dir() . '/qtips/',
1311
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1312
+			];
1313
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1314
+		}
1315
+	}
1316
+
1317
+
1318
+	/**
1319
+	 * _set_nav_tabs
1320
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1321
+	 * wish to add additional tabs or modify accordingly.
1322
+	 *
1323
+	 * @return void
1324
+	 * @throws InvalidArgumentException
1325
+	 * @throws InvalidInterfaceException
1326
+	 * @throws InvalidDataTypeException
1327
+	 */
1328
+	protected function _set_nav_tabs()
1329
+	{
1330
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1331
+		$i = 0;
1332
+		foreach ($this->_page_config as $slug => $config) {
1333
+			if (! is_array($config) || empty($config['nav'])) {
1334
+				continue;
1335
+			}
1336
+			// no nav tab for this config
1337
+			// check for persistent flag
1338
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1339
+				// nav tab is only to appear when route requested.
1340
+				continue;
1341
+			}
1342
+			if (! $this->check_user_access($slug, true)) {
1343
+				// no nav tab because current user does not have access.
1344
+				continue;
1345
+			}
1346
+			$css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1347
+			$this->_nav_tabs[ $slug ] = [
1348
+				'url'       => isset($config['nav']['url'])
1349
+					? $config['nav']['url']
1350
+					: self::add_query_args_and_nonce(
1351
+						['action' => $slug],
1352
+						$this->_admin_base_url
1353
+					),
1354
+				'link_text' => isset($config['nav']['label'])
1355
+					? $config['nav']['label']
1356
+					: ucwords(
1357
+						str_replace('_', ' ', $slug)
1358
+					),
1359
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1360
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1361
+			];
1362
+			$i++;
1363
+		}
1364
+		// if $this->_nav_tabs is empty then lets set the default
1365
+		if (empty($this->_nav_tabs)) {
1366
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1367
+				'url'       => $this->_admin_base_url,
1368
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1369
+				'css_class' => 'nav-tab-active',
1370
+				'order'     => 10,
1371
+			];
1372
+		}
1373
+		// now let's sort the tabs according to order
1374
+		usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1375
+	}
1376
+
1377
+
1378
+	/**
1379
+	 * _set_current_labels
1380
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1381
+	 * property array
1382
+	 *
1383
+	 * @return void
1384
+	 */
1385
+	private function _set_current_labels()
1386
+	{
1387
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1388
+			foreach ($this->_route_config['labels'] as $label => $text) {
1389
+				if (is_array($text)) {
1390
+					foreach ($text as $sublabel => $subtext) {
1391
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1392
+					}
1393
+				} else {
1394
+					$this->_labels[ $label ] = $text;
1395
+				}
1396
+			}
1397
+		}
1398
+	}
1399
+
1400
+
1401
+	/**
1402
+	 *        verifies user access for this admin page
1403
+	 *
1404
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1405
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1406
+	 *                               return false if verify fail.
1407
+	 * @return bool
1408
+	 * @throws InvalidArgumentException
1409
+	 * @throws InvalidDataTypeException
1410
+	 * @throws InvalidInterfaceException
1411
+	 */
1412
+	public function check_user_access($route_to_check = '', $verify_only = false)
1413
+	{
1414
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1415
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1416
+		$capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1417
+						  && is_array(
1418
+							  $this->_page_routes[ $route_to_check ]
1419
+						  )
1420
+						  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1421
+			? $this->_page_routes[ $route_to_check ]['capability'] : null;
1422
+		if (empty($capability) && empty($route_to_check)) {
1423
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1424
+				: $this->_route['capability'];
1425
+		} else {
1426
+			$capability = empty($capability) ? 'manage_options' : $capability;
1427
+		}
1428
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1429
+		if (
1430
+			! $this->request->isAjax()
1431
+			&& (
1432
+				! function_exists('is_admin')
1433
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1434
+					$capability,
1435
+					$this->page_slug
1436
+					. '_'
1437
+					. $route_to_check,
1438
+					$id
1439
+				)
1440
+			)
1441
+		) {
1442
+			if ($verify_only) {
1443
+				return false;
1444
+			}
1445
+			if (is_user_logged_in()) {
1446
+				wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1447
+			} else {
1448
+				return false;
1449
+			}
1450
+		}
1451
+		return true;
1452
+	}
1453
+
1454
+
1455
+	/**
1456
+	 * admin_init_global
1457
+	 * This runs all the code that we want executed within the WP admin_init hook.
1458
+	 * This method executes for ALL EE Admin pages.
1459
+	 *
1460
+	 * @return void
1461
+	 */
1462
+	public function admin_init_global()
1463
+	{
1464
+	}
1465
+
1466
+
1467
+	/**
1468
+	 * wp_loaded_global
1469
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1470
+	 * EE_Admin page and will execute on every EE Admin Page load
1471
+	 *
1472
+	 * @return void
1473
+	 */
1474
+	public function wp_loaded()
1475
+	{
1476
+	}
1477
+
1478
+
1479
+	/**
1480
+	 * admin_notices
1481
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1482
+	 * ALL EE_Admin pages.
1483
+	 *
1484
+	 * @return void
1485
+	 */
1486
+	public function admin_notices_global()
1487
+	{
1488
+		$this->_display_no_javascript_warning();
1489
+		$this->_display_espresso_notices();
1490
+	}
1491
+
1492
+
1493
+	public function network_admin_notices_global()
1494
+	{
1495
+		$this->_display_no_javascript_warning();
1496
+		$this->_display_espresso_notices();
1497
+	}
1498
+
1499
+
1500
+	/**
1501
+	 * admin_footer_scripts_global
1502
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1503
+	 * will apply on ALL EE_Admin pages.
1504
+	 *
1505
+	 * @return void
1506
+	 */
1507
+	public function admin_footer_scripts_global()
1508
+	{
1509
+		$this->_add_admin_page_ajax_loading_img();
1510
+		$this->_add_admin_page_overlay();
1511
+		// if metaboxes are present we need to add the nonce field
1512
+		if (
1513
+			isset($this->_route_config['metaboxes'])
1514
+			|| isset($this->_route_config['list_table'])
1515
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1516
+		) {
1517
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1518
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1519
+		}
1520
+	}
1521
+
1522
+
1523
+	/**
1524
+	 * admin_footer_global
1525
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1526
+	 * ALL EE_Admin Pages.
1527
+	 *
1528
+	 * @return void
1529
+	 */
1530
+	public function admin_footer_global()
1531
+	{
1532
+		// dialog container for dialog helper
1533
+		echo '
1534 1534
         <div class="ee-admin-dialog-container auto-hide hidden">
1535 1535
             <div class="ee-notices"></div>
1536 1536
             <div class="ee-admin-dialog-container-inner-content"></div>
1537 1537
         </div>
1538 1538
         ';
1539 1539
 
1540
-        // current set timezone for timezone js
1541
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1542
-    }
1543
-
1544
-
1545
-    /**
1546
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1547
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1548
-     * help popups then in your templates or your content you set "triggers" for the content using the
1549
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1550
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1551
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1552
-     * for the
1553
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1554
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1555
-     *    'help_trigger_id' => array(
1556
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1557
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1558
-     *    )
1559
-     * );
1560
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1561
-     *
1562
-     * @param array $help_array
1563
-     * @param bool  $display
1564
-     * @return string content
1565
-     * @throws DomainException
1566
-     * @throws EE_Error
1567
-     */
1568
-    protected function _set_help_popup_content($help_array = [], $display = false)
1569
-    {
1570
-        $content    = '';
1571
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1572
-        // loop through the array and setup content
1573
-        foreach ($help_array as $trigger => $help) {
1574
-            // make sure the array is setup properly
1575
-            if (! isset($help['title']) || ! isset($help['content'])) {
1576
-                throw new EE_Error(
1577
-                    esc_html__(
1578
-                        'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1579
-                        'event_espresso'
1580
-                    )
1581
-                );
1582
-            }
1583
-            // we're good so let's setup the template vars and then assign parsed template content to our content.
1584
-            $template_args = [
1585
-                'help_popup_id'      => $trigger,
1586
-                'help_popup_title'   => $help['title'],
1587
-                'help_popup_content' => $help['content'],
1588
-            ];
1589
-            $content       .= EEH_Template::display_template(
1590
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1591
-                $template_args,
1592
-                true
1593
-            );
1594
-        }
1595
-        if ($display) {
1596
-            echo wp_kses($content, AllowedTags::getWithFormTags());
1597
-            return '';
1598
-        }
1599
-        return $content;
1600
-    }
1601
-
1602
-
1603
-    /**
1604
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1605
-     *
1606
-     * @return array properly formatted array for help popup content
1607
-     * @throws EE_Error
1608
-     */
1609
-    private function _get_help_content()
1610
-    {
1611
-        // what is the method we're looking for?
1612
-        $method_name = '_help_popup_content_' . $this->_req_action;
1613
-        // if method doesn't exist let's get out.
1614
-        if (! method_exists($this, $method_name)) {
1615
-            return [];
1616
-        }
1617
-        // k we're good to go let's retrieve the help array
1618
-        $help_array = call_user_func([$this, $method_name]);
1619
-        // make sure we've got an array!
1620
-        if (! is_array($help_array)) {
1621
-            throw new EE_Error(
1622
-                esc_html__(
1623
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1624
-                    'event_espresso'
1625
-                )
1626
-            );
1627
-        }
1628
-        return $help_array;
1629
-    }
1630
-
1631
-
1632
-    /**
1633
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1634
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1635
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1636
-     *
1637
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1638
-     * @param boolean $display    if false then we return the trigger string
1639
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1640
-     * @return string
1641
-     * @throws DomainException
1642
-     * @throws EE_Error
1643
-     */
1644
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1645
-    {
1646
-        if ($this->request->isAjax()) {
1647
-            return '';
1648
-        }
1649
-        // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1650
-        $help_array   = $this->_get_help_content();
1651
-        $help_content = '';
1652
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1653
-            $help_array[ $trigger_id ] = [
1654
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1655
-                'content' => esc_html__(
1656
-                    'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1657
-                    'event_espresso'
1658
-                ),
1659
-            ];
1660
-            $help_content              = $this->_set_help_popup_content($help_array);
1661
-        }
1662
-        // let's setup the trigger
1663
-        $content = '<a class="ee-dialog" href="?height='
1664
-                   . esc_attr($dimensions[0])
1665
-                   . '&width='
1666
-                   . esc_attr($dimensions[1])
1667
-                   . '&inlineId='
1668
-                   . esc_attr($trigger_id)
1669
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1670
-        $content .= $help_content;
1671
-        if ($display) {
1672
-            echo wp_kses($content, AllowedTags::getWithFormTags());
1673
-            return '';
1674
-        }
1675
-        return $content;
1676
-    }
1677
-
1678
-
1679
-    /**
1680
-     * _add_global_screen_options
1681
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1682
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1683
-     *
1684
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1685
-     *         see also WP_Screen object documents...
1686
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1687
-     * @abstract
1688
-     * @return void
1689
-     */
1690
-    private function _add_global_screen_options()
1691
-    {
1692
-    }
1693
-
1694
-
1695
-    /**
1696
-     * _add_global_feature_pointers
1697
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1698
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1699
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1700
-     *
1701
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1702
-     *         extended) also see:
1703
-     * @link   http://eamann.com/tech/wordpress-portland/
1704
-     * @abstract
1705
-     * @return void
1706
-     */
1707
-    private function _add_global_feature_pointers()
1708
-    {
1709
-    }
1710
-
1711
-
1712
-    /**
1713
-     * load_global_scripts_styles
1714
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1715
-     *
1716
-     * @return void
1717
-     */
1718
-    public function load_global_scripts_styles()
1719
-    {
1720
-        /** STYLES **/
1721
-        // add debugging styles
1722
-        if (WP_DEBUG) {
1723
-            add_action('admin_head', [$this, 'add_xdebug_style']);
1724
-        }
1725
-        // register all styles
1726
-        wp_register_style(
1727
-            'espresso-ui-theme',
1728
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1729
-            [],
1730
-            EVENT_ESPRESSO_VERSION
1731
-        );
1732
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1733
-        // helpers styles
1734
-        wp_register_style(
1735
-            'ee-text-links',
1736
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1737
-            [],
1738
-            EVENT_ESPRESSO_VERSION
1739
-        );
1740
-        /** SCRIPTS **/
1741
-        // register all scripts
1742
-        wp_register_script(
1743
-            'ee-dialog',
1744
-            EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1745
-            ['jquery', 'jquery-ui-draggable'],
1746
-            EVENT_ESPRESSO_VERSION,
1747
-            true
1748
-        );
1749
-        wp_register_script(
1750
-            'ee_admin_js',
1751
-            EE_ADMIN_URL . 'assets/ee-admin-page.js',
1752
-            ['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1753
-            EVENT_ESPRESSO_VERSION,
1754
-            true
1755
-        );
1756
-        wp_register_script(
1757
-            'jquery-ui-timepicker-addon',
1758
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1759
-            ['jquery-ui-datepicker', 'jquery-ui-slider'],
1760
-            EVENT_ESPRESSO_VERSION,
1761
-            true
1762
-        );
1763
-        // script for sorting tables
1764
-        wp_register_script(
1765
-            'espresso_ajax_table_sorting',
1766
-            EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1767
-            ['ee_admin_js', 'jquery-ui-sortable'],
1768
-            EVENT_ESPRESSO_VERSION,
1769
-            true
1770
-        );
1771
-        // script for parsing uri's
1772
-        wp_register_script(
1773
-            'ee-parse-uri',
1774
-            EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1775
-            [],
1776
-            EVENT_ESPRESSO_VERSION,
1777
-            true
1778
-        );
1779
-        // and parsing associative serialized form elements
1780
-        wp_register_script(
1781
-            'ee-serialize-full-array',
1782
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1783
-            ['jquery'],
1784
-            EVENT_ESPRESSO_VERSION,
1785
-            true
1786
-        );
1787
-        // helpers scripts
1788
-        wp_register_script(
1789
-            'ee-text-links',
1790
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1791
-            ['jquery'],
1792
-            EVENT_ESPRESSO_VERSION,
1793
-            true
1794
-        );
1795
-        wp_register_script(
1796
-            'ee-moment-core',
1797
-            EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1798
-            [],
1799
-            EVENT_ESPRESSO_VERSION,
1800
-            true
1801
-        );
1802
-        wp_register_script(
1803
-            'ee-moment',
1804
-            EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1805
-            ['ee-moment-core'],
1806
-            EVENT_ESPRESSO_VERSION,
1807
-            true
1808
-        );
1809
-        wp_register_script(
1810
-            'ee-datepicker',
1811
-            EE_ADMIN_URL . 'assets/ee-datepicker.js',
1812
-            ['jquery-ui-timepicker-addon', 'ee-moment'],
1813
-            EVENT_ESPRESSO_VERSION,
1814
-            true
1815
-        );
1816
-        // google charts
1817
-        wp_register_script(
1818
-            'google-charts',
1819
-            'https://www.gstatic.com/charts/loader.js',
1820
-            [],
1821
-            EVENT_ESPRESSO_VERSION
1822
-        );
1823
-        // ENQUEUE ALL BASICS BY DEFAULT
1824
-        wp_enqueue_style('ee-admin-css');
1825
-        wp_enqueue_script('ee_admin_js');
1826
-        wp_enqueue_script('ee-accounting');
1827
-        wp_enqueue_script('jquery-validate');
1828
-        // taking care of metaboxes
1829
-        if (
1830
-            empty($this->_cpt_route)
1831
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1832
-        ) {
1833
-            wp_enqueue_script('dashboard');
1834
-        }
1835
-        // LOCALIZED DATA
1836
-        // localize script for ajax lazy loading
1837
-        $lazy_loader_container_ids = apply_filters(
1838
-            'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1839
-            ['espresso_news_post_box_content']
1840
-        );
1841
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1842
-        add_filter(
1843
-            'admin_body_class',
1844
-            function ($classes) {
1845
-                if (strpos($classes, 'espresso-admin') === false) {
1846
-                    $classes .= ' espresso-admin';
1847
-                }
1848
-                return $classes;
1849
-            }
1850
-        );
1851
-    }
1852
-
1853
-
1854
-    /**
1855
-     *        admin_footer_scripts_eei18n_js_strings
1856
-     *
1857
-     * @return        void
1858
-     */
1859
-    public function admin_footer_scripts_eei18n_js_strings()
1860
-    {
1861
-        EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1862
-        EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1863
-            __(
1864
-                'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1865
-                'event_espresso'
1866
-            )
1867
-        );
1868
-        EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1869
-        EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1870
-        EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1871
-        EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1872
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1873
-        EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1874
-        EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1875
-        EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1876
-        EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1877
-        EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1878
-        EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1879
-        EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1880
-        EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1881
-        EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1882
-        EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1883
-        EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1884
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1885
-        EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1886
-        EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1887
-        EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1888
-        EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1889
-        EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1890
-        EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1891
-        EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1892
-        EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1893
-        EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1894
-        EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1895
-        EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1896
-        EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1897
-        EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1898
-        EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1899
-        EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1900
-        EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1901
-        EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1902
-        EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1903
-        EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1904
-        EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1905
-        EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1906
-    }
1907
-
1908
-
1909
-    /**
1910
-     *        load enhanced xdebug styles for ppl with failing eyesight
1911
-     *
1912
-     * @return        void
1913
-     */
1914
-    public function add_xdebug_style()
1915
-    {
1916
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1917
-    }
1918
-
1919
-
1920
-    /************************/
1921
-    /** LIST TABLE METHODS **/
1922
-    /************************/
1923
-    /**
1924
-     * this sets up the list table if the current view requires it.
1925
-     *
1926
-     * @return void
1927
-     * @throws EE_Error
1928
-     */
1929
-    protected function _set_list_table()
1930
-    {
1931
-        // first is this a list_table view?
1932
-        if (! isset($this->_route_config['list_table'])) {
1933
-            return;
1934
-        } //not a list_table view so get out.
1935
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
1936
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
1937
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1938
-            // user error msg
1939
-            $error_msg = esc_html__(
1940
-                'An error occurred. The requested list table views could not be found.',
1941
-                'event_espresso'
1942
-            );
1943
-            // developer error msg
1944
-            $error_msg .= '||'
1945
-                          . sprintf(
1946
-                              esc_html__(
1947
-                                  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
1948
-                                  'event_espresso'
1949
-                              ),
1950
-                              $this->_req_action,
1951
-                              $list_table_view
1952
-                          );
1953
-            throw new EE_Error($error_msg);
1954
-        }
1955
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1956
-        $this->_views = apply_filters(
1957
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
1958
-            $this->_views
1959
-        );
1960
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1961
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1962
-        $this->_set_list_table_view();
1963
-        $this->_set_list_table_object();
1964
-    }
1965
-
1966
-
1967
-    /**
1968
-     * set current view for List Table
1969
-     *
1970
-     * @return void
1971
-     */
1972
-    protected function _set_list_table_view()
1973
-    {
1974
-        $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1975
-        $status = $this->request->getRequestParam('status', null, 'key');
1976
-        $this->_view = $status && array_key_exists($status, $this->_views)
1977
-            ? $status
1978
-            : $this->_view;
1979
-    }
1980
-
1981
-
1982
-    /**
1983
-     * _set_list_table_object
1984
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1985
-     *
1986
-     * @throws InvalidInterfaceException
1987
-     * @throws InvalidArgumentException
1988
-     * @throws InvalidDataTypeException
1989
-     * @throws EE_Error
1990
-     * @throws InvalidInterfaceException
1991
-     */
1992
-    protected function _set_list_table_object()
1993
-    {
1994
-        if (isset($this->_route_config['list_table'])) {
1995
-            if (! class_exists($this->_route_config['list_table'])) {
1996
-                throw new EE_Error(
1997
-                    sprintf(
1998
-                        esc_html__(
1999
-                            'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2000
-                            'event_espresso'
2001
-                        ),
2002
-                        $this->_route_config['list_table'],
2003
-                        get_class($this)
2004
-                    )
2005
-                );
2006
-            }
2007
-            $this->_list_table_object = $this->loader->getShared(
2008
-                $this->_route_config['list_table'],
2009
-                [$this]
2010
-            );
2011
-        }
2012
-    }
2013
-
2014
-
2015
-    /**
2016
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2017
-     *
2018
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2019
-     *                                                    urls.  The array should be indexed by the view it is being
2020
-     *                                                    added to.
2021
-     * @return array
2022
-     */
2023
-    public function get_list_table_view_RLs($extra_query_args = [])
2024
-    {
2025
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2026
-        if (empty($this->_views)) {
2027
-            $this->_views = [];
2028
-        }
2029
-        // cycle thru views
2030
-        foreach ($this->_views as $key => $view) {
2031
-            $query_args = [];
2032
-            // check for current view
2033
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2034
-            $query_args['action']                        = $this->_req_action;
2035
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2036
-            $query_args['status']                        = $view['slug'];
2037
-            // merge any other arguments sent in.
2038
-            if (isset($extra_query_args[ $view['slug'] ])) {
2039
-                $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2040
-            }
2041
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2042
-        }
2043
-        return $this->_views;
2044
-    }
2045
-
2046
-
2047
-    /**
2048
-     * _entries_per_page_dropdown
2049
-     * generates a dropdown box for selecting the number of visible rows in an admin page list table
2050
-     *
2051
-     * @param int $max_entries total number of rows in the table
2052
-     * @return string
2053
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2054
-     *         WP does it.
2055
-     */
2056
-    protected function _entries_per_page_dropdown($max_entries = 0)
2057
-    {
2058
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2059
-        $values   = [10, 25, 50, 100];
2060
-        $per_page = $this->request->getRequestParam('per_page', 10, 'int');
2061
-        if ($max_entries) {
2062
-            $values[] = $max_entries;
2063
-            sort($values);
2064
-        }
2065
-        $entries_per_page_dropdown = '
1540
+		// current set timezone for timezone js
1541
+		echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1542
+	}
1543
+
1544
+
1545
+	/**
1546
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1547
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1548
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1549
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1550
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1551
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1552
+	 * for the
1553
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1554
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1555
+	 *    'help_trigger_id' => array(
1556
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1557
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1558
+	 *    )
1559
+	 * );
1560
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1561
+	 *
1562
+	 * @param array $help_array
1563
+	 * @param bool  $display
1564
+	 * @return string content
1565
+	 * @throws DomainException
1566
+	 * @throws EE_Error
1567
+	 */
1568
+	protected function _set_help_popup_content($help_array = [], $display = false)
1569
+	{
1570
+		$content    = '';
1571
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1572
+		// loop through the array and setup content
1573
+		foreach ($help_array as $trigger => $help) {
1574
+			// make sure the array is setup properly
1575
+			if (! isset($help['title']) || ! isset($help['content'])) {
1576
+				throw new EE_Error(
1577
+					esc_html__(
1578
+						'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1579
+						'event_espresso'
1580
+					)
1581
+				);
1582
+			}
1583
+			// we're good so let's setup the template vars and then assign parsed template content to our content.
1584
+			$template_args = [
1585
+				'help_popup_id'      => $trigger,
1586
+				'help_popup_title'   => $help['title'],
1587
+				'help_popup_content' => $help['content'],
1588
+			];
1589
+			$content       .= EEH_Template::display_template(
1590
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1591
+				$template_args,
1592
+				true
1593
+			);
1594
+		}
1595
+		if ($display) {
1596
+			echo wp_kses($content, AllowedTags::getWithFormTags());
1597
+			return '';
1598
+		}
1599
+		return $content;
1600
+	}
1601
+
1602
+
1603
+	/**
1604
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1605
+	 *
1606
+	 * @return array properly formatted array for help popup content
1607
+	 * @throws EE_Error
1608
+	 */
1609
+	private function _get_help_content()
1610
+	{
1611
+		// what is the method we're looking for?
1612
+		$method_name = '_help_popup_content_' . $this->_req_action;
1613
+		// if method doesn't exist let's get out.
1614
+		if (! method_exists($this, $method_name)) {
1615
+			return [];
1616
+		}
1617
+		// k we're good to go let's retrieve the help array
1618
+		$help_array = call_user_func([$this, $method_name]);
1619
+		// make sure we've got an array!
1620
+		if (! is_array($help_array)) {
1621
+			throw new EE_Error(
1622
+				esc_html__(
1623
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1624
+					'event_espresso'
1625
+				)
1626
+			);
1627
+		}
1628
+		return $help_array;
1629
+	}
1630
+
1631
+
1632
+	/**
1633
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1634
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1635
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1636
+	 *
1637
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1638
+	 * @param boolean $display    if false then we return the trigger string
1639
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1640
+	 * @return string
1641
+	 * @throws DomainException
1642
+	 * @throws EE_Error
1643
+	 */
1644
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1645
+	{
1646
+		if ($this->request->isAjax()) {
1647
+			return '';
1648
+		}
1649
+		// let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1650
+		$help_array   = $this->_get_help_content();
1651
+		$help_content = '';
1652
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1653
+			$help_array[ $trigger_id ] = [
1654
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1655
+				'content' => esc_html__(
1656
+					'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1657
+					'event_espresso'
1658
+				),
1659
+			];
1660
+			$help_content              = $this->_set_help_popup_content($help_array);
1661
+		}
1662
+		// let's setup the trigger
1663
+		$content = '<a class="ee-dialog" href="?height='
1664
+				   . esc_attr($dimensions[0])
1665
+				   . '&width='
1666
+				   . esc_attr($dimensions[1])
1667
+				   . '&inlineId='
1668
+				   . esc_attr($trigger_id)
1669
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1670
+		$content .= $help_content;
1671
+		if ($display) {
1672
+			echo wp_kses($content, AllowedTags::getWithFormTags());
1673
+			return '';
1674
+		}
1675
+		return $content;
1676
+	}
1677
+
1678
+
1679
+	/**
1680
+	 * _add_global_screen_options
1681
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1682
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1683
+	 *
1684
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1685
+	 *         see also WP_Screen object documents...
1686
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1687
+	 * @abstract
1688
+	 * @return void
1689
+	 */
1690
+	private function _add_global_screen_options()
1691
+	{
1692
+	}
1693
+
1694
+
1695
+	/**
1696
+	 * _add_global_feature_pointers
1697
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1698
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1699
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1700
+	 *
1701
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1702
+	 *         extended) also see:
1703
+	 * @link   http://eamann.com/tech/wordpress-portland/
1704
+	 * @abstract
1705
+	 * @return void
1706
+	 */
1707
+	private function _add_global_feature_pointers()
1708
+	{
1709
+	}
1710
+
1711
+
1712
+	/**
1713
+	 * load_global_scripts_styles
1714
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1715
+	 *
1716
+	 * @return void
1717
+	 */
1718
+	public function load_global_scripts_styles()
1719
+	{
1720
+		/** STYLES **/
1721
+		// add debugging styles
1722
+		if (WP_DEBUG) {
1723
+			add_action('admin_head', [$this, 'add_xdebug_style']);
1724
+		}
1725
+		// register all styles
1726
+		wp_register_style(
1727
+			'espresso-ui-theme',
1728
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1729
+			[],
1730
+			EVENT_ESPRESSO_VERSION
1731
+		);
1732
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1733
+		// helpers styles
1734
+		wp_register_style(
1735
+			'ee-text-links',
1736
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1737
+			[],
1738
+			EVENT_ESPRESSO_VERSION
1739
+		);
1740
+		/** SCRIPTS **/
1741
+		// register all scripts
1742
+		wp_register_script(
1743
+			'ee-dialog',
1744
+			EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1745
+			['jquery', 'jquery-ui-draggable'],
1746
+			EVENT_ESPRESSO_VERSION,
1747
+			true
1748
+		);
1749
+		wp_register_script(
1750
+			'ee_admin_js',
1751
+			EE_ADMIN_URL . 'assets/ee-admin-page.js',
1752
+			['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1753
+			EVENT_ESPRESSO_VERSION,
1754
+			true
1755
+		);
1756
+		wp_register_script(
1757
+			'jquery-ui-timepicker-addon',
1758
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1759
+			['jquery-ui-datepicker', 'jquery-ui-slider'],
1760
+			EVENT_ESPRESSO_VERSION,
1761
+			true
1762
+		);
1763
+		// script for sorting tables
1764
+		wp_register_script(
1765
+			'espresso_ajax_table_sorting',
1766
+			EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1767
+			['ee_admin_js', 'jquery-ui-sortable'],
1768
+			EVENT_ESPRESSO_VERSION,
1769
+			true
1770
+		);
1771
+		// script for parsing uri's
1772
+		wp_register_script(
1773
+			'ee-parse-uri',
1774
+			EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1775
+			[],
1776
+			EVENT_ESPRESSO_VERSION,
1777
+			true
1778
+		);
1779
+		// and parsing associative serialized form elements
1780
+		wp_register_script(
1781
+			'ee-serialize-full-array',
1782
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1783
+			['jquery'],
1784
+			EVENT_ESPRESSO_VERSION,
1785
+			true
1786
+		);
1787
+		// helpers scripts
1788
+		wp_register_script(
1789
+			'ee-text-links',
1790
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1791
+			['jquery'],
1792
+			EVENT_ESPRESSO_VERSION,
1793
+			true
1794
+		);
1795
+		wp_register_script(
1796
+			'ee-moment-core',
1797
+			EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1798
+			[],
1799
+			EVENT_ESPRESSO_VERSION,
1800
+			true
1801
+		);
1802
+		wp_register_script(
1803
+			'ee-moment',
1804
+			EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1805
+			['ee-moment-core'],
1806
+			EVENT_ESPRESSO_VERSION,
1807
+			true
1808
+		);
1809
+		wp_register_script(
1810
+			'ee-datepicker',
1811
+			EE_ADMIN_URL . 'assets/ee-datepicker.js',
1812
+			['jquery-ui-timepicker-addon', 'ee-moment'],
1813
+			EVENT_ESPRESSO_VERSION,
1814
+			true
1815
+		);
1816
+		// google charts
1817
+		wp_register_script(
1818
+			'google-charts',
1819
+			'https://www.gstatic.com/charts/loader.js',
1820
+			[],
1821
+			EVENT_ESPRESSO_VERSION
1822
+		);
1823
+		// ENQUEUE ALL BASICS BY DEFAULT
1824
+		wp_enqueue_style('ee-admin-css');
1825
+		wp_enqueue_script('ee_admin_js');
1826
+		wp_enqueue_script('ee-accounting');
1827
+		wp_enqueue_script('jquery-validate');
1828
+		// taking care of metaboxes
1829
+		if (
1830
+			empty($this->_cpt_route)
1831
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1832
+		) {
1833
+			wp_enqueue_script('dashboard');
1834
+		}
1835
+		// LOCALIZED DATA
1836
+		// localize script for ajax lazy loading
1837
+		$lazy_loader_container_ids = apply_filters(
1838
+			'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1839
+			['espresso_news_post_box_content']
1840
+		);
1841
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1842
+		add_filter(
1843
+			'admin_body_class',
1844
+			function ($classes) {
1845
+				if (strpos($classes, 'espresso-admin') === false) {
1846
+					$classes .= ' espresso-admin';
1847
+				}
1848
+				return $classes;
1849
+			}
1850
+		);
1851
+	}
1852
+
1853
+
1854
+	/**
1855
+	 *        admin_footer_scripts_eei18n_js_strings
1856
+	 *
1857
+	 * @return        void
1858
+	 */
1859
+	public function admin_footer_scripts_eei18n_js_strings()
1860
+	{
1861
+		EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1862
+		EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1863
+			__(
1864
+				'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1865
+				'event_espresso'
1866
+			)
1867
+		);
1868
+		EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1869
+		EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1870
+		EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1871
+		EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1872
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1873
+		EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1874
+		EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1875
+		EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1876
+		EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1877
+		EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1878
+		EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1879
+		EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1880
+		EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1881
+		EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1882
+		EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1883
+		EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1884
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1885
+		EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1886
+		EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1887
+		EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1888
+		EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1889
+		EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1890
+		EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1891
+		EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1892
+		EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1893
+		EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1894
+		EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1895
+		EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1896
+		EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1897
+		EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1898
+		EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1899
+		EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1900
+		EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1901
+		EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1902
+		EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1903
+		EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1904
+		EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1905
+		EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1906
+	}
1907
+
1908
+
1909
+	/**
1910
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1911
+	 *
1912
+	 * @return        void
1913
+	 */
1914
+	public function add_xdebug_style()
1915
+	{
1916
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1917
+	}
1918
+
1919
+
1920
+	/************************/
1921
+	/** LIST TABLE METHODS **/
1922
+	/************************/
1923
+	/**
1924
+	 * this sets up the list table if the current view requires it.
1925
+	 *
1926
+	 * @return void
1927
+	 * @throws EE_Error
1928
+	 */
1929
+	protected function _set_list_table()
1930
+	{
1931
+		// first is this a list_table view?
1932
+		if (! isset($this->_route_config['list_table'])) {
1933
+			return;
1934
+		} //not a list_table view so get out.
1935
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
1936
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
1937
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1938
+			// user error msg
1939
+			$error_msg = esc_html__(
1940
+				'An error occurred. The requested list table views could not be found.',
1941
+				'event_espresso'
1942
+			);
1943
+			// developer error msg
1944
+			$error_msg .= '||'
1945
+						  . sprintf(
1946
+							  esc_html__(
1947
+								  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
1948
+								  'event_espresso'
1949
+							  ),
1950
+							  $this->_req_action,
1951
+							  $list_table_view
1952
+						  );
1953
+			throw new EE_Error($error_msg);
1954
+		}
1955
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1956
+		$this->_views = apply_filters(
1957
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
1958
+			$this->_views
1959
+		);
1960
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1961
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1962
+		$this->_set_list_table_view();
1963
+		$this->_set_list_table_object();
1964
+	}
1965
+
1966
+
1967
+	/**
1968
+	 * set current view for List Table
1969
+	 *
1970
+	 * @return void
1971
+	 */
1972
+	protected function _set_list_table_view()
1973
+	{
1974
+		$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1975
+		$status = $this->request->getRequestParam('status', null, 'key');
1976
+		$this->_view = $status && array_key_exists($status, $this->_views)
1977
+			? $status
1978
+			: $this->_view;
1979
+	}
1980
+
1981
+
1982
+	/**
1983
+	 * _set_list_table_object
1984
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1985
+	 *
1986
+	 * @throws InvalidInterfaceException
1987
+	 * @throws InvalidArgumentException
1988
+	 * @throws InvalidDataTypeException
1989
+	 * @throws EE_Error
1990
+	 * @throws InvalidInterfaceException
1991
+	 */
1992
+	protected function _set_list_table_object()
1993
+	{
1994
+		if (isset($this->_route_config['list_table'])) {
1995
+			if (! class_exists($this->_route_config['list_table'])) {
1996
+				throw new EE_Error(
1997
+					sprintf(
1998
+						esc_html__(
1999
+							'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2000
+							'event_espresso'
2001
+						),
2002
+						$this->_route_config['list_table'],
2003
+						get_class($this)
2004
+					)
2005
+				);
2006
+			}
2007
+			$this->_list_table_object = $this->loader->getShared(
2008
+				$this->_route_config['list_table'],
2009
+				[$this]
2010
+			);
2011
+		}
2012
+	}
2013
+
2014
+
2015
+	/**
2016
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2017
+	 *
2018
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2019
+	 *                                                    urls.  The array should be indexed by the view it is being
2020
+	 *                                                    added to.
2021
+	 * @return array
2022
+	 */
2023
+	public function get_list_table_view_RLs($extra_query_args = [])
2024
+	{
2025
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2026
+		if (empty($this->_views)) {
2027
+			$this->_views = [];
2028
+		}
2029
+		// cycle thru views
2030
+		foreach ($this->_views as $key => $view) {
2031
+			$query_args = [];
2032
+			// check for current view
2033
+			$this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2034
+			$query_args['action']                        = $this->_req_action;
2035
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2036
+			$query_args['status']                        = $view['slug'];
2037
+			// merge any other arguments sent in.
2038
+			if (isset($extra_query_args[ $view['slug'] ])) {
2039
+				$query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2040
+			}
2041
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2042
+		}
2043
+		return $this->_views;
2044
+	}
2045
+
2046
+
2047
+	/**
2048
+	 * _entries_per_page_dropdown
2049
+	 * generates a dropdown box for selecting the number of visible rows in an admin page list table
2050
+	 *
2051
+	 * @param int $max_entries total number of rows in the table
2052
+	 * @return string
2053
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2054
+	 *         WP does it.
2055
+	 */
2056
+	protected function _entries_per_page_dropdown($max_entries = 0)
2057
+	{
2058
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2059
+		$values   = [10, 25, 50, 100];
2060
+		$per_page = $this->request->getRequestParam('per_page', 10, 'int');
2061
+		if ($max_entries) {
2062
+			$values[] = $max_entries;
2063
+			sort($values);
2064
+		}
2065
+		$entries_per_page_dropdown = '
2066 2066
 			<div id="entries-per-page-dv" class="alignleft actions">
2067 2067
 				<label class="hide-if-no-js">
2068 2068
 					Show
2069 2069
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2070
-        foreach ($values as $value) {
2071
-            if ($value < $max_entries) {
2072
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2073
-                $entries_per_page_dropdown .= '
2070
+		foreach ($values as $value) {
2071
+			if ($value < $max_entries) {
2072
+				$selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2073
+				$entries_per_page_dropdown .= '
2074 2074
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2075
-            }
2076
-        }
2077
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2078
-        $entries_per_page_dropdown .= '
2075
+			}
2076
+		}
2077
+		$selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2078
+		$entries_per_page_dropdown .= '
2079 2079
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2080
-        $entries_per_page_dropdown .= '
2080
+		$entries_per_page_dropdown .= '
2081 2081
 					</select>
2082 2082
 					entries
2083 2083
 				</label>
2084 2084
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2085 2085
 			</div>
2086 2086
 		';
2087
-        return $entries_per_page_dropdown;
2088
-    }
2089
-
2090
-
2091
-    /**
2092
-     *        _set_search_attributes
2093
-     *
2094
-     * @return        void
2095
-     */
2096
-    public function _set_search_attributes()
2097
-    {
2098
-        $this->_template_args['search']['btn_label'] = sprintf(
2099
-            esc_html__('Search %s', 'event_espresso'),
2100
-            empty($this->_search_btn_label) ? $this->page_label
2101
-                : $this->_search_btn_label
2102
-        );
2103
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2104
-    }
2105
-
2106
-
2107
-
2108
-    /*** END LIST TABLE METHODS **/
2109
-
2110
-
2111
-    /**
2112
-     * _add_registered_metaboxes
2113
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2114
-     *
2115
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2116
-     * @return void
2117
-     * @throws EE_Error
2118
-     */
2119
-    private function _add_registered_meta_boxes()
2120
-    {
2121
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2122
-        // we only add meta boxes if the page_route calls for it
2123
-        if (
2124
-            is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2125
-            && is_array(
2126
-                $this->_route_config['metaboxes']
2127
-            )
2128
-        ) {
2129
-            // this simply loops through the callbacks provided
2130
-            // and checks if there is a corresponding callback registered by the child
2131
-            // if there is then we go ahead and process the metabox loader.
2132
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2133
-                // first check for Closures
2134
-                if ($metabox_callback instanceof Closure) {
2135
-                    $result = $metabox_callback();
2136
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2137
-                    $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2138
-                } else {
2139
-                    $result = call_user_func([$this, &$metabox_callback]);
2140
-                }
2141
-                if ($result === false) {
2142
-                    // user error msg
2143
-                    $error_msg = esc_html__(
2144
-                        'An error occurred. The  requested metabox could not be found.',
2145
-                        'event_espresso'
2146
-                    );
2147
-                    // developer error msg
2148
-                    $error_msg .= '||'
2149
-                                  . sprintf(
2150
-                                      esc_html__(
2151
-                                          'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2152
-                                          'event_espresso'
2153
-                                      ),
2154
-                                      $metabox_callback
2155
-                                  );
2156
-                    throw new EE_Error($error_msg);
2157
-                }
2158
-            }
2159
-        }
2160
-    }
2161
-
2162
-
2163
-    /**
2164
-     * _add_screen_columns
2165
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2166
-     * the dynamic column template and we'll setup the column options for the page.
2167
-     *
2168
-     * @return void
2169
-     */
2170
-    private function _add_screen_columns()
2171
-    {
2172
-        if (
2173
-            is_array($this->_route_config)
2174
-            && isset($this->_route_config['columns'])
2175
-            && is_array($this->_route_config['columns'])
2176
-            && count($this->_route_config['columns']) === 2
2177
-        ) {
2178
-            add_screen_option(
2179
-                'layout_columns',
2180
-                [
2181
-                    'max'     => (int) $this->_route_config['columns'][0],
2182
-                    'default' => (int) $this->_route_config['columns'][1],
2183
-                ]
2184
-            );
2185
-            $this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2186
-            $screen_id                                           = $this->_current_screen->id;
2187
-            $screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2188
-            $total_columns                                       = ! empty($screen_columns)
2189
-                ? $screen_columns
2190
-                : $this->_route_config['columns'][1];
2191
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2192
-            $this->_template_args['current_page']                = $this->_wp_page_slug;
2193
-            $this->_template_args['screen']                      = $this->_current_screen;
2194
-            $this->_column_template_path                         = EE_ADMIN_TEMPLATE
2195
-                                                                   . 'admin_details_metabox_column_wrapper.template.php';
2196
-            // finally if we don't have has_metaboxes set in the route config
2197
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2198
-            $this->_route_config['has_metaboxes'] = true;
2199
-        }
2200
-    }
2201
-
2202
-
2203
-
2204
-    /** GLOBALLY AVAILABLE METABOXES **/
2205
-
2206
-
2207
-    /**
2208
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2209
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2210
-     * these get loaded on.
2211
-     */
2212
-    private function _espresso_news_post_box()
2213
-    {
2214
-        $news_box_title = apply_filters(
2215
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2216
-            esc_html__('New @ Event Espresso', 'event_espresso')
2217
-        );
2218
-        add_meta_box(
2219
-            'espresso_news_post_box',
2220
-            $news_box_title,
2221
-            [
2222
-                $this,
2223
-                'espresso_news_post_box',
2224
-            ],
2225
-            $this->_wp_page_slug,
2226
-            'side'
2227
-        );
2228
-    }
2229
-
2230
-
2231
-    /**
2232
-     * Code for setting up espresso ratings request metabox.
2233
-     */
2234
-    protected function _espresso_ratings_request()
2235
-    {
2236
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2237
-            return;
2238
-        }
2239
-        $ratings_box_title = apply_filters(
2240
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2241
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2242
-        );
2243
-        add_meta_box(
2244
-            'espresso_ratings_request',
2245
-            $ratings_box_title,
2246
-            [
2247
-                $this,
2248
-                'espresso_ratings_request',
2249
-            ],
2250
-            $this->_wp_page_slug,
2251
-            'side'
2252
-        );
2253
-    }
2254
-
2255
-
2256
-    /**
2257
-     * Code for setting up espresso ratings request metabox content.
2258
-     *
2259
-     * @throws DomainException
2260
-     */
2261
-    public function espresso_ratings_request()
2262
-    {
2263
-        EEH_Template::display_template(
2264
-            EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2265
-            []
2266
-        );
2267
-    }
2268
-
2269
-
2270
-    public static function cached_rss_display($rss_id, $url)
2271
-    {
2272
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2273
-                     . esc_html__('Loading&#8230;', 'event_espresso')
2274
-                     . '</p><p class="hide-if-js">'
2275
-                     . esc_html__('This widget requires JavaScript.', 'event_espresso')
2276
-                     . '</p>';
2277
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2278
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2279
-        $post      = '</div>' . "\n";
2280
-        $cache_key = 'ee_rss_' . md5($rss_id);
2281
-        $output    = get_transient($cache_key);
2282
-        if ($output !== false) {
2283
-            echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags());
2284
-            return true;
2285
-        }
2286
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2287
-            echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags());
2288
-            return false;
2289
-        }
2290
-        ob_start();
2291
-        wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2292
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2293
-        return true;
2294
-    }
2295
-
2296
-
2297
-    public function espresso_news_post_box()
2298
-    {
2299
-        ?>
2087
+		return $entries_per_page_dropdown;
2088
+	}
2089
+
2090
+
2091
+	/**
2092
+	 *        _set_search_attributes
2093
+	 *
2094
+	 * @return        void
2095
+	 */
2096
+	public function _set_search_attributes()
2097
+	{
2098
+		$this->_template_args['search']['btn_label'] = sprintf(
2099
+			esc_html__('Search %s', 'event_espresso'),
2100
+			empty($this->_search_btn_label) ? $this->page_label
2101
+				: $this->_search_btn_label
2102
+		);
2103
+		$this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2104
+	}
2105
+
2106
+
2107
+
2108
+	/*** END LIST TABLE METHODS **/
2109
+
2110
+
2111
+	/**
2112
+	 * _add_registered_metaboxes
2113
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2114
+	 *
2115
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2116
+	 * @return void
2117
+	 * @throws EE_Error
2118
+	 */
2119
+	private function _add_registered_meta_boxes()
2120
+	{
2121
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2122
+		// we only add meta boxes if the page_route calls for it
2123
+		if (
2124
+			is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2125
+			&& is_array(
2126
+				$this->_route_config['metaboxes']
2127
+			)
2128
+		) {
2129
+			// this simply loops through the callbacks provided
2130
+			// and checks if there is a corresponding callback registered by the child
2131
+			// if there is then we go ahead and process the metabox loader.
2132
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2133
+				// first check for Closures
2134
+				if ($metabox_callback instanceof Closure) {
2135
+					$result = $metabox_callback();
2136
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2137
+					$result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2138
+				} else {
2139
+					$result = call_user_func([$this, &$metabox_callback]);
2140
+				}
2141
+				if ($result === false) {
2142
+					// user error msg
2143
+					$error_msg = esc_html__(
2144
+						'An error occurred. The  requested metabox could not be found.',
2145
+						'event_espresso'
2146
+					);
2147
+					// developer error msg
2148
+					$error_msg .= '||'
2149
+								  . sprintf(
2150
+									  esc_html__(
2151
+										  'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2152
+										  'event_espresso'
2153
+									  ),
2154
+									  $metabox_callback
2155
+								  );
2156
+					throw new EE_Error($error_msg);
2157
+				}
2158
+			}
2159
+		}
2160
+	}
2161
+
2162
+
2163
+	/**
2164
+	 * _add_screen_columns
2165
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2166
+	 * the dynamic column template and we'll setup the column options for the page.
2167
+	 *
2168
+	 * @return void
2169
+	 */
2170
+	private function _add_screen_columns()
2171
+	{
2172
+		if (
2173
+			is_array($this->_route_config)
2174
+			&& isset($this->_route_config['columns'])
2175
+			&& is_array($this->_route_config['columns'])
2176
+			&& count($this->_route_config['columns']) === 2
2177
+		) {
2178
+			add_screen_option(
2179
+				'layout_columns',
2180
+				[
2181
+					'max'     => (int) $this->_route_config['columns'][0],
2182
+					'default' => (int) $this->_route_config['columns'][1],
2183
+				]
2184
+			);
2185
+			$this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2186
+			$screen_id                                           = $this->_current_screen->id;
2187
+			$screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2188
+			$total_columns                                       = ! empty($screen_columns)
2189
+				? $screen_columns
2190
+				: $this->_route_config['columns'][1];
2191
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2192
+			$this->_template_args['current_page']                = $this->_wp_page_slug;
2193
+			$this->_template_args['screen']                      = $this->_current_screen;
2194
+			$this->_column_template_path                         = EE_ADMIN_TEMPLATE
2195
+																   . 'admin_details_metabox_column_wrapper.template.php';
2196
+			// finally if we don't have has_metaboxes set in the route config
2197
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2198
+			$this->_route_config['has_metaboxes'] = true;
2199
+		}
2200
+	}
2201
+
2202
+
2203
+
2204
+	/** GLOBALLY AVAILABLE METABOXES **/
2205
+
2206
+
2207
+	/**
2208
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2209
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2210
+	 * these get loaded on.
2211
+	 */
2212
+	private function _espresso_news_post_box()
2213
+	{
2214
+		$news_box_title = apply_filters(
2215
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2216
+			esc_html__('New @ Event Espresso', 'event_espresso')
2217
+		);
2218
+		add_meta_box(
2219
+			'espresso_news_post_box',
2220
+			$news_box_title,
2221
+			[
2222
+				$this,
2223
+				'espresso_news_post_box',
2224
+			],
2225
+			$this->_wp_page_slug,
2226
+			'side'
2227
+		);
2228
+	}
2229
+
2230
+
2231
+	/**
2232
+	 * Code for setting up espresso ratings request metabox.
2233
+	 */
2234
+	protected function _espresso_ratings_request()
2235
+	{
2236
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2237
+			return;
2238
+		}
2239
+		$ratings_box_title = apply_filters(
2240
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2241
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2242
+		);
2243
+		add_meta_box(
2244
+			'espresso_ratings_request',
2245
+			$ratings_box_title,
2246
+			[
2247
+				$this,
2248
+				'espresso_ratings_request',
2249
+			],
2250
+			$this->_wp_page_slug,
2251
+			'side'
2252
+		);
2253
+	}
2254
+
2255
+
2256
+	/**
2257
+	 * Code for setting up espresso ratings request metabox content.
2258
+	 *
2259
+	 * @throws DomainException
2260
+	 */
2261
+	public function espresso_ratings_request()
2262
+	{
2263
+		EEH_Template::display_template(
2264
+			EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2265
+			[]
2266
+		);
2267
+	}
2268
+
2269
+
2270
+	public static function cached_rss_display($rss_id, $url)
2271
+	{
2272
+		$loading   = '<p class="widget-loading hide-if-no-js">'
2273
+					 . esc_html__('Loading&#8230;', 'event_espresso')
2274
+					 . '</p><p class="hide-if-js">'
2275
+					 . esc_html__('This widget requires JavaScript.', 'event_espresso')
2276
+					 . '</p>';
2277
+		$pre       = '<div class="espresso-rss-display">' . "\n\t";
2278
+		$pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2279
+		$post      = '</div>' . "\n";
2280
+		$cache_key = 'ee_rss_' . md5($rss_id);
2281
+		$output    = get_transient($cache_key);
2282
+		if ($output !== false) {
2283
+			echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags());
2284
+			return true;
2285
+		}
2286
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2287
+			echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags());
2288
+			return false;
2289
+		}
2290
+		ob_start();
2291
+		wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2292
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2293
+		return true;
2294
+	}
2295
+
2296
+
2297
+	public function espresso_news_post_box()
2298
+	{
2299
+		?>
2300 2300
         <div class="padding">
2301 2301
             <div id="espresso_news_post_box_content" class="infolinks">
2302 2302
                 <?php
2303
-                // Get RSS Feed(s)
2304
-                self::cached_rss_display(
2305
-                    'espresso_news_post_box_content',
2306
-                    esc_url_raw(
2307
-                        apply_filters(
2308
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2309
-                            'https://eventespresso.com/feed/'
2310
-                        )
2311
-                    )
2312
-                );
2313
-                ?>
2303
+				// Get RSS Feed(s)
2304
+				self::cached_rss_display(
2305
+					'espresso_news_post_box_content',
2306
+					esc_url_raw(
2307
+						apply_filters(
2308
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2309
+							'https://eventespresso.com/feed/'
2310
+						)
2311
+					)
2312
+				);
2313
+				?>
2314 2314
             </div>
2315 2315
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2316 2316
         </div>
2317 2317
         <?php
2318
-    }
2319
-
2320
-
2321
-    private function _espresso_links_post_box()
2322
-    {
2323
-        // Hiding until we actually have content to put in here...
2324
-        // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2325
-    }
2326
-
2327
-
2328
-    public function espresso_links_post_box()
2329
-    {
2330
-        // Hiding until we actually have content to put in here...
2331
-        // EEH_Template::display_template(
2332
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2333
-        // );
2334
-    }
2335
-
2336
-
2337
-    protected function _espresso_sponsors_post_box()
2338
-    {
2339
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2340
-            add_meta_box(
2341
-                'espresso_sponsors_post_box',
2342
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2343
-                [$this, 'espresso_sponsors_post_box'],
2344
-                $this->_wp_page_slug,
2345
-                'side'
2346
-            );
2347
-        }
2348
-    }
2349
-
2350
-
2351
-    public function espresso_sponsors_post_box()
2352
-    {
2353
-        EEH_Template::display_template(
2354
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2355
-        );
2356
-    }
2357
-
2358
-
2359
-    private function _publish_post_box()
2360
-    {
2361
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2362
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2363
-        // then we'll use that for the metabox label.
2364
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2365
-        if (! empty($this->_labels['publishbox'])) {
2366
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2367
-                : $this->_labels['publishbox'];
2368
-        } else {
2369
-            $box_label = esc_html__('Publish', 'event_espresso');
2370
-        }
2371
-        $box_label = apply_filters(
2372
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2373
-            $box_label,
2374
-            $this->_req_action,
2375
-            $this
2376
-        );
2377
-        add_meta_box(
2378
-            $meta_box_ref,
2379
-            $box_label,
2380
-            [$this, 'editor_overview'],
2381
-            $this->_current_screen->id,
2382
-            'side',
2383
-            'high'
2384
-        );
2385
-    }
2386
-
2387
-
2388
-    public function editor_overview()
2389
-    {
2390
-        // if we have extra content set let's add it in if not make sure its empty
2391
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2392
-            ? $this->_template_args['publish_box_extra_content']
2393
-            : '';
2394
-        echo EEH_Template::display_template(
2395
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2396
-            $this->_template_args,
2397
-            true
2398
-        );
2399
-    }
2400
-
2401
-
2402
-    /** end of globally available metaboxes section **/
2403
-
2404
-
2405
-    /**
2406
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2407
-     * protected method.
2408
-     *
2409
-     * @param string $name
2410
-     * @param int    $id
2411
-     * @param bool   $delete
2412
-     * @param string $save_close_redirect_URL
2413
-     * @param bool   $both_btns
2414
-     * @throws EE_Error
2415
-     * @throws InvalidArgumentException
2416
-     * @throws InvalidDataTypeException
2417
-     * @throws InvalidInterfaceException
2418
-     * @see   $this->_set_publish_post_box_vars for param details
2419
-     * @since 4.6.0
2420
-     */
2421
-    public function set_publish_post_box_vars(
2422
-        $name = '',
2423
-        $id = 0,
2424
-        $delete = false,
2425
-        $save_close_redirect_URL = '',
2426
-        $both_btns = true
2427
-    ) {
2428
-        $this->_set_publish_post_box_vars(
2429
-            $name,
2430
-            $id,
2431
-            $delete,
2432
-            $save_close_redirect_URL,
2433
-            $both_btns
2434
-        );
2435
-    }
2436
-
2437
-
2438
-    /**
2439
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2440
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2441
-     * save, and save and close buttons to work properly, then you will want to include a
2442
-     * values for the name and id arguments.
2443
-     *
2444
-     * @param string  $name                       key used for the action ID (i.e. event_id)
2445
-     * @param int     $id                         id attached to the item published
2446
-     * @param string  $delete                     page route callback for the delete action
2447
-     * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2448
-     * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2449
-     *                                            the Save button
2450
-     * @throws EE_Error
2451
-     * @throws InvalidArgumentException
2452
-     * @throws InvalidDataTypeException
2453
-     * @throws InvalidInterfaceException
2454
-     * @todo  Add in validation for name/id arguments.
2455
-     */
2456
-    protected function _set_publish_post_box_vars(
2457
-        $name = '',
2458
-        $id = 0,
2459
-        $delete = '',
2460
-        $save_close_redirect_URL = '',
2461
-        $both_btns = true
2462
-    ) {
2463
-        // if Save & Close, use a custom redirect URL or default to the main page?
2464
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2465
-            ? $save_close_redirect_URL
2466
-            : $this->_admin_base_url;
2467
-        // create the Save & Close and Save buttons
2468
-        $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2469
-        // if we have extra content set let's add it in if not make sure its empty
2470
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2471
-            ? $this->_template_args['publish_box_extra_content']
2472
-            : '';
2473
-        if ($delete && ! empty($id)) {
2474
-            // make sure we have a default if just true is sent.
2475
-            $delete           = ! empty($delete) ? $delete : 'delete';
2476
-            $delete_link_args = [$name => $id];
2477
-            $delete           = $this->get_action_link_or_button(
2478
-                $delete,
2479
-                $delete,
2480
-                $delete_link_args,
2481
-                'submitdelete deletion',
2482
-                '',
2483
-                false
2484
-            );
2485
-        }
2486
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2487
-        if (! empty($name) && ! empty($id)) {
2488
-            $hidden_field_arr[ $name ] = [
2489
-                'type'  => 'hidden',
2490
-                'value' => $id,
2491
-            ];
2492
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2493
-        } else {
2494
-            $hf = '';
2495
-        }
2496
-        // add hidden field
2497
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2498
-            ? $hf[ $name ]['field']
2499
-            : $hf;
2500
-    }
2501
-
2502
-
2503
-    /**
2504
-     * displays an error message to ppl who have javascript disabled
2505
-     *
2506
-     * @return void
2507
-     */
2508
-    private function _display_no_javascript_warning()
2509
-    {
2510
-        ?>
2318
+	}
2319
+
2320
+
2321
+	private function _espresso_links_post_box()
2322
+	{
2323
+		// Hiding until we actually have content to put in here...
2324
+		// add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2325
+	}
2326
+
2327
+
2328
+	public function espresso_links_post_box()
2329
+	{
2330
+		// Hiding until we actually have content to put in here...
2331
+		// EEH_Template::display_template(
2332
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2333
+		// );
2334
+	}
2335
+
2336
+
2337
+	protected function _espresso_sponsors_post_box()
2338
+	{
2339
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2340
+			add_meta_box(
2341
+				'espresso_sponsors_post_box',
2342
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2343
+				[$this, 'espresso_sponsors_post_box'],
2344
+				$this->_wp_page_slug,
2345
+				'side'
2346
+			);
2347
+		}
2348
+	}
2349
+
2350
+
2351
+	public function espresso_sponsors_post_box()
2352
+	{
2353
+		EEH_Template::display_template(
2354
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2355
+		);
2356
+	}
2357
+
2358
+
2359
+	private function _publish_post_box()
2360
+	{
2361
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2362
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2363
+		// then we'll use that for the metabox label.
2364
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2365
+		if (! empty($this->_labels['publishbox'])) {
2366
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2367
+				: $this->_labels['publishbox'];
2368
+		} else {
2369
+			$box_label = esc_html__('Publish', 'event_espresso');
2370
+		}
2371
+		$box_label = apply_filters(
2372
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2373
+			$box_label,
2374
+			$this->_req_action,
2375
+			$this
2376
+		);
2377
+		add_meta_box(
2378
+			$meta_box_ref,
2379
+			$box_label,
2380
+			[$this, 'editor_overview'],
2381
+			$this->_current_screen->id,
2382
+			'side',
2383
+			'high'
2384
+		);
2385
+	}
2386
+
2387
+
2388
+	public function editor_overview()
2389
+	{
2390
+		// if we have extra content set let's add it in if not make sure its empty
2391
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2392
+			? $this->_template_args['publish_box_extra_content']
2393
+			: '';
2394
+		echo EEH_Template::display_template(
2395
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2396
+			$this->_template_args,
2397
+			true
2398
+		);
2399
+	}
2400
+
2401
+
2402
+	/** end of globally available metaboxes section **/
2403
+
2404
+
2405
+	/**
2406
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2407
+	 * protected method.
2408
+	 *
2409
+	 * @param string $name
2410
+	 * @param int    $id
2411
+	 * @param bool   $delete
2412
+	 * @param string $save_close_redirect_URL
2413
+	 * @param bool   $both_btns
2414
+	 * @throws EE_Error
2415
+	 * @throws InvalidArgumentException
2416
+	 * @throws InvalidDataTypeException
2417
+	 * @throws InvalidInterfaceException
2418
+	 * @see   $this->_set_publish_post_box_vars for param details
2419
+	 * @since 4.6.0
2420
+	 */
2421
+	public function set_publish_post_box_vars(
2422
+		$name = '',
2423
+		$id = 0,
2424
+		$delete = false,
2425
+		$save_close_redirect_URL = '',
2426
+		$both_btns = true
2427
+	) {
2428
+		$this->_set_publish_post_box_vars(
2429
+			$name,
2430
+			$id,
2431
+			$delete,
2432
+			$save_close_redirect_URL,
2433
+			$both_btns
2434
+		);
2435
+	}
2436
+
2437
+
2438
+	/**
2439
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2440
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2441
+	 * save, and save and close buttons to work properly, then you will want to include a
2442
+	 * values for the name and id arguments.
2443
+	 *
2444
+	 * @param string  $name                       key used for the action ID (i.e. event_id)
2445
+	 * @param int     $id                         id attached to the item published
2446
+	 * @param string  $delete                     page route callback for the delete action
2447
+	 * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2448
+	 * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2449
+	 *                                            the Save button
2450
+	 * @throws EE_Error
2451
+	 * @throws InvalidArgumentException
2452
+	 * @throws InvalidDataTypeException
2453
+	 * @throws InvalidInterfaceException
2454
+	 * @todo  Add in validation for name/id arguments.
2455
+	 */
2456
+	protected function _set_publish_post_box_vars(
2457
+		$name = '',
2458
+		$id = 0,
2459
+		$delete = '',
2460
+		$save_close_redirect_URL = '',
2461
+		$both_btns = true
2462
+	) {
2463
+		// if Save & Close, use a custom redirect URL or default to the main page?
2464
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2465
+			? $save_close_redirect_URL
2466
+			: $this->_admin_base_url;
2467
+		// create the Save & Close and Save buttons
2468
+		$this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2469
+		// if we have extra content set let's add it in if not make sure its empty
2470
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2471
+			? $this->_template_args['publish_box_extra_content']
2472
+			: '';
2473
+		if ($delete && ! empty($id)) {
2474
+			// make sure we have a default if just true is sent.
2475
+			$delete           = ! empty($delete) ? $delete : 'delete';
2476
+			$delete_link_args = [$name => $id];
2477
+			$delete           = $this->get_action_link_or_button(
2478
+				$delete,
2479
+				$delete,
2480
+				$delete_link_args,
2481
+				'submitdelete deletion',
2482
+				'',
2483
+				false
2484
+			);
2485
+		}
2486
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2487
+		if (! empty($name) && ! empty($id)) {
2488
+			$hidden_field_arr[ $name ] = [
2489
+				'type'  => 'hidden',
2490
+				'value' => $id,
2491
+			];
2492
+			$hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2493
+		} else {
2494
+			$hf = '';
2495
+		}
2496
+		// add hidden field
2497
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2498
+			? $hf[ $name ]['field']
2499
+			: $hf;
2500
+	}
2501
+
2502
+
2503
+	/**
2504
+	 * displays an error message to ppl who have javascript disabled
2505
+	 *
2506
+	 * @return void
2507
+	 */
2508
+	private function _display_no_javascript_warning()
2509
+	{
2510
+		?>
2511 2511
         <noscript>
2512 2512
             <div id="no-js-message" class="error">
2513 2513
                 <p style="font-size:1.3em;">
2514 2514
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2515 2515
                     <?php esc_html_e(
2516
-                        'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2517
-                        'event_espresso'
2518
-                    ); ?>
2516
+						'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2517
+						'event_espresso'
2518
+					); ?>
2519 2519
                 </p>
2520 2520
             </div>
2521 2521
         </noscript>
2522 2522
         <?php
2523
-    }
2524
-
2525
-
2526
-    /**
2527
-     * displays espresso success and/or error notices
2528
-     *
2529
-     * @return void
2530
-     */
2531
-    protected function _display_espresso_notices()
2532
-    {
2533
-        $notices = $this->_get_transient(true);
2534
-        echo stripslashes($notices);
2535
-    }
2536
-
2537
-
2538
-    /**
2539
-     * spinny things pacify the masses
2540
-     *
2541
-     * @return void
2542
-     */
2543
-    protected function _add_admin_page_ajax_loading_img()
2544
-    {
2545
-        ?>
2523
+	}
2524
+
2525
+
2526
+	/**
2527
+	 * displays espresso success and/or error notices
2528
+	 *
2529
+	 * @return void
2530
+	 */
2531
+	protected function _display_espresso_notices()
2532
+	{
2533
+		$notices = $this->_get_transient(true);
2534
+		echo stripslashes($notices);
2535
+	}
2536
+
2537
+
2538
+	/**
2539
+	 * spinny things pacify the masses
2540
+	 *
2541
+	 * @return void
2542
+	 */
2543
+	protected function _add_admin_page_ajax_loading_img()
2544
+	{
2545
+		?>
2546 2546
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2547 2547
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2548
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2548
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2549 2549
         </div>
2550 2550
         <?php
2551
-    }
2551
+	}
2552 2552
 
2553 2553
 
2554
-    /**
2555
-     * add admin page overlay for modal boxes
2556
-     *
2557
-     * @return void
2558
-     */
2559
-    protected function _add_admin_page_overlay()
2560
-    {
2561
-        ?>
2554
+	/**
2555
+	 * add admin page overlay for modal boxes
2556
+	 *
2557
+	 * @return void
2558
+	 */
2559
+	protected function _add_admin_page_overlay()
2560
+	{
2561
+		?>
2562 2562
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2563 2563
         <?php
2564
-    }
2565
-
2566
-
2567
-    /**
2568
-     * facade for add_meta_box
2569
-     *
2570
-     * @param string  $action        where the metabox gets displayed
2571
-     * @param string  $title         Title of Metabox (output in metabox header)
2572
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2573
-     *                               instead of the one created in here.
2574
-     * @param array   $callback_args an array of args supplied for the metabox
2575
-     * @param string  $column        what metabox column
2576
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2577
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2578
-     *                               created but just set our own callback for wp's add_meta_box.
2579
-     * @throws DomainException
2580
-     */
2581
-    public function _add_admin_page_meta_box(
2582
-        $action,
2583
-        $title,
2584
-        $callback,
2585
-        $callback_args,
2586
-        $column = 'normal',
2587
-        $priority = 'high',
2588
-        $create_func = true
2589
-    ) {
2590
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2591
-        // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2592
-        if (empty($callback_args) && $create_func) {
2593
-            $callback_args = [
2594
-                'template_path' => $this->_template_path,
2595
-                'template_args' => $this->_template_args,
2596
-            ];
2597
-        }
2598
-        // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2599
-        $call_back_func = $create_func
2600
-            ? function ($post, $metabox) {
2601
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2602
-                echo EEH_Template::display_template(
2603
-                    $metabox['args']['template_path'],
2604
-                    $metabox['args']['template_args'],
2605
-                    true
2606
-                );
2607
-            }
2608
-            : $callback;
2609
-        add_meta_box(
2610
-            str_replace('_', '-', $action) . '-mbox',
2611
-            $title,
2612
-            $call_back_func,
2613
-            $this->_wp_page_slug,
2614
-            $column,
2615
-            $priority,
2616
-            $callback_args
2617
-        );
2618
-    }
2619
-
2620
-
2621
-    /**
2622
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2623
-     *
2624
-     * @throws DomainException
2625
-     * @throws EE_Error
2626
-     */
2627
-    public function display_admin_page_with_metabox_columns()
2628
-    {
2629
-        $this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2630
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2631
-            $this->_column_template_path,
2632
-            $this->_template_args,
2633
-            true
2634
-        );
2635
-        // the final wrapper
2636
-        $this->admin_page_wrapper();
2637
-    }
2638
-
2639
-
2640
-    /**
2641
-     * generates  HTML wrapper for an admin details page
2642
-     *
2643
-     * @return void
2644
-     * @throws EE_Error
2645
-     * @throws DomainException
2646
-     */
2647
-    public function display_admin_page_with_sidebar()
2648
-    {
2649
-        $this->_display_admin_page(true);
2650
-    }
2651
-
2652
-
2653
-    /**
2654
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2655
-     *
2656
-     * @return void
2657
-     * @throws EE_Error
2658
-     * @throws DomainException
2659
-     */
2660
-    public function display_admin_page_with_no_sidebar()
2661
-    {
2662
-        $this->_display_admin_page();
2663
-    }
2664
-
2665
-
2666
-    /**
2667
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2668
-     *
2669
-     * @return void
2670
-     * @throws EE_Error
2671
-     * @throws DomainException
2672
-     */
2673
-    public function display_about_admin_page()
2674
-    {
2675
-        $this->_display_admin_page(false, true);
2676
-    }
2677
-
2678
-
2679
-    /**
2680
-     * display_admin_page
2681
-     * contains the code for actually displaying an admin page
2682
-     *
2683
-     * @param boolean $sidebar true with sidebar, false without
2684
-     * @param boolean $about   use the about_admin_wrapper instead of the default.
2685
-     * @return void
2686
-     * @throws DomainException
2687
-     * @throws EE_Error
2688
-     */
2689
-    private function _display_admin_page($sidebar = false, $about = false)
2690
-    {
2691
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2692
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2693
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2694
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2695
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2696
-        $this->_template_args['current_page']              = $this->_wp_page_slug;
2697
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2698
-            ? 'poststuff'
2699
-            : 'espresso-default-admin';
2700
-        $template_path                                     = $sidebar
2701
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2702
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2703
-        if ($this->request->isAjax()) {
2704
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2705
-        }
2706
-        $template_path                                     = ! empty($this->_column_template_path)
2707
-            ? $this->_column_template_path : $template_path;
2708
-        $this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2709
-            ? $this->_template_args['admin_page_content']
2710
-            : '';
2711
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2712
-            ? $this->_template_args['before_admin_page_content']
2713
-            : '';
2714
-        $this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2715
-            ? $this->_template_args['after_admin_page_content']
2716
-            : '';
2717
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
2718
-            $template_path,
2719
-            $this->_template_args,
2720
-            true
2721
-        );
2722
-        // the final template wrapper
2723
-        $this->admin_page_wrapper($about);
2724
-    }
2725
-
2726
-
2727
-    /**
2728
-     * This is used to display caf preview pages.
2729
-     *
2730
-     * @param string $utm_campaign_source what is the key used for google analytics link
2731
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2732
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2733
-     * @return void
2734
-     * @throws DomainException
2735
-     * @throws EE_Error
2736
-     * @throws InvalidArgumentException
2737
-     * @throws InvalidDataTypeException
2738
-     * @throws InvalidInterfaceException
2739
-     * @since 4.3.2
2740
-     */
2741
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2742
-    {
2743
-        // let's generate a default preview action button if there isn't one already present.
2744
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2745
-            'Upgrade to Event Espresso 4 Right Now',
2746
-            'event_espresso'
2747
-        );
2748
-        $buy_now_url                                   = add_query_arg(
2749
-            [
2750
-                'ee_ver'       => 'ee4',
2751
-                'utm_source'   => 'ee4_plugin_admin',
2752
-                'utm_medium'   => 'link',
2753
-                'utm_campaign' => $utm_campaign_source,
2754
-                'utm_content'  => 'buy_now_button',
2755
-            ],
2756
-            'https://eventespresso.com/pricing/'
2757
-        );
2758
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2759
-            ? $this->get_action_link_or_button(
2760
-                '',
2761
-                'buy_now',
2762
-                [],
2763
-                'button-primary button-large',
2764
-                esc_url_raw($buy_now_url),
2765
-                true
2766
-            )
2767
-            : $this->_template_args['preview_action_button'];
2768
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2769
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2770
-            $this->_template_args,
2771
-            true
2772
-        );
2773
-        $this->_display_admin_page($display_sidebar);
2774
-    }
2775
-
2776
-
2777
-    /**
2778
-     * display_admin_list_table_page_with_sidebar
2779
-     * generates HTML wrapper for an admin_page with list_table
2780
-     *
2781
-     * @return void
2782
-     * @throws EE_Error
2783
-     * @throws DomainException
2784
-     */
2785
-    public function display_admin_list_table_page_with_sidebar()
2786
-    {
2787
-        $this->_display_admin_list_table_page(true);
2788
-    }
2789
-
2790
-
2791
-    /**
2792
-     * display_admin_list_table_page_with_no_sidebar
2793
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2794
-     *
2795
-     * @return void
2796
-     * @throws EE_Error
2797
-     * @throws DomainException
2798
-     */
2799
-    public function display_admin_list_table_page_with_no_sidebar()
2800
-    {
2801
-        $this->_display_admin_list_table_page();
2802
-    }
2803
-
2804
-
2805
-    /**
2806
-     * generates html wrapper for an admin_list_table page
2807
-     *
2808
-     * @param boolean $sidebar whether to display with sidebar or not.
2809
-     * @return void
2810
-     * @throws DomainException
2811
-     * @throws EE_Error
2812
-     */
2813
-    private function _display_admin_list_table_page($sidebar = false)
2814
-    {
2815
-        // setup search attributes
2816
-        $this->_set_search_attributes();
2817
-        $this->_template_args['current_page']     = $this->_wp_page_slug;
2818
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2819
-        $this->_template_args['table_url']        = $this->request->isAjax()
2820
-            ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2821
-            : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2822
-        $this->_template_args['list_table']       = $this->_list_table_object;
2823
-        $this->_template_args['current_route']    = $this->_req_action;
2824
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2825
-        $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2826
-        if (! empty($ajax_sorting_callback)) {
2827
-            $sortable_list_table_form_fields = wp_nonce_field(
2828
-                $ajax_sorting_callback . '_nonce',
2829
-                $ajax_sorting_callback . '_nonce',
2830
-                false,
2831
-                false
2832
-            );
2833
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2834
-                                                . $this->page_slug
2835
-                                                . '" />';
2836
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2837
-                                                . $ajax_sorting_callback
2838
-                                                . '" />';
2839
-        } else {
2840
-            $sortable_list_table_form_fields = '';
2841
-        }
2842
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2843
-        $hidden_form_fields                                      =
2844
-            isset($this->_template_args['list_table_hidden_fields'])
2845
-                ? $this->_template_args['list_table_hidden_fields']
2846
-                : '';
2847
-        $nonce_ref                                               = $this->_req_action . '_nonce';
2848
-        $hidden_form_fields                                      .= '<input type="hidden" name="'
2849
-                                                                    . $nonce_ref
2850
-                                                                    . '" value="'
2851
-                                                                    . wp_create_nonce($nonce_ref)
2852
-                                                                    . '">';
2853
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2854
-        // display message about search results?
2855
-        $search = $this->request->getRequestParam('s');
2856
-        $this->_template_args['before_list_table'] .= ! empty($search)
2857
-            ? '<p class="ee-search-results">' . sprintf(
2858
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2859
-                trim($search, '%')
2860
-            ) . '</p>'
2861
-            : '';
2862
-        // filter before_list_table template arg
2863
-        $this->_template_args['before_list_table'] = apply_filters(
2864
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2865
-            $this->_template_args['before_list_table'],
2866
-            $this->page_slug,
2867
-            $this->request->requestParams(),
2868
-            $this->_req_action
2869
-        );
2870
-        // convert to array and filter again
2871
-        // arrays are easier to inject new items in a specific location,
2872
-        // but would not be backwards compatible, so we have to add a new filter
2873
-        $this->_template_args['before_list_table'] = implode(
2874
-            " \n",
2875
-            (array) apply_filters(
2876
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2877
-                (array) $this->_template_args['before_list_table'],
2878
-                $this->page_slug,
2879
-                $this->request->requestParams(),
2880
-                $this->_req_action
2881
-            )
2882
-        );
2883
-        // filter after_list_table template arg
2884
-        $this->_template_args['after_list_table'] = apply_filters(
2885
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2886
-            $this->_template_args['after_list_table'],
2887
-            $this->page_slug,
2888
-            $this->request->requestParams(),
2889
-            $this->_req_action
2890
-        );
2891
-        // convert to array and filter again
2892
-        // arrays are easier to inject new items in a specific location,
2893
-        // but would not be backwards compatible, so we have to add a new filter
2894
-        $this->_template_args['after_list_table']   = implode(
2895
-            " \n",
2896
-            (array) apply_filters(
2897
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2898
-                (array) $this->_template_args['after_list_table'],
2899
-                $this->page_slug,
2900
-                $this->request->requestParams(),
2901
-                $this->_req_action
2902
-            )
2903
-        );
2904
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2905
-            $template_path,
2906
-            $this->_template_args,
2907
-            true
2908
-        );
2909
-        // the final template wrapper
2910
-        if ($sidebar) {
2911
-            $this->display_admin_page_with_sidebar();
2912
-        } else {
2913
-            $this->display_admin_page_with_no_sidebar();
2914
-        }
2915
-    }
2916
-
2917
-
2918
-    /**
2919
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
2920
-     * html string for the legend.
2921
-     * $items are expected in an array in the following format:
2922
-     * $legend_items = array(
2923
-     *        'item_id' => array(
2924
-     *            'icon' => 'http://url_to_icon_being_described.png',
2925
-     *            'desc' => esc_html__('localized description of item');
2926
-     *        )
2927
-     * );
2928
-     *
2929
-     * @param array $items see above for format of array
2930
-     * @return string html string of legend
2931
-     * @throws DomainException
2932
-     */
2933
-    protected function _display_legend($items)
2934
-    {
2935
-        $this->_template_args['items'] = apply_filters(
2936
-            'FHEE__EE_Admin_Page___display_legend__items',
2937
-            (array) $items,
2938
-            $this
2939
-        );
2940
-        return EEH_Template::display_template(
2941
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
2942
-            $this->_template_args,
2943
-            true
2944
-        );
2945
-    }
2946
-
2947
-
2948
-    /**
2949
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2950
-     * The returned json object is created from an array in the following format:
2951
-     * array(
2952
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2953
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
2954
-     *  'notices' => '', // - contains any EE_Error formatted notices
2955
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2956
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
2957
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
2958
-     *  that might be included in here)
2959
-     * )
2960
-     * The json object is populated by whatever is set in the $_template_args property.
2961
-     *
2962
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
2963
-     *                                 instead of displayed.
2964
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
2965
-     * @return void
2966
-     * @throws EE_Error
2967
-     */
2968
-    protected function _return_json($sticky_notices = false, $notices_arguments = [])
2969
-    {
2970
-        // make sure any EE_Error notices have been handled.
2971
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
2972
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
2973
-        unset($this->_template_args['data']);
2974
-        $json = [
2975
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2976
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2977
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2978
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2979
-            'notices'   => EE_Error::get_notices(),
2980
-            'content'   => isset($this->_template_args['admin_page_content'])
2981
-                ? $this->_template_args['admin_page_content'] : '',
2982
-            'data'      => array_merge($data, ['template_args' => $this->_template_args]),
2983
-            'isEEajax'  => true
2984
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2985
-        ];
2986
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
2987
-        if (null === error_get_last() || ! headers_sent()) {
2988
-            header('Content-Type: application/json; charset=UTF-8');
2989
-        }
2990
-        echo wp_json_encode($json);
2991
-        exit();
2992
-    }
2993
-
2994
-
2995
-    /**
2996
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2997
-     *
2998
-     * @return void
2999
-     * @throws EE_Error
3000
-     */
3001
-    public function return_json()
3002
-    {
3003
-        if ($this->request->isAjax()) {
3004
-            $this->_return_json();
3005
-        } else {
3006
-            throw new EE_Error(
3007
-                sprintf(
3008
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3009
-                    __FUNCTION__
3010
-                )
3011
-            );
3012
-        }
3013
-    }
3014
-
3015
-
3016
-    /**
3017
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3018
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3019
-     *
3020
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3021
-     */
3022
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3023
-    {
3024
-        $this->_hook_obj = $hook_obj;
3025
-    }
3026
-
3027
-
3028
-    /**
3029
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3030
-     *
3031
-     * @param boolean $about whether to use the special about page wrapper or default.
3032
-     * @return void
3033
-     * @throws DomainException
3034
-     * @throws EE_Error
3035
-     */
3036
-    public function admin_page_wrapper($about = false)
3037
-    {
3038
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3039
-        $this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3040
-        $this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3041
-        $this->_template_args['admin_page_title']          = $this->_admin_page_title;
3042
-
3043
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3044
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3045
-            isset($this->_template_args['before_admin_page_content'])
3046
-                ? $this->_template_args['before_admin_page_content']
3047
-                : ''
3048
-        );
3049
-
3050
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3051
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3052
-            isset($this->_template_args['after_admin_page_content'])
3053
-                ? $this->_template_args['after_admin_page_content']
3054
-                : ''
3055
-        );
3056
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3057
-
3058
-        if ($this->request->isAjax()) {
3059
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3060
-                // $template_path,
3061
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3062
-                $this->_template_args,
3063
-                true
3064
-            );
3065
-            $this->_return_json();
3066
-        }
3067
-        // load settings page wrapper template
3068
-        $template_path = $about
3069
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3070
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3071
-
3072
-        EEH_Template::display_template($template_path, $this->_template_args);
3073
-    }
3074
-
3075
-
3076
-    /**
3077
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3078
-     *
3079
-     * @return string html
3080
-     * @throws EE_Error
3081
-     */
3082
-    protected function _get_main_nav_tabs()
3083
-    {
3084
-        // let's generate the html using the EEH_Tabbed_Content helper.
3085
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3086
-        // (rather than setting in the page_routes array)
3087
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3088
-    }
3089
-
3090
-
3091
-    /**
3092
-     *        sort nav tabs
3093
-     *
3094
-     * @param $a
3095
-     * @param $b
3096
-     * @return int
3097
-     */
3098
-    private function _sort_nav_tabs($a, $b)
3099
-    {
3100
-        if ($a['order'] === $b['order']) {
3101
-            return 0;
3102
-        }
3103
-        return ($a['order'] < $b['order']) ? -1 : 1;
3104
-    }
3105
-
3106
-
3107
-    /**
3108
-     *    generates HTML for the forms used on admin pages
3109
-     *
3110
-     * @param array  $input_vars   - array of input field details
3111
-     * @param string $generator    (options are 'string' or 'array', basically use this to indicate which generator to
3112
-     *                             use)
3113
-     * @param bool   $id
3114
-     * @return array|string
3115
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3116
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3117
-     */
3118
-    protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3119
-    {
3120
-        return $generator === 'string'
3121
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3122
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3123
-    }
3124
-
3125
-
3126
-    /**
3127
-     * generates the "Save" and "Save & Close" buttons for edit forms
3128
-     *
3129
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3130
-     *                                   Close" button.
3131
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3132
-     *                                   'Save', [1] => 'save & close')
3133
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3134
-     *                                   via the "name" value in the button).  We can also use this to just dump
3135
-     *                                   default actions by submitting some other value.
3136
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3137
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3138
-     *                                   close (normal form handling).
3139
-     */
3140
-    protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3141
-    {
3142
-        // make sure $text and $actions are in an array
3143
-        $text          = (array) $text;
3144
-        $actions       = (array) $actions;
3145
-        $referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3146
-        $button_text   = ! empty($text)
3147
-            ? $text
3148
-            : [
3149
-                esc_html__('Save', 'event_espresso'),
3150
-                esc_html__('Save and Close', 'event_espresso'),
3151
-            ];
3152
-        $default_names = ['save', 'save_and_close'];
3153
-        $buttons = '';
3154
-        foreach ($button_text as $key => $button) {
3155
-            $ref     = $default_names[ $key ];
3156
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3157
-            $buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3158
-                        . 'value="' . $button . '" name="' . $name . '" '
3159
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3160
-            if (! $both) {
3161
-                break;
3162
-            }
3163
-        }
3164
-        // add in a hidden index for the current page (so save and close redirects properly)
3165
-        $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3166
-                   . $referrer_url
3167
-                   . '" />';
3168
-        $this->_template_args['save_buttons'] = $buttons;
3169
-    }
3170
-
3171
-
3172
-    /**
3173
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3174
-     *
3175
-     * @param string $route
3176
-     * @param array  $additional_hidden_fields
3177
-     * @see   $this->_set_add_edit_form_tags() for details on params
3178
-     * @since 4.6.0
3179
-     */
3180
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3181
-    {
3182
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3183
-    }
3184
-
3185
-
3186
-    /**
3187
-     * set form open and close tags on add/edit pages.
3188
-     *
3189
-     * @param string $route                    the route you want the form to direct to
3190
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3191
-     * @return void
3192
-     */
3193
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3194
-    {
3195
-        if (empty($route)) {
3196
-            $user_msg = esc_html__(
3197
-                'An error occurred. No action was set for this page\'s form.',
3198
-                'event_espresso'
3199
-            );
3200
-            $dev_msg  = $user_msg . "\n"
3201
-                        . sprintf(
3202
-                            esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3203
-                            __FUNCTION__,
3204
-                            __CLASS__
3205
-                        );
3206
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3207
-        }
3208
-        // open form
3209
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3210
-                                                             . $this->_admin_base_url
3211
-                                                             . '" id="'
3212
-                                                             . $route
3213
-                                                             . '_event_form" >';
3214
-        // add nonce
3215
-        $nonce                                             =
3216
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3217
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3218
-        // add REQUIRED form action
3219
-        $hidden_fields = [
3220
-            'action' => ['type' => 'hidden', 'value' => $route],
3221
-        ];
3222
-        // merge arrays
3223
-        $hidden_fields = is_array($additional_hidden_fields)
3224
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3225
-            : $hidden_fields;
3226
-        // generate form fields
3227
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3228
-        // add fields to form
3229
-        foreach ((array) $form_fields as $form_field) {
3230
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3231
-        }
3232
-        // close form
3233
-        $this->_template_args['after_admin_page_content'] = '</form>';
3234
-    }
3235
-
3236
-
3237
-    /**
3238
-     * Public Wrapper for _redirect_after_action() method since its
3239
-     * discovered it would be useful for external code to have access.
3240
-     *
3241
-     * @param bool   $success
3242
-     * @param string $what
3243
-     * @param string $action_desc
3244
-     * @param array  $query_args
3245
-     * @param bool   $override_overwrite
3246
-     * @throws EE_Error
3247
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3248
-     * @since 4.5.0
3249
-     */
3250
-    public function redirect_after_action(
3251
-        $success = false,
3252
-        $what = 'item',
3253
-        $action_desc = 'processed',
3254
-        $query_args = [],
3255
-        $override_overwrite = false
3256
-    ) {
3257
-        $this->_redirect_after_action(
3258
-            $success,
3259
-            $what,
3260
-            $action_desc,
3261
-            $query_args,
3262
-            $override_overwrite
3263
-        );
3264
-    }
3265
-
3266
-
3267
-    /**
3268
-     * Helper method for merging existing request data with the returned redirect url.
3269
-     *
3270
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3271
-     * filters are still applied.
3272
-     *
3273
-     * @param array $new_route_data
3274
-     * @return array
3275
-     */
3276
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3277
-    {
3278
-        foreach ($this->request->requestParams() as $ref => $value) {
3279
-            // unset nonces
3280
-            if (strpos($ref, 'nonce') !== false) {
3281
-                $this->request->unSetRequestParam($ref);
3282
-                continue;
3283
-            }
3284
-            // urlencode values.
3285
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3286
-            $this->request->setRequestParam($ref, $value);
3287
-        }
3288
-        return array_merge($this->request->requestParams(), $new_route_data);
3289
-    }
3290
-
3291
-
3292
-    /**
3293
-     *    _redirect_after_action
3294
-     *
3295
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3296
-     * @param string $what               - what the action was performed on
3297
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3298
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3299
-     *                                   action is completed
3300
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3301
-     *                                   override this so that they show.
3302
-     * @return void
3303
-     * @throws EE_Error
3304
-     */
3305
-    protected function _redirect_after_action(
3306
-        $success = 0,
3307
-        $what = 'item',
3308
-        $action_desc = 'processed',
3309
-        $query_args = [],
3310
-        $override_overwrite = false
3311
-    ) {
3312
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3313
-        // class name for actions/filters.
3314
-        $classname = get_class($this);
3315
-        // set redirect url.
3316
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3317
-        // otherwise we go with whatever is set as the _admin_base_url
3318
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3319
-        $notices      = EE_Error::get_notices(false);
3320
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3321
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3322
-            EE_Error::overwrite_success();
3323
-        }
3324
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3325
-            // how many records affected ? more than one record ? or just one ?
3326
-            if ($success > 1) {
3327
-                // set plural msg
3328
-                EE_Error::add_success(
3329
-                    sprintf(
3330
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3331
-                        $what,
3332
-                        $action_desc
3333
-                    ),
3334
-                    __FILE__,
3335
-                    __FUNCTION__,
3336
-                    __LINE__
3337
-                );
3338
-            } elseif ($success === 1) {
3339
-                // set singular msg
3340
-                EE_Error::add_success(
3341
-                    sprintf(
3342
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3343
-                        $what,
3344
-                        $action_desc
3345
-                    ),
3346
-                    __FILE__,
3347
-                    __FUNCTION__,
3348
-                    __LINE__
3349
-                );
3350
-            }
3351
-        }
3352
-        // check that $query_args isn't something crazy
3353
-        if (! is_array($query_args)) {
3354
-            $query_args = [];
3355
-        }
3356
-        /**
3357
-         * Allow injecting actions before the query_args are modified for possible different
3358
-         * redirections on save and close actions
3359
-         *
3360
-         * @param array $query_args       The original query_args array coming into the
3361
-         *                                method.
3362
-         * @since 4.2.0
3363
-         */
3364
-        do_action(
3365
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3366
-            $query_args
3367
-        );
3368
-        // calculate where we're going (if we have a "save and close" button pushed)
3369
-
3370
-        if (
3371
-            $this->request->requestParamIsSet('save_and_close')
3372
-            && $this->request->requestParamIsSet('save_and_close_referrer')
3373
-        ) {
3374
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3375
-            $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3376
-            // regenerate query args array from referrer URL
3377
-            parse_str($parsed_url['query'], $query_args);
3378
-            // correct page and action will be in the query args now
3379
-            $redirect_url = admin_url('admin.php');
3380
-        }
3381
-        // merge any default query_args set in _default_route_query_args property
3382
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3383
-            $args_to_merge = [];
3384
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3385
-                // is there a wp_referer array in our _default_route_query_args property?
3386
-                if ($query_param === 'wp_referer') {
3387
-                    $query_value = (array) $query_value;
3388
-                    foreach ($query_value as $reference => $value) {
3389
-                        if (strpos($reference, 'nonce') !== false) {
3390
-                            continue;
3391
-                        }
3392
-                        // finally we will override any arguments in the referer with
3393
-                        // what might be set on the _default_route_query_args array.
3394
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3395
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3396
-                        } else {
3397
-                            $args_to_merge[ $reference ] = urlencode($value);
3398
-                        }
3399
-                    }
3400
-                    continue;
3401
-                }
3402
-                $args_to_merge[ $query_param ] = $query_value;
3403
-            }
3404
-            // now let's merge these arguments but override with what was specifically sent in to the
3405
-            // redirect.
3406
-            $query_args = array_merge($args_to_merge, $query_args);
3407
-        }
3408
-        $this->_process_notices($query_args);
3409
-        // generate redirect url
3410
-        // if redirecting to anything other than the main page, add a nonce
3411
-        if (isset($query_args['action'])) {
3412
-            // manually generate wp_nonce and merge that with the query vars
3413
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3414
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3415
-        }
3416
-        // we're adding some hooks and filters in here for processing any things just before redirects
3417
-        // (example: an admin page has done an insert or update and we want to run something after that).
3418
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3419
-        $redirect_url = apply_filters(
3420
-            'FHEE_redirect_' . $classname . $this->_req_action,
3421
-            self::add_query_args_and_nonce($query_args, $redirect_url),
3422
-            $query_args
3423
-        );
3424
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3425
-        if ($this->request->isAjax()) {
3426
-            $default_data                    = [
3427
-                'close'        => true,
3428
-                'redirect_url' => $redirect_url,
3429
-                'where'        => 'main',
3430
-                'what'         => 'append',
3431
-            ];
3432
-            $this->_template_args['success'] = $success;
3433
-            $this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3434
-                $default_data,
3435
-                $this->_template_args['data']
3436
-            ) : $default_data;
3437
-            $this->_return_json();
3438
-        }
3439
-        wp_safe_redirect($redirect_url);
3440
-        exit();
3441
-    }
3442
-
3443
-
3444
-    /**
3445
-     * process any notices before redirecting (or returning ajax request)
3446
-     * This method sets the $this->_template_args['notices'] attribute;
3447
-     *
3448
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3449
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3450
-     *                                  page_routes haven't been defined yet.
3451
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3452
-     *                                  still save a transient for the notice.
3453
-     * @return void
3454
-     * @throws EE_Error
3455
-     */
3456
-    protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3457
-    {
3458
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3459
-        if ($this->request->isAjax()) {
3460
-            $notices = EE_Error::get_notices(false);
3461
-            if (empty($this->_template_args['success'])) {
3462
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3463
-            }
3464
-            if (empty($this->_template_args['errors'])) {
3465
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3466
-            }
3467
-            if (empty($this->_template_args['attention'])) {
3468
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3469
-            }
3470
-        }
3471
-        $this->_template_args['notices'] = EE_Error::get_notices();
3472
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3473
-        if (! $this->request->isAjax() || $sticky_notices) {
3474
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3475
-            $this->_add_transient(
3476
-                $route,
3477
-                $this->_template_args['notices'],
3478
-                true,
3479
-                $skip_route_verify
3480
-            );
3481
-        }
3482
-    }
3483
-
3484
-
3485
-    /**
3486
-     * get_action_link_or_button
3487
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3488
-     *
3489
-     * @param string $action        use this to indicate which action the url is generated with.
3490
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3491
-     *                              property.
3492
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3493
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3494
-     * @param string $base_url      If this is not provided
3495
-     *                              the _admin_base_url will be used as the default for the button base_url.
3496
-     *                              Otherwise this value will be used.
3497
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3498
-     * @return string
3499
-     * @throws InvalidArgumentException
3500
-     * @throws InvalidInterfaceException
3501
-     * @throws InvalidDataTypeException
3502
-     * @throws EE_Error
3503
-     */
3504
-    public function get_action_link_or_button(
3505
-        $action,
3506
-        $type = 'add',
3507
-        $extra_request = [],
3508
-        $class = 'button-primary',
3509
-        $base_url = '',
3510
-        $exclude_nonce = false
3511
-    ) {
3512
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3513
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3514
-            throw new EE_Error(
3515
-                sprintf(
3516
-                    esc_html__(
3517
-                        'There is no page route for given action for the button.  This action was given: %s',
3518
-                        'event_espresso'
3519
-                    ),
3520
-                    $action
3521
-                )
3522
-            );
3523
-        }
3524
-        if (! isset($this->_labels['buttons'][ $type ])) {
3525
-            throw new EE_Error(
3526
-                sprintf(
3527
-                    esc_html__(
3528
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3529
-                        'event_espresso'
3530
-                    ),
3531
-                    $type
3532
-                )
3533
-            );
3534
-        }
3535
-        // finally check user access for this button.
3536
-        $has_access = $this->check_user_access($action, true);
3537
-        if (! $has_access) {
3538
-            return '';
3539
-        }
3540
-        $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3541
-        $query_args = [
3542
-            'action' => $action,
3543
-        ];
3544
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3545
-        if (! empty($extra_request)) {
3546
-            $query_args = array_merge($extra_request, $query_args);
3547
-        }
3548
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3549
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3550
-    }
3551
-
3552
-
3553
-    /**
3554
-     * _per_page_screen_option
3555
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3556
-     *
3557
-     * @return void
3558
-     * @throws InvalidArgumentException
3559
-     * @throws InvalidInterfaceException
3560
-     * @throws InvalidDataTypeException
3561
-     */
3562
-    protected function _per_page_screen_option()
3563
-    {
3564
-        $option = 'per_page';
3565
-        $args   = [
3566
-            'label'   => apply_filters(
3567
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3568
-                $this->_admin_page_title,
3569
-                $this
3570
-            ),
3571
-            'default' => (int) apply_filters(
3572
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3573
-                20
3574
-            ),
3575
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3576
-        ];
3577
-        // ONLY add the screen option if the user has access to it.
3578
-        if ($this->check_user_access($this->_current_view, true)) {
3579
-            add_screen_option($option, $args);
3580
-        }
3581
-    }
3582
-
3583
-
3584
-    /**
3585
-     * set_per_page_screen_option
3586
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3587
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3588
-     * admin_menu.
3589
-     *
3590
-     * @return void
3591
-     */
3592
-    private function _set_per_page_screen_options()
3593
-    {
3594
-        if ($this->request->requestParamIsSet('wp_screen_options')) {
3595
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3596
-            if (! $user = wp_get_current_user()) {
3597
-                return;
3598
-            }
3599
-            $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3600
-            if (! $option) {
3601
-                return;
3602
-            }
3603
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3604
-            $map_option = $option;
3605
-            $option     = str_replace('-', '_', $option);
3606
-            switch ($map_option) {
3607
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3608
-                    $max_value = apply_filters(
3609
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3610
-                        999,
3611
-                        $this->_current_page,
3612
-                        $this->_current_view
3613
-                    );
3614
-                    if ($value < 1) {
3615
-                        return;
3616
-                    }
3617
-                    $value = min($value, $max_value);
3618
-                    break;
3619
-                default:
3620
-                    $value = apply_filters(
3621
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3622
-                        false,
3623
-                        $option,
3624
-                        $value
3625
-                    );
3626
-                    if (false === $value) {
3627
-                        return;
3628
-                    }
3629
-                    break;
3630
-            }
3631
-            update_user_meta($user->ID, $option, $value);
3632
-            wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3633
-            exit;
3634
-        }
3635
-    }
3636
-
3637
-
3638
-    /**
3639
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3640
-     *
3641
-     * @param array $data array that will be assigned to template args.
3642
-     */
3643
-    public function set_template_args($data)
3644
-    {
3645
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3646
-    }
3647
-
3648
-
3649
-    /**
3650
-     * This makes available the WP transient system for temporarily moving data between routes
3651
-     *
3652
-     * @param string $route             the route that should receive the transient
3653
-     * @param array  $data              the data that gets sent
3654
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3655
-     *                                  normal route transient.
3656
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3657
-     *                                  when we are adding a transient before page_routes have been defined.
3658
-     * @return void
3659
-     * @throws EE_Error
3660
-     */
3661
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3662
-    {
3663
-        $user_id = get_current_user_id();
3664
-        if (! $skip_route_verify) {
3665
-            $this->_verify_route($route);
3666
-        }
3667
-        // now let's set the string for what kind of transient we're setting
3668
-        $transient = $notices
3669
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3670
-            : 'rte_tx_' . $route . '_' . $user_id;
3671
-        $data      = $notices ? ['notices' => $data] : $data;
3672
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3673
-        $existing = is_multisite() && is_network_admin()
3674
-            ? get_site_transient($transient)
3675
-            : get_transient($transient);
3676
-        if ($existing) {
3677
-            $data = array_merge((array) $data, (array) $existing);
3678
-        }
3679
-        if (is_multisite() && is_network_admin()) {
3680
-            set_site_transient($transient, $data, 8);
3681
-        } else {
3682
-            set_transient($transient, $data, 8);
3683
-        }
3684
-    }
3685
-
3686
-
3687
-    /**
3688
-     * this retrieves the temporary transient that has been set for moving data between routes.
3689
-     *
3690
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3691
-     * @param string $route
3692
-     * @return mixed data
3693
-     */
3694
-    protected function _get_transient($notices = false, $route = '')
3695
-    {
3696
-        $user_id   = get_current_user_id();
3697
-        $route     = ! $route ? $this->_req_action : $route;
3698
-        $transient = $notices
3699
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3700
-            : 'rte_tx_' . $route . '_' . $user_id;
3701
-        $data      = is_multisite() && is_network_admin()
3702
-            ? get_site_transient($transient)
3703
-            : get_transient($transient);
3704
-        // delete transient after retrieval (just in case it hasn't expired);
3705
-        if (is_multisite() && is_network_admin()) {
3706
-            delete_site_transient($transient);
3707
-        } else {
3708
-            delete_transient($transient);
3709
-        }
3710
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3711
-    }
3712
-
3713
-
3714
-    /**
3715
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3716
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3717
-     * default route callback on the EE_Admin page you want it run.)
3718
-     *
3719
-     * @return void
3720
-     */
3721
-    protected function _transient_garbage_collection()
3722
-    {
3723
-        global $wpdb;
3724
-        // retrieve all existing transients
3725
-        $query =
3726
-            "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3727
-        if ($results = $wpdb->get_results($query)) {
3728
-            foreach ($results as $result) {
3729
-                $transient = str_replace('_transient_', '', $result->option_name);
3730
-                get_transient($transient);
3731
-                if (is_multisite() && is_network_admin()) {
3732
-                    get_site_transient($transient);
3733
-                }
3734
-            }
3735
-        }
3736
-    }
3737
-
3738
-
3739
-    /**
3740
-     * get_view
3741
-     *
3742
-     * @return string content of _view property
3743
-     */
3744
-    public function get_view()
3745
-    {
3746
-        return $this->_view;
3747
-    }
3748
-
3749
-
3750
-    /**
3751
-     * getter for the protected $_views property
3752
-     *
3753
-     * @return array
3754
-     */
3755
-    public function get_views()
3756
-    {
3757
-        return $this->_views;
3758
-    }
3759
-
3760
-
3761
-    /**
3762
-     * get_current_page
3763
-     *
3764
-     * @return string _current_page property value
3765
-     */
3766
-    public function get_current_page()
3767
-    {
3768
-        return $this->_current_page;
3769
-    }
3770
-
3771
-
3772
-    /**
3773
-     * get_current_view
3774
-     *
3775
-     * @return string _current_view property value
3776
-     */
3777
-    public function get_current_view()
3778
-    {
3779
-        return $this->_current_view;
3780
-    }
3781
-
3782
-
3783
-    /**
3784
-     * get_current_screen
3785
-     *
3786
-     * @return object The current WP_Screen object
3787
-     */
3788
-    public function get_current_screen()
3789
-    {
3790
-        return $this->_current_screen;
3791
-    }
3792
-
3793
-
3794
-    /**
3795
-     * get_current_page_view_url
3796
-     *
3797
-     * @return string This returns the url for the current_page_view.
3798
-     */
3799
-    public function get_current_page_view_url()
3800
-    {
3801
-        return $this->_current_page_view_url;
3802
-    }
3803
-
3804
-
3805
-    /**
3806
-     * just returns the Request
3807
-     *
3808
-     * @return RequestInterface
3809
-     */
3810
-    public function get_request()
3811
-    {
3812
-        return $this->request;
3813
-    }
3814
-
3815
-
3816
-    /**
3817
-     * just returns the _req_data property
3818
-     *
3819
-     * @return array
3820
-     */
3821
-    public function get_request_data()
3822
-    {
3823
-        return $this->request->requestParams();
3824
-    }
3825
-
3826
-
3827
-    /**
3828
-     * returns the _req_data protected property
3829
-     *
3830
-     * @return string
3831
-     */
3832
-    public function get_req_action()
3833
-    {
3834
-        return $this->_req_action;
3835
-    }
3836
-
3837
-
3838
-    /**
3839
-     * @return bool  value of $_is_caf property
3840
-     */
3841
-    public function is_caf()
3842
-    {
3843
-        return $this->_is_caf;
3844
-    }
3845
-
3846
-
3847
-    /**
3848
-     * @return mixed
3849
-     */
3850
-    public function default_espresso_metaboxes()
3851
-    {
3852
-        return $this->_default_espresso_metaboxes;
3853
-    }
3854
-
3855
-
3856
-    /**
3857
-     * @return mixed
3858
-     */
3859
-    public function admin_base_url()
3860
-    {
3861
-        return $this->_admin_base_url;
3862
-    }
3863
-
3864
-
3865
-    /**
3866
-     * @return mixed
3867
-     */
3868
-    public function wp_page_slug()
3869
-    {
3870
-        return $this->_wp_page_slug;
3871
-    }
3872
-
3873
-
3874
-    /**
3875
-     * updates  espresso configuration settings
3876
-     *
3877
-     * @param string                   $tab
3878
-     * @param EE_Config_Base|EE_Config $config
3879
-     * @param string                   $file file where error occurred
3880
-     * @param string                   $func function  where error occurred
3881
-     * @param string                   $line line no where error occurred
3882
-     * @return boolean
3883
-     */
3884
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3885
-    {
3886
-        // remove any options that are NOT going to be saved with the config settings.
3887
-        if (isset($config->core->ee_ueip_optin)) {
3888
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3889
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3890
-            update_option('ee_ueip_has_notified', true);
3891
-        }
3892
-        // and save it (note we're also doing the network save here)
3893
-        $net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3894
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3895
-        if ($config_saved && $net_saved) {
3896
-            EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3897
-            return true;
3898
-        }
3899
-        EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3900
-        return false;
3901
-    }
3902
-
3903
-
3904
-    /**
3905
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3906
-     *
3907
-     * @return array
3908
-     */
3909
-    public function get_yes_no_values()
3910
-    {
3911
-        return $this->_yes_no_values;
3912
-    }
3913
-
3914
-
3915
-    protected function _get_dir()
3916
-    {
3917
-        $reflector = new ReflectionClass(get_class($this));
3918
-        return dirname($reflector->getFileName());
3919
-    }
3920
-
3921
-
3922
-    /**
3923
-     * A helper for getting a "next link".
3924
-     *
3925
-     * @param string $url   The url to link to
3926
-     * @param string $class The class to use.
3927
-     * @return string
3928
-     */
3929
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3930
-    {
3931
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3932
-    }
3933
-
3934
-
3935
-    /**
3936
-     * A helper for getting a "previous link".
3937
-     *
3938
-     * @param string $url   The url to link to
3939
-     * @param string $class The class to use.
3940
-     * @return string
3941
-     */
3942
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3943
-    {
3944
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3945
-    }
3946
-
3947
-
3948
-
3949
-
3950
-
3951
-
3952
-
3953
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3954
-
3955
-
3956
-    /**
3957
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
3958
-     * 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
3959
-     * _req_data array.
3960
-     *
3961
-     * @return bool success/fail
3962
-     * @throws EE_Error
3963
-     * @throws InvalidArgumentException
3964
-     * @throws ReflectionException
3965
-     * @throws InvalidDataTypeException
3966
-     * @throws InvalidInterfaceException
3967
-     */
3968
-    protected function _process_resend_registration()
3969
-    {
3970
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3971
-        do_action(
3972
-            'AHEE__EE_Admin_Page___process_resend_registration',
3973
-            $this->_template_args['success'],
3974
-            $this->request->requestParams()
3975
-        );
3976
-        return $this->_template_args['success'];
3977
-    }
3978
-
3979
-
3980
-    /**
3981
-     * This automatically processes any payment message notifications when manual payment has been applied.
3982
-     *
3983
-     * @param EE_Payment $payment
3984
-     * @return bool success/fail
3985
-     */
3986
-    protected function _process_payment_notification(EE_Payment $payment)
3987
-    {
3988
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3989
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3990
-        $this->_template_args['success'] = apply_filters(
3991
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
3992
-            false,
3993
-            $payment
3994
-        );
3995
-        return $this->_template_args['success'];
3996
-    }
3997
-
3998
-
3999
-    /**
4000
-     * @param EEM_Base      $entity_model
4001
-     * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4002
-     * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4003
-     * @param string        $delete_column  name of the field that denotes whether entity is trashed
4004
-     * @param callable|null $callback       called after entity is trashed, restored, or deleted
4005
-     * @return int|float
4006
-     * @throws EE_Error
4007
-     */
4008
-    protected function trashRestoreDeleteEntities(
4009
-        EEM_Base $entity_model,
4010
-        string $entity_PK_name,
4011
-        string $action = EE_Admin_List_Table::ACTION_DELETE,
4012
-        string $delete_column = '',
4013
-        callable $callback = null
4014
-    ) {
4015
-        $entity_PK      = $entity_model->get_primary_key_field();
4016
-        $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4017
-        $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4018
-        // grab ID if deleting a single entity
4019
-        if ($this->request->requestParamIsSet($entity_PK_name)) {
4020
-            $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4021
-            return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4022
-        }
4023
-        // or grab checkbox array if bulk deleting
4024
-        $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4025
-        if (empty($checkboxes)) {
4026
-            return 0;
4027
-        }
4028
-        $success = 0;
4029
-        $IDs     = array_keys($checkboxes);
4030
-        // cycle thru bulk action checkboxes
4031
-        foreach ($IDs as $ID) {
4032
-            // increment $success
4033
-            if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4034
-                $success++;
4035
-            }
4036
-        }
4037
-        $count = (int) count($checkboxes);
4038
-        // if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4039
-        // otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4040
-        return $success === $count ? $count : $success / $count;
4041
-    }
4042
-
4043
-
4044
-    /**
4045
-     * @param EE_Primary_Key_Field_Base $entity_PK
4046
-     * @return string
4047
-     * @throws EE_Error
4048
-     * @since   4.10.30.p
4049
-     */
4050
-    private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string
4051
-    {
4052
-        $entity_PK_type = $entity_PK->getSchemaType();
4053
-        switch ($entity_PK_type) {
4054
-            case 'boolean':
4055
-                return 'bool';
4056
-            case 'integer':
4057
-                return 'int';
4058
-            case 'number':
4059
-                return 'float';
4060
-            case 'string':
4061
-                return 'string';
4062
-        }
4063
-        throw new RuntimeException(
4064
-            sprintf(
4065
-                esc_html__(
4066
-                    '"%1$s" is an invalid schema type for the %2$s primary key.',
4067
-                    'event_espresso'
4068
-                ),
4069
-                $entity_PK_type,
4070
-                $entity_PK->get_name()
4071
-            )
4072
-        );
4073
-    }
4074
-
4075
-
4076
-    /**
4077
-     * @param EEM_Base      $entity_model
4078
-     * @param int|string    $entity_ID
4079
-     * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4080
-     * @param string        $delete_column name of the field that denotes whether entity is trashed
4081
-     * @param callable|null $callback      called after entity is trashed, restored, or deleted
4082
-     * @return bool
4083
-     */
4084
-    protected function trashRestoreDeleteEntity(
4085
-        EEM_Base $entity_model,
4086
-        $entity_ID,
4087
-        string $action,
4088
-        string $delete_column,
4089
-        callable $callback = null
4090
-    ) {
4091
-        $entity_ID = absint($entity_ID);
4092
-        if (! $entity_ID) {
4093
-            $this->trashRestoreDeleteError($action, $entity_model);
4094
-        }
4095
-        $result = 0;
4096
-        try {
4097
-            switch ($action) {
4098
-                case EE_Admin_List_Table::ACTION_DELETE:
4099
-                    $result = (bool) $entity_model->delete_permanently_by_ID($entity_ID);
4100
-                    break;
4101
-                case EE_Admin_List_Table::ACTION_RESTORE:
4102
-                    $this->validateDeleteColumn($entity_model, $delete_column);
4103
-                    $result = $entity_model->update_by_ID([$delete_column => 0], $entity_ID);
4104
-                    break;
4105
-                case EE_Admin_List_Table::ACTION_TRASH:
4106
-                    $this->validateDeleteColumn($entity_model, $delete_column);
4107
-                    $result = $entity_model->update_by_ID([$delete_column => 1], $entity_ID);
4108
-                    break;
4109
-            }
4110
-        } catch (Exception $exception) {
4111
-            $this->trashRestoreDeleteError($action, $entity_model, $exception);
4112
-        }
4113
-        if (is_callable($callback)) {
4114
-            call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4115
-        }
4116
-        return $result;
4117
-    }
4118
-
4119
-
4120
-    /**
4121
-     * @param EEM_Base $entity_model
4122
-     * @param string   $delete_column
4123
-     * @since 4.10.30.p
4124
-     */
4125
-    private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column)
4126
-    {
4127
-        if (empty($delete_column)) {
4128
-            throw new DomainException(
4129
-                sprintf(
4130
-                    esc_html__(
4131
-                        'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4132
-                        'event_espresso'
4133
-                    ),
4134
-                    $entity_model->get_this_model_name()
4135
-                )
4136
-            );
4137
-        }
4138
-        if (! $entity_model->has_field($delete_column)) {
4139
-            throw new DomainException(
4140
-                sprintf(
4141
-                    esc_html__(
4142
-                        'The %1$s field does not exist on the %2$s model.',
4143
-                        'event_espresso'
4144
-                    ),
4145
-                    $delete_column,
4146
-                    $entity_model->get_this_model_name()
4147
-                )
4148
-            );
4149
-        }
4150
-    }
4151
-
4152
-
4153
-    /**
4154
-     * @param EEM_Base       $entity_model
4155
-     * @param Exception|null $exception
4156
-     * @param string         $action
4157
-     * @since 4.10.30.p
4158
-     */
4159
-    private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, ?Exception $exception = null)
4160
-    {
4161
-        if ($exception instanceof Exception) {
4162
-            throw new RuntimeException(
4163
-                sprintf(
4164
-                    esc_html__(
4165
-                        'Could not %1$s the %2$s because the following error occurred: %3$s',
4166
-                        'event_espresso'
4167
-                    ),
4168
-                    $action,
4169
-                    $entity_model->get_this_model_name(),
4170
-                    $exception->getMessage()
4171
-                )
4172
-            );
4173
-        }
4174
-        throw new RuntimeException(
4175
-            sprintf(
4176
-                esc_html__(
4177
-                    'Could not %1$s the %2$s because an invalid ID was received.',
4178
-                    'event_espresso'
4179
-                ),
4180
-                $action,
4181
-                $entity_model->get_this_model_name()
4182
-            )
4183
-        );
4184
-    }
2564
+	}
2565
+
2566
+
2567
+	/**
2568
+	 * facade for add_meta_box
2569
+	 *
2570
+	 * @param string  $action        where the metabox gets displayed
2571
+	 * @param string  $title         Title of Metabox (output in metabox header)
2572
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2573
+	 *                               instead of the one created in here.
2574
+	 * @param array   $callback_args an array of args supplied for the metabox
2575
+	 * @param string  $column        what metabox column
2576
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2577
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2578
+	 *                               created but just set our own callback for wp's add_meta_box.
2579
+	 * @throws DomainException
2580
+	 */
2581
+	public function _add_admin_page_meta_box(
2582
+		$action,
2583
+		$title,
2584
+		$callback,
2585
+		$callback_args,
2586
+		$column = 'normal',
2587
+		$priority = 'high',
2588
+		$create_func = true
2589
+	) {
2590
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2591
+		// if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2592
+		if (empty($callback_args) && $create_func) {
2593
+			$callback_args = [
2594
+				'template_path' => $this->_template_path,
2595
+				'template_args' => $this->_template_args,
2596
+			];
2597
+		}
2598
+		// if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2599
+		$call_back_func = $create_func
2600
+			? function ($post, $metabox) {
2601
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2602
+				echo EEH_Template::display_template(
2603
+					$metabox['args']['template_path'],
2604
+					$metabox['args']['template_args'],
2605
+					true
2606
+				);
2607
+			}
2608
+			: $callback;
2609
+		add_meta_box(
2610
+			str_replace('_', '-', $action) . '-mbox',
2611
+			$title,
2612
+			$call_back_func,
2613
+			$this->_wp_page_slug,
2614
+			$column,
2615
+			$priority,
2616
+			$callback_args
2617
+		);
2618
+	}
2619
+
2620
+
2621
+	/**
2622
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2623
+	 *
2624
+	 * @throws DomainException
2625
+	 * @throws EE_Error
2626
+	 */
2627
+	public function display_admin_page_with_metabox_columns()
2628
+	{
2629
+		$this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2630
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2631
+			$this->_column_template_path,
2632
+			$this->_template_args,
2633
+			true
2634
+		);
2635
+		// the final wrapper
2636
+		$this->admin_page_wrapper();
2637
+	}
2638
+
2639
+
2640
+	/**
2641
+	 * generates  HTML wrapper for an admin details page
2642
+	 *
2643
+	 * @return void
2644
+	 * @throws EE_Error
2645
+	 * @throws DomainException
2646
+	 */
2647
+	public function display_admin_page_with_sidebar()
2648
+	{
2649
+		$this->_display_admin_page(true);
2650
+	}
2651
+
2652
+
2653
+	/**
2654
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2655
+	 *
2656
+	 * @return void
2657
+	 * @throws EE_Error
2658
+	 * @throws DomainException
2659
+	 */
2660
+	public function display_admin_page_with_no_sidebar()
2661
+	{
2662
+		$this->_display_admin_page();
2663
+	}
2664
+
2665
+
2666
+	/**
2667
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2668
+	 *
2669
+	 * @return void
2670
+	 * @throws EE_Error
2671
+	 * @throws DomainException
2672
+	 */
2673
+	public function display_about_admin_page()
2674
+	{
2675
+		$this->_display_admin_page(false, true);
2676
+	}
2677
+
2678
+
2679
+	/**
2680
+	 * display_admin_page
2681
+	 * contains the code for actually displaying an admin page
2682
+	 *
2683
+	 * @param boolean $sidebar true with sidebar, false without
2684
+	 * @param boolean $about   use the about_admin_wrapper instead of the default.
2685
+	 * @return void
2686
+	 * @throws DomainException
2687
+	 * @throws EE_Error
2688
+	 */
2689
+	private function _display_admin_page($sidebar = false, $about = false)
2690
+	{
2691
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2692
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2693
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2694
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2695
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2696
+		$this->_template_args['current_page']              = $this->_wp_page_slug;
2697
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2698
+			? 'poststuff'
2699
+			: 'espresso-default-admin';
2700
+		$template_path                                     = $sidebar
2701
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2702
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2703
+		if ($this->request->isAjax()) {
2704
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2705
+		}
2706
+		$template_path                                     = ! empty($this->_column_template_path)
2707
+			? $this->_column_template_path : $template_path;
2708
+		$this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2709
+			? $this->_template_args['admin_page_content']
2710
+			: '';
2711
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2712
+			? $this->_template_args['before_admin_page_content']
2713
+			: '';
2714
+		$this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2715
+			? $this->_template_args['after_admin_page_content']
2716
+			: '';
2717
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
2718
+			$template_path,
2719
+			$this->_template_args,
2720
+			true
2721
+		);
2722
+		// the final template wrapper
2723
+		$this->admin_page_wrapper($about);
2724
+	}
2725
+
2726
+
2727
+	/**
2728
+	 * This is used to display caf preview pages.
2729
+	 *
2730
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2731
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2732
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2733
+	 * @return void
2734
+	 * @throws DomainException
2735
+	 * @throws EE_Error
2736
+	 * @throws InvalidArgumentException
2737
+	 * @throws InvalidDataTypeException
2738
+	 * @throws InvalidInterfaceException
2739
+	 * @since 4.3.2
2740
+	 */
2741
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2742
+	{
2743
+		// let's generate a default preview action button if there isn't one already present.
2744
+		$this->_labels['buttons']['buy_now']           = esc_html__(
2745
+			'Upgrade to Event Espresso 4 Right Now',
2746
+			'event_espresso'
2747
+		);
2748
+		$buy_now_url                                   = add_query_arg(
2749
+			[
2750
+				'ee_ver'       => 'ee4',
2751
+				'utm_source'   => 'ee4_plugin_admin',
2752
+				'utm_medium'   => 'link',
2753
+				'utm_campaign' => $utm_campaign_source,
2754
+				'utm_content'  => 'buy_now_button',
2755
+			],
2756
+			'https://eventespresso.com/pricing/'
2757
+		);
2758
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2759
+			? $this->get_action_link_or_button(
2760
+				'',
2761
+				'buy_now',
2762
+				[],
2763
+				'button-primary button-large',
2764
+				esc_url_raw($buy_now_url),
2765
+				true
2766
+			)
2767
+			: $this->_template_args['preview_action_button'];
2768
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
2769
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2770
+			$this->_template_args,
2771
+			true
2772
+		);
2773
+		$this->_display_admin_page($display_sidebar);
2774
+	}
2775
+
2776
+
2777
+	/**
2778
+	 * display_admin_list_table_page_with_sidebar
2779
+	 * generates HTML wrapper for an admin_page with list_table
2780
+	 *
2781
+	 * @return void
2782
+	 * @throws EE_Error
2783
+	 * @throws DomainException
2784
+	 */
2785
+	public function display_admin_list_table_page_with_sidebar()
2786
+	{
2787
+		$this->_display_admin_list_table_page(true);
2788
+	}
2789
+
2790
+
2791
+	/**
2792
+	 * display_admin_list_table_page_with_no_sidebar
2793
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2794
+	 *
2795
+	 * @return void
2796
+	 * @throws EE_Error
2797
+	 * @throws DomainException
2798
+	 */
2799
+	public function display_admin_list_table_page_with_no_sidebar()
2800
+	{
2801
+		$this->_display_admin_list_table_page();
2802
+	}
2803
+
2804
+
2805
+	/**
2806
+	 * generates html wrapper for an admin_list_table page
2807
+	 *
2808
+	 * @param boolean $sidebar whether to display with sidebar or not.
2809
+	 * @return void
2810
+	 * @throws DomainException
2811
+	 * @throws EE_Error
2812
+	 */
2813
+	private function _display_admin_list_table_page($sidebar = false)
2814
+	{
2815
+		// setup search attributes
2816
+		$this->_set_search_attributes();
2817
+		$this->_template_args['current_page']     = $this->_wp_page_slug;
2818
+		$template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2819
+		$this->_template_args['table_url']        = $this->request->isAjax()
2820
+			? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2821
+			: add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2822
+		$this->_template_args['list_table']       = $this->_list_table_object;
2823
+		$this->_template_args['current_route']    = $this->_req_action;
2824
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2825
+		$ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2826
+		if (! empty($ajax_sorting_callback)) {
2827
+			$sortable_list_table_form_fields = wp_nonce_field(
2828
+				$ajax_sorting_callback . '_nonce',
2829
+				$ajax_sorting_callback . '_nonce',
2830
+				false,
2831
+				false
2832
+			);
2833
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2834
+												. $this->page_slug
2835
+												. '" />';
2836
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2837
+												. $ajax_sorting_callback
2838
+												. '" />';
2839
+		} else {
2840
+			$sortable_list_table_form_fields = '';
2841
+		}
2842
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2843
+		$hidden_form_fields                                      =
2844
+			isset($this->_template_args['list_table_hidden_fields'])
2845
+				? $this->_template_args['list_table_hidden_fields']
2846
+				: '';
2847
+		$nonce_ref                                               = $this->_req_action . '_nonce';
2848
+		$hidden_form_fields                                      .= '<input type="hidden" name="'
2849
+																	. $nonce_ref
2850
+																	. '" value="'
2851
+																	. wp_create_nonce($nonce_ref)
2852
+																	. '">';
2853
+		$this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2854
+		// display message about search results?
2855
+		$search = $this->request->getRequestParam('s');
2856
+		$this->_template_args['before_list_table'] .= ! empty($search)
2857
+			? '<p class="ee-search-results">' . sprintf(
2858
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2859
+				trim($search, '%')
2860
+			) . '</p>'
2861
+			: '';
2862
+		// filter before_list_table template arg
2863
+		$this->_template_args['before_list_table'] = apply_filters(
2864
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2865
+			$this->_template_args['before_list_table'],
2866
+			$this->page_slug,
2867
+			$this->request->requestParams(),
2868
+			$this->_req_action
2869
+		);
2870
+		// convert to array and filter again
2871
+		// arrays are easier to inject new items in a specific location,
2872
+		// but would not be backwards compatible, so we have to add a new filter
2873
+		$this->_template_args['before_list_table'] = implode(
2874
+			" \n",
2875
+			(array) apply_filters(
2876
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2877
+				(array) $this->_template_args['before_list_table'],
2878
+				$this->page_slug,
2879
+				$this->request->requestParams(),
2880
+				$this->_req_action
2881
+			)
2882
+		);
2883
+		// filter after_list_table template arg
2884
+		$this->_template_args['after_list_table'] = apply_filters(
2885
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2886
+			$this->_template_args['after_list_table'],
2887
+			$this->page_slug,
2888
+			$this->request->requestParams(),
2889
+			$this->_req_action
2890
+		);
2891
+		// convert to array and filter again
2892
+		// arrays are easier to inject new items in a specific location,
2893
+		// but would not be backwards compatible, so we have to add a new filter
2894
+		$this->_template_args['after_list_table']   = implode(
2895
+			" \n",
2896
+			(array) apply_filters(
2897
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2898
+				(array) $this->_template_args['after_list_table'],
2899
+				$this->page_slug,
2900
+				$this->request->requestParams(),
2901
+				$this->_req_action
2902
+			)
2903
+		);
2904
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2905
+			$template_path,
2906
+			$this->_template_args,
2907
+			true
2908
+		);
2909
+		// the final template wrapper
2910
+		if ($sidebar) {
2911
+			$this->display_admin_page_with_sidebar();
2912
+		} else {
2913
+			$this->display_admin_page_with_no_sidebar();
2914
+		}
2915
+	}
2916
+
2917
+
2918
+	/**
2919
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
2920
+	 * html string for the legend.
2921
+	 * $items are expected in an array in the following format:
2922
+	 * $legend_items = array(
2923
+	 *        'item_id' => array(
2924
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2925
+	 *            'desc' => esc_html__('localized description of item');
2926
+	 *        )
2927
+	 * );
2928
+	 *
2929
+	 * @param array $items see above for format of array
2930
+	 * @return string html string of legend
2931
+	 * @throws DomainException
2932
+	 */
2933
+	protected function _display_legend($items)
2934
+	{
2935
+		$this->_template_args['items'] = apply_filters(
2936
+			'FHEE__EE_Admin_Page___display_legend__items',
2937
+			(array) $items,
2938
+			$this
2939
+		);
2940
+		return EEH_Template::display_template(
2941
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
2942
+			$this->_template_args,
2943
+			true
2944
+		);
2945
+	}
2946
+
2947
+
2948
+	/**
2949
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2950
+	 * The returned json object is created from an array in the following format:
2951
+	 * array(
2952
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2953
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
2954
+	 *  'notices' => '', // - contains any EE_Error formatted notices
2955
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2956
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
2957
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
2958
+	 *  that might be included in here)
2959
+	 * )
2960
+	 * The json object is populated by whatever is set in the $_template_args property.
2961
+	 *
2962
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
2963
+	 *                                 instead of displayed.
2964
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
2965
+	 * @return void
2966
+	 * @throws EE_Error
2967
+	 */
2968
+	protected function _return_json($sticky_notices = false, $notices_arguments = [])
2969
+	{
2970
+		// make sure any EE_Error notices have been handled.
2971
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
2972
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
2973
+		unset($this->_template_args['data']);
2974
+		$json = [
2975
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2976
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2977
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2978
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2979
+			'notices'   => EE_Error::get_notices(),
2980
+			'content'   => isset($this->_template_args['admin_page_content'])
2981
+				? $this->_template_args['admin_page_content'] : '',
2982
+			'data'      => array_merge($data, ['template_args' => $this->_template_args]),
2983
+			'isEEajax'  => true
2984
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2985
+		];
2986
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2987
+		if (null === error_get_last() || ! headers_sent()) {
2988
+			header('Content-Type: application/json; charset=UTF-8');
2989
+		}
2990
+		echo wp_json_encode($json);
2991
+		exit();
2992
+	}
2993
+
2994
+
2995
+	/**
2996
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2997
+	 *
2998
+	 * @return void
2999
+	 * @throws EE_Error
3000
+	 */
3001
+	public function return_json()
3002
+	{
3003
+		if ($this->request->isAjax()) {
3004
+			$this->_return_json();
3005
+		} else {
3006
+			throw new EE_Error(
3007
+				sprintf(
3008
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3009
+					__FUNCTION__
3010
+				)
3011
+			);
3012
+		}
3013
+	}
3014
+
3015
+
3016
+	/**
3017
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3018
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3019
+	 *
3020
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3021
+	 */
3022
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3023
+	{
3024
+		$this->_hook_obj = $hook_obj;
3025
+	}
3026
+
3027
+
3028
+	/**
3029
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3030
+	 *
3031
+	 * @param boolean $about whether to use the special about page wrapper or default.
3032
+	 * @return void
3033
+	 * @throws DomainException
3034
+	 * @throws EE_Error
3035
+	 */
3036
+	public function admin_page_wrapper($about = false)
3037
+	{
3038
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3039
+		$this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3040
+		$this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3041
+		$this->_template_args['admin_page_title']          = $this->_admin_page_title;
3042
+
3043
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3044
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3045
+			isset($this->_template_args['before_admin_page_content'])
3046
+				? $this->_template_args['before_admin_page_content']
3047
+				: ''
3048
+		);
3049
+
3050
+		$this->_template_args['after_admin_page_content']  = apply_filters(
3051
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3052
+			isset($this->_template_args['after_admin_page_content'])
3053
+				? $this->_template_args['after_admin_page_content']
3054
+				: ''
3055
+		);
3056
+		$this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3057
+
3058
+		if ($this->request->isAjax()) {
3059
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3060
+				// $template_path,
3061
+				EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3062
+				$this->_template_args,
3063
+				true
3064
+			);
3065
+			$this->_return_json();
3066
+		}
3067
+		// load settings page wrapper template
3068
+		$template_path = $about
3069
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3070
+			: EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3071
+
3072
+		EEH_Template::display_template($template_path, $this->_template_args);
3073
+	}
3074
+
3075
+
3076
+	/**
3077
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3078
+	 *
3079
+	 * @return string html
3080
+	 * @throws EE_Error
3081
+	 */
3082
+	protected function _get_main_nav_tabs()
3083
+	{
3084
+		// let's generate the html using the EEH_Tabbed_Content helper.
3085
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3086
+		// (rather than setting in the page_routes array)
3087
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3088
+	}
3089
+
3090
+
3091
+	/**
3092
+	 *        sort nav tabs
3093
+	 *
3094
+	 * @param $a
3095
+	 * @param $b
3096
+	 * @return int
3097
+	 */
3098
+	private function _sort_nav_tabs($a, $b)
3099
+	{
3100
+		if ($a['order'] === $b['order']) {
3101
+			return 0;
3102
+		}
3103
+		return ($a['order'] < $b['order']) ? -1 : 1;
3104
+	}
3105
+
3106
+
3107
+	/**
3108
+	 *    generates HTML for the forms used on admin pages
3109
+	 *
3110
+	 * @param array  $input_vars   - array of input field details
3111
+	 * @param string $generator    (options are 'string' or 'array', basically use this to indicate which generator to
3112
+	 *                             use)
3113
+	 * @param bool   $id
3114
+	 * @return array|string
3115
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3116
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3117
+	 */
3118
+	protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3119
+	{
3120
+		return $generator === 'string'
3121
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3122
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3123
+	}
3124
+
3125
+
3126
+	/**
3127
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3128
+	 *
3129
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3130
+	 *                                   Close" button.
3131
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3132
+	 *                                   'Save', [1] => 'save & close')
3133
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3134
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3135
+	 *                                   default actions by submitting some other value.
3136
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3137
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3138
+	 *                                   close (normal form handling).
3139
+	 */
3140
+	protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3141
+	{
3142
+		// make sure $text and $actions are in an array
3143
+		$text          = (array) $text;
3144
+		$actions       = (array) $actions;
3145
+		$referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3146
+		$button_text   = ! empty($text)
3147
+			? $text
3148
+			: [
3149
+				esc_html__('Save', 'event_espresso'),
3150
+				esc_html__('Save and Close', 'event_espresso'),
3151
+			];
3152
+		$default_names = ['save', 'save_and_close'];
3153
+		$buttons = '';
3154
+		foreach ($button_text as $key => $button) {
3155
+			$ref     = $default_names[ $key ];
3156
+			$name    = ! empty($actions) ? $actions[ $key ] : $ref;
3157
+			$buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3158
+						. 'value="' . $button . '" name="' . $name . '" '
3159
+						. 'id="' . $this->_current_view . '_' . $ref . '" />';
3160
+			if (! $both) {
3161
+				break;
3162
+			}
3163
+		}
3164
+		// add in a hidden index for the current page (so save and close redirects properly)
3165
+		$buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3166
+				   . $referrer_url
3167
+				   . '" />';
3168
+		$this->_template_args['save_buttons'] = $buttons;
3169
+	}
3170
+
3171
+
3172
+	/**
3173
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3174
+	 *
3175
+	 * @param string $route
3176
+	 * @param array  $additional_hidden_fields
3177
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3178
+	 * @since 4.6.0
3179
+	 */
3180
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3181
+	{
3182
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3183
+	}
3184
+
3185
+
3186
+	/**
3187
+	 * set form open and close tags on add/edit pages.
3188
+	 *
3189
+	 * @param string $route                    the route you want the form to direct to
3190
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3191
+	 * @return void
3192
+	 */
3193
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3194
+	{
3195
+		if (empty($route)) {
3196
+			$user_msg = esc_html__(
3197
+				'An error occurred. No action was set for this page\'s form.',
3198
+				'event_espresso'
3199
+			);
3200
+			$dev_msg  = $user_msg . "\n"
3201
+						. sprintf(
3202
+							esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3203
+							__FUNCTION__,
3204
+							__CLASS__
3205
+						);
3206
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3207
+		}
3208
+		// open form
3209
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3210
+															 . $this->_admin_base_url
3211
+															 . '" id="'
3212
+															 . $route
3213
+															 . '_event_form" >';
3214
+		// add nonce
3215
+		$nonce                                             =
3216
+			wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3217
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3218
+		// add REQUIRED form action
3219
+		$hidden_fields = [
3220
+			'action' => ['type' => 'hidden', 'value' => $route],
3221
+		];
3222
+		// merge arrays
3223
+		$hidden_fields = is_array($additional_hidden_fields)
3224
+			? array_merge($hidden_fields, $additional_hidden_fields)
3225
+			: $hidden_fields;
3226
+		// generate form fields
3227
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3228
+		// add fields to form
3229
+		foreach ((array) $form_fields as $form_field) {
3230
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3231
+		}
3232
+		// close form
3233
+		$this->_template_args['after_admin_page_content'] = '</form>';
3234
+	}
3235
+
3236
+
3237
+	/**
3238
+	 * Public Wrapper for _redirect_after_action() method since its
3239
+	 * discovered it would be useful for external code to have access.
3240
+	 *
3241
+	 * @param bool   $success
3242
+	 * @param string $what
3243
+	 * @param string $action_desc
3244
+	 * @param array  $query_args
3245
+	 * @param bool   $override_overwrite
3246
+	 * @throws EE_Error
3247
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3248
+	 * @since 4.5.0
3249
+	 */
3250
+	public function redirect_after_action(
3251
+		$success = false,
3252
+		$what = 'item',
3253
+		$action_desc = 'processed',
3254
+		$query_args = [],
3255
+		$override_overwrite = false
3256
+	) {
3257
+		$this->_redirect_after_action(
3258
+			$success,
3259
+			$what,
3260
+			$action_desc,
3261
+			$query_args,
3262
+			$override_overwrite
3263
+		);
3264
+	}
3265
+
3266
+
3267
+	/**
3268
+	 * Helper method for merging existing request data with the returned redirect url.
3269
+	 *
3270
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3271
+	 * filters are still applied.
3272
+	 *
3273
+	 * @param array $new_route_data
3274
+	 * @return array
3275
+	 */
3276
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3277
+	{
3278
+		foreach ($this->request->requestParams() as $ref => $value) {
3279
+			// unset nonces
3280
+			if (strpos($ref, 'nonce') !== false) {
3281
+				$this->request->unSetRequestParam($ref);
3282
+				continue;
3283
+			}
3284
+			// urlencode values.
3285
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3286
+			$this->request->setRequestParam($ref, $value);
3287
+		}
3288
+		return array_merge($this->request->requestParams(), $new_route_data);
3289
+	}
3290
+
3291
+
3292
+	/**
3293
+	 *    _redirect_after_action
3294
+	 *
3295
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3296
+	 * @param string $what               - what the action was performed on
3297
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3298
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3299
+	 *                                   action is completed
3300
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3301
+	 *                                   override this so that they show.
3302
+	 * @return void
3303
+	 * @throws EE_Error
3304
+	 */
3305
+	protected function _redirect_after_action(
3306
+		$success = 0,
3307
+		$what = 'item',
3308
+		$action_desc = 'processed',
3309
+		$query_args = [],
3310
+		$override_overwrite = false
3311
+	) {
3312
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3313
+		// class name for actions/filters.
3314
+		$classname = get_class($this);
3315
+		// set redirect url.
3316
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3317
+		// otherwise we go with whatever is set as the _admin_base_url
3318
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3319
+		$notices      = EE_Error::get_notices(false);
3320
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3321
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3322
+			EE_Error::overwrite_success();
3323
+		}
3324
+		if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3325
+			// how many records affected ? more than one record ? or just one ?
3326
+			if ($success > 1) {
3327
+				// set plural msg
3328
+				EE_Error::add_success(
3329
+					sprintf(
3330
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3331
+						$what,
3332
+						$action_desc
3333
+					),
3334
+					__FILE__,
3335
+					__FUNCTION__,
3336
+					__LINE__
3337
+				);
3338
+			} elseif ($success === 1) {
3339
+				// set singular msg
3340
+				EE_Error::add_success(
3341
+					sprintf(
3342
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3343
+						$what,
3344
+						$action_desc
3345
+					),
3346
+					__FILE__,
3347
+					__FUNCTION__,
3348
+					__LINE__
3349
+				);
3350
+			}
3351
+		}
3352
+		// check that $query_args isn't something crazy
3353
+		if (! is_array($query_args)) {
3354
+			$query_args = [];
3355
+		}
3356
+		/**
3357
+		 * Allow injecting actions before the query_args are modified for possible different
3358
+		 * redirections on save and close actions
3359
+		 *
3360
+		 * @param array $query_args       The original query_args array coming into the
3361
+		 *                                method.
3362
+		 * @since 4.2.0
3363
+		 */
3364
+		do_action(
3365
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3366
+			$query_args
3367
+		);
3368
+		// calculate where we're going (if we have a "save and close" button pushed)
3369
+
3370
+		if (
3371
+			$this->request->requestParamIsSet('save_and_close')
3372
+			&& $this->request->requestParamIsSet('save_and_close_referrer')
3373
+		) {
3374
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3375
+			$parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3376
+			// regenerate query args array from referrer URL
3377
+			parse_str($parsed_url['query'], $query_args);
3378
+			// correct page and action will be in the query args now
3379
+			$redirect_url = admin_url('admin.php');
3380
+		}
3381
+		// merge any default query_args set in _default_route_query_args property
3382
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3383
+			$args_to_merge = [];
3384
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3385
+				// is there a wp_referer array in our _default_route_query_args property?
3386
+				if ($query_param === 'wp_referer') {
3387
+					$query_value = (array) $query_value;
3388
+					foreach ($query_value as $reference => $value) {
3389
+						if (strpos($reference, 'nonce') !== false) {
3390
+							continue;
3391
+						}
3392
+						// finally we will override any arguments in the referer with
3393
+						// what might be set on the _default_route_query_args array.
3394
+						if (isset($this->_default_route_query_args[ $reference ])) {
3395
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3396
+						} else {
3397
+							$args_to_merge[ $reference ] = urlencode($value);
3398
+						}
3399
+					}
3400
+					continue;
3401
+				}
3402
+				$args_to_merge[ $query_param ] = $query_value;
3403
+			}
3404
+			// now let's merge these arguments but override with what was specifically sent in to the
3405
+			// redirect.
3406
+			$query_args = array_merge($args_to_merge, $query_args);
3407
+		}
3408
+		$this->_process_notices($query_args);
3409
+		// generate redirect url
3410
+		// if redirecting to anything other than the main page, add a nonce
3411
+		if (isset($query_args['action'])) {
3412
+			// manually generate wp_nonce and merge that with the query vars
3413
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3414
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3415
+		}
3416
+		// we're adding some hooks and filters in here for processing any things just before redirects
3417
+		// (example: an admin page has done an insert or update and we want to run something after that).
3418
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3419
+		$redirect_url = apply_filters(
3420
+			'FHEE_redirect_' . $classname . $this->_req_action,
3421
+			self::add_query_args_and_nonce($query_args, $redirect_url),
3422
+			$query_args
3423
+		);
3424
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3425
+		if ($this->request->isAjax()) {
3426
+			$default_data                    = [
3427
+				'close'        => true,
3428
+				'redirect_url' => $redirect_url,
3429
+				'where'        => 'main',
3430
+				'what'         => 'append',
3431
+			];
3432
+			$this->_template_args['success'] = $success;
3433
+			$this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3434
+				$default_data,
3435
+				$this->_template_args['data']
3436
+			) : $default_data;
3437
+			$this->_return_json();
3438
+		}
3439
+		wp_safe_redirect($redirect_url);
3440
+		exit();
3441
+	}
3442
+
3443
+
3444
+	/**
3445
+	 * process any notices before redirecting (or returning ajax request)
3446
+	 * This method sets the $this->_template_args['notices'] attribute;
3447
+	 *
3448
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3449
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3450
+	 *                                  page_routes haven't been defined yet.
3451
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3452
+	 *                                  still save a transient for the notice.
3453
+	 * @return void
3454
+	 * @throws EE_Error
3455
+	 */
3456
+	protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3457
+	{
3458
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3459
+		if ($this->request->isAjax()) {
3460
+			$notices = EE_Error::get_notices(false);
3461
+			if (empty($this->_template_args['success'])) {
3462
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3463
+			}
3464
+			if (empty($this->_template_args['errors'])) {
3465
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3466
+			}
3467
+			if (empty($this->_template_args['attention'])) {
3468
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3469
+			}
3470
+		}
3471
+		$this->_template_args['notices'] = EE_Error::get_notices();
3472
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3473
+		if (! $this->request->isAjax() || $sticky_notices) {
3474
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3475
+			$this->_add_transient(
3476
+				$route,
3477
+				$this->_template_args['notices'],
3478
+				true,
3479
+				$skip_route_verify
3480
+			);
3481
+		}
3482
+	}
3483
+
3484
+
3485
+	/**
3486
+	 * get_action_link_or_button
3487
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3488
+	 *
3489
+	 * @param string $action        use this to indicate which action the url is generated with.
3490
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3491
+	 *                              property.
3492
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3493
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3494
+	 * @param string $base_url      If this is not provided
3495
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3496
+	 *                              Otherwise this value will be used.
3497
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3498
+	 * @return string
3499
+	 * @throws InvalidArgumentException
3500
+	 * @throws InvalidInterfaceException
3501
+	 * @throws InvalidDataTypeException
3502
+	 * @throws EE_Error
3503
+	 */
3504
+	public function get_action_link_or_button(
3505
+		$action,
3506
+		$type = 'add',
3507
+		$extra_request = [],
3508
+		$class = 'button-primary',
3509
+		$base_url = '',
3510
+		$exclude_nonce = false
3511
+	) {
3512
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3513
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3514
+			throw new EE_Error(
3515
+				sprintf(
3516
+					esc_html__(
3517
+						'There is no page route for given action for the button.  This action was given: %s',
3518
+						'event_espresso'
3519
+					),
3520
+					$action
3521
+				)
3522
+			);
3523
+		}
3524
+		if (! isset($this->_labels['buttons'][ $type ])) {
3525
+			throw new EE_Error(
3526
+				sprintf(
3527
+					esc_html__(
3528
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3529
+						'event_espresso'
3530
+					),
3531
+					$type
3532
+				)
3533
+			);
3534
+		}
3535
+		// finally check user access for this button.
3536
+		$has_access = $this->check_user_access($action, true);
3537
+		if (! $has_access) {
3538
+			return '';
3539
+		}
3540
+		$_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3541
+		$query_args = [
3542
+			'action' => $action,
3543
+		];
3544
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3545
+		if (! empty($extra_request)) {
3546
+			$query_args = array_merge($extra_request, $query_args);
3547
+		}
3548
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3549
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3550
+	}
3551
+
3552
+
3553
+	/**
3554
+	 * _per_page_screen_option
3555
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3556
+	 *
3557
+	 * @return void
3558
+	 * @throws InvalidArgumentException
3559
+	 * @throws InvalidInterfaceException
3560
+	 * @throws InvalidDataTypeException
3561
+	 */
3562
+	protected function _per_page_screen_option()
3563
+	{
3564
+		$option = 'per_page';
3565
+		$args   = [
3566
+			'label'   => apply_filters(
3567
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3568
+				$this->_admin_page_title,
3569
+				$this
3570
+			),
3571
+			'default' => (int) apply_filters(
3572
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3573
+				20
3574
+			),
3575
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3576
+		];
3577
+		// ONLY add the screen option if the user has access to it.
3578
+		if ($this->check_user_access($this->_current_view, true)) {
3579
+			add_screen_option($option, $args);
3580
+		}
3581
+	}
3582
+
3583
+
3584
+	/**
3585
+	 * set_per_page_screen_option
3586
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3587
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3588
+	 * admin_menu.
3589
+	 *
3590
+	 * @return void
3591
+	 */
3592
+	private function _set_per_page_screen_options()
3593
+	{
3594
+		if ($this->request->requestParamIsSet('wp_screen_options')) {
3595
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3596
+			if (! $user = wp_get_current_user()) {
3597
+				return;
3598
+			}
3599
+			$option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3600
+			if (! $option) {
3601
+				return;
3602
+			}
3603
+			$value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3604
+			$map_option = $option;
3605
+			$option     = str_replace('-', '_', $option);
3606
+			switch ($map_option) {
3607
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3608
+					$max_value = apply_filters(
3609
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3610
+						999,
3611
+						$this->_current_page,
3612
+						$this->_current_view
3613
+					);
3614
+					if ($value < 1) {
3615
+						return;
3616
+					}
3617
+					$value = min($value, $max_value);
3618
+					break;
3619
+				default:
3620
+					$value = apply_filters(
3621
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3622
+						false,
3623
+						$option,
3624
+						$value
3625
+					);
3626
+					if (false === $value) {
3627
+						return;
3628
+					}
3629
+					break;
3630
+			}
3631
+			update_user_meta($user->ID, $option, $value);
3632
+			wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3633
+			exit;
3634
+		}
3635
+	}
3636
+
3637
+
3638
+	/**
3639
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3640
+	 *
3641
+	 * @param array $data array that will be assigned to template args.
3642
+	 */
3643
+	public function set_template_args($data)
3644
+	{
3645
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3646
+	}
3647
+
3648
+
3649
+	/**
3650
+	 * This makes available the WP transient system for temporarily moving data between routes
3651
+	 *
3652
+	 * @param string $route             the route that should receive the transient
3653
+	 * @param array  $data              the data that gets sent
3654
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3655
+	 *                                  normal route transient.
3656
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3657
+	 *                                  when we are adding a transient before page_routes have been defined.
3658
+	 * @return void
3659
+	 * @throws EE_Error
3660
+	 */
3661
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3662
+	{
3663
+		$user_id = get_current_user_id();
3664
+		if (! $skip_route_verify) {
3665
+			$this->_verify_route($route);
3666
+		}
3667
+		// now let's set the string for what kind of transient we're setting
3668
+		$transient = $notices
3669
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3670
+			: 'rte_tx_' . $route . '_' . $user_id;
3671
+		$data      = $notices ? ['notices' => $data] : $data;
3672
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3673
+		$existing = is_multisite() && is_network_admin()
3674
+			? get_site_transient($transient)
3675
+			: get_transient($transient);
3676
+		if ($existing) {
3677
+			$data = array_merge((array) $data, (array) $existing);
3678
+		}
3679
+		if (is_multisite() && is_network_admin()) {
3680
+			set_site_transient($transient, $data, 8);
3681
+		} else {
3682
+			set_transient($transient, $data, 8);
3683
+		}
3684
+	}
3685
+
3686
+
3687
+	/**
3688
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3689
+	 *
3690
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3691
+	 * @param string $route
3692
+	 * @return mixed data
3693
+	 */
3694
+	protected function _get_transient($notices = false, $route = '')
3695
+	{
3696
+		$user_id   = get_current_user_id();
3697
+		$route     = ! $route ? $this->_req_action : $route;
3698
+		$transient = $notices
3699
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3700
+			: 'rte_tx_' . $route . '_' . $user_id;
3701
+		$data      = is_multisite() && is_network_admin()
3702
+			? get_site_transient($transient)
3703
+			: get_transient($transient);
3704
+		// delete transient after retrieval (just in case it hasn't expired);
3705
+		if (is_multisite() && is_network_admin()) {
3706
+			delete_site_transient($transient);
3707
+		} else {
3708
+			delete_transient($transient);
3709
+		}
3710
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3711
+	}
3712
+
3713
+
3714
+	/**
3715
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3716
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3717
+	 * default route callback on the EE_Admin page you want it run.)
3718
+	 *
3719
+	 * @return void
3720
+	 */
3721
+	protected function _transient_garbage_collection()
3722
+	{
3723
+		global $wpdb;
3724
+		// retrieve all existing transients
3725
+		$query =
3726
+			"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3727
+		if ($results = $wpdb->get_results($query)) {
3728
+			foreach ($results as $result) {
3729
+				$transient = str_replace('_transient_', '', $result->option_name);
3730
+				get_transient($transient);
3731
+				if (is_multisite() && is_network_admin()) {
3732
+					get_site_transient($transient);
3733
+				}
3734
+			}
3735
+		}
3736
+	}
3737
+
3738
+
3739
+	/**
3740
+	 * get_view
3741
+	 *
3742
+	 * @return string content of _view property
3743
+	 */
3744
+	public function get_view()
3745
+	{
3746
+		return $this->_view;
3747
+	}
3748
+
3749
+
3750
+	/**
3751
+	 * getter for the protected $_views property
3752
+	 *
3753
+	 * @return array
3754
+	 */
3755
+	public function get_views()
3756
+	{
3757
+		return $this->_views;
3758
+	}
3759
+
3760
+
3761
+	/**
3762
+	 * get_current_page
3763
+	 *
3764
+	 * @return string _current_page property value
3765
+	 */
3766
+	public function get_current_page()
3767
+	{
3768
+		return $this->_current_page;
3769
+	}
3770
+
3771
+
3772
+	/**
3773
+	 * get_current_view
3774
+	 *
3775
+	 * @return string _current_view property value
3776
+	 */
3777
+	public function get_current_view()
3778
+	{
3779
+		return $this->_current_view;
3780
+	}
3781
+
3782
+
3783
+	/**
3784
+	 * get_current_screen
3785
+	 *
3786
+	 * @return object The current WP_Screen object
3787
+	 */
3788
+	public function get_current_screen()
3789
+	{
3790
+		return $this->_current_screen;
3791
+	}
3792
+
3793
+
3794
+	/**
3795
+	 * get_current_page_view_url
3796
+	 *
3797
+	 * @return string This returns the url for the current_page_view.
3798
+	 */
3799
+	public function get_current_page_view_url()
3800
+	{
3801
+		return $this->_current_page_view_url;
3802
+	}
3803
+
3804
+
3805
+	/**
3806
+	 * just returns the Request
3807
+	 *
3808
+	 * @return RequestInterface
3809
+	 */
3810
+	public function get_request()
3811
+	{
3812
+		return $this->request;
3813
+	}
3814
+
3815
+
3816
+	/**
3817
+	 * just returns the _req_data property
3818
+	 *
3819
+	 * @return array
3820
+	 */
3821
+	public function get_request_data()
3822
+	{
3823
+		return $this->request->requestParams();
3824
+	}
3825
+
3826
+
3827
+	/**
3828
+	 * returns the _req_data protected property
3829
+	 *
3830
+	 * @return string
3831
+	 */
3832
+	public function get_req_action()
3833
+	{
3834
+		return $this->_req_action;
3835
+	}
3836
+
3837
+
3838
+	/**
3839
+	 * @return bool  value of $_is_caf property
3840
+	 */
3841
+	public function is_caf()
3842
+	{
3843
+		return $this->_is_caf;
3844
+	}
3845
+
3846
+
3847
+	/**
3848
+	 * @return mixed
3849
+	 */
3850
+	public function default_espresso_metaboxes()
3851
+	{
3852
+		return $this->_default_espresso_metaboxes;
3853
+	}
3854
+
3855
+
3856
+	/**
3857
+	 * @return mixed
3858
+	 */
3859
+	public function admin_base_url()
3860
+	{
3861
+		return $this->_admin_base_url;
3862
+	}
3863
+
3864
+
3865
+	/**
3866
+	 * @return mixed
3867
+	 */
3868
+	public function wp_page_slug()
3869
+	{
3870
+		return $this->_wp_page_slug;
3871
+	}
3872
+
3873
+
3874
+	/**
3875
+	 * updates  espresso configuration settings
3876
+	 *
3877
+	 * @param string                   $tab
3878
+	 * @param EE_Config_Base|EE_Config $config
3879
+	 * @param string                   $file file where error occurred
3880
+	 * @param string                   $func function  where error occurred
3881
+	 * @param string                   $line line no where error occurred
3882
+	 * @return boolean
3883
+	 */
3884
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3885
+	{
3886
+		// remove any options that are NOT going to be saved with the config settings.
3887
+		if (isset($config->core->ee_ueip_optin)) {
3888
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3889
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3890
+			update_option('ee_ueip_has_notified', true);
3891
+		}
3892
+		// and save it (note we're also doing the network save here)
3893
+		$net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3894
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3895
+		if ($config_saved && $net_saved) {
3896
+			EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3897
+			return true;
3898
+		}
3899
+		EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3900
+		return false;
3901
+	}
3902
+
3903
+
3904
+	/**
3905
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3906
+	 *
3907
+	 * @return array
3908
+	 */
3909
+	public function get_yes_no_values()
3910
+	{
3911
+		return $this->_yes_no_values;
3912
+	}
3913
+
3914
+
3915
+	protected function _get_dir()
3916
+	{
3917
+		$reflector = new ReflectionClass(get_class($this));
3918
+		return dirname($reflector->getFileName());
3919
+	}
3920
+
3921
+
3922
+	/**
3923
+	 * A helper for getting a "next link".
3924
+	 *
3925
+	 * @param string $url   The url to link to
3926
+	 * @param string $class The class to use.
3927
+	 * @return string
3928
+	 */
3929
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3930
+	{
3931
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3932
+	}
3933
+
3934
+
3935
+	/**
3936
+	 * A helper for getting a "previous link".
3937
+	 *
3938
+	 * @param string $url   The url to link to
3939
+	 * @param string $class The class to use.
3940
+	 * @return string
3941
+	 */
3942
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3943
+	{
3944
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3945
+	}
3946
+
3947
+
3948
+
3949
+
3950
+
3951
+
3952
+
3953
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3954
+
3955
+
3956
+	/**
3957
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
3958
+	 * 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
3959
+	 * _req_data array.
3960
+	 *
3961
+	 * @return bool success/fail
3962
+	 * @throws EE_Error
3963
+	 * @throws InvalidArgumentException
3964
+	 * @throws ReflectionException
3965
+	 * @throws InvalidDataTypeException
3966
+	 * @throws InvalidInterfaceException
3967
+	 */
3968
+	protected function _process_resend_registration()
3969
+	{
3970
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3971
+		do_action(
3972
+			'AHEE__EE_Admin_Page___process_resend_registration',
3973
+			$this->_template_args['success'],
3974
+			$this->request->requestParams()
3975
+		);
3976
+		return $this->_template_args['success'];
3977
+	}
3978
+
3979
+
3980
+	/**
3981
+	 * This automatically processes any payment message notifications when manual payment has been applied.
3982
+	 *
3983
+	 * @param EE_Payment $payment
3984
+	 * @return bool success/fail
3985
+	 */
3986
+	protected function _process_payment_notification(EE_Payment $payment)
3987
+	{
3988
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3989
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3990
+		$this->_template_args['success'] = apply_filters(
3991
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
3992
+			false,
3993
+			$payment
3994
+		);
3995
+		return $this->_template_args['success'];
3996
+	}
3997
+
3998
+
3999
+	/**
4000
+	 * @param EEM_Base      $entity_model
4001
+	 * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4002
+	 * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4003
+	 * @param string        $delete_column  name of the field that denotes whether entity is trashed
4004
+	 * @param callable|null $callback       called after entity is trashed, restored, or deleted
4005
+	 * @return int|float
4006
+	 * @throws EE_Error
4007
+	 */
4008
+	protected function trashRestoreDeleteEntities(
4009
+		EEM_Base $entity_model,
4010
+		string $entity_PK_name,
4011
+		string $action = EE_Admin_List_Table::ACTION_DELETE,
4012
+		string $delete_column = '',
4013
+		callable $callback = null
4014
+	) {
4015
+		$entity_PK      = $entity_model->get_primary_key_field();
4016
+		$entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4017
+		$entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4018
+		// grab ID if deleting a single entity
4019
+		if ($this->request->requestParamIsSet($entity_PK_name)) {
4020
+			$ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4021
+			return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4022
+		}
4023
+		// or grab checkbox array if bulk deleting
4024
+		$checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4025
+		if (empty($checkboxes)) {
4026
+			return 0;
4027
+		}
4028
+		$success = 0;
4029
+		$IDs     = array_keys($checkboxes);
4030
+		// cycle thru bulk action checkboxes
4031
+		foreach ($IDs as $ID) {
4032
+			// increment $success
4033
+			if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4034
+				$success++;
4035
+			}
4036
+		}
4037
+		$count = (int) count($checkboxes);
4038
+		// if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4039
+		// otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4040
+		return $success === $count ? $count : $success / $count;
4041
+	}
4042
+
4043
+
4044
+	/**
4045
+	 * @param EE_Primary_Key_Field_Base $entity_PK
4046
+	 * @return string
4047
+	 * @throws EE_Error
4048
+	 * @since   4.10.30.p
4049
+	 */
4050
+	private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string
4051
+	{
4052
+		$entity_PK_type = $entity_PK->getSchemaType();
4053
+		switch ($entity_PK_type) {
4054
+			case 'boolean':
4055
+				return 'bool';
4056
+			case 'integer':
4057
+				return 'int';
4058
+			case 'number':
4059
+				return 'float';
4060
+			case 'string':
4061
+				return 'string';
4062
+		}
4063
+		throw new RuntimeException(
4064
+			sprintf(
4065
+				esc_html__(
4066
+					'"%1$s" is an invalid schema type for the %2$s primary key.',
4067
+					'event_espresso'
4068
+				),
4069
+				$entity_PK_type,
4070
+				$entity_PK->get_name()
4071
+			)
4072
+		);
4073
+	}
4074
+
4075
+
4076
+	/**
4077
+	 * @param EEM_Base      $entity_model
4078
+	 * @param int|string    $entity_ID
4079
+	 * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4080
+	 * @param string        $delete_column name of the field that denotes whether entity is trashed
4081
+	 * @param callable|null $callback      called after entity is trashed, restored, or deleted
4082
+	 * @return bool
4083
+	 */
4084
+	protected function trashRestoreDeleteEntity(
4085
+		EEM_Base $entity_model,
4086
+		$entity_ID,
4087
+		string $action,
4088
+		string $delete_column,
4089
+		callable $callback = null
4090
+	) {
4091
+		$entity_ID = absint($entity_ID);
4092
+		if (! $entity_ID) {
4093
+			$this->trashRestoreDeleteError($action, $entity_model);
4094
+		}
4095
+		$result = 0;
4096
+		try {
4097
+			switch ($action) {
4098
+				case EE_Admin_List_Table::ACTION_DELETE:
4099
+					$result = (bool) $entity_model->delete_permanently_by_ID($entity_ID);
4100
+					break;
4101
+				case EE_Admin_List_Table::ACTION_RESTORE:
4102
+					$this->validateDeleteColumn($entity_model, $delete_column);
4103
+					$result = $entity_model->update_by_ID([$delete_column => 0], $entity_ID);
4104
+					break;
4105
+				case EE_Admin_List_Table::ACTION_TRASH:
4106
+					$this->validateDeleteColumn($entity_model, $delete_column);
4107
+					$result = $entity_model->update_by_ID([$delete_column => 1], $entity_ID);
4108
+					break;
4109
+			}
4110
+		} catch (Exception $exception) {
4111
+			$this->trashRestoreDeleteError($action, $entity_model, $exception);
4112
+		}
4113
+		if (is_callable($callback)) {
4114
+			call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4115
+		}
4116
+		return $result;
4117
+	}
4118
+
4119
+
4120
+	/**
4121
+	 * @param EEM_Base $entity_model
4122
+	 * @param string   $delete_column
4123
+	 * @since 4.10.30.p
4124
+	 */
4125
+	private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column)
4126
+	{
4127
+		if (empty($delete_column)) {
4128
+			throw new DomainException(
4129
+				sprintf(
4130
+					esc_html__(
4131
+						'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4132
+						'event_espresso'
4133
+					),
4134
+					$entity_model->get_this_model_name()
4135
+				)
4136
+			);
4137
+		}
4138
+		if (! $entity_model->has_field($delete_column)) {
4139
+			throw new DomainException(
4140
+				sprintf(
4141
+					esc_html__(
4142
+						'The %1$s field does not exist on the %2$s model.',
4143
+						'event_espresso'
4144
+					),
4145
+					$delete_column,
4146
+					$entity_model->get_this_model_name()
4147
+				)
4148
+			);
4149
+		}
4150
+	}
4151
+
4152
+
4153
+	/**
4154
+	 * @param EEM_Base       $entity_model
4155
+	 * @param Exception|null $exception
4156
+	 * @param string         $action
4157
+	 * @since 4.10.30.p
4158
+	 */
4159
+	private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, ?Exception $exception = null)
4160
+	{
4161
+		if ($exception instanceof Exception) {
4162
+			throw new RuntimeException(
4163
+				sprintf(
4164
+					esc_html__(
4165
+						'Could not %1$s the %2$s because the following error occurred: %3$s',
4166
+						'event_espresso'
4167
+					),
4168
+					$action,
4169
+					$entity_model->get_this_model_name(),
4170
+					$exception->getMessage()
4171
+				)
4172
+			);
4173
+		}
4174
+		throw new RuntimeException(
4175
+			sprintf(
4176
+				esc_html__(
4177
+					'Could not %1$s the %2$s because an invalid ID was received.',
4178
+					'event_espresso'
4179
+				),
4180
+				$action,
4181
+				$entity_model->get_this_model_name()
4182
+			)
4183
+		);
4184
+	}
4185 4185
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Country.class.php 1 patch
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -10,207 +10,207 @@
 block discarded – undo
10 10
 class EE_Country extends EE_Base_Class
11 11
 {
12 12
 
13
-    /**
14
-     * @param array $props_n_values
15
-     * @return EE_Country|mixed
16
-     * @throws EE_Error
17
-     * @throws ReflectionException
18
-     */
19
-    public static function new_instance($props_n_values = [])
20
-    {
21
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
22
-        return $has_object ? $has_object : new self($props_n_values);
23
-    }
24
-
25
-
26
-    /**
27
-     * @param array $props_n_values
28
-     * @return EE_Country
29
-     * @throws EE_Error
30
-     * @throws ReflectionException
31
-     */
32
-    public static function new_instance_from_db($props_n_values = [])
33
-    {
34
-        return new self($props_n_values, true);
35
-    }
36
-
37
-
38
-    /**
39
-     * Gets the country name
40
-     *
41
-     * @return string
42
-     * @throws EE_Error
43
-     * @throws ReflectionException
44
-     */
45
-    public function name()
46
-    {
47
-        return $this->get('CNT_name');
48
-    }
49
-
50
-
51
-    /**
52
-     * Whether the country is active/enabled
53
-     *
54
-     * @return bool
55
-     * @throws EE_Error
56
-     * @throws ReflectionException
57
-     */
58
-    public function isActive()
59
-    {
60
-        return (bool) $this->get('CNT_active');
61
-    }
62
-
63
-
64
-    /**
65
-     * Gets the country ISO3
66
-     *
67
-     * @return string
68
-     * @throws EE_Error
69
-     * @throws ReflectionException
70
-     */
71
-    public function ISO3()
72
-    {
73
-        return $this->get('CNT_ISO3');
74
-    }
75
-
76
-
77
-    /**
78
-     * gets the country's currency code
79
-     *
80
-     * @return string
81
-     * @throws EE_Error
82
-     * @throws ReflectionException
83
-     */
84
-    public function currency_code()
85
-    {
86
-        return $this->get('CNT_cur_code');
87
-    }
88
-
89
-
90
-    /**
91
-     * gets the country's currency sign/symbol
92
-     *
93
-     * @return string
94
-     * @throws EE_Error
95
-     * @throws ReflectionException
96
-     */
97
-    public function currency_sign()
98
-    {
99
-        $CNT_cur_sign = $this->get('CNT_cur_sign');
100
-        return $CNT_cur_sign ? $CNT_cur_sign : '';
101
-    }
102
-
103
-
104
-    /**
105
-     * Currency name singular
106
-     *
107
-     * @return string
108
-     * @throws EE_Error
109
-     * @throws ReflectionException
110
-     */
111
-    public function currency_name_single()
112
-    {
113
-        return $this->get('CNT_cur_single');
114
-    }
115
-
116
-
117
-    /**
118
-     * Currency name plural
119
-     *
120
-     * @return string
121
-     * @throws EE_Error
122
-     * @throws ReflectionException
123
-     */
124
-    public function currency_name_plural()
125
-    {
126
-        return $this->get('CNT_cur_plural');
127
-    }
128
-
129
-
130
-    /**
131
-     * currency_sign_before - ie: $TRUE  or  FALSE$
132
-     *
133
-     * @return boolean
134
-     * @throws EE_Error
135
-     * @throws ReflectionException
136
-     */
137
-    public function currency_sign_before()
138
-    {
139
-        return (bool) $this->get('CNT_cur_sign_b4');
140
-    }
141
-
142
-
143
-    /**
144
-     * currency_decimal_places : 2 = 0.00   3 = 0.000
145
-     *
146
-     * @return integer
147
-     * @throws EE_Error
148
-     * @throws ReflectionException
149
-     */
150
-    public function currency_decimal_places()
151
-    {
152
-        return $this->get('CNT_cur_dec_plc');
153
-    }
154
-
155
-
156
-    /**
157
-     * currency_decimal_mark :   (comma) ',' = 0,01   or   (decimal) '.' = 0.01
158
-     *
159
-     * @return string
160
-     * @throws EE_Error
161
-     * @throws ReflectionException
162
-     */
163
-    public function currency_decimal_mark()
164
-    {
165
-        return $this->get('CNT_cur_dec_mrk');
166
-    }
167
-
168
-
169
-    /**
170
-     * currency thousands separator:   (comma) ',' = 1,000   or   (decimal) '.' = 1.000
171
-     *
172
-     * @return string
173
-     * @throws EE_Error
174
-     * @throws ReflectionException
175
-     */
176
-    public function currency_thousands_separator()
177
-    {
178
-        return $this->get('CNT_cur_thsnds');
179
-    }
180
-
181
-
182
-    /**
183
-     * @return bool
184
-     * @throws EE_Error
185
-     * @throws ReflectionException
186
-     * @since 4.10.30.p
187
-     */
188
-    public function isEU()
189
-    {
190
-        return (bool) $this->get('CNT_is_EU');
191
-    }
192
-
193
-
194
-    /**
195
-     * Country Telephone Code: +1
196
-     *
197
-     * @return string
198
-     * @throws EE_Error
199
-     * @throws ReflectionException
200
-     * @since 4.10.30.p
201
-     */
202
-    public function telephoneCode()
203
-    {
204
-        return $this->get('CNT_tel_code');
205
-    }
206
-
207
-
208
-    /**
209
-     * @deprecated 4.10.30.p
210
-     * @return bool
211
-     */
212
-    public function is_active()
213
-    {
214
-        return $this->isActive();
215
-    }
13
+	/**
14
+	 * @param array $props_n_values
15
+	 * @return EE_Country|mixed
16
+	 * @throws EE_Error
17
+	 * @throws ReflectionException
18
+	 */
19
+	public static function new_instance($props_n_values = [])
20
+	{
21
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
22
+		return $has_object ? $has_object : new self($props_n_values);
23
+	}
24
+
25
+
26
+	/**
27
+	 * @param array $props_n_values
28
+	 * @return EE_Country
29
+	 * @throws EE_Error
30
+	 * @throws ReflectionException
31
+	 */
32
+	public static function new_instance_from_db($props_n_values = [])
33
+	{
34
+		return new self($props_n_values, true);
35
+	}
36
+
37
+
38
+	/**
39
+	 * Gets the country name
40
+	 *
41
+	 * @return string
42
+	 * @throws EE_Error
43
+	 * @throws ReflectionException
44
+	 */
45
+	public function name()
46
+	{
47
+		return $this->get('CNT_name');
48
+	}
49
+
50
+
51
+	/**
52
+	 * Whether the country is active/enabled
53
+	 *
54
+	 * @return bool
55
+	 * @throws EE_Error
56
+	 * @throws ReflectionException
57
+	 */
58
+	public function isActive()
59
+	{
60
+		return (bool) $this->get('CNT_active');
61
+	}
62
+
63
+
64
+	/**
65
+	 * Gets the country ISO3
66
+	 *
67
+	 * @return string
68
+	 * @throws EE_Error
69
+	 * @throws ReflectionException
70
+	 */
71
+	public function ISO3()
72
+	{
73
+		return $this->get('CNT_ISO3');
74
+	}
75
+
76
+
77
+	/**
78
+	 * gets the country's currency code
79
+	 *
80
+	 * @return string
81
+	 * @throws EE_Error
82
+	 * @throws ReflectionException
83
+	 */
84
+	public function currency_code()
85
+	{
86
+		return $this->get('CNT_cur_code');
87
+	}
88
+
89
+
90
+	/**
91
+	 * gets the country's currency sign/symbol
92
+	 *
93
+	 * @return string
94
+	 * @throws EE_Error
95
+	 * @throws ReflectionException
96
+	 */
97
+	public function currency_sign()
98
+	{
99
+		$CNT_cur_sign = $this->get('CNT_cur_sign');
100
+		return $CNT_cur_sign ? $CNT_cur_sign : '';
101
+	}
102
+
103
+
104
+	/**
105
+	 * Currency name singular
106
+	 *
107
+	 * @return string
108
+	 * @throws EE_Error
109
+	 * @throws ReflectionException
110
+	 */
111
+	public function currency_name_single()
112
+	{
113
+		return $this->get('CNT_cur_single');
114
+	}
115
+
116
+
117
+	/**
118
+	 * Currency name plural
119
+	 *
120
+	 * @return string
121
+	 * @throws EE_Error
122
+	 * @throws ReflectionException
123
+	 */
124
+	public function currency_name_plural()
125
+	{
126
+		return $this->get('CNT_cur_plural');
127
+	}
128
+
129
+
130
+	/**
131
+	 * currency_sign_before - ie: $TRUE  or  FALSE$
132
+	 *
133
+	 * @return boolean
134
+	 * @throws EE_Error
135
+	 * @throws ReflectionException
136
+	 */
137
+	public function currency_sign_before()
138
+	{
139
+		return (bool) $this->get('CNT_cur_sign_b4');
140
+	}
141
+
142
+
143
+	/**
144
+	 * currency_decimal_places : 2 = 0.00   3 = 0.000
145
+	 *
146
+	 * @return integer
147
+	 * @throws EE_Error
148
+	 * @throws ReflectionException
149
+	 */
150
+	public function currency_decimal_places()
151
+	{
152
+		return $this->get('CNT_cur_dec_plc');
153
+	}
154
+
155
+
156
+	/**
157
+	 * currency_decimal_mark :   (comma) ',' = 0,01   or   (decimal) '.' = 0.01
158
+	 *
159
+	 * @return string
160
+	 * @throws EE_Error
161
+	 * @throws ReflectionException
162
+	 */
163
+	public function currency_decimal_mark()
164
+	{
165
+		return $this->get('CNT_cur_dec_mrk');
166
+	}
167
+
168
+
169
+	/**
170
+	 * currency thousands separator:   (comma) ',' = 1,000   or   (decimal) '.' = 1.000
171
+	 *
172
+	 * @return string
173
+	 * @throws EE_Error
174
+	 * @throws ReflectionException
175
+	 */
176
+	public function currency_thousands_separator()
177
+	{
178
+		return $this->get('CNT_cur_thsnds');
179
+	}
180
+
181
+
182
+	/**
183
+	 * @return bool
184
+	 * @throws EE_Error
185
+	 * @throws ReflectionException
186
+	 * @since 4.10.30.p
187
+	 */
188
+	public function isEU()
189
+	{
190
+		return (bool) $this->get('CNT_is_EU');
191
+	}
192
+
193
+
194
+	/**
195
+	 * Country Telephone Code: +1
196
+	 *
197
+	 * @return string
198
+	 * @throws EE_Error
199
+	 * @throws ReflectionException
200
+	 * @since 4.10.30.p
201
+	 */
202
+	public function telephoneCode()
203
+	{
204
+		return $this->get('CNT_tel_code');
205
+	}
206
+
207
+
208
+	/**
209
+	 * @deprecated 4.10.30.p
210
+	 * @return bool
211
+	 */
212
+	public function is_active()
213
+	{
214
+		return $this->isActive();
215
+	}
216 216
 }
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/Pricing_Admin_Page.core.php 1 patch
Indentation   +1259 added lines, -1259 removed lines patch added patch discarded remove patch
@@ -12,1270 +12,1270 @@
 block discarded – undo
12 12
 class Pricing_Admin_Page extends EE_Admin_Page
13 13
 {
14 14
 
15
-    protected function _init_page_props()
16
-    {
17
-        $this->page_slug        = PRICING_PG_SLUG;
18
-        $this->page_label       = PRICING_LABEL;
19
-        $this->_admin_base_url  = PRICING_ADMIN_URL;
20
-        $this->_admin_base_path = PRICING_ADMIN;
21
-    }
22
-
23
-
24
-    protected function _ajax_hooks()
25
-    {
26
-        add_action('wp_ajax_espresso_update_prices_order', [$this, 'update_price_order']);
27
-    }
28
-
29
-
30
-    protected function _define_page_props()
31
-    {
32
-        $this->_admin_page_title = PRICING_LABEL;
33
-        $this->_labels           = [
34
-            'buttons' => [
35
-                'add'         => esc_html__('Add New Default Price', 'event_espresso'),
36
-                'edit'        => esc_html__('Edit Default Price', 'event_espresso'),
37
-                'delete'      => esc_html__('Delete Default Price', 'event_espresso'),
38
-                'add_type'    => esc_html__('Add New Default Price Type', 'event_espresso'),
39
-                'edit_type'   => esc_html__('Edit Price Type', 'event_espresso'),
40
-                'delete_type' => esc_html__('Delete Price Type', 'event_espresso'),
41
-            ],
42
-        ];
43
-    }
44
-
45
-
46
-    /**
47
-     * an array for storing request actions and their corresponding methods
48
-     *
49
-     * @return void
50
-     */
51
-    protected function _set_page_routes()
52
-    {
53
-        $PRC_ID             = $this->request->getRequestParam('PRC_ID', 0, DataType::INTEGER);
54
-        $PRT_ID             = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
55
-        $this->_page_routes = [
56
-            'default'                     => [
57
-                'func'       => '_price_overview_list_table',
58
-                'capability' => 'ee_read_default_prices',
59
-            ],
60
-            'add_new_price'               => [
61
-                'func'       => '_edit_price_details',
62
-                'args'       => ['new_price' => true],
63
-                'capability' => 'ee_edit_default_prices',
64
-            ],
65
-            'edit_price'                  => [
66
-                'func'       => '_edit_price_details',
67
-                'args'       => ['new_price' => false],
68
-                'capability' => 'ee_edit_default_price',
69
-                'obj_id'     => $PRC_ID,
70
-            ],
71
-            'insert_price'                => [
72
-                'func'       => '_insert_or_update_price',
73
-                'args'       => ['new_price' => true],
74
-                'noheader'   => true,
75
-                'capability' => 'ee_edit_default_prices',
76
-            ],
77
-            'update_price'                => [
78
-                'func'       => '_insert_or_update_price',
79
-                'args'       => ['new_price' => false],
80
-                'noheader'   => true,
81
-                'capability' => 'ee_edit_default_price',
82
-                'obj_id'     => $PRC_ID,
83
-            ],
84
-            'trash_price'                 => [
85
-                'func'       => '_trash_or_restore_price',
86
-                'args'       => ['trash' => true],
87
-                'noheader'   => true,
88
-                'capability' => 'ee_delete_default_price',
89
-                'obj_id'     => $PRC_ID,
90
-            ],
91
-            'restore_price'               => [
92
-                'func'       => '_trash_or_restore_price',
93
-                'args'       => ['trash' => false],
94
-                'noheader'   => true,
95
-                'capability' => 'ee_delete_default_price',
96
-                'obj_id'     => $PRC_ID,
97
-            ],
98
-            'delete_price'                => [
99
-                'func'       => '_delete_price',
100
-                'noheader'   => true,
101
-                'capability' => 'ee_delete_default_price',
102
-                'obj_id'     => $PRC_ID,
103
-            ],
104
-            'espresso_update_price_order' => [
105
-                'func'       => 'update_price_order',
106
-                'noheader'   => true,
107
-                'capability' => 'ee_edit_default_prices',
108
-            ],
109
-            // price types
110
-            'price_types'                 => [
111
-                'func'       => '_price_types_overview_list_table',
112
-                'capability' => 'ee_read_default_price_types',
113
-            ],
114
-            'add_new_price_type'          => [
115
-                'func'       => '_edit_price_type_details',
116
-                'capability' => 'ee_edit_default_price_types',
117
-            ],
118
-            'edit_price_type'             => [
119
-                'func'       => '_edit_price_type_details',
120
-                'capability' => 'ee_edit_default_price_type',
121
-                'obj_id'     => $PRT_ID,
122
-            ],
123
-            'insert_price_type'           => [
124
-                'func'       => '_insert_or_update_price_type',
125
-                'args'       => ['new_price_type' => true],
126
-                'noheader'   => true,
127
-                'capability' => 'ee_edit_default_price_types',
128
-            ],
129
-            'update_price_type'           => [
130
-                'func'       => '_insert_or_update_price_type',
131
-                'args'       => ['new_price_type' => false],
132
-                'noheader'   => true,
133
-                'capability' => 'ee_edit_default_price_type',
134
-                'obj_id'     => $PRT_ID,
135
-            ],
136
-            'trash_price_type'            => [
137
-                'func'       => '_trash_or_restore_price_type',
138
-                'args'       => ['trash' => true],
139
-                'noheader'   => true,
140
-                'capability' => 'ee_delete_default_price_type',
141
-                'obj_id'     => $PRT_ID,
142
-            ],
143
-            'restore_price_type'          => [
144
-                'func'       => '_trash_or_restore_price_type',
145
-                'args'       => ['trash' => false],
146
-                'noheader'   => true,
147
-                'capability' => 'ee_delete_default_price_type',
148
-                'obj_id'     => $PRT_ID,
149
-            ],
150
-            'delete_price_type'           => [
151
-                'func'       => '_delete_price_type',
152
-                'noheader'   => true,
153
-                'capability' => 'ee_delete_default_price_type',
154
-                'obj_id'     => $PRT_ID,
155
-            ],
156
-            'tax_settings'                => [
157
-                'func'       => '_tax_settings',
158
-                'capability' => 'manage_options',
159
-            ],
160
-            'update_tax_settings'         => [
161
-                'func'       => '_update_tax_settings',
162
-                'capability' => 'manage_options',
163
-                'noheader'   => true,
164
-            ],
165
-        ];
166
-    }
167
-
168
-
169
-    protected function _set_page_config()
170
-    {
171
-        $PRC_ID             = $this->request->getRequestParam('id', 0, DataType::INTEGER);
172
-        $this->_page_config = [
173
-            'default'            => [
174
-                'nav'           => [
175
-                    'label' => esc_html__('Default Pricing', 'event_espresso'),
176
-                    'order' => 10,
177
-                ],
178
-                'list_table'    => 'Prices_List_Table',
179
-                'metaboxes'     => $this->_default_espresso_metaboxes,
180
-                'help_tabs'     => [
181
-                    'pricing_default_pricing_help_tab'                           => [
182
-                        'title'    => esc_html__('Default Pricing', 'event_espresso'),
183
-                        'filename' => 'pricing_default_pricing',
184
-                    ],
185
-                    'pricing_default_pricing_table_column_headings_help_tab'     => [
186
-                        'title'    => esc_html__('Default Pricing Table Column Headings', 'event_espresso'),
187
-                        'filename' => 'pricing_default_pricing_table_column_headings',
188
-                    ],
189
-                    'pricing_default_pricing_views_bulk_actions_search_help_tab' => [
190
-                        'title'    => esc_html__('Default Pricing Views & Bulk Actions & Search', 'event_espresso'),
191
-                        'filename' => 'pricing_default_pricing_views_bulk_actions_search',
192
-                    ],
193
-                ],
194
-                'require_nonce' => false,
195
-            ],
196
-            'add_new_price'      => [
197
-                'nav'           => [
198
-                    'label'      => esc_html__('Add New Default Price', 'event_espresso'),
199
-                    'order'      => 20,
200
-                    'persistent' => false,
201
-                ],
202
-                'help_tabs'     => [
203
-                    'add_new_default_price_help_tab' => [
204
-                        'title'    => esc_html__('Add New Default Price', 'event_espresso'),
205
-                        'filename' => 'pricing_add_new_default_price',
206
-                    ],
207
-                ],
208
-                'metaboxes'     => array_merge(
209
-                    ['_publish_post_box'],
210
-                    $this->_default_espresso_metaboxes
211
-                ),
212
-                'require_nonce' => false,
213
-            ],
214
-            'edit_price'         => [
215
-                'nav'           => [
216
-                    'label'      => esc_html__('Edit Default Price', 'event_espresso'),
217
-                    'order'      => 20,
218
-                    'url'        => $PRC_ID
219
-                        ? add_query_arg(['id' => $PRC_ID], $this->_current_page_view_url)
220
-                        : $this->_admin_base_url,
221
-                    'persistent' => false,
222
-                ],
223
-                'metaboxes'     => array_merge(
224
-                    ['_publish_post_box'],
225
-                    $this->_default_espresso_metaboxes
226
-                ),
227
-                'help_tabs'     => [
228
-                    'edit_default_price_help_tab' => [
229
-                        'title'    => esc_html__('Edit Default Price', 'event_espresso'),
230
-                        'filename' => 'pricing_edit_default_price',
231
-                    ],
232
-                ],
233
-                'require_nonce' => false,
234
-            ],
235
-            'price_types'        => [
236
-                'nav'           => [
237
-                    'label' => esc_html__('Price Types', 'event_espresso'),
238
-                    'order' => 30,
239
-                ],
240
-                'list_table'    => 'Price_Types_List_Table',
241
-                'help_tabs'     => [
242
-                    'pricing_price_types_help_tab'                           => [
243
-                        'title'    => esc_html__('Price Types', 'event_espresso'),
244
-                        'filename' => 'pricing_price_types',
245
-                    ],
246
-                    'pricing_price_types_table_column_headings_help_tab'     => [
247
-                        'title'    => esc_html__('Price Types Table Column Headings', 'event_espresso'),
248
-                        'filename' => 'pricing_price_types_table_column_headings',
249
-                    ],
250
-                    'pricing_price_types_views_bulk_actions_search_help_tab' => [
251
-                        'title'    => esc_html__('Price Types Views & Bulk Actions & Search', 'event_espresso'),
252
-                        'filename' => 'pricing_price_types_views_bulk_actions_search',
253
-                    ],
254
-                ],
255
-                'metaboxes'     => $this->_default_espresso_metaboxes,
256
-                'require_nonce' => false,
257
-            ],
258
-            'add_new_price_type' => [
259
-                'nav'           => [
260
-                    'label'      => esc_html__('Add New Price Type', 'event_espresso'),
261
-                    'order'      => 40,
262
-                    'persistent' => false,
263
-                ],
264
-                'help_tabs'     => [
265
-                    'add_new_price_type_help_tab' => [
266
-                        'title'    => esc_html__('Add New Price Type', 'event_espresso'),
267
-                        'filename' => 'pricing_add_new_price_type',
268
-                    ],
269
-                ],
270
-                'metaboxes'     => array_merge(
271
-                    ['_publish_post_box'],
272
-                    $this->_default_espresso_metaboxes
273
-                ),
274
-                'require_nonce' => false,
275
-            ],
276
-            'edit_price_type'    => [
277
-                'nav'           => [
278
-                    'label'      => esc_html__('Edit Price Type', 'event_espresso'),
279
-                    'order'      => 40,
280
-                    'persistent' => false,
281
-                ],
282
-                'help_tabs'     => [
283
-                    'edit_price_type_help_tab' => [
284
-                        'title'    => esc_html__('Edit Price Type', 'event_espresso'),
285
-                        'filename' => 'pricing_edit_price_type',
286
-                    ],
287
-                ],
288
-                'metaboxes'     => array_merge(
289
-                    ['_publish_post_box'],
290
-                    $this->_default_espresso_metaboxes
291
-                ),
292
-                'require_nonce' => false,
293
-            ],
294
-            'tax_settings'       => [
295
-                'nav'           => [
296
-                    'label' => esc_html__('Tax Settings', 'event_espresso'),
297
-                    'order' => 40,
298
-                ],
299
-                'labels'        => [
300
-                    'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'),
301
-                ],
302
-                'metaboxes'     => array_merge(
303
-                    ['_publish_post_box'],
304
-                    $this->_default_espresso_metaboxes
305
-                ),
306
-                'require_nonce' => true,
307
-            ],
308
-        ];
309
-    }
310
-
311
-
312
-    protected function _add_screen_options()
313
-    {
314
-        // todo
315
-    }
316
-
317
-
318
-    protected function _add_screen_options_default()
319
-    {
320
-        $this->_per_page_screen_option();
321
-    }
322
-
323
-
324
-    protected function _add_screen_options_price_types()
325
-    {
326
-        $page_title              = $this->_admin_page_title;
327
-        $this->_admin_page_title = esc_html__('Price Types', 'event_espresso');
328
-        $this->_per_page_screen_option();
329
-        $this->_admin_page_title = $page_title;
330
-    }
331
-
332
-
333
-    protected function _add_feature_pointers()
334
-    {
335
-    }
336
-
337
-
338
-    public function load_scripts_styles()
339
-    {
340
-        // styles
341
-        wp_enqueue_style('espresso-ui-theme');
342
-        wp_register_style(
343
-            'espresso_PRICING',
344
-            PRICING_ASSETS_URL . 'espresso_pricing_admin.css',
345
-            [],
346
-            EVENT_ESPRESSO_VERSION
347
-        );
348
-        wp_enqueue_style('espresso_PRICING');
349
-
350
-        // scripts
351
-        wp_enqueue_script('ee_admin_js');
352
-        wp_enqueue_script('jquery-ui-position');
353
-        wp_enqueue_script('jquery-ui-widget');
354
-        wp_register_script(
355
-            'espresso_PRICING',
356
-            PRICING_ASSETS_URL . 'espresso_pricing_admin.js',
357
-            ['jquery'],
358
-            EVENT_ESPRESSO_VERSION,
359
-            true
360
-        );
361
-        wp_enqueue_script('espresso_PRICING');
362
-    }
363
-
364
-
365
-    public function load_scripts_styles_default()
366
-    {
367
-        wp_enqueue_script('espresso_ajax_table_sorting');
368
-    }
369
-
370
-
371
-    public function admin_footer_scripts()
372
-    {
373
-    }
374
-
375
-
376
-    public function admin_init()
377
-    {
378
-    }
379
-
380
-
381
-    public function admin_notices()
382
-    {
383
-    }
384
-
385
-
386
-    protected function _set_list_table_views_default()
387
-    {
388
-        $this->_views = [
389
-            'all' => [
390
-                'slug'        => 'all',
391
-                'label'       => esc_html__('View All Default Pricing', 'event_espresso'),
392
-                'count'       => 0,
393
-                'bulk_action' => [
394
-                    'trash_price' => esc_html__('Move to Trash', 'event_espresso'),
395
-                ],
396
-            ],
397
-        ];
398
-
399
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) {
400
-            $this->_views['trashed'] = [
401
-                'slug'        => 'trashed',
402
-                'label'       => esc_html__('Trash', 'event_espresso'),
403
-                'count'       => 0,
404
-                'bulk_action' => [
405
-                    'restore_price' => esc_html__('Restore from Trash', 'event_espresso'),
406
-                    'delete_price'  => esc_html__('Delete Permanently', 'event_espresso'),
407
-                ],
408
-            ];
409
-        }
410
-    }
411
-
412
-
413
-    protected function _set_list_table_views_price_types()
414
-    {
415
-        $this->_views = [
416
-            'all' => [
417
-                'slug'        => 'all',
418
-                'label'       => esc_html__('All', 'event_espresso'),
419
-                'count'       => 0,
420
-                'bulk_action' => [
421
-                    'trash_price_type' => esc_html__('Move to Trash', 'event_espresso'),
422
-                ],
423
-            ],
424
-        ];
425
-
426
-        if (
427
-            EE_Registry::instance()->CAP->current_user_can(
428
-                'ee_delete_default_price_types',
429
-                'pricing_trash_price_type'
430
-            )
431
-        ) {
432
-            $this->_views['trashed'] = [
433
-                'slug'        => 'trashed',
434
-                'label'       => esc_html__('Trash', 'event_espresso'),
435
-                'count'       => 0,
436
-                'bulk_action' => [
437
-                    'restore_price_type' => esc_html__('Restore from Trash', 'event_espresso'),
438
-                    'delete_price_type'  => esc_html__('Delete Permanently', 'event_espresso'),
439
-                ],
440
-            ];
441
-        }
442
-    }
443
-
444
-
445
-    /**
446
-     * generates HTML for main Prices Admin page
447
-     *
448
-     * @return void
449
-     * @throws EE_Error
450
-     */
451
-    protected function _price_overview_list_table()
452
-    {
453
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
454
-            'add_new_price',
455
-            'add',
456
-            [],
457
-            'add-new-h2'
458
-        );
459
-        $this->_admin_page_title .= $this->_learn_more_about_pricing_link();
460
-        $this->_search_btn_label = esc_html__('Default Prices', 'event_espresso');
461
-        $this->display_admin_list_table_page_with_sidebar();
462
-    }
463
-
464
-
465
-    /**
466
-     * retrieve data for Prices List table
467
-     *
468
-     * @param int  $per_page how many prices displayed per page
469
-     * @param bool $count    return the count or objects
470
-     * @param bool $trashed  whether the current view is of the trash can - eww yuck!
471
-     * @return EE_Soft_Delete_Base_Class[]|int int = count || array of price objects
472
-     * @throws EE_Error
473
-     * @throws ReflectionException
474
-     */
475
-    public function get_prices_overview_data(int $per_page = 10, bool $count = false, bool $trashed = false)
476
-    {
477
-        // start with an empty array
478
-        $event_pricing = [];
479
-
480
-        require_once(PRICING_ADMIN . 'Prices_List_Table.class.php');
481
-
482
-        $orderby = $this->request->getRequestParam('orderby', '');
483
-        $order   = $this->request->getRequestParam('order', 'ASC');
484
-
485
-        switch ($orderby) {
486
-            case 'name':
487
-                $orderby = ['PRC_name' => $order];
488
-                break;
489
-            case 'type':
490
-                $orderby = ['Price_Type.PRT_name' => $order];
491
-                break;
492
-            case 'amount':
493
-                $orderby = ['PRC_amount' => $order];
494
-                break;
495
-            default:
496
-                $orderby = ['PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order];
497
-        }
498
-
499
-        $current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
500
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
501
-
502
-        $where = [
503
-            'PRC_is_default' => 1,
504
-            'PRC_deleted'    => $trashed,
505
-        ];
506
-
507
-        $offset = ($current_page - 1) * $per_page;
508
-        $limit  = [$offset, $per_page];
509
-
510
-        $search_term = $this->request->getRequestParam('s');
511
-        if ($search_term) {
512
-            $search_term = "%{$search_term}%";
513
-            $where['OR'] = [
514
-                'PRC_name'            => ['LIKE', $search_term],
515
-                'PRC_desc'            => ['LIKE', $search_term],
516
-                'PRC_amount'          => ['LIKE', $search_term],
517
-                'Price_Type.PRT_name' => ['LIKE', $search_term],
518
-            ];
519
-        }
520
-
521
-        $query_params = [
522
-            $where,
523
-            'order_by' => $orderby,
524
-            'limit'    => $limit,
525
-            'group_by' => 'PRC_ID',
526
-        ];
527
-
528
-        if ($count) {
529
-            return $trashed
530
-                ? EEM_Price::instance()->count([$where])
531
-                : EEM_Price::instance()->count_deleted_and_undeleted([$where]);
532
-        }
533
-        return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params);
534
-    }
535
-
536
-
537
-    /**
538
-     * @return void
539
-     * @throws EE_Error
540
-     * @throws ReflectionException
541
-     */
542
-    protected function _edit_price_details()
543
-    {
544
-        // grab price ID
545
-        $PRC_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
546
-        // change page title based on request action
547
-        switch ($this->_req_action) {
548
-            case 'add_new_price':
549
-                $this->_admin_page_title = esc_html__('Add New Price', 'event_espresso');
550
-                break;
551
-            case 'edit_price':
552
-                $this->_admin_page_title = esc_html__('Edit Price', 'event_espresso');
553
-                break;
554
-            default:
555
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
556
-        }
557
-        // add PRC_ID to title if editing
558
-        $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title;
559
-
560
-        if ($PRC_ID) {
561
-            $price                    = EEM_Price::instance()->get_one_by_ID($PRC_ID);
562
-            $additional_hidden_fields = [
563
-                'PRC_ID' => ['type' => 'hidden', 'value' => $PRC_ID],
564
-            ];
565
-            $this->_set_add_edit_form_tags('update_price', $additional_hidden_fields);
566
-        } else {
567
-            $price = EEM_Price::instance()->get_new_price();
568
-            $this->_set_add_edit_form_tags('insert_price');
569
-        }
570
-
571
-        if (! $price instanceof EE_Price) {
572
-            throw new RuntimeException(
573
-                sprintf(
574
-                    esc_html__(
575
-                        'A valid Price could not be retrieved from the database with ID: %1$s',
576
-                        'event_espresso'
577
-                    ),
578
-                    $PRC_ID
579
-                )
580
-            );
581
-        }
582
-
583
-        $this->_template_args['PRC_ID'] = $PRC_ID;
584
-        $this->_template_args['price']  = $price;
585
-
586
-        $default_base_price = $price->type_obj() && $price->type_obj()->base_type() === 1;
587
-
588
-        $this->_template_args['default_base_price'] = $default_base_price;
589
-
590
-        // get price types
591
-        $price_types = EEM_Price_Type::instance()->get_all([['PBT_ID' => ['!=', 1]]]);
592
-        if (empty($price_types)) {
593
-            $msg = esc_html__(
594
-                'You have no price types defined. Please add a price type before adding a price.',
595
-                'event_espresso'
596
-            );
597
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
598
-            $this->display_admin_page_with_sidebar();
599
-        }
600
-        $attributes       = [];
601
-        $price_type_names = [];
602
-        $attributes[]     = 'id="PRT_ID"';
603
-        if ($default_base_price) {
604
-            $attributes[]       = 'disabled="disabled"';
605
-            $price_type_names[] = ['id' => 1, 'text' => esc_html__('Base Price', 'event_espresso')];
606
-        }
607
-        foreach ($price_types as $type) {
608
-            $price_type_names[] = ['id' => $type->ID(), 'text' => $type->name()];
609
-        }
610
-        $this->_template_args['attributes']  = implode(' ', $attributes);
611
-        $this->_template_args['price_types'] = $price_type_names;
612
-
613
-        $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
614
-        $this->_template_args['admin_page_content']            = $this->_edit_price_details_meta_box();
615
-
616
-        $this->_set_publish_post_box_vars('id', $PRC_ID);
617
-        // the details template wrapper
618
-        $this->display_admin_page_with_sidebar();
619
-    }
620
-
621
-
622
-    /**
623
-     *
624
-     * @return string
625
-     */
626
-    public function _edit_price_details_meta_box(): string
627
-    {
628
-        return EEH_Template::display_template(
629
-            PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php',
630
-            $this->_template_args,
631
-            true
632
-        );
633
-    }
634
-
635
-
636
-    /**
637
-     * @return array
638
-     * @throws EE_Error
639
-     * @throws ReflectionException
640
-     */
641
-    protected function set_price_column_values(): array
642
-    {
643
-        $PRC_order = 0;
644
-        $PRT_ID    = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
645
-        if ($PRT_ID) {
646
-            /** @var EE_Price_Type $price_type */
647
-            $price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
648
-            if ($price_type instanceof EE_Price_Type) {
649
-                $PRC_order = $price_type->order();
650
-            }
651
-        }
652
-        return [
653
-            'PRT_ID'         => $PRT_ID,
654
-            'PRC_amount'     => $this->request->getRequestParam('PRC_amount', 0, DataType::FLOAT),
655
-            'PRC_name'       => $this->request->getRequestParam('PRC_name'),
656
-            'PRC_desc'       => $this->request->getRequestParam('PRC_desc'),
657
-            'PRC_is_default' => 1,
658
-            'PRC_overrides'  => null,
659
-            'PRC_order'      => $PRC_order,
660
-            'PRC_deleted'    => 0,
661
-            'PRC_parent'     => 0,
662
-        ];
663
-    }
664
-
665
-
666
-    /**
667
-     * @param bool $insert - whether to insert or update
668
-     * @return void
669
-     * @throws EE_Error
670
-     * @throws ReflectionException
671
-     */
672
-    protected function _insert_or_update_price(bool $insert = false)
673
-    {
674
-        // why be so pessimistic ???  : (
675
-        $updated = 0;
676
-
677
-        $set_column_values = $this->set_price_column_values();
678
-        // is this a new Price ?
679
-        if ($insert) {
680
-            // run the insert
681
-            $PRC_ID = EEM_Price::instance()->insert($set_column_values);
682
-            if ($PRC_ID) {
683
-                // make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type
684
-                $price = EEM_price::instance()->get_one_by_ID($PRC_ID);
685
-                if (
686
-                    $price instanceof EE_Price
687
-                    && $price->type_obj() instanceof EE_Price_type
688
-                    && $price->type_obj()->base_type() !== EEM_Price_Type::base_type_tax
689
-                ) {
690
-                    $ticket = EEM_Ticket::instance()->get_one_by_ID(1);
691
-                    $ticket->_add_relation_to($price, 'Price');
692
-                    $ticket->save();
693
-                }
694
-                $updated = 1;
695
-            }
696
-            $action_desc = 'created';
697
-        } else {
698
-            $PRC_ID = $this->request->getRequestParam('PRC_ID', 0, DataType::INTEGER);
699
-            // run the update
700
-            $where_cols_n_values = ['PRC_ID' => $PRC_ID];
701
-            $updated             = EEM_Price::instance()->update($set_column_values, [$where_cols_n_values]);
702
-
703
-            $price = EEM_Price::instance()->get_one_by_ID($PRC_ID);
704
-            if ($price instanceof EE_Price && $price->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
705
-                // if this is $PRC_ID == 1,
706
-                // then we need to update the default ticket attached to this price so the TKT_price value is updated.
707
-                if ($PRC_ID === 1) {
708
-                    $ticket = $price->get_first_related('Ticket');
709
-                    if ($ticket) {
710
-                        $ticket->set('TKT_price', $price->get('PRC_amount'));
711
-                        $ticket->set('TKT_name', $price->get('PRC_name'));
712
-                        $ticket->set('TKT_description', $price->get('PRC_desc'));
713
-                        $ticket->save();
714
-                    }
715
-                } else {
716
-                    // we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type.
717
-                    $ticket = EEM_Ticket::instance()->get_one_by_ID(1);
718
-                    $ticket->_add_relation_to($PRC_ID, 'Price');
719
-                    $ticket->save();
720
-                }
721
-            }
722
-
723
-            $action_desc = 'updated';
724
-        }
725
-
726
-        $query_args = ['action' => 'edit_price', 'id' => $PRC_ID];
727
-
728
-        $this->_redirect_after_action($updated, 'Prices', $action_desc, $query_args);
729
-    }
730
-
731
-
732
-    /**
733
-     * @param bool $trash - whether to move item to trash (TRUE) or restore it (FALSE)
734
-     * @return void
735
-     * @throws EE_Error
736
-     * @throws ReflectionException
737
-     */
738
-    protected function _trash_or_restore_price(bool $trash = true)
739
-    {
740
-        $entity_model = EEM_Price::instance();
741
-        $action       = $trash ? EE_Admin_List_Table::ACTION_TRASH : EE_Admin_List_Table::ACTION_RESTORE;
742
-        $result       = $this->trashRestoreDeleteEntities(
743
-            $entity_model,
744
-            'id',
745
-            $action,
746
-            'PRC_deleted',
747
-            [$this, 'adjustTicketRelations']
748
-        );
749
-
750
-        if ($result) {
751
-            $msg = $trash
752
-                ? esc_html(
753
-                    _n(
754
-                        'The Price has been trashed',
755
-                        'The Prices have been trashed',
756
-                        $result,
757
-                        'event_espresso'
758
-                    )
759
-                )
760
-                : esc_html(
761
-                    _n(
762
-                        'The Price has been restored',
763
-                        'The Prices have been restored',
764
-                        $result,
765
-                        'event_espresso'
766
-                    )
767
-                );
768
-            EE_Error::add_success($msg);
769
-        }
770
-
771
-        $this->_redirect_after_action(
772
-            $result,
773
-            _n('Price', 'Prices', $result, 'event_espresso'),
774
-            $trash ? 'trashed' : 'restored',
775
-            ['action' => 'default'],
776
-            true
777
-        );
778
-    }
779
-
780
-
781
-    /**
782
-     * @param EEM_Base   $entity_model
783
-     * @param int|string $entity_ID
784
-     * @param string     $action
785
-     * @param int        $result
786
-     * @throws EE_Error
787
-     * @throws ReflectionException
788
-     * @since 4.10.30.p
789
-     */
790
-    public function adjustTicketRelations(EEM_Base $entity_model, $entity_ID, string $action, int $result)
791
-    {
792
-        if (! $entity_ID || (float) $result < 1) {
793
-            return;
794
-        }
795
-
796
-        $entity = $entity_model->get_one_by_ID($entity_ID);
797
-        if (! $entity instanceof EE_Price || $entity->type_obj()->base_type() === EEM_Price_Type::base_type_tax) {
798
-            return;
799
-        }
800
-
801
-        // get default tickets for updating
802
-        $default_tickets = EEM_Ticket::instance()->get_all_default_tickets();
803
-        foreach ($default_tickets as $default_ticket) {
804
-            if (! $default_ticket instanceof EE_Ticket) {
805
-                continue;
806
-            }
807
-            switch ($action) {
808
-                case EE_Admin_List_Table::ACTION_DELETE:
809
-                case EE_Admin_List_Table::ACTION_TRASH:
810
-                    // if trashing then remove relations to base default ticket.
811
-                    $default_ticket->_remove_relation_to($entity_ID, 'Price');
812
-                    break;
813
-                case EE_Admin_List_Table::ACTION_RESTORE:
814
-                    // if restoring then add back to base default ticket
815
-                    $default_ticket->_add_relation_to($entity_ID, 'Price');
816
-                    break;
817
-            }
818
-            $default_ticket->save();
819
-        }
820
-    }
821
-
822
-
823
-    /**
824
-     * @return void
825
-     * @throws EE_Error
826
-     * @throws ReflectionException
827
-     */
828
-    protected function _delete_price()
829
-    {
830
-        $entity_model = EEM_Price::instance();
831
-        $deleted      = $this->trashRestoreDeleteEntities($entity_model, 'id');
832
-        $entity       = $entity_model->item_name($deleted);
833
-        $this->_redirect_after_action($deleted, $entity, 'deleted', ['action' => 'default']);
834
-    }
835
-
836
-
837
-    /**
838
-     * @throws EE_Error
839
-     * @throws ReflectionException
840
-     */
841
-    public function update_price_order()
842
-    {
843
-        // grab our row IDs
844
-        $row_ids = $this->request->getRequestParam('row_ids', '');
845
-        $row_ids = explode(',', rtrim($row_ids, ','));
846
-
847
-        $all_updated = true;
848
-        foreach ($row_ids as $i => $row_id) {
849
-            // Update the prices when re-ordering
850
-            $fields_n_values = ['PRC_order' => $i + 1];
851
-            $query_params    = [['PRC_ID' => absint($row_id)]];
852
-            // any failure will toggle $all_updated to false
853
-            $all_updated = $row_id && EEM_Price::instance()->update($fields_n_values, $query_params) !== false
854
-                ? $all_updated
855
-                : false;
856
-        }
857
-        $success = $all_updated ? esc_html__('Price order was updated successfully.', 'event_espresso') : false;
858
-        $errors  = ! $all_updated ? esc_html__('An error occurred. The price order was not updated.', 'event_espresso')
859
-            : false;
860
-
861
-        echo wp_json_encode(['return_data' => false, 'success' => $success, 'errors' => $errors]);
862
-        die();
863
-    }
864
-
865
-
866
-    /******************************************************************************************************************
15
+	protected function _init_page_props()
16
+	{
17
+		$this->page_slug        = PRICING_PG_SLUG;
18
+		$this->page_label       = PRICING_LABEL;
19
+		$this->_admin_base_url  = PRICING_ADMIN_URL;
20
+		$this->_admin_base_path = PRICING_ADMIN;
21
+	}
22
+
23
+
24
+	protected function _ajax_hooks()
25
+	{
26
+		add_action('wp_ajax_espresso_update_prices_order', [$this, 'update_price_order']);
27
+	}
28
+
29
+
30
+	protected function _define_page_props()
31
+	{
32
+		$this->_admin_page_title = PRICING_LABEL;
33
+		$this->_labels           = [
34
+			'buttons' => [
35
+				'add'         => esc_html__('Add New Default Price', 'event_espresso'),
36
+				'edit'        => esc_html__('Edit Default Price', 'event_espresso'),
37
+				'delete'      => esc_html__('Delete Default Price', 'event_espresso'),
38
+				'add_type'    => esc_html__('Add New Default Price Type', 'event_espresso'),
39
+				'edit_type'   => esc_html__('Edit Price Type', 'event_espresso'),
40
+				'delete_type' => esc_html__('Delete Price Type', 'event_espresso'),
41
+			],
42
+		];
43
+	}
44
+
45
+
46
+	/**
47
+	 * an array for storing request actions and their corresponding methods
48
+	 *
49
+	 * @return void
50
+	 */
51
+	protected function _set_page_routes()
52
+	{
53
+		$PRC_ID             = $this->request->getRequestParam('PRC_ID', 0, DataType::INTEGER);
54
+		$PRT_ID             = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
55
+		$this->_page_routes = [
56
+			'default'                     => [
57
+				'func'       => '_price_overview_list_table',
58
+				'capability' => 'ee_read_default_prices',
59
+			],
60
+			'add_new_price'               => [
61
+				'func'       => '_edit_price_details',
62
+				'args'       => ['new_price' => true],
63
+				'capability' => 'ee_edit_default_prices',
64
+			],
65
+			'edit_price'                  => [
66
+				'func'       => '_edit_price_details',
67
+				'args'       => ['new_price' => false],
68
+				'capability' => 'ee_edit_default_price',
69
+				'obj_id'     => $PRC_ID,
70
+			],
71
+			'insert_price'                => [
72
+				'func'       => '_insert_or_update_price',
73
+				'args'       => ['new_price' => true],
74
+				'noheader'   => true,
75
+				'capability' => 'ee_edit_default_prices',
76
+			],
77
+			'update_price'                => [
78
+				'func'       => '_insert_or_update_price',
79
+				'args'       => ['new_price' => false],
80
+				'noheader'   => true,
81
+				'capability' => 'ee_edit_default_price',
82
+				'obj_id'     => $PRC_ID,
83
+			],
84
+			'trash_price'                 => [
85
+				'func'       => '_trash_or_restore_price',
86
+				'args'       => ['trash' => true],
87
+				'noheader'   => true,
88
+				'capability' => 'ee_delete_default_price',
89
+				'obj_id'     => $PRC_ID,
90
+			],
91
+			'restore_price'               => [
92
+				'func'       => '_trash_or_restore_price',
93
+				'args'       => ['trash' => false],
94
+				'noheader'   => true,
95
+				'capability' => 'ee_delete_default_price',
96
+				'obj_id'     => $PRC_ID,
97
+			],
98
+			'delete_price'                => [
99
+				'func'       => '_delete_price',
100
+				'noheader'   => true,
101
+				'capability' => 'ee_delete_default_price',
102
+				'obj_id'     => $PRC_ID,
103
+			],
104
+			'espresso_update_price_order' => [
105
+				'func'       => 'update_price_order',
106
+				'noheader'   => true,
107
+				'capability' => 'ee_edit_default_prices',
108
+			],
109
+			// price types
110
+			'price_types'                 => [
111
+				'func'       => '_price_types_overview_list_table',
112
+				'capability' => 'ee_read_default_price_types',
113
+			],
114
+			'add_new_price_type'          => [
115
+				'func'       => '_edit_price_type_details',
116
+				'capability' => 'ee_edit_default_price_types',
117
+			],
118
+			'edit_price_type'             => [
119
+				'func'       => '_edit_price_type_details',
120
+				'capability' => 'ee_edit_default_price_type',
121
+				'obj_id'     => $PRT_ID,
122
+			],
123
+			'insert_price_type'           => [
124
+				'func'       => '_insert_or_update_price_type',
125
+				'args'       => ['new_price_type' => true],
126
+				'noheader'   => true,
127
+				'capability' => 'ee_edit_default_price_types',
128
+			],
129
+			'update_price_type'           => [
130
+				'func'       => '_insert_or_update_price_type',
131
+				'args'       => ['new_price_type' => false],
132
+				'noheader'   => true,
133
+				'capability' => 'ee_edit_default_price_type',
134
+				'obj_id'     => $PRT_ID,
135
+			],
136
+			'trash_price_type'            => [
137
+				'func'       => '_trash_or_restore_price_type',
138
+				'args'       => ['trash' => true],
139
+				'noheader'   => true,
140
+				'capability' => 'ee_delete_default_price_type',
141
+				'obj_id'     => $PRT_ID,
142
+			],
143
+			'restore_price_type'          => [
144
+				'func'       => '_trash_or_restore_price_type',
145
+				'args'       => ['trash' => false],
146
+				'noheader'   => true,
147
+				'capability' => 'ee_delete_default_price_type',
148
+				'obj_id'     => $PRT_ID,
149
+			],
150
+			'delete_price_type'           => [
151
+				'func'       => '_delete_price_type',
152
+				'noheader'   => true,
153
+				'capability' => 'ee_delete_default_price_type',
154
+				'obj_id'     => $PRT_ID,
155
+			],
156
+			'tax_settings'                => [
157
+				'func'       => '_tax_settings',
158
+				'capability' => 'manage_options',
159
+			],
160
+			'update_tax_settings'         => [
161
+				'func'       => '_update_tax_settings',
162
+				'capability' => 'manage_options',
163
+				'noheader'   => true,
164
+			],
165
+		];
166
+	}
167
+
168
+
169
+	protected function _set_page_config()
170
+	{
171
+		$PRC_ID             = $this->request->getRequestParam('id', 0, DataType::INTEGER);
172
+		$this->_page_config = [
173
+			'default'            => [
174
+				'nav'           => [
175
+					'label' => esc_html__('Default Pricing', 'event_espresso'),
176
+					'order' => 10,
177
+				],
178
+				'list_table'    => 'Prices_List_Table',
179
+				'metaboxes'     => $this->_default_espresso_metaboxes,
180
+				'help_tabs'     => [
181
+					'pricing_default_pricing_help_tab'                           => [
182
+						'title'    => esc_html__('Default Pricing', 'event_espresso'),
183
+						'filename' => 'pricing_default_pricing',
184
+					],
185
+					'pricing_default_pricing_table_column_headings_help_tab'     => [
186
+						'title'    => esc_html__('Default Pricing Table Column Headings', 'event_espresso'),
187
+						'filename' => 'pricing_default_pricing_table_column_headings',
188
+					],
189
+					'pricing_default_pricing_views_bulk_actions_search_help_tab' => [
190
+						'title'    => esc_html__('Default Pricing Views & Bulk Actions & Search', 'event_espresso'),
191
+						'filename' => 'pricing_default_pricing_views_bulk_actions_search',
192
+					],
193
+				],
194
+				'require_nonce' => false,
195
+			],
196
+			'add_new_price'      => [
197
+				'nav'           => [
198
+					'label'      => esc_html__('Add New Default Price', 'event_espresso'),
199
+					'order'      => 20,
200
+					'persistent' => false,
201
+				],
202
+				'help_tabs'     => [
203
+					'add_new_default_price_help_tab' => [
204
+						'title'    => esc_html__('Add New Default Price', 'event_espresso'),
205
+						'filename' => 'pricing_add_new_default_price',
206
+					],
207
+				],
208
+				'metaboxes'     => array_merge(
209
+					['_publish_post_box'],
210
+					$this->_default_espresso_metaboxes
211
+				),
212
+				'require_nonce' => false,
213
+			],
214
+			'edit_price'         => [
215
+				'nav'           => [
216
+					'label'      => esc_html__('Edit Default Price', 'event_espresso'),
217
+					'order'      => 20,
218
+					'url'        => $PRC_ID
219
+						? add_query_arg(['id' => $PRC_ID], $this->_current_page_view_url)
220
+						: $this->_admin_base_url,
221
+					'persistent' => false,
222
+				],
223
+				'metaboxes'     => array_merge(
224
+					['_publish_post_box'],
225
+					$this->_default_espresso_metaboxes
226
+				),
227
+				'help_tabs'     => [
228
+					'edit_default_price_help_tab' => [
229
+						'title'    => esc_html__('Edit Default Price', 'event_espresso'),
230
+						'filename' => 'pricing_edit_default_price',
231
+					],
232
+				],
233
+				'require_nonce' => false,
234
+			],
235
+			'price_types'        => [
236
+				'nav'           => [
237
+					'label' => esc_html__('Price Types', 'event_espresso'),
238
+					'order' => 30,
239
+				],
240
+				'list_table'    => 'Price_Types_List_Table',
241
+				'help_tabs'     => [
242
+					'pricing_price_types_help_tab'                           => [
243
+						'title'    => esc_html__('Price Types', 'event_espresso'),
244
+						'filename' => 'pricing_price_types',
245
+					],
246
+					'pricing_price_types_table_column_headings_help_tab'     => [
247
+						'title'    => esc_html__('Price Types Table Column Headings', 'event_espresso'),
248
+						'filename' => 'pricing_price_types_table_column_headings',
249
+					],
250
+					'pricing_price_types_views_bulk_actions_search_help_tab' => [
251
+						'title'    => esc_html__('Price Types Views & Bulk Actions & Search', 'event_espresso'),
252
+						'filename' => 'pricing_price_types_views_bulk_actions_search',
253
+					],
254
+				],
255
+				'metaboxes'     => $this->_default_espresso_metaboxes,
256
+				'require_nonce' => false,
257
+			],
258
+			'add_new_price_type' => [
259
+				'nav'           => [
260
+					'label'      => esc_html__('Add New Price Type', 'event_espresso'),
261
+					'order'      => 40,
262
+					'persistent' => false,
263
+				],
264
+				'help_tabs'     => [
265
+					'add_new_price_type_help_tab' => [
266
+						'title'    => esc_html__('Add New Price Type', 'event_espresso'),
267
+						'filename' => 'pricing_add_new_price_type',
268
+					],
269
+				],
270
+				'metaboxes'     => array_merge(
271
+					['_publish_post_box'],
272
+					$this->_default_espresso_metaboxes
273
+				),
274
+				'require_nonce' => false,
275
+			],
276
+			'edit_price_type'    => [
277
+				'nav'           => [
278
+					'label'      => esc_html__('Edit Price Type', 'event_espresso'),
279
+					'order'      => 40,
280
+					'persistent' => false,
281
+				],
282
+				'help_tabs'     => [
283
+					'edit_price_type_help_tab' => [
284
+						'title'    => esc_html__('Edit Price Type', 'event_espresso'),
285
+						'filename' => 'pricing_edit_price_type',
286
+					],
287
+				],
288
+				'metaboxes'     => array_merge(
289
+					['_publish_post_box'],
290
+					$this->_default_espresso_metaboxes
291
+				),
292
+				'require_nonce' => false,
293
+			],
294
+			'tax_settings'       => [
295
+				'nav'           => [
296
+					'label' => esc_html__('Tax Settings', 'event_espresso'),
297
+					'order' => 40,
298
+				],
299
+				'labels'        => [
300
+					'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'),
301
+				],
302
+				'metaboxes'     => array_merge(
303
+					['_publish_post_box'],
304
+					$this->_default_espresso_metaboxes
305
+				),
306
+				'require_nonce' => true,
307
+			],
308
+		];
309
+	}
310
+
311
+
312
+	protected function _add_screen_options()
313
+	{
314
+		// todo
315
+	}
316
+
317
+
318
+	protected function _add_screen_options_default()
319
+	{
320
+		$this->_per_page_screen_option();
321
+	}
322
+
323
+
324
+	protected function _add_screen_options_price_types()
325
+	{
326
+		$page_title              = $this->_admin_page_title;
327
+		$this->_admin_page_title = esc_html__('Price Types', 'event_espresso');
328
+		$this->_per_page_screen_option();
329
+		$this->_admin_page_title = $page_title;
330
+	}
331
+
332
+
333
+	protected function _add_feature_pointers()
334
+	{
335
+	}
336
+
337
+
338
+	public function load_scripts_styles()
339
+	{
340
+		// styles
341
+		wp_enqueue_style('espresso-ui-theme');
342
+		wp_register_style(
343
+			'espresso_PRICING',
344
+			PRICING_ASSETS_URL . 'espresso_pricing_admin.css',
345
+			[],
346
+			EVENT_ESPRESSO_VERSION
347
+		);
348
+		wp_enqueue_style('espresso_PRICING');
349
+
350
+		// scripts
351
+		wp_enqueue_script('ee_admin_js');
352
+		wp_enqueue_script('jquery-ui-position');
353
+		wp_enqueue_script('jquery-ui-widget');
354
+		wp_register_script(
355
+			'espresso_PRICING',
356
+			PRICING_ASSETS_URL . 'espresso_pricing_admin.js',
357
+			['jquery'],
358
+			EVENT_ESPRESSO_VERSION,
359
+			true
360
+		);
361
+		wp_enqueue_script('espresso_PRICING');
362
+	}
363
+
364
+
365
+	public function load_scripts_styles_default()
366
+	{
367
+		wp_enqueue_script('espresso_ajax_table_sorting');
368
+	}
369
+
370
+
371
+	public function admin_footer_scripts()
372
+	{
373
+	}
374
+
375
+
376
+	public function admin_init()
377
+	{
378
+	}
379
+
380
+
381
+	public function admin_notices()
382
+	{
383
+	}
384
+
385
+
386
+	protected function _set_list_table_views_default()
387
+	{
388
+		$this->_views = [
389
+			'all' => [
390
+				'slug'        => 'all',
391
+				'label'       => esc_html__('View All Default Pricing', 'event_espresso'),
392
+				'count'       => 0,
393
+				'bulk_action' => [
394
+					'trash_price' => esc_html__('Move to Trash', 'event_espresso'),
395
+				],
396
+			],
397
+		];
398
+
399
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) {
400
+			$this->_views['trashed'] = [
401
+				'slug'        => 'trashed',
402
+				'label'       => esc_html__('Trash', 'event_espresso'),
403
+				'count'       => 0,
404
+				'bulk_action' => [
405
+					'restore_price' => esc_html__('Restore from Trash', 'event_espresso'),
406
+					'delete_price'  => esc_html__('Delete Permanently', 'event_espresso'),
407
+				],
408
+			];
409
+		}
410
+	}
411
+
412
+
413
+	protected function _set_list_table_views_price_types()
414
+	{
415
+		$this->_views = [
416
+			'all' => [
417
+				'slug'        => 'all',
418
+				'label'       => esc_html__('All', 'event_espresso'),
419
+				'count'       => 0,
420
+				'bulk_action' => [
421
+					'trash_price_type' => esc_html__('Move to Trash', 'event_espresso'),
422
+				],
423
+			],
424
+		];
425
+
426
+		if (
427
+			EE_Registry::instance()->CAP->current_user_can(
428
+				'ee_delete_default_price_types',
429
+				'pricing_trash_price_type'
430
+			)
431
+		) {
432
+			$this->_views['trashed'] = [
433
+				'slug'        => 'trashed',
434
+				'label'       => esc_html__('Trash', 'event_espresso'),
435
+				'count'       => 0,
436
+				'bulk_action' => [
437
+					'restore_price_type' => esc_html__('Restore from Trash', 'event_espresso'),
438
+					'delete_price_type'  => esc_html__('Delete Permanently', 'event_espresso'),
439
+				],
440
+			];
441
+		}
442
+	}
443
+
444
+
445
+	/**
446
+	 * generates HTML for main Prices Admin page
447
+	 *
448
+	 * @return void
449
+	 * @throws EE_Error
450
+	 */
451
+	protected function _price_overview_list_table()
452
+	{
453
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
454
+			'add_new_price',
455
+			'add',
456
+			[],
457
+			'add-new-h2'
458
+		);
459
+		$this->_admin_page_title .= $this->_learn_more_about_pricing_link();
460
+		$this->_search_btn_label = esc_html__('Default Prices', 'event_espresso');
461
+		$this->display_admin_list_table_page_with_sidebar();
462
+	}
463
+
464
+
465
+	/**
466
+	 * retrieve data for Prices List table
467
+	 *
468
+	 * @param int  $per_page how many prices displayed per page
469
+	 * @param bool $count    return the count or objects
470
+	 * @param bool $trashed  whether the current view is of the trash can - eww yuck!
471
+	 * @return EE_Soft_Delete_Base_Class[]|int int = count || array of price objects
472
+	 * @throws EE_Error
473
+	 * @throws ReflectionException
474
+	 */
475
+	public function get_prices_overview_data(int $per_page = 10, bool $count = false, bool $trashed = false)
476
+	{
477
+		// start with an empty array
478
+		$event_pricing = [];
479
+
480
+		require_once(PRICING_ADMIN . 'Prices_List_Table.class.php');
481
+
482
+		$orderby = $this->request->getRequestParam('orderby', '');
483
+		$order   = $this->request->getRequestParam('order', 'ASC');
484
+
485
+		switch ($orderby) {
486
+			case 'name':
487
+				$orderby = ['PRC_name' => $order];
488
+				break;
489
+			case 'type':
490
+				$orderby = ['Price_Type.PRT_name' => $order];
491
+				break;
492
+			case 'amount':
493
+				$orderby = ['PRC_amount' => $order];
494
+				break;
495
+			default:
496
+				$orderby = ['PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order];
497
+		}
498
+
499
+		$current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
500
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
501
+
502
+		$where = [
503
+			'PRC_is_default' => 1,
504
+			'PRC_deleted'    => $trashed,
505
+		];
506
+
507
+		$offset = ($current_page - 1) * $per_page;
508
+		$limit  = [$offset, $per_page];
509
+
510
+		$search_term = $this->request->getRequestParam('s');
511
+		if ($search_term) {
512
+			$search_term = "%{$search_term}%";
513
+			$where['OR'] = [
514
+				'PRC_name'            => ['LIKE', $search_term],
515
+				'PRC_desc'            => ['LIKE', $search_term],
516
+				'PRC_amount'          => ['LIKE', $search_term],
517
+				'Price_Type.PRT_name' => ['LIKE', $search_term],
518
+			];
519
+		}
520
+
521
+		$query_params = [
522
+			$where,
523
+			'order_by' => $orderby,
524
+			'limit'    => $limit,
525
+			'group_by' => 'PRC_ID',
526
+		];
527
+
528
+		if ($count) {
529
+			return $trashed
530
+				? EEM_Price::instance()->count([$where])
531
+				: EEM_Price::instance()->count_deleted_and_undeleted([$where]);
532
+		}
533
+		return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params);
534
+	}
535
+
536
+
537
+	/**
538
+	 * @return void
539
+	 * @throws EE_Error
540
+	 * @throws ReflectionException
541
+	 */
542
+	protected function _edit_price_details()
543
+	{
544
+		// grab price ID
545
+		$PRC_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
546
+		// change page title based on request action
547
+		switch ($this->_req_action) {
548
+			case 'add_new_price':
549
+				$this->_admin_page_title = esc_html__('Add New Price', 'event_espresso');
550
+				break;
551
+			case 'edit_price':
552
+				$this->_admin_page_title = esc_html__('Edit Price', 'event_espresso');
553
+				break;
554
+			default:
555
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
556
+		}
557
+		// add PRC_ID to title if editing
558
+		$this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title;
559
+
560
+		if ($PRC_ID) {
561
+			$price                    = EEM_Price::instance()->get_one_by_ID($PRC_ID);
562
+			$additional_hidden_fields = [
563
+				'PRC_ID' => ['type' => 'hidden', 'value' => $PRC_ID],
564
+			];
565
+			$this->_set_add_edit_form_tags('update_price', $additional_hidden_fields);
566
+		} else {
567
+			$price = EEM_Price::instance()->get_new_price();
568
+			$this->_set_add_edit_form_tags('insert_price');
569
+		}
570
+
571
+		if (! $price instanceof EE_Price) {
572
+			throw new RuntimeException(
573
+				sprintf(
574
+					esc_html__(
575
+						'A valid Price could not be retrieved from the database with ID: %1$s',
576
+						'event_espresso'
577
+					),
578
+					$PRC_ID
579
+				)
580
+			);
581
+		}
582
+
583
+		$this->_template_args['PRC_ID'] = $PRC_ID;
584
+		$this->_template_args['price']  = $price;
585
+
586
+		$default_base_price = $price->type_obj() && $price->type_obj()->base_type() === 1;
587
+
588
+		$this->_template_args['default_base_price'] = $default_base_price;
589
+
590
+		// get price types
591
+		$price_types = EEM_Price_Type::instance()->get_all([['PBT_ID' => ['!=', 1]]]);
592
+		if (empty($price_types)) {
593
+			$msg = esc_html__(
594
+				'You have no price types defined. Please add a price type before adding a price.',
595
+				'event_espresso'
596
+			);
597
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
598
+			$this->display_admin_page_with_sidebar();
599
+		}
600
+		$attributes       = [];
601
+		$price_type_names = [];
602
+		$attributes[]     = 'id="PRT_ID"';
603
+		if ($default_base_price) {
604
+			$attributes[]       = 'disabled="disabled"';
605
+			$price_type_names[] = ['id' => 1, 'text' => esc_html__('Base Price', 'event_espresso')];
606
+		}
607
+		foreach ($price_types as $type) {
608
+			$price_type_names[] = ['id' => $type->ID(), 'text' => $type->name()];
609
+		}
610
+		$this->_template_args['attributes']  = implode(' ', $attributes);
611
+		$this->_template_args['price_types'] = $price_type_names;
612
+
613
+		$this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
614
+		$this->_template_args['admin_page_content']            = $this->_edit_price_details_meta_box();
615
+
616
+		$this->_set_publish_post_box_vars('id', $PRC_ID);
617
+		// the details template wrapper
618
+		$this->display_admin_page_with_sidebar();
619
+	}
620
+
621
+
622
+	/**
623
+	 *
624
+	 * @return string
625
+	 */
626
+	public function _edit_price_details_meta_box(): string
627
+	{
628
+		return EEH_Template::display_template(
629
+			PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php',
630
+			$this->_template_args,
631
+			true
632
+		);
633
+	}
634
+
635
+
636
+	/**
637
+	 * @return array
638
+	 * @throws EE_Error
639
+	 * @throws ReflectionException
640
+	 */
641
+	protected function set_price_column_values(): array
642
+	{
643
+		$PRC_order = 0;
644
+		$PRT_ID    = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
645
+		if ($PRT_ID) {
646
+			/** @var EE_Price_Type $price_type */
647
+			$price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
648
+			if ($price_type instanceof EE_Price_Type) {
649
+				$PRC_order = $price_type->order();
650
+			}
651
+		}
652
+		return [
653
+			'PRT_ID'         => $PRT_ID,
654
+			'PRC_amount'     => $this->request->getRequestParam('PRC_amount', 0, DataType::FLOAT),
655
+			'PRC_name'       => $this->request->getRequestParam('PRC_name'),
656
+			'PRC_desc'       => $this->request->getRequestParam('PRC_desc'),
657
+			'PRC_is_default' => 1,
658
+			'PRC_overrides'  => null,
659
+			'PRC_order'      => $PRC_order,
660
+			'PRC_deleted'    => 0,
661
+			'PRC_parent'     => 0,
662
+		];
663
+	}
664
+
665
+
666
+	/**
667
+	 * @param bool $insert - whether to insert or update
668
+	 * @return void
669
+	 * @throws EE_Error
670
+	 * @throws ReflectionException
671
+	 */
672
+	protected function _insert_or_update_price(bool $insert = false)
673
+	{
674
+		// why be so pessimistic ???  : (
675
+		$updated = 0;
676
+
677
+		$set_column_values = $this->set_price_column_values();
678
+		// is this a new Price ?
679
+		if ($insert) {
680
+			// run the insert
681
+			$PRC_ID = EEM_Price::instance()->insert($set_column_values);
682
+			if ($PRC_ID) {
683
+				// make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type
684
+				$price = EEM_price::instance()->get_one_by_ID($PRC_ID);
685
+				if (
686
+					$price instanceof EE_Price
687
+					&& $price->type_obj() instanceof EE_Price_type
688
+					&& $price->type_obj()->base_type() !== EEM_Price_Type::base_type_tax
689
+				) {
690
+					$ticket = EEM_Ticket::instance()->get_one_by_ID(1);
691
+					$ticket->_add_relation_to($price, 'Price');
692
+					$ticket->save();
693
+				}
694
+				$updated = 1;
695
+			}
696
+			$action_desc = 'created';
697
+		} else {
698
+			$PRC_ID = $this->request->getRequestParam('PRC_ID', 0, DataType::INTEGER);
699
+			// run the update
700
+			$where_cols_n_values = ['PRC_ID' => $PRC_ID];
701
+			$updated             = EEM_Price::instance()->update($set_column_values, [$where_cols_n_values]);
702
+
703
+			$price = EEM_Price::instance()->get_one_by_ID($PRC_ID);
704
+			if ($price instanceof EE_Price && $price->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
705
+				// if this is $PRC_ID == 1,
706
+				// then we need to update the default ticket attached to this price so the TKT_price value is updated.
707
+				if ($PRC_ID === 1) {
708
+					$ticket = $price->get_first_related('Ticket');
709
+					if ($ticket) {
710
+						$ticket->set('TKT_price', $price->get('PRC_amount'));
711
+						$ticket->set('TKT_name', $price->get('PRC_name'));
712
+						$ticket->set('TKT_description', $price->get('PRC_desc'));
713
+						$ticket->save();
714
+					}
715
+				} else {
716
+					// we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type.
717
+					$ticket = EEM_Ticket::instance()->get_one_by_ID(1);
718
+					$ticket->_add_relation_to($PRC_ID, 'Price');
719
+					$ticket->save();
720
+				}
721
+			}
722
+
723
+			$action_desc = 'updated';
724
+		}
725
+
726
+		$query_args = ['action' => 'edit_price', 'id' => $PRC_ID];
727
+
728
+		$this->_redirect_after_action($updated, 'Prices', $action_desc, $query_args);
729
+	}
730
+
731
+
732
+	/**
733
+	 * @param bool $trash - whether to move item to trash (TRUE) or restore it (FALSE)
734
+	 * @return void
735
+	 * @throws EE_Error
736
+	 * @throws ReflectionException
737
+	 */
738
+	protected function _trash_or_restore_price(bool $trash = true)
739
+	{
740
+		$entity_model = EEM_Price::instance();
741
+		$action       = $trash ? EE_Admin_List_Table::ACTION_TRASH : EE_Admin_List_Table::ACTION_RESTORE;
742
+		$result       = $this->trashRestoreDeleteEntities(
743
+			$entity_model,
744
+			'id',
745
+			$action,
746
+			'PRC_deleted',
747
+			[$this, 'adjustTicketRelations']
748
+		);
749
+
750
+		if ($result) {
751
+			$msg = $trash
752
+				? esc_html(
753
+					_n(
754
+						'The Price has been trashed',
755
+						'The Prices have been trashed',
756
+						$result,
757
+						'event_espresso'
758
+					)
759
+				)
760
+				: esc_html(
761
+					_n(
762
+						'The Price has been restored',
763
+						'The Prices have been restored',
764
+						$result,
765
+						'event_espresso'
766
+					)
767
+				);
768
+			EE_Error::add_success($msg);
769
+		}
770
+
771
+		$this->_redirect_after_action(
772
+			$result,
773
+			_n('Price', 'Prices', $result, 'event_espresso'),
774
+			$trash ? 'trashed' : 'restored',
775
+			['action' => 'default'],
776
+			true
777
+		);
778
+	}
779
+
780
+
781
+	/**
782
+	 * @param EEM_Base   $entity_model
783
+	 * @param int|string $entity_ID
784
+	 * @param string     $action
785
+	 * @param int        $result
786
+	 * @throws EE_Error
787
+	 * @throws ReflectionException
788
+	 * @since 4.10.30.p
789
+	 */
790
+	public function adjustTicketRelations(EEM_Base $entity_model, $entity_ID, string $action, int $result)
791
+	{
792
+		if (! $entity_ID || (float) $result < 1) {
793
+			return;
794
+		}
795
+
796
+		$entity = $entity_model->get_one_by_ID($entity_ID);
797
+		if (! $entity instanceof EE_Price || $entity->type_obj()->base_type() === EEM_Price_Type::base_type_tax) {
798
+			return;
799
+		}
800
+
801
+		// get default tickets for updating
802
+		$default_tickets = EEM_Ticket::instance()->get_all_default_tickets();
803
+		foreach ($default_tickets as $default_ticket) {
804
+			if (! $default_ticket instanceof EE_Ticket) {
805
+				continue;
806
+			}
807
+			switch ($action) {
808
+				case EE_Admin_List_Table::ACTION_DELETE:
809
+				case EE_Admin_List_Table::ACTION_TRASH:
810
+					// if trashing then remove relations to base default ticket.
811
+					$default_ticket->_remove_relation_to($entity_ID, 'Price');
812
+					break;
813
+				case EE_Admin_List_Table::ACTION_RESTORE:
814
+					// if restoring then add back to base default ticket
815
+					$default_ticket->_add_relation_to($entity_ID, 'Price');
816
+					break;
817
+			}
818
+			$default_ticket->save();
819
+		}
820
+	}
821
+
822
+
823
+	/**
824
+	 * @return void
825
+	 * @throws EE_Error
826
+	 * @throws ReflectionException
827
+	 */
828
+	protected function _delete_price()
829
+	{
830
+		$entity_model = EEM_Price::instance();
831
+		$deleted      = $this->trashRestoreDeleteEntities($entity_model, 'id');
832
+		$entity       = $entity_model->item_name($deleted);
833
+		$this->_redirect_after_action($deleted, $entity, 'deleted', ['action' => 'default']);
834
+	}
835
+
836
+
837
+	/**
838
+	 * @throws EE_Error
839
+	 * @throws ReflectionException
840
+	 */
841
+	public function update_price_order()
842
+	{
843
+		// grab our row IDs
844
+		$row_ids = $this->request->getRequestParam('row_ids', '');
845
+		$row_ids = explode(',', rtrim($row_ids, ','));
846
+
847
+		$all_updated = true;
848
+		foreach ($row_ids as $i => $row_id) {
849
+			// Update the prices when re-ordering
850
+			$fields_n_values = ['PRC_order' => $i + 1];
851
+			$query_params    = [['PRC_ID' => absint($row_id)]];
852
+			// any failure will toggle $all_updated to false
853
+			$all_updated = $row_id && EEM_Price::instance()->update($fields_n_values, $query_params) !== false
854
+				? $all_updated
855
+				: false;
856
+		}
857
+		$success = $all_updated ? esc_html__('Price order was updated successfully.', 'event_espresso') : false;
858
+		$errors  = ! $all_updated ? esc_html__('An error occurred. The price order was not updated.', 'event_espresso')
859
+			: false;
860
+
861
+		echo wp_json_encode(['return_data' => false, 'success' => $success, 'errors' => $errors]);
862
+		die();
863
+	}
864
+
865
+
866
+	/******************************************************************************************************************
867 867
      ***********************************************  TICKET PRICE TYPES  *********************************************
868 868
      ******************************************************************************************************************/
869 869
 
870 870
 
871
-    /**
872
-     * generates HTML for main Prices Admin page
873
-     *
874
-     * @return void
875
-     * @throws EE_Error
876
-     */
877
-    protected function _price_types_overview_list_table()
878
-    {
879
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
880
-            'add_new_price_type',
881
-            'add_type',
882
-            [],
883
-            'add-new-h2'
884
-        );
885
-        $this->_admin_page_title .= $this->_learn_more_about_pricing_link();
886
-        $this->_search_btn_label = esc_html__('Price Types', 'event_espresso');
887
-        $this->display_admin_list_table_page_with_sidebar();
888
-    }
889
-
890
-
891
-    /**
892
-     * retrieve data for Price Types List table
893
-     *
894
-     * @param int  $per_page how many prices displayed per page
895
-     * @param bool $count    return the count or objects
896
-     * @param bool $trashed  whether the current view is of the trash can - eww yuck!
897
-     * @return EE_Soft_Delete_Base_Class[]|int int = count || array of price objects
898
-     * @throws EE_Error
899
-     * @throws ReflectionException
900
-     */
901
-    public function get_price_types_overview_data(int $per_page = 10, bool $count = false, bool $trashed = false)
902
-    {
903
-        // start with an empty array
904
-        require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php');
905
-
906
-        $orderby = $this->request->getRequestParam('orderby', '');
907
-        $order   = $this->request->getRequestParam('order', 'ASC');
908
-
909
-        switch ($orderby) {
910
-            case 'name':
911
-                $orderby = ['PRT_name' => $order];
912
-                break;
913
-            default:
914
-                $orderby = ['PRT_order' => $order];
915
-        }
916
-
917
-        $current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
918
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
919
-
920
-        $offset = ($current_page - 1) * $per_page;
921
-        $limit  = [$offset, $per_page];
922
-
923
-        $where = ['PRT_deleted' => $trashed, 'PBT_ID' => ['!=', 1]];
924
-
925
-        $search_term = $this->request->getRequestParam('s');
926
-        if ($search_term) {
927
-            $where['OR'] = [
928
-                'PRT_name' => ['LIKE', "%{$search_term}%"],
929
-            ];
930
-        }
931
-        $query_params = [
932
-            $where,
933
-            'order_by' => $orderby,
934
-            'limit'    => $limit,
935
-        ];
936
-        return $count
937
-            ? EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params)
938
-            : EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params);
939
-    }
940
-
941
-
942
-    /**
943
-     * _edit_price_type_details
944
-     *
945
-     * @return void
946
-     * @throws EE_Error
947
-     * @throws ReflectionException
948
-     */
949
-    protected function _edit_price_type_details()
950
-    {
951
-        // grab price type ID
952
-        $PRT_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
953
-        // change page title based on request action
954
-        switch ($this->_req_action) {
955
-            case 'add_new_price_type':
956
-                $this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso');
957
-                break;
958
-            case 'edit_price_type':
959
-                $this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso');
960
-                break;
961
-            default:
962
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
963
-        }
964
-        // add PRT_ID to title if editing
965
-        $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title;
966
-
967
-        if ($PRT_ID) {
968
-            $price_type               = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
969
-            $additional_hidden_fields = ['PRT_ID' => ['type' => 'hidden', 'value' => $PRT_ID]];
970
-            $this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields);
971
-        } else {
972
-            $price_type = EEM_Price_Type::instance()->get_new_price_type();
973
-            $this->_set_add_edit_form_tags('insert_price_type');
974
-        }
975
-
976
-        if (! $price_type instanceof EE_Price_Type) {
977
-            throw new RuntimeException(
978
-                sprintf(
979
-                    esc_html__(
980
-                        'A valid Price Type could not be retrieved from the database with ID: %1$s',
981
-                        'event_espresso'
982
-                    ),
983
-                    $PRT_ID
984
-                )
985
-            );
986
-        }
987
-
988
-        $this->_template_args['PRT_ID']     = $PRT_ID;
989
-        $this->_template_args['price_type'] = $price_type;
990
-
991
-        $base_types    = EEM_Price_Type::instance()->get_base_types();
992
-        $select_values = [];
993
-        foreach ($base_types as $ref => $text) {
994
-            if ($ref == EEM_Price_Type::base_type_base_price) {
995
-                // do not allow creation of base_type_base_prices because that's a system only base type.
996
-                continue;
997
-            }
998
-            $select_values[] = ['id' => $ref, 'text' => $text];
999
-        }
1000
-
1001
-        $this->_template_args['base_type_select'] = EEH_Form_Fields::select_input(
1002
-            'base_type',
1003
-            $select_values,
1004
-            $price_type->base_type(),
1005
-            'id="price-type-base-type-slct"'
1006
-        );
1007
-
1008
-        $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
1009
-        $this->_template_args['admin_page_content']            = $this->_edit_price_type_details_meta_box();
1010
-
1011
-        $redirect_URL = add_query_arg(['action' => 'price_types'], $this->_admin_base_url);
1012
-        $this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL);
1013
-        // the details template wrapper
1014
-        $this->display_admin_page_with_sidebar();
1015
-    }
1016
-
1017
-
1018
-    /**
1019
-     * _edit_price_type_details_meta_box
1020
-     *
1021
-     * @return string
1022
-     */
1023
-    public function _edit_price_type_details_meta_box(): string
1024
-    {
1025
-        return EEH_Template::display_template(
1026
-            PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php',
1027
-            $this->_template_args,
1028
-            true
1029
-        );
1030
-    }
1031
-
1032
-
1033
-    /**
1034
-     * @return array
1035
-     */
1036
-    protected function set_price_type_column_values(): array
1037
-    {
1038
-        $base_type  = $this->request->getRequestParam(
1039
-            'base_type',
1040
-            EEM_Price_Type::base_type_base_price,
1041
-            DataType::INTEGER
1042
-        );
1043
-        $is_percent = $this->request->getRequestParam('PRT_is_percent', 0, DataType::INTEGER);
1044
-        $order      = $this->request->getRequestParam('PRT_order', 0, DataType::INTEGER);
1045
-        switch ($base_type) {
1046
-            case EEM_Price_Type::base_type_base_price:
1047
-                $is_percent = 0;
1048
-                $order      = 0;
1049
-                break;
1050
-
1051
-            case EEM_Price_Type::base_type_discount:
1052
-            case EEM_Price_Type::base_type_surcharge:
1053
-                break;
1054
-
1055
-            case EEM_Price_Type::base_type_tax:
1056
-                $is_percent = 1;
1057
-                break;
1058
-        }
1059
-
1060
-        return [
1061
-            'PBT_ID'         => $base_type,
1062
-            'PRT_name'       => $this->request->getRequestParam('PRT_name', ''),
1063
-            'PRT_is_percent' => $is_percent,
1064
-            'PRT_order'      => $order,
1065
-            'PRT_deleted'    => 0,
1066
-        ];
1067
-    }
1068
-
1069
-
1070
-    /**
1071
-     * @param bool $new_price_type - whether to insert or update
1072
-     * @return void
1073
-     * @throws EE_Error
1074
-     * @throws ReflectionException
1075
-     */
1076
-    protected function _insert_or_update_price_type(bool $new_price_type = false)
1077
-    {
1078
-        // why be so pessimistic ???  : (
1079
-        $success = 0;
1080
-
1081
-        $set_column_values = $this->set_price_type_column_values();
1082
-        // is this a new Price ?
1083
-        if ($new_price_type) {
1084
-            // run the insert
1085
-            if ($PRT_ID = EEM_Price_Type::instance()->insert($set_column_values)) {
1086
-                $success = 1;
1087
-            }
1088
-            $action_desc = 'created';
1089
-        } else {
1090
-            $PRT_ID = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
1091
-            // run the update
1092
-            $where_cols_n_values = ['PRT_ID' => $PRT_ID];
1093
-            if (EEM_Price_Type::instance()->update($set_column_values, [$where_cols_n_values])) {
1094
-                $success = 1;
1095
-            }
1096
-            $action_desc = 'updated';
1097
-        }
1098
-
1099
-        $query_args = ['action' => 'edit_price_type', 'id' => $PRT_ID];
1100
-        $this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args);
1101
-    }
1102
-
1103
-
1104
-    /**
1105
-     * @param bool $trash - whether to move item to trash (TRUE) or restore it (FALSE)
1106
-     * @return void
1107
-     * @throws EE_Error
1108
-     * @throws ReflectionException
1109
-     */
1110
-    protected function _trash_or_restore_price_type(bool $trash = true)
1111
-    {
1112
-        $entity_model = EEM_Price_Type::instance();
1113
-        $action       = $trash ? EE_Admin_List_Table::ACTION_TRASH : EE_Admin_List_Table::ACTION_RESTORE;
1114
-        $success      = $this->trashRestoreDeleteEntities($entity_model, 'id', $action, 'PRT_deleted');
1115
-        if ($success) {
1116
-            $msg = $trash
1117
-                ? esc_html(
1118
-                    _n(
1119
-                        'The Price Type has been trashed',
1120
-                        'The Price Types have been trashed',
1121
-                        $success,
1122
-                        'event_espresso'
1123
-                    )
1124
-                )
1125
-                : esc_html(
1126
-                    _n(
1127
-                        'The Price Type has been restored',
1128
-                        'The Price Types have been restored',
1129
-                        $success,
1130
-                        'event_espresso'
1131
-                    )
1132
-                );
1133
-            EE_Error::add_success($msg);
1134
-        }
1135
-        $this->_redirect_after_action('', '', '', ['action' => 'price_types'], true);
1136
-    }
1137
-
1138
-
1139
-    /**
1140
-     * @return void
1141
-     * @throws EE_Error
1142
-     * @throws ReflectionException
1143
-     */
1144
-    protected function _delete_price_type()
1145
-    {
1146
-        $entity_model = EEM_Price_Type::instance();
1147
-        $deleted      = $this->trashRestoreDeleteEntities($entity_model, 'id');
1148
-        $this->_redirect_after_action(
1149
-            $deleted,
1150
-            $entity_model->item_name($deleted),
1151
-            'deleted',
1152
-            ['action' => 'price_types']
1153
-        );
1154
-    }
1155
-
1156
-
1157
-    /**
1158
-     * @return string
1159
-     */
1160
-    protected function _learn_more_about_pricing_link(): string
1161
-    {
1162
-        return '
871
+	/**
872
+	 * generates HTML for main Prices Admin page
873
+	 *
874
+	 * @return void
875
+	 * @throws EE_Error
876
+	 */
877
+	protected function _price_types_overview_list_table()
878
+	{
879
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
880
+			'add_new_price_type',
881
+			'add_type',
882
+			[],
883
+			'add-new-h2'
884
+		);
885
+		$this->_admin_page_title .= $this->_learn_more_about_pricing_link();
886
+		$this->_search_btn_label = esc_html__('Price Types', 'event_espresso');
887
+		$this->display_admin_list_table_page_with_sidebar();
888
+	}
889
+
890
+
891
+	/**
892
+	 * retrieve data for Price Types List table
893
+	 *
894
+	 * @param int  $per_page how many prices displayed per page
895
+	 * @param bool $count    return the count or objects
896
+	 * @param bool $trashed  whether the current view is of the trash can - eww yuck!
897
+	 * @return EE_Soft_Delete_Base_Class[]|int int = count || array of price objects
898
+	 * @throws EE_Error
899
+	 * @throws ReflectionException
900
+	 */
901
+	public function get_price_types_overview_data(int $per_page = 10, bool $count = false, bool $trashed = false)
902
+	{
903
+		// start with an empty array
904
+		require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php');
905
+
906
+		$orderby = $this->request->getRequestParam('orderby', '');
907
+		$order   = $this->request->getRequestParam('order', 'ASC');
908
+
909
+		switch ($orderby) {
910
+			case 'name':
911
+				$orderby = ['PRT_name' => $order];
912
+				break;
913
+			default:
914
+				$orderby = ['PRT_order' => $order];
915
+		}
916
+
917
+		$current_page = $this->request->getRequestParam('paged', 1, DataType::INTEGER);
918
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, DataType::INTEGER);
919
+
920
+		$offset = ($current_page - 1) * $per_page;
921
+		$limit  = [$offset, $per_page];
922
+
923
+		$where = ['PRT_deleted' => $trashed, 'PBT_ID' => ['!=', 1]];
924
+
925
+		$search_term = $this->request->getRequestParam('s');
926
+		if ($search_term) {
927
+			$where['OR'] = [
928
+				'PRT_name' => ['LIKE', "%{$search_term}%"],
929
+			];
930
+		}
931
+		$query_params = [
932
+			$where,
933
+			'order_by' => $orderby,
934
+			'limit'    => $limit,
935
+		];
936
+		return $count
937
+			? EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params)
938
+			: EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params);
939
+	}
940
+
941
+
942
+	/**
943
+	 * _edit_price_type_details
944
+	 *
945
+	 * @return void
946
+	 * @throws EE_Error
947
+	 * @throws ReflectionException
948
+	 */
949
+	protected function _edit_price_type_details()
950
+	{
951
+		// grab price type ID
952
+		$PRT_ID = $this->request->getRequestParam('id', 0, DataType::INTEGER);
953
+		// change page title based on request action
954
+		switch ($this->_req_action) {
955
+			case 'add_new_price_type':
956
+				$this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso');
957
+				break;
958
+			case 'edit_price_type':
959
+				$this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso');
960
+				break;
961
+			default:
962
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
963
+		}
964
+		// add PRT_ID to title if editing
965
+		$this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title;
966
+
967
+		if ($PRT_ID) {
968
+			$price_type               = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
969
+			$additional_hidden_fields = ['PRT_ID' => ['type' => 'hidden', 'value' => $PRT_ID]];
970
+			$this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields);
971
+		} else {
972
+			$price_type = EEM_Price_Type::instance()->get_new_price_type();
973
+			$this->_set_add_edit_form_tags('insert_price_type');
974
+		}
975
+
976
+		if (! $price_type instanceof EE_Price_Type) {
977
+			throw new RuntimeException(
978
+				sprintf(
979
+					esc_html__(
980
+						'A valid Price Type could not be retrieved from the database with ID: %1$s',
981
+						'event_espresso'
982
+					),
983
+					$PRT_ID
984
+				)
985
+			);
986
+		}
987
+
988
+		$this->_template_args['PRT_ID']     = $PRT_ID;
989
+		$this->_template_args['price_type'] = $price_type;
990
+
991
+		$base_types    = EEM_Price_Type::instance()->get_base_types();
992
+		$select_values = [];
993
+		foreach ($base_types as $ref => $text) {
994
+			if ($ref == EEM_Price_Type::base_type_base_price) {
995
+				// do not allow creation of base_type_base_prices because that's a system only base type.
996
+				continue;
997
+			}
998
+			$select_values[] = ['id' => $ref, 'text' => $text];
999
+		}
1000
+
1001
+		$this->_template_args['base_type_select'] = EEH_Form_Fields::select_input(
1002
+			'base_type',
1003
+			$select_values,
1004
+			$price_type->base_type(),
1005
+			'id="price-type-base-type-slct"'
1006
+		);
1007
+
1008
+		$this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
1009
+		$this->_template_args['admin_page_content']            = $this->_edit_price_type_details_meta_box();
1010
+
1011
+		$redirect_URL = add_query_arg(['action' => 'price_types'], $this->_admin_base_url);
1012
+		$this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL);
1013
+		// the details template wrapper
1014
+		$this->display_admin_page_with_sidebar();
1015
+	}
1016
+
1017
+
1018
+	/**
1019
+	 * _edit_price_type_details_meta_box
1020
+	 *
1021
+	 * @return string
1022
+	 */
1023
+	public function _edit_price_type_details_meta_box(): string
1024
+	{
1025
+		return EEH_Template::display_template(
1026
+			PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php',
1027
+			$this->_template_args,
1028
+			true
1029
+		);
1030
+	}
1031
+
1032
+
1033
+	/**
1034
+	 * @return array
1035
+	 */
1036
+	protected function set_price_type_column_values(): array
1037
+	{
1038
+		$base_type  = $this->request->getRequestParam(
1039
+			'base_type',
1040
+			EEM_Price_Type::base_type_base_price,
1041
+			DataType::INTEGER
1042
+		);
1043
+		$is_percent = $this->request->getRequestParam('PRT_is_percent', 0, DataType::INTEGER);
1044
+		$order      = $this->request->getRequestParam('PRT_order', 0, DataType::INTEGER);
1045
+		switch ($base_type) {
1046
+			case EEM_Price_Type::base_type_base_price:
1047
+				$is_percent = 0;
1048
+				$order      = 0;
1049
+				break;
1050
+
1051
+			case EEM_Price_Type::base_type_discount:
1052
+			case EEM_Price_Type::base_type_surcharge:
1053
+				break;
1054
+
1055
+			case EEM_Price_Type::base_type_tax:
1056
+				$is_percent = 1;
1057
+				break;
1058
+		}
1059
+
1060
+		return [
1061
+			'PBT_ID'         => $base_type,
1062
+			'PRT_name'       => $this->request->getRequestParam('PRT_name', ''),
1063
+			'PRT_is_percent' => $is_percent,
1064
+			'PRT_order'      => $order,
1065
+			'PRT_deleted'    => 0,
1066
+		];
1067
+	}
1068
+
1069
+
1070
+	/**
1071
+	 * @param bool $new_price_type - whether to insert or update
1072
+	 * @return void
1073
+	 * @throws EE_Error
1074
+	 * @throws ReflectionException
1075
+	 */
1076
+	protected function _insert_or_update_price_type(bool $new_price_type = false)
1077
+	{
1078
+		// why be so pessimistic ???  : (
1079
+		$success = 0;
1080
+
1081
+		$set_column_values = $this->set_price_type_column_values();
1082
+		// is this a new Price ?
1083
+		if ($new_price_type) {
1084
+			// run the insert
1085
+			if ($PRT_ID = EEM_Price_Type::instance()->insert($set_column_values)) {
1086
+				$success = 1;
1087
+			}
1088
+			$action_desc = 'created';
1089
+		} else {
1090
+			$PRT_ID = $this->request->getRequestParam('PRT_ID', 0, DataType::INTEGER);
1091
+			// run the update
1092
+			$where_cols_n_values = ['PRT_ID' => $PRT_ID];
1093
+			if (EEM_Price_Type::instance()->update($set_column_values, [$where_cols_n_values])) {
1094
+				$success = 1;
1095
+			}
1096
+			$action_desc = 'updated';
1097
+		}
1098
+
1099
+		$query_args = ['action' => 'edit_price_type', 'id' => $PRT_ID];
1100
+		$this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args);
1101
+	}
1102
+
1103
+
1104
+	/**
1105
+	 * @param bool $trash - whether to move item to trash (TRUE) or restore it (FALSE)
1106
+	 * @return void
1107
+	 * @throws EE_Error
1108
+	 * @throws ReflectionException
1109
+	 */
1110
+	protected function _trash_or_restore_price_type(bool $trash = true)
1111
+	{
1112
+		$entity_model = EEM_Price_Type::instance();
1113
+		$action       = $trash ? EE_Admin_List_Table::ACTION_TRASH : EE_Admin_List_Table::ACTION_RESTORE;
1114
+		$success      = $this->trashRestoreDeleteEntities($entity_model, 'id', $action, 'PRT_deleted');
1115
+		if ($success) {
1116
+			$msg = $trash
1117
+				? esc_html(
1118
+					_n(
1119
+						'The Price Type has been trashed',
1120
+						'The Price Types have been trashed',
1121
+						$success,
1122
+						'event_espresso'
1123
+					)
1124
+				)
1125
+				: esc_html(
1126
+					_n(
1127
+						'The Price Type has been restored',
1128
+						'The Price Types have been restored',
1129
+						$success,
1130
+						'event_espresso'
1131
+					)
1132
+				);
1133
+			EE_Error::add_success($msg);
1134
+		}
1135
+		$this->_redirect_after_action('', '', '', ['action' => 'price_types'], true);
1136
+	}
1137
+
1138
+
1139
+	/**
1140
+	 * @return void
1141
+	 * @throws EE_Error
1142
+	 * @throws ReflectionException
1143
+	 */
1144
+	protected function _delete_price_type()
1145
+	{
1146
+		$entity_model = EEM_Price_Type::instance();
1147
+		$deleted      = $this->trashRestoreDeleteEntities($entity_model, 'id');
1148
+		$this->_redirect_after_action(
1149
+			$deleted,
1150
+			$entity_model->item_name($deleted),
1151
+			'deleted',
1152
+			['action' => 'price_types']
1153
+		);
1154
+	}
1155
+
1156
+
1157
+	/**
1158
+	 * @return string
1159
+	 */
1160
+	protected function _learn_more_about_pricing_link(): string
1161
+	{
1162
+		return '
1163 1163
             <a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >
1164 1164
                 ' . esc_html__('learn more about how pricing works', 'event_espresso') . '
1165 1165
             </a>';
1166
-    }
1167
-
1168
-
1169
-    /**
1170
-     * @throws EE_Error
1171
-     */
1172
-    protected function _tax_settings()
1173
-    {
1174
-        $this->_set_add_edit_form_tags('update_tax_settings');
1175
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
1176
-        $this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html();
1177
-        $this->display_admin_page_with_sidebar();
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * @return EE_Form_Section_Proper
1183
-     * @throws EE_Error
1184
-     */
1185
-    protected function tax_settings_form(): EE_Form_Section_Proper
1186
-    {
1187
-        $tax_settings = EE_Config::instance()->tax_settings;
1188
-        return new EE_Form_Section_Proper(
1189
-            [
1190
-                'name'            => 'tax_settings_form',
1191
-                'html_id'         => 'tax_settings_form',
1192
-                'html_class'      => 'padding',
1193
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1194
-                'subsections'     => apply_filters(
1195
-                    'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections',
1196
-                    [
1197
-                        'tax_settings' => new EE_Form_Section_Proper(
1198
-                            [
1199
-                                'name'            => 'tax_settings_tbl',
1200
-                                'html_id'         => 'tax_settings_tbl',
1201
-                                'html_class'      => 'form-table',
1202
-                                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1203
-                                'subsections'     => [
1204
-                                    'prices_displayed_including_taxes' => new EE_Yes_No_Input(
1205
-                                        [
1206
-                                            'html_label_text'         => esc_html__(
1207
-                                                'Show Prices With Taxes Included?',
1208
-                                                'event_espresso'
1209
-                                            ),
1210
-                                            'html_help_text'          => esc_html__(
1211
-                                                'Indicates whether or not to display prices with the taxes included',
1212
-                                                'event_espresso'
1213
-                                            ),
1214
-                                            'default'                 => $tax_settings->prices_displayed_including_taxes
1215
-                                                                         ?? true,
1216
-                                            'display_html_label_text' => false,
1217
-                                        ]
1218
-                                    ),
1219
-                                ],
1220
-                            ]
1221
-                        ),
1222
-                    ]
1223
-                ),
1224
-            ]
1225
-        );
1226
-    }
1227
-
1228
-
1229
-    /**
1230
-     * _update_tax_settings
1231
-     *
1232
-     * @return void
1233
-     * @throws EE_Error
1234
-     * @throws ReflectionException
1235
-     * @since 4.9.13
1236
-     */
1237
-    public function _update_tax_settings()
1238
-    {
1239
-        $tax_settings = EE_Config::instance()->tax_settings;
1240
-        if (! $tax_settings instanceof EE_Tax_Config) {
1241
-            $tax_settings = new EE_Tax_Config();
1242
-        }
1243
-        try {
1244
-            $tax_form = $this->tax_settings_form();
1245
-            // check for form submission
1246
-            if ($tax_form->was_submitted()) {
1247
-                // capture form data
1248
-                $tax_form->receive_form_submission();
1249
-                // validate form data
1250
-                if ($tax_form->is_valid()) {
1251
-                    // grab validated data from form
1252
-                    $valid_data = $tax_form->valid_data();
1253
-                    // set data on config
1254
-                    $tax_settings->prices_displayed_including_taxes =
1255
-                        $valid_data['tax_settings']['prices_displayed_including_taxes'];
1256
-                } else {
1257
-                    if ($tax_form->submission_error_message() !== '') {
1258
-                        EE_Error::add_error(
1259
-                            $tax_form->submission_error_message(),
1260
-                            __FILE__,
1261
-                            __FUNCTION__,
1262
-                            __LINE__
1263
-                        );
1264
-                    }
1265
-                }
1266
-            }
1267
-        } catch (EE_Error $e) {
1268
-            EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__);
1269
-        }
1270
-
1271
-        $what    = 'Tax Settings';
1272
-        $success = $this->_update_espresso_configuration(
1273
-            $what,
1274
-            $tax_settings,
1275
-            __FILE__,
1276
-            __FUNCTION__,
1277
-            __LINE__
1278
-        );
1279
-        $this->_redirect_after_action($success, $what, 'updated', ['action' => 'tax_settings']);
1280
-    }
1166
+	}
1167
+
1168
+
1169
+	/**
1170
+	 * @throws EE_Error
1171
+	 */
1172
+	protected function _tax_settings()
1173
+	{
1174
+		$this->_set_add_edit_form_tags('update_tax_settings');
1175
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
1176
+		$this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html();
1177
+		$this->display_admin_page_with_sidebar();
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * @return EE_Form_Section_Proper
1183
+	 * @throws EE_Error
1184
+	 */
1185
+	protected function tax_settings_form(): EE_Form_Section_Proper
1186
+	{
1187
+		$tax_settings = EE_Config::instance()->tax_settings;
1188
+		return new EE_Form_Section_Proper(
1189
+			[
1190
+				'name'            => 'tax_settings_form',
1191
+				'html_id'         => 'tax_settings_form',
1192
+				'html_class'      => 'padding',
1193
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1194
+				'subsections'     => apply_filters(
1195
+					'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections',
1196
+					[
1197
+						'tax_settings' => new EE_Form_Section_Proper(
1198
+							[
1199
+								'name'            => 'tax_settings_tbl',
1200
+								'html_id'         => 'tax_settings_tbl',
1201
+								'html_class'      => 'form-table',
1202
+								'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1203
+								'subsections'     => [
1204
+									'prices_displayed_including_taxes' => new EE_Yes_No_Input(
1205
+										[
1206
+											'html_label_text'         => esc_html__(
1207
+												'Show Prices With Taxes Included?',
1208
+												'event_espresso'
1209
+											),
1210
+											'html_help_text'          => esc_html__(
1211
+												'Indicates whether or not to display prices with the taxes included',
1212
+												'event_espresso'
1213
+											),
1214
+											'default'                 => $tax_settings->prices_displayed_including_taxes
1215
+																		 ?? true,
1216
+											'display_html_label_text' => false,
1217
+										]
1218
+									),
1219
+								],
1220
+							]
1221
+						),
1222
+					]
1223
+				),
1224
+			]
1225
+		);
1226
+	}
1227
+
1228
+
1229
+	/**
1230
+	 * _update_tax_settings
1231
+	 *
1232
+	 * @return void
1233
+	 * @throws EE_Error
1234
+	 * @throws ReflectionException
1235
+	 * @since 4.9.13
1236
+	 */
1237
+	public function _update_tax_settings()
1238
+	{
1239
+		$tax_settings = EE_Config::instance()->tax_settings;
1240
+		if (! $tax_settings instanceof EE_Tax_Config) {
1241
+			$tax_settings = new EE_Tax_Config();
1242
+		}
1243
+		try {
1244
+			$tax_form = $this->tax_settings_form();
1245
+			// check for form submission
1246
+			if ($tax_form->was_submitted()) {
1247
+				// capture form data
1248
+				$tax_form->receive_form_submission();
1249
+				// validate form data
1250
+				if ($tax_form->is_valid()) {
1251
+					// grab validated data from form
1252
+					$valid_data = $tax_form->valid_data();
1253
+					// set data on config
1254
+					$tax_settings->prices_displayed_including_taxes =
1255
+						$valid_data['tax_settings']['prices_displayed_including_taxes'];
1256
+				} else {
1257
+					if ($tax_form->submission_error_message() !== '') {
1258
+						EE_Error::add_error(
1259
+							$tax_form->submission_error_message(),
1260
+							__FILE__,
1261
+							__FUNCTION__,
1262
+							__LINE__
1263
+						);
1264
+					}
1265
+				}
1266
+			}
1267
+		} catch (EE_Error $e) {
1268
+			EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__);
1269
+		}
1270
+
1271
+		$what    = 'Tax Settings';
1272
+		$success = $this->_update_espresso_configuration(
1273
+			$what,
1274
+			$tax_settings,
1275
+			__FILE__,
1276
+			__FUNCTION__,
1277
+			__LINE__
1278
+		);
1279
+		$this->_redirect_after_action($success, $what, 'updated', ['action' => 'tax_settings']);
1280
+	}
1281 1281
 }
Please login to merge, or discard this patch.