Completed
Branch ADMIN-REFRESH (2561dd)
by
unknown
05:35 queued 03:03
created
core/helpers/EEH_Template.helper.php 2 patches
Indentation   +920 added lines, -920 removed lines patch added patch discarded remove patch
@@ -6,36 +6,36 @@  discard block
 block discarded – undo
6 6
 use EventEspresso\core\services\request\RequestInterface;
7 7
 
8 8
 if (! function_exists('espresso_get_template_part')) {
9
-    /**
10
-     * espresso_get_template_part
11
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
12
-     * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
13
-     *
14
-     * @param string $slug The slug name for the generic template.
15
-     * @param string $name The name of the specialised template.
16
-     */
17
-    function espresso_get_template_part($slug = null, $name = null)
18
-    {
19
-        EEH_Template::get_template_part($slug, $name);
20
-    }
9
+	/**
10
+	 * espresso_get_template_part
11
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
12
+	 * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
13
+	 *
14
+	 * @param string $slug The slug name for the generic template.
15
+	 * @param string $name The name of the specialised template.
16
+	 */
17
+	function espresso_get_template_part($slug = null, $name = null)
18
+	{
19
+		EEH_Template::get_template_part($slug, $name);
20
+	}
21 21
 }
22 22
 
23 23
 
24 24
 if (! function_exists('espresso_get_object_css_class')) {
25
-    /**
26
-     * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27
-     *
28
-     * @param EE_Base_Class $object the EE object the css class is being generated for
29
-     * @param string        $prefix added to the beginning of the generated class
30
-     * @param string        $suffix added to the end of the generated class
31
-     * @return string
32
-     * @throws EE_Error
33
-     * @throws ReflectionException
34
-     */
35
-    function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
36
-    {
37
-        return EEH_Template::get_object_css_class($object, $prefix, $suffix);
38
-    }
25
+	/**
26
+	 * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27
+	 *
28
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
29
+	 * @param string        $prefix added to the beginning of the generated class
30
+	 * @param string        $suffix added to the end of the generated class
31
+	 * @return string
32
+	 * @throws EE_Error
33
+	 * @throws ReflectionException
34
+	 */
35
+	function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
36
+	{
37
+		return EEH_Template::get_object_css_class($object, $prefix, $suffix);
38
+	}
39 39
 }
40 40
 
41 41
 
@@ -50,640 +50,640 @@  discard block
 block discarded – undo
50 50
 class EEH_Template
51 51
 {
52 52
 
53
-    private static $_espresso_themes = [];
54
-
55
-
56
-    /**
57
-     *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
58
-     *
59
-     * @return boolean
60
-     */
61
-    public static function is_espresso_theme()
62
-    {
63
-        return wp_get_theme()->get('TextDomain') === 'event_espresso';
64
-    }
65
-
66
-
67
-    /**
68
-     *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
69
-     *    load its functions.php file ( if not already loaded )
70
-     *
71
-     * @return void
72
-     */
73
-    public static function load_espresso_theme_functions()
74
-    {
75
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
76
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
77
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
78
-            }
79
-        }
80
-    }
81
-
82
-
83
-    /**
84
-     *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
85
-     *
86
-     * @return array
87
-     */
88
-    public static function get_espresso_themes()
89
-    {
90
-        if (empty(EEH_Template::$_espresso_themes)) {
91
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
92
-            if (empty($espresso_themes)) {
93
-                return [];
94
-            }
95
-            if (($key = array_search('global_assets', $espresso_themes)) !== false) {
96
-                unset($espresso_themes[ $key ]);
97
-            }
98
-            EEH_Template::$_espresso_themes = [];
99
-            foreach ($espresso_themes as $espresso_theme) {
100
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
101
-            }
102
-        }
103
-        return EEH_Template::$_espresso_themes;
104
-    }
105
-
106
-
107
-    /**
108
-     * EEH_Template::get_template_part
109
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
110
-     * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
111
-     * filtering based off of the entire template part name
112
-     *
113
-     * @param string $slug The slug name for the generic template.
114
-     * @param string $name The name of the specialised template.
115
-     * @param array  $template_args
116
-     * @param bool   $return_string
117
-     * @return string        the html output for the formatted money value
118
-     */
119
-    public static function get_template_part(
120
-        $slug = null,
121
-        $name = null,
122
-        $template_args = [],
123
-        $return_string = false
124
-    ) {
125
-        do_action("get_template_part_{$slug}-{$name}", $slug, $name);
126
-        $templates = [];
127
-        $name      = (string) $name;
128
-        if ($name != '') {
129
-            $templates[] = "{$slug}-{$name}.php";
130
-        }
131
-        // allow template parts to be turned off via something like:
132
-        // add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
133
-        if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
134
-            return EEH_Template::locate_template($templates, $template_args, true, $return_string);
135
-        }
136
-        return '';
137
-    }
138
-
139
-
140
-    /**
141
-     *    locate_template
142
-     *    locate a template file by looking in the following places, in the following order:
143
-     *        <server path up to>/wp-content/themes/<current active WordPress theme>/
144
-     *        <assumed full absolute server path>
145
-     *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
146
-     *        <server path up to>/wp-content/uploads/espresso/templates/
147
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
148
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
149
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/
150
-     *    as soon as the template is found in one of these locations, it will be returned or loaded
151
-     *        Example:
152
-     *          You are using the WordPress Twenty Sixteen theme,
153
-     *        and you want to customize the "some-event.template.php" template,
154
-     *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
155
-     *          Assuming WP is installed on your server in the "/home/public_html/" folder,
156
-     *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
157
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
158
-     *        /relative/path/to/some-event.template.php
159
-     *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
160
-     *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
161
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
162
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
163
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
164
-     *          Had you passed an absolute path to your template that was in some other location,
165
-     *        ie: "/absolute/path/to/some-event.template.php"
166
-     *          then the search would have been :
167
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
168
-     *        /absolute/path/to/some-event.template.php
169
-     *          and stopped there upon finding it in the second location
170
-     *
171
-     * @param array|string $templates       array of template file names including extension (or just a single string)
172
-     * @param array        $template_args   an array of arguments to be extracted for use in the template
173
-     * @param boolean      $load            whether to pass the located template path on to the
174
-     *                                      EEH_Template::display_template() method or simply return it
175
-     * @param boolean      $return_string   whether to send output immediately to screen, or capture and return as a
176
-     *                                      string
177
-     * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
178
-     *                                      generate a custom template or not. Used in places where you don't actually
179
-     *                                      load the template, you just want to know if there's a custom version of it.
180
-     * @return mixed
181
-     * @throws DomainException
182
-     * @throws InvalidArgumentException
183
-     * @throws InvalidDataTypeException
184
-     * @throws InvalidInterfaceException
185
-     */
186
-    public static function locate_template(
187
-        $templates = [],
188
-        $template_args = [],
189
-        $load = true,
190
-        $return_string = true,
191
-        $check_if_custom = false
192
-    ) {
193
-        // first use WP locate_template to check for template in the current theme folder
194
-        $template_path = locate_template($templates);
195
-
196
-        if ($check_if_custom && ! empty($template_path)) {
197
-            return true;
198
-        }
199
-
200
-        // not in the theme
201
-        if (empty($template_path)) {
202
-            // not even a template to look for ?
203
-            if (empty($templates)) {
204
-                $loader = LoaderFactory::getLoader();
205
-                /** @var RequestInterface $request */
206
-                $request = $loader->getShared(RequestInterface::class);
207
-                // get post_type
208
-                $post_type = $request->getRequestParam('post_type');
209
-                /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
210
-                $custom_post_types = $loader->getShared(
211
-                    'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
212
-                );
213
-                // get array of EE Custom Post Types
214
-                $EE_CPTs = $custom_post_types->getDefinitions();
215
-                // build template name based on request
216
-                if (isset($EE_CPTs[ $post_type ])) {
217
-                    $archive_or_single = is_archive() ? 'archive' : '';
218
-                    $archive_or_single = is_single() ? 'single' : $archive_or_single;
219
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
220
-                }
221
-            }
222
-            // currently active EE template theme
223
-            $current_theme = EE_Config::get_current_theme();
224
-
225
-            // array of paths to folders that may contain templates
226
-            $template_folder_paths = [
227
-                // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
228
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
229
-                // then in the root of the /wp-content/uploads/espresso/templates/ folder
230
-                EVENT_ESPRESSO_TEMPLATE_DIR,
231
-            ];
232
-
233
-            // add core plugin folders for checking only if we're not $check_if_custom
234
-            if (! $check_if_custom) {
235
-                $core_paths            = [
236
-                    // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
237
-                    EE_PUBLIC . $current_theme,
238
-                    // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
239
-                    EE_TEMPLATES . $current_theme,
240
-                    // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
241
-                    EE_PLUGIN_DIR_PATH,
242
-                ];
243
-                $template_folder_paths = array_merge($template_folder_paths, $core_paths);
244
-            }
245
-
246
-            // now filter that array
247
-            $template_folder_paths = apply_filters(
248
-                'FHEE__EEH_Template__locate_template__template_folder_paths',
249
-                $template_folder_paths
250
-            );
251
-            $templates             = is_array($templates) ? $templates : [$templates];
252
-            $template_folder_paths =
253
-                is_array($template_folder_paths) ? $template_folder_paths : [$template_folder_paths];
254
-            // array to hold all possible template paths
255
-            $full_template_paths = [];
256
-            $file_name           = '';
257
-
258
-            // loop through $templates
259
-            foreach ($templates as $template) {
260
-                // normalize directory separators
261
-                $template                      = EEH_File::standardise_directory_separators($template);
262
-                $file_name                     = basename($template);
263
-                $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
264
-                // while looping through all template folder paths
265
-                foreach ($template_folder_paths as $template_folder_path) {
266
-                    // normalize directory separators
267
-                    $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
268
-                    // determine if any common base path exists between the two paths
269
-                    $common_base_path = EEH_Template::_find_common_base_path(
270
-                        [$template_folder_path, $template_path_minus_file_name]
271
-                    );
272
-                    if ($common_base_path !== '') {
273
-                        // both paths have a common base, so just tack the filename onto our search path
274
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
275
-                    } else {
276
-                        // no common base path, so let's just concatenate
277
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
278
-                    }
279
-                    // build up our template locations array by adding our resolved paths
280
-                    $full_template_paths[] = $resolved_path;
281
-                }
282
-                // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
283
-                array_unshift($full_template_paths, $template);
284
-                // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
285
-                array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
286
-            }
287
-            // filter final array of full template paths
288
-            $full_template_paths = apply_filters(
289
-                'FHEE__EEH_Template__locate_template__full_template_paths',
290
-                $full_template_paths,
291
-                $file_name
292
-            );
293
-            // now loop through our final array of template location paths and check each location
294
-            foreach ((array) $full_template_paths as $full_template_path) {
295
-                if (is_readable($full_template_path)) {
296
-                    $template_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $full_template_path);
297
-                    break;
298
-                }
299
-            }
300
-        }
301
-
302
-        // hook that can be used to display the full template path that will be used
303
-        do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
304
-
305
-        // if we got it and you want to see it...
306
-        if ($template_path && $load && ! $check_if_custom) {
307
-            if ($return_string) {
308
-                return EEH_Template::display_template($template_path, $template_args, true);
309
-            }
310
-            EEH_Template::display_template($template_path, $template_args);
311
-        }
312
-        return $check_if_custom && ! empty($template_path) ? true : $template_path;
313
-    }
314
-
315
-
316
-    /**
317
-     * _find_common_base_path
318
-     * given two paths, this determines if there is a common base path between the two
319
-     *
320
-     * @param array $paths
321
-     * @return string
322
-     */
323
-    protected static function _find_common_base_path($paths)
324
-    {
325
-        $last_offset      = 0;
326
-        $common_base_path = '';
327
-        while (($index = strpos($paths[0], '/', $last_offset)) !== false) {
328
-            $dir_length = $index - $last_offset + 1;
329
-            $directory  = substr($paths[0], $last_offset, $dir_length);
330
-            foreach ($paths as $path) {
331
-                if (substr($path, $last_offset, $dir_length) != $directory) {
332
-                    return $common_base_path;
333
-                }
334
-            }
335
-            $common_base_path .= $directory;
336
-            $last_offset      = $index + 1;
337
-        }
338
-        return substr($common_base_path, 0, -1);
339
-    }
340
-
341
-
342
-    /**
343
-     * load and display a template
344
-     *
345
-     * @param bool|string $template_path    server path to the file to be loaded, including file name and extension
346
-     * @param array       $template_args    an array of arguments to be extracted for use in the template
347
-     * @param boolean     $return_string    whether to send output immediately to screen, or capture and return as a
348
-     *                                      string
349
-     * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
350
-     *                                      not found or is not readable
351
-     * @return string
352
-     * @throws DomainException
353
-     */
354
-    public static function display_template(
355
-        $template_path = false,
356
-        $template_args = [],
357
-        $return_string = false,
358
-        $throw_exceptions = false
359
-    ) {
360
-
361
-        /**
362
-         * These two filters are intended for last minute changes to templates being loaded and/or template arg
363
-         * modifications.  NOTE... modifying these things can cause breakage as most templates running through
364
-         * the display_template method are templates we DON'T want modified (usually because of js
365
-         * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
366
-         * using this.
367
-         *
368
-         * @since 4.6.0
369
-         */
370
-        $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
371
-        $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
372
-
373
-        // you gimme nuttin - YOU GET NUTTIN !!
374
-        if (! $template_path || ! is_readable($template_path)) {
375
-            // ignore whether template is accessible ?
376
-            if ($throw_exceptions) {
377
-                throw new DomainException(
378
-                    esc_html__('Invalid, unreadable, or missing file.', 'event_espresso')
379
-                );
380
-            }
381
-            return '';
382
-        }
383
-        // if $template_args are not in an array, then make it so
384
-        if (! is_array($template_args) && ! is_object($template_args)) {
385
-            $template_args = [$template_args];
386
-        }
387
-        extract($template_args, EXTR_SKIP);
388
-
389
-        if ($return_string) {
390
-            // because we want to return a string, we are going to capture the output
391
-            ob_start();
392
-            include($template_path);
393
-            return ob_get_clean();
394
-        }
395
-        include($template_path);
396
-        return '';
397
-    }
398
-
399
-
400
-    /**
401
-     * get_object_css_class - attempts to generate a css class based on the type of EE object passed
402
-     *
403
-     * @param EE_Base_Class $object the EE object the css class is being generated for
404
-     * @param string        $prefix added to the beginning of the generated class
405
-     * @param string        $suffix added to the end of the generated class
406
-     * @return string
407
-     * @throws EE_Error
408
-     * @throws ReflectionException
409
-     */
410
-    public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
411
-    {
412
-        // in the beginning...
413
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
414
-        // da muddle
415
-        $class = '';
416
-        // the end
417
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
418
-        // is the passed object an EE object ?
419
-        if ($object instanceof EE_Base_Class) {
420
-            // grab the exact type of object
421
-            $obj_class = get_class($object);
422
-            // depending on the type of object...
423
-            switch ($obj_class) {
424
-                // no specifics just yet...
425
-                default:
426
-                    $class = strtolower(str_replace('_', '-', $obj_class));
427
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
428
-            }
429
-        }
430
-        return $prefix . $class . $suffix;
431
-    }
432
-
433
-
434
-    /**
435
-     * EEH_Template::format_currency
436
-     * This helper takes a raw float value and formats it according to the default config country currency settings, or
437
-     * the country currency settings from the supplied country ISO code
438
-     *
439
-     * @param float   $amount       raw money value
440
-     * @param boolean $return_raw   whether to return the formatted float value only with no currency sign or code
441
-     * @param boolean $display_code whether to display the country code (USD). Default = TRUE
442
-     * @param string  $CNT_ISO      2 letter ISO code for a country
443
-     * @param string  $cur_code_span_class
444
-     * @return string        the html output for the formatted money value
445
-     */
446
-    public static function format_currency(
447
-        $amount = null,
448
-        $return_raw = false,
449
-        $display_code = true,
450
-        $CNT_ISO = '',
451
-        $cur_code_span_class = 'currency-code'
452
-    ) {
453
-        // ensure amount was received
454
-        if ($amount === null) {
455
-            $msg = esc_html__('In order to format currency, an amount needs to be passed.', 'event_espresso');
456
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
457
-            return '';
458
-        }
459
-        // ensure amount is float
460
-        $amount  = (float) apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
461
-        $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
462
-        // filter raw amount (allows 0.00 to be changed to "free" for example)
463
-        $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
464
-        // still a number, or was amount converted to a string like "free" ?
465
-        if (! is_float($amount_formatted)) {
466
-            return esc_html($amount_formatted);
467
-        }
468
-        try {
469
-            // was a country ISO code passed ? if so generate currency config object for that country
470
-            $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
471
-        } catch (Exception $e) {
472
-            // eat exception
473
-            $mny = null;
474
-        }
475
-        // verify results
476
-        if (! $mny instanceof EE_Currency_Config) {
477
-            // set default config country currency settings
478
-            $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
479
-                ? EE_Registry::instance()->CFG->currency
480
-                : new EE_Currency_Config();
481
-        }
482
-        // format float
483
-        $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
484
-        // add formatting ?
485
-        if (! $return_raw) {
486
-            // add currency sign
487
-            if ($mny->sign_b4) {
488
-                if ($amount >= 0) {
489
-                    $amount_formatted = $mny->sign . $amount_formatted;
490
-                } else {
491
-                    $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
492
-                }
493
-            } else {
494
-                $amount_formatted = $amount_formatted . $mny->sign;
495
-            }
496
-
497
-            // filter to allow global setting of display_code
498
-            $display_code = (bool) apply_filters(
499
-                'FHEE__EEH_Template__format_currency__display_code',
500
-                $display_code
501
-            );
502
-
503
-            // add currency code ?
504
-            $amount_formatted = $display_code
505
-                ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>'
506
-                : $amount_formatted;
507
-        }
508
-        // filter results
509
-        $amount_formatted = apply_filters(
510
-            'FHEE__EEH_Template__format_currency__amount_formatted',
511
-            $amount_formatted,
512
-            $mny,
513
-            $return_raw
514
-        );
515
-        // clean up vars
516
-        unset($mny);
517
-        // return formatted currency amount
518
-        return $amount_formatted;
519
-    }
520
-
521
-
522
-    /**
523
-     * This function is used for outputting the localized label for a given status id in the schema requested (and
524
-     * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
525
-     * related status model or model object (i.e. in documentation etc.)
526
-     *
527
-     * @param string  $status_id  Status ID matching a registered status in the esp_status table.  If there is no
528
-     *                            match, then 'Unknown' will be returned.
529
-     * @param boolean $plural     Whether to return plural or not
530
-     * @param string  $schema     'UPPER', 'lower', or 'Sentence'
531
-     * @return string             The localized label for the status id.
532
-     * @throws EE_Error
533
-     */
534
-    public static function pretty_status($status_id, $plural = false, $schema = 'upper')
535
-    {
536
-        $status = EEM_Status::instance()->localized_status(
537
-            [$status_id => esc_html__('unknown', 'event_espresso')],
538
-            $plural,
539
-            $schema
540
-        );
541
-        return $status[ $status_id ];
542
-    }
543
-
544
-
545
-    /**
546
-     * This helper just returns a button or link for the given parameters
547
-     *
548
-     * @param string $url   the url for the link, note that `esc_url` will be called on it
549
-     * @param string $label What is the label you want displayed for the button
550
-     * @param string $class what class is used for the button (defaults to 'button--primary')
551
-     * @param string $icon
552
-     * @param string $title
553
-     * @return string the html output for the button
554
-     */
555
-    public static function get_button_or_link($url, $label, $class = 'button button--primary', $icon = '', $title = '')
556
-    {
557
-        $icon_html = '';
558
-        if (! empty($icon)) {
559
-            $dashicons = preg_split("(ee-icon |dashicons )", $icon);
560
-            $dashicons = array_filter($dashicons);
561
-            $count     = count($dashicons);
562
-            $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
563
-            foreach ($dashicons as $dashicon) {
564
-                $type      = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
565
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
566
-            }
567
-            $icon_html .= $count > 1 ? '</span>' : '';
568
-        }
569
-        // sanitize & escape
570
-        $id    = sanitize_title_with_dashes($label);
571
-        $url   = esc_url_raw($url);
572
-        $class = esc_attr($class);
573
-        $title = esc_attr($title);
574
-        $class .= $title ? ' ee-aria-tooltip' : '';
575
-        $title = $title ? " aria-label='{$title}'" : '';
576
-        $label = esc_html($label);
577
-        return "<a id='{$id}' href='{$url}' class='{$class}'{$title}>{$icon_html}{$label}</a>";
578
-    }
579
-
580
-
581
-    /**
582
-     * This returns a generated link that will load the related help tab on admin pages.
583
-     *
584
-     * @param string      $help_tab_id the id for the connected help tab
585
-     * @param bool|string $page        The page identifier for the page the help tab is on
586
-     * @param bool|string $action      The action (route) for the admin page the help tab is on.
587
-     * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
588
-     * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
589
-     * @return string              generated link
590
-     */
591
-    public static function get_help_tab_link(
592
-        $help_tab_id,
593
-        $page = false,
594
-        $action = false,
595
-        $icon_style = false,
596
-        $help_text = false
597
-    ) {
598
-        global $allowedtags;
599
-        /** @var RequestInterface $request */
600
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
601
-        $page    = $page ?: $request->getRequestParam('page', '', 'key');
602
-        $action  = $action ?: $request->getRequestParam('action', 'default', 'key');
603
-
604
-
605
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
606
-        $icon      = ! $icon_style ? 'dashicons-editor-help' : $icon_style;
607
-        $help_text = ! $help_text ? '' : $help_text;
608
-        return '
53
+	private static $_espresso_themes = [];
54
+
55
+
56
+	/**
57
+	 *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
58
+	 *
59
+	 * @return boolean
60
+	 */
61
+	public static function is_espresso_theme()
62
+	{
63
+		return wp_get_theme()->get('TextDomain') === 'event_espresso';
64
+	}
65
+
66
+
67
+	/**
68
+	 *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
69
+	 *    load its functions.php file ( if not already loaded )
70
+	 *
71
+	 * @return void
72
+	 */
73
+	public static function load_espresso_theme_functions()
74
+	{
75
+		if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
76
+			if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
77
+				require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
78
+			}
79
+		}
80
+	}
81
+
82
+
83
+	/**
84
+	 *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
85
+	 *
86
+	 * @return array
87
+	 */
88
+	public static function get_espresso_themes()
89
+	{
90
+		if (empty(EEH_Template::$_espresso_themes)) {
91
+			$espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
92
+			if (empty($espresso_themes)) {
93
+				return [];
94
+			}
95
+			if (($key = array_search('global_assets', $espresso_themes)) !== false) {
96
+				unset($espresso_themes[ $key ]);
97
+			}
98
+			EEH_Template::$_espresso_themes = [];
99
+			foreach ($espresso_themes as $espresso_theme) {
100
+				EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
101
+			}
102
+		}
103
+		return EEH_Template::$_espresso_themes;
104
+	}
105
+
106
+
107
+	/**
108
+	 * EEH_Template::get_template_part
109
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
110
+	 * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
111
+	 * filtering based off of the entire template part name
112
+	 *
113
+	 * @param string $slug The slug name for the generic template.
114
+	 * @param string $name The name of the specialised template.
115
+	 * @param array  $template_args
116
+	 * @param bool   $return_string
117
+	 * @return string        the html output for the formatted money value
118
+	 */
119
+	public static function get_template_part(
120
+		$slug = null,
121
+		$name = null,
122
+		$template_args = [],
123
+		$return_string = false
124
+	) {
125
+		do_action("get_template_part_{$slug}-{$name}", $slug, $name);
126
+		$templates = [];
127
+		$name      = (string) $name;
128
+		if ($name != '') {
129
+			$templates[] = "{$slug}-{$name}.php";
130
+		}
131
+		// allow template parts to be turned off via something like:
132
+		// add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
133
+		if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
134
+			return EEH_Template::locate_template($templates, $template_args, true, $return_string);
135
+		}
136
+		return '';
137
+	}
138
+
139
+
140
+	/**
141
+	 *    locate_template
142
+	 *    locate a template file by looking in the following places, in the following order:
143
+	 *        <server path up to>/wp-content/themes/<current active WordPress theme>/
144
+	 *        <assumed full absolute server path>
145
+	 *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
146
+	 *        <server path up to>/wp-content/uploads/espresso/templates/
147
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
148
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
149
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/
150
+	 *    as soon as the template is found in one of these locations, it will be returned or loaded
151
+	 *        Example:
152
+	 *          You are using the WordPress Twenty Sixteen theme,
153
+	 *        and you want to customize the "some-event.template.php" template,
154
+	 *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
155
+	 *          Assuming WP is installed on your server in the "/home/public_html/" folder,
156
+	 *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
157
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
158
+	 *        /relative/path/to/some-event.template.php
159
+	 *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
160
+	 *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
161
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
162
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
163
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
164
+	 *          Had you passed an absolute path to your template that was in some other location,
165
+	 *        ie: "/absolute/path/to/some-event.template.php"
166
+	 *          then the search would have been :
167
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
168
+	 *        /absolute/path/to/some-event.template.php
169
+	 *          and stopped there upon finding it in the second location
170
+	 *
171
+	 * @param array|string $templates       array of template file names including extension (or just a single string)
172
+	 * @param array        $template_args   an array of arguments to be extracted for use in the template
173
+	 * @param boolean      $load            whether to pass the located template path on to the
174
+	 *                                      EEH_Template::display_template() method or simply return it
175
+	 * @param boolean      $return_string   whether to send output immediately to screen, or capture and return as a
176
+	 *                                      string
177
+	 * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
178
+	 *                                      generate a custom template or not. Used in places where you don't actually
179
+	 *                                      load the template, you just want to know if there's a custom version of it.
180
+	 * @return mixed
181
+	 * @throws DomainException
182
+	 * @throws InvalidArgumentException
183
+	 * @throws InvalidDataTypeException
184
+	 * @throws InvalidInterfaceException
185
+	 */
186
+	public static function locate_template(
187
+		$templates = [],
188
+		$template_args = [],
189
+		$load = true,
190
+		$return_string = true,
191
+		$check_if_custom = false
192
+	) {
193
+		// first use WP locate_template to check for template in the current theme folder
194
+		$template_path = locate_template($templates);
195
+
196
+		if ($check_if_custom && ! empty($template_path)) {
197
+			return true;
198
+		}
199
+
200
+		// not in the theme
201
+		if (empty($template_path)) {
202
+			// not even a template to look for ?
203
+			if (empty($templates)) {
204
+				$loader = LoaderFactory::getLoader();
205
+				/** @var RequestInterface $request */
206
+				$request = $loader->getShared(RequestInterface::class);
207
+				// get post_type
208
+				$post_type = $request->getRequestParam('post_type');
209
+				/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
210
+				$custom_post_types = $loader->getShared(
211
+					'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
212
+				);
213
+				// get array of EE Custom Post Types
214
+				$EE_CPTs = $custom_post_types->getDefinitions();
215
+				// build template name based on request
216
+				if (isset($EE_CPTs[ $post_type ])) {
217
+					$archive_or_single = is_archive() ? 'archive' : '';
218
+					$archive_or_single = is_single() ? 'single' : $archive_or_single;
219
+					$templates         = $archive_or_single . '-' . $post_type . '.php';
220
+				}
221
+			}
222
+			// currently active EE template theme
223
+			$current_theme = EE_Config::get_current_theme();
224
+
225
+			// array of paths to folders that may contain templates
226
+			$template_folder_paths = [
227
+				// first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
228
+				EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
229
+				// then in the root of the /wp-content/uploads/espresso/templates/ folder
230
+				EVENT_ESPRESSO_TEMPLATE_DIR,
231
+			];
232
+
233
+			// add core plugin folders for checking only if we're not $check_if_custom
234
+			if (! $check_if_custom) {
235
+				$core_paths            = [
236
+					// in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
237
+					EE_PUBLIC . $current_theme,
238
+					// in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
239
+					EE_TEMPLATES . $current_theme,
240
+					// or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
241
+					EE_PLUGIN_DIR_PATH,
242
+				];
243
+				$template_folder_paths = array_merge($template_folder_paths, $core_paths);
244
+			}
245
+
246
+			// now filter that array
247
+			$template_folder_paths = apply_filters(
248
+				'FHEE__EEH_Template__locate_template__template_folder_paths',
249
+				$template_folder_paths
250
+			);
251
+			$templates             = is_array($templates) ? $templates : [$templates];
252
+			$template_folder_paths =
253
+				is_array($template_folder_paths) ? $template_folder_paths : [$template_folder_paths];
254
+			// array to hold all possible template paths
255
+			$full_template_paths = [];
256
+			$file_name           = '';
257
+
258
+			// loop through $templates
259
+			foreach ($templates as $template) {
260
+				// normalize directory separators
261
+				$template                      = EEH_File::standardise_directory_separators($template);
262
+				$file_name                     = basename($template);
263
+				$template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
264
+				// while looping through all template folder paths
265
+				foreach ($template_folder_paths as $template_folder_path) {
266
+					// normalize directory separators
267
+					$template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
268
+					// determine if any common base path exists between the two paths
269
+					$common_base_path = EEH_Template::_find_common_base_path(
270
+						[$template_folder_path, $template_path_minus_file_name]
271
+					);
272
+					if ($common_base_path !== '') {
273
+						// both paths have a common base, so just tack the filename onto our search path
274
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
275
+					} else {
276
+						// no common base path, so let's just concatenate
277
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
278
+					}
279
+					// build up our template locations array by adding our resolved paths
280
+					$full_template_paths[] = $resolved_path;
281
+				}
282
+				// if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
283
+				array_unshift($full_template_paths, $template);
284
+				// path to the directory of the current theme: /wp-content/themes/(current WP theme)/
285
+				array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
286
+			}
287
+			// filter final array of full template paths
288
+			$full_template_paths = apply_filters(
289
+				'FHEE__EEH_Template__locate_template__full_template_paths',
290
+				$full_template_paths,
291
+				$file_name
292
+			);
293
+			// now loop through our final array of template location paths and check each location
294
+			foreach ((array) $full_template_paths as $full_template_path) {
295
+				if (is_readable($full_template_path)) {
296
+					$template_path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $full_template_path);
297
+					break;
298
+				}
299
+			}
300
+		}
301
+
302
+		// hook that can be used to display the full template path that will be used
303
+		do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
304
+
305
+		// if we got it and you want to see it...
306
+		if ($template_path && $load && ! $check_if_custom) {
307
+			if ($return_string) {
308
+				return EEH_Template::display_template($template_path, $template_args, true);
309
+			}
310
+			EEH_Template::display_template($template_path, $template_args);
311
+		}
312
+		return $check_if_custom && ! empty($template_path) ? true : $template_path;
313
+	}
314
+
315
+
316
+	/**
317
+	 * _find_common_base_path
318
+	 * given two paths, this determines if there is a common base path between the two
319
+	 *
320
+	 * @param array $paths
321
+	 * @return string
322
+	 */
323
+	protected static function _find_common_base_path($paths)
324
+	{
325
+		$last_offset      = 0;
326
+		$common_base_path = '';
327
+		while (($index = strpos($paths[0], '/', $last_offset)) !== false) {
328
+			$dir_length = $index - $last_offset + 1;
329
+			$directory  = substr($paths[0], $last_offset, $dir_length);
330
+			foreach ($paths as $path) {
331
+				if (substr($path, $last_offset, $dir_length) != $directory) {
332
+					return $common_base_path;
333
+				}
334
+			}
335
+			$common_base_path .= $directory;
336
+			$last_offset      = $index + 1;
337
+		}
338
+		return substr($common_base_path, 0, -1);
339
+	}
340
+
341
+
342
+	/**
343
+	 * load and display a template
344
+	 *
345
+	 * @param bool|string $template_path    server path to the file to be loaded, including file name and extension
346
+	 * @param array       $template_args    an array of arguments to be extracted for use in the template
347
+	 * @param boolean     $return_string    whether to send output immediately to screen, or capture and return as a
348
+	 *                                      string
349
+	 * @param bool        $throw_exceptions if set to true, will throw an exception if the template is either
350
+	 *                                      not found or is not readable
351
+	 * @return string
352
+	 * @throws DomainException
353
+	 */
354
+	public static function display_template(
355
+		$template_path = false,
356
+		$template_args = [],
357
+		$return_string = false,
358
+		$throw_exceptions = false
359
+	) {
360
+
361
+		/**
362
+		 * These two filters are intended for last minute changes to templates being loaded and/or template arg
363
+		 * modifications.  NOTE... modifying these things can cause breakage as most templates running through
364
+		 * the display_template method are templates we DON'T want modified (usually because of js
365
+		 * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
366
+		 * using this.
367
+		 *
368
+		 * @since 4.6.0
369
+		 */
370
+		$template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
371
+		$template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
372
+
373
+		// you gimme nuttin - YOU GET NUTTIN !!
374
+		if (! $template_path || ! is_readable($template_path)) {
375
+			// ignore whether template is accessible ?
376
+			if ($throw_exceptions) {
377
+				throw new DomainException(
378
+					esc_html__('Invalid, unreadable, or missing file.', 'event_espresso')
379
+				);
380
+			}
381
+			return '';
382
+		}
383
+		// if $template_args are not in an array, then make it so
384
+		if (! is_array($template_args) && ! is_object($template_args)) {
385
+			$template_args = [$template_args];
386
+		}
387
+		extract($template_args, EXTR_SKIP);
388
+
389
+		if ($return_string) {
390
+			// because we want to return a string, we are going to capture the output
391
+			ob_start();
392
+			include($template_path);
393
+			return ob_get_clean();
394
+		}
395
+		include($template_path);
396
+		return '';
397
+	}
398
+
399
+
400
+	/**
401
+	 * get_object_css_class - attempts to generate a css class based on the type of EE object passed
402
+	 *
403
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
404
+	 * @param string        $prefix added to the beginning of the generated class
405
+	 * @param string        $suffix added to the end of the generated class
406
+	 * @return string
407
+	 * @throws EE_Error
408
+	 * @throws ReflectionException
409
+	 */
410
+	public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
411
+	{
412
+		// in the beginning...
413
+		$prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
414
+		// da muddle
415
+		$class = '';
416
+		// the end
417
+		$suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
418
+		// is the passed object an EE object ?
419
+		if ($object instanceof EE_Base_Class) {
420
+			// grab the exact type of object
421
+			$obj_class = get_class($object);
422
+			// depending on the type of object...
423
+			switch ($obj_class) {
424
+				// no specifics just yet...
425
+				default:
426
+					$class = strtolower(str_replace('_', '-', $obj_class));
427
+					$class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
428
+			}
429
+		}
430
+		return $prefix . $class . $suffix;
431
+	}
432
+
433
+
434
+	/**
435
+	 * EEH_Template::format_currency
436
+	 * This helper takes a raw float value and formats it according to the default config country currency settings, or
437
+	 * the country currency settings from the supplied country ISO code
438
+	 *
439
+	 * @param float   $amount       raw money value
440
+	 * @param boolean $return_raw   whether to return the formatted float value only with no currency sign or code
441
+	 * @param boolean $display_code whether to display the country code (USD). Default = TRUE
442
+	 * @param string  $CNT_ISO      2 letter ISO code for a country
443
+	 * @param string  $cur_code_span_class
444
+	 * @return string        the html output for the formatted money value
445
+	 */
446
+	public static function format_currency(
447
+		$amount = null,
448
+		$return_raw = false,
449
+		$display_code = true,
450
+		$CNT_ISO = '',
451
+		$cur_code_span_class = 'currency-code'
452
+	) {
453
+		// ensure amount was received
454
+		if ($amount === null) {
455
+			$msg = esc_html__('In order to format currency, an amount needs to be passed.', 'event_espresso');
456
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
457
+			return '';
458
+		}
459
+		// ensure amount is float
460
+		$amount  = (float) apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
461
+		$CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
462
+		// filter raw amount (allows 0.00 to be changed to "free" for example)
463
+		$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
464
+		// still a number, or was amount converted to a string like "free" ?
465
+		if (! is_float($amount_formatted)) {
466
+			return esc_html($amount_formatted);
467
+		}
468
+		try {
469
+			// was a country ISO code passed ? if so generate currency config object for that country
470
+			$mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
471
+		} catch (Exception $e) {
472
+			// eat exception
473
+			$mny = null;
474
+		}
475
+		// verify results
476
+		if (! $mny instanceof EE_Currency_Config) {
477
+			// set default config country currency settings
478
+			$mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
479
+				? EE_Registry::instance()->CFG->currency
480
+				: new EE_Currency_Config();
481
+		}
482
+		// format float
483
+		$amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
484
+		// add formatting ?
485
+		if (! $return_raw) {
486
+			// add currency sign
487
+			if ($mny->sign_b4) {
488
+				if ($amount >= 0) {
489
+					$amount_formatted = $mny->sign . $amount_formatted;
490
+				} else {
491
+					$amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
492
+				}
493
+			} else {
494
+				$amount_formatted = $amount_formatted . $mny->sign;
495
+			}
496
+
497
+			// filter to allow global setting of display_code
498
+			$display_code = (bool) apply_filters(
499
+				'FHEE__EEH_Template__format_currency__display_code',
500
+				$display_code
501
+			);
502
+
503
+			// add currency code ?
504
+			$amount_formatted = $display_code
505
+				? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>'
506
+				: $amount_formatted;
507
+		}
508
+		// filter results
509
+		$amount_formatted = apply_filters(
510
+			'FHEE__EEH_Template__format_currency__amount_formatted',
511
+			$amount_formatted,
512
+			$mny,
513
+			$return_raw
514
+		);
515
+		// clean up vars
516
+		unset($mny);
517
+		// return formatted currency amount
518
+		return $amount_formatted;
519
+	}
520
+
521
+
522
+	/**
523
+	 * This function is used for outputting the localized label for a given status id in the schema requested (and
524
+	 * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
525
+	 * related status model or model object (i.e. in documentation etc.)
526
+	 *
527
+	 * @param string  $status_id  Status ID matching a registered status in the esp_status table.  If there is no
528
+	 *                            match, then 'Unknown' will be returned.
529
+	 * @param boolean $plural     Whether to return plural or not
530
+	 * @param string  $schema     'UPPER', 'lower', or 'Sentence'
531
+	 * @return string             The localized label for the status id.
532
+	 * @throws EE_Error
533
+	 */
534
+	public static function pretty_status($status_id, $plural = false, $schema = 'upper')
535
+	{
536
+		$status = EEM_Status::instance()->localized_status(
537
+			[$status_id => esc_html__('unknown', 'event_espresso')],
538
+			$plural,
539
+			$schema
540
+		);
541
+		return $status[ $status_id ];
542
+	}
543
+
544
+
545
+	/**
546
+	 * This helper just returns a button or link for the given parameters
547
+	 *
548
+	 * @param string $url   the url for the link, note that `esc_url` will be called on it
549
+	 * @param string $label What is the label you want displayed for the button
550
+	 * @param string $class what class is used for the button (defaults to 'button--primary')
551
+	 * @param string $icon
552
+	 * @param string $title
553
+	 * @return string the html output for the button
554
+	 */
555
+	public static function get_button_or_link($url, $label, $class = 'button button--primary', $icon = '', $title = '')
556
+	{
557
+		$icon_html = '';
558
+		if (! empty($icon)) {
559
+			$dashicons = preg_split("(ee-icon |dashicons )", $icon);
560
+			$dashicons = array_filter($dashicons);
561
+			$count     = count($dashicons);
562
+			$icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
563
+			foreach ($dashicons as $dashicon) {
564
+				$type      = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
565
+				$icon_html .= '<span class="' . $type . $dashicon . '"></span>';
566
+			}
567
+			$icon_html .= $count > 1 ? '</span>' : '';
568
+		}
569
+		// sanitize & escape
570
+		$id    = sanitize_title_with_dashes($label);
571
+		$url   = esc_url_raw($url);
572
+		$class = esc_attr($class);
573
+		$title = esc_attr($title);
574
+		$class .= $title ? ' ee-aria-tooltip' : '';
575
+		$title = $title ? " aria-label='{$title}'" : '';
576
+		$label = esc_html($label);
577
+		return "<a id='{$id}' href='{$url}' class='{$class}'{$title}>{$icon_html}{$label}</a>";
578
+	}
579
+
580
+
581
+	/**
582
+	 * This returns a generated link that will load the related help tab on admin pages.
583
+	 *
584
+	 * @param string      $help_tab_id the id for the connected help tab
585
+	 * @param bool|string $page        The page identifier for the page the help tab is on
586
+	 * @param bool|string $action      The action (route) for the admin page the help tab is on.
587
+	 * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
588
+	 * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
589
+	 * @return string              generated link
590
+	 */
591
+	public static function get_help_tab_link(
592
+		$help_tab_id,
593
+		$page = false,
594
+		$action = false,
595
+		$icon_style = false,
596
+		$help_text = false
597
+	) {
598
+		global $allowedtags;
599
+		/** @var RequestInterface $request */
600
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
601
+		$page    = $page ?: $request->getRequestParam('page', '', 'key');
602
+		$action  = $action ?: $request->getRequestParam('action', 'default', 'key');
603
+
604
+
605
+		$help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
606
+		$icon      = ! $icon_style ? 'dashicons-editor-help' : $icon_style;
607
+		$help_text = ! $help_text ? '' : $help_text;
608
+		return '
609 609
         	<a 	id="' . esc_attr($help_tab_lnk) . '" 
610 610
         		class="espresso-help-tab-lnk ee-help-btn ee-aria-tooltip dashicons ' . esc_attr($icon) . '" 
611 611
         		aria-label="' . esc_attr__(
612
-                        'Click to open the \'Help\' tab for more information about this feature.',
613
-                        'event_espresso'
614
-                ) . '" 
612
+						'Click to open the \'Help\' tab for more information about this feature.',
613
+						'event_espresso'
614
+				) . '" 
615 615
 		    >
616 616
 		    	' . wp_kses($help_text, $allowedtags) . '
617 617
 			</a>';
618
-    }
619
-
620
-
621
-    /**
622
-     * This is a helper method to generate a status legend for a given status array.
623
-     * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
624
-     * status_array.
625
-     *
626
-     * @param array  $status_array   array of statuses that will make up the legend. In format:
627
-     *                               array(
628
-     *                               'status_item' => 'status_name'
629
-     *                               )
630
-     * @param string $active_status  This is used to indicate what the active status is IF that is to be highlighted in
631
-     *                               the legend.
632
-     * @return string               html structure for status.
633
-     * @throws EE_Error
634
-     */
635
-    public static function status_legend($status_array, $active_status = '')
636
-    {
637
-        if (! is_array($status_array)) {
638
-            throw new EE_Error(
639
-                esc_html__(
640
-                    'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
641
-                    'event_espresso'
642
-                )
643
-            );
644
-        }
645
-
646
-        $content = '
618
+	}
619
+
620
+
621
+	/**
622
+	 * This is a helper method to generate a status legend for a given status array.
623
+	 * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
624
+	 * status_array.
625
+	 *
626
+	 * @param array  $status_array   array of statuses that will make up the legend. In format:
627
+	 *                               array(
628
+	 *                               'status_item' => 'status_name'
629
+	 *                               )
630
+	 * @param string $active_status  This is used to indicate what the active status is IF that is to be highlighted in
631
+	 *                               the legend.
632
+	 * @return string               html structure for status.
633
+	 * @throws EE_Error
634
+	 */
635
+	public static function status_legend($status_array, $active_status = '')
636
+	{
637
+		if (! is_array($status_array)) {
638
+			throw new EE_Error(
639
+				esc_html__(
640
+					'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
641
+					'event_espresso'
642
+				)
643
+			);
644
+		}
645
+
646
+		$content = '
647 647
             <div class="ee-list-table-legend-container">
648 648
                 <h4 class="status-legend-title">
649 649
                     ' . esc_html__('Status Legend', 'event_espresso') . '
650 650
                 </h4>
651 651
                 <dl class="ee-list-table-legend">';
652 652
 
653
-        foreach ($status_array as $item => $status) {
654
-            $active_class = $active_status == $status ? 'class="ee-is-active-status"' : '';
655
-            $content      .= '
653
+		foreach ($status_array as $item => $status) {
654
+			$active_class = $active_status == $status ? 'class="ee-is-active-status"' : '';
655
+			$content      .= '
656 656
                     <dt id="' . esc_attr('ee-legend-item-tooltip-' . $item) . '" ' . $active_class . '>
657 657
                         <span class="' . esc_attr('ee-status-legend ee-status-bg--' . $status) . '"></span>
658 658
                         <span class="ee-legend-description">
659 659
                             ' . EEH_Template::pretty_status($status, false, 'sentence') . '
660 660
                         </span>
661 661
                     </dt>';
662
-        }
662
+		}
663 663
 
664
-        $content .= '
664
+		$content .= '
665 665
                 </dl>
666 666
             </div>
667 667
 ';
668
-        return $content;
669
-    }
670
-
671
-
672
-    /**
673
-     * Gets HTML for laying out a deeply-nested array (and objects) in a format
674
-     * that's nice for presenting in the wp admin
675
-     *
676
-     * @param mixed $data
677
-     * @return string
678
-     */
679
-    public static function layout_array_as_table($data)
680
-    {
681
-        if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
682
-            $data = (array) $data;
683
-        }
684
-        ob_start();
685
-        if (is_array($data)) {
686
-            if (EEH_Array::is_associative_array($data)) { ?>
668
+		return $content;
669
+	}
670
+
671
+
672
+	/**
673
+	 * Gets HTML for laying out a deeply-nested array (and objects) in a format
674
+	 * that's nice for presenting in the wp admin
675
+	 *
676
+	 * @param mixed $data
677
+	 * @return string
678
+	 */
679
+	public static function layout_array_as_table($data)
680
+	{
681
+		if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
682
+			$data = (array) $data;
683
+		}
684
+		ob_start();
685
+		if (is_array($data)) {
686
+			if (EEH_Array::is_associative_array($data)) { ?>
687 687
                 <table class="widefat">
688 688
                     <tbody>
689 689
                     <?php foreach ($data as $data_key => $data_values) { ?>
@@ -701,292 +701,292 @@  discard block
 block discarded – undo
701 701
             <?php } else { ?>
702 702
                 <ul>
703 703
                     <?php
704
-                    foreach ($data as $datum) {
705
-                        echo "<li>";
706
-                        echo self::layout_array_as_table($datum);
707
-                        echo "</li>";
708
-                    } ?>
704
+					foreach ($data as $datum) {
705
+						echo "<li>";
706
+						echo self::layout_array_as_table($datum);
707
+						echo "</li>";
708
+					} ?>
709 709
                 </ul>
710 710
             <?php }
711
-        } else {
712
-            // simple value
713
-            echo esc_html($data);
714
-        }
715
-        return ob_get_clean();
716
-    }
717
-
718
-
719
-    /**
720
-     * wrapper for self::get_paging_html() that simply echos the generated paging html
721
-     *
722
-     * @param        $total_items
723
-     * @param        $current
724
-     * @param        $per_page
725
-     * @param        $url
726
-     * @param bool   $show_num_field
727
-     * @param string $paged_arg_name
728
-     * @param array  $items_label
729
-     * @see   self:get_paging_html() for argument docs.
730
-     * @since 4.4.0
731
-     */
732
-    public static function paging_html(
733
-        $total_items,
734
-        $current,
735
-        $per_page,
736
-        $url,
737
-        $show_num_field = true,
738
-        $paged_arg_name = 'paged',
739
-        $items_label = []
740
-    ) {
741
-        echo self::get_paging_html(
742
-            $total_items,
743
-            $current,
744
-            $per_page,
745
-            $url,
746
-            $show_num_field,
747
-            $paged_arg_name,
748
-            $items_label
749
-        );
750
-    }
751
-
752
-
753
-    /**
754
-     * A method for generating paging similar to WP_List_Table
755
-     *
756
-     * @param integer $total_items      How many total items there are to page.
757
-     * @param integer $current          What the current page is.
758
-     * @param integer $per_page         How many items per page.
759
-     * @param string  $url              What the base url for page links is.
760
-     * @param boolean $show_num_field   Whether to show the input for changing page number.
761
-     * @param string  $paged_arg_name   The name of the key for the paged query argument.
762
-     * @param array   $items_label      An array of singular/plural values for the items label:
763
-     *                                  array(
764
-     *                                  'single' => 'item',
765
-     *                                  'plural' => 'items'
766
-     *                                  )
767
-     * @return  string
768
-     * @since    4.4.0
769
-     * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
770
-     */
771
-    public static function get_paging_html(
772
-        $total_items,
773
-        $current,
774
-        $per_page,
775
-        $url,
776
-        $show_num_field = true,
777
-        $paged_arg_name = 'paged',
778
-        $items_label = []
779
-    ) {
780
-        $page_links     = [];
781
-        $disable_first  = $disable_last = '';
782
-        $total_items    = (int) $total_items;
783
-        $per_page       = (int) $per_page;
784
-        $current        = (int) $current;
785
-        $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
786
-
787
-        // filter items_label
788
-        $items_label = apply_filters(
789
-            'FHEE__EEH_Template__get_paging_html__items_label',
790
-            $items_label
791
-        );
792
-
793
-        if (
794
-            empty($items_label)
795
-            || ! is_array($items_label)
796
-            || ! isset($items_label['single'])
797
-            || ! isset($items_label['plural'])
798
-        ) {
799
-            $items_label = [
800
-                'single' => esc_html__('1 item', 'event_espresso'),
801
-                'plural' => esc_html__('%s items', 'event_espresso'),
802
-            ];
803
-        } else {
804
-            $items_label = [
805
-                'single' => '1 ' . esc_html($items_label['single']),
806
-                'plural' => '%s ' . esc_html($items_label['plural']),
807
-            ];
808
-        }
809
-
810
-        $total_pages = ceil($total_items / $per_page);
811
-
812
-        if ($total_pages <= 1) {
813
-            return '';
814
-        }
815
-
816
-        $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
817
-
818
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
819
-
820
-        if ($current === 1) {
821
-            $disable_first = ' disabled';
822
-        }
823
-        if ($current == $total_pages) {
824
-            $disable_last = ' disabled';
825
-        }
826
-
827
-        $page_links[] = sprintf(
828
-            "<a class='%s' title='%s' href='%s'>%s</a>",
829
-            'first-page' . $disable_first,
830
-            esc_attr__('Go to the first page', 'event_espresso'),
831
-            esc_url_raw(remove_query_arg($paged_arg_name, $url)),
832
-            '&laquo;'
833
-        );
834
-
835
-        $page_links[] = sprintf(
836
-            '<a class="%s" title="%s" href="%s">%s</a>',
837
-            'prev-page' . $disable_first,
838
-            esc_attr__('Go to the previous page', 'event_espresso'),
839
-            esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
840
-            '&lsaquo;'
841
-        );
842
-
843
-        if (! $show_num_field) {
844
-            $html_current_page = $current;
845
-        } else {
846
-            $html_current_page = sprintf(
847
-                "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
848
-                esc_attr__('Current page', 'event_espresso'),
849
-                esc_attr($current),
850
-                strlen($total_pages)
851
-            );
852
-        }
853
-
854
-        $html_total_pages = sprintf(
855
-            '<span class="total-pages">%s</span>',
856
-            number_format_i18n($total_pages)
857
-        );
858
-        $page_links[]     = sprintf(
859
-            _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
860
-            $html_current_page,
861
-            $html_total_pages,
862
-            '<span class="paging-input">',
863
-            '</span>'
864
-        );
865
-
866
-        $page_links[] = sprintf(
867
-            '<a class="%s" title="%s" href="%s">%s</a>',
868
-            'next-page' . $disable_last,
869
-            esc_attr__('Go to the next page', 'event_espresso'),
870
-            esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
871
-            '&rsaquo;'
872
-        );
873
-
874
-        $page_links[] = sprintf(
875
-            '<a class="%s" title="%s" href="%s">%s</a>',
876
-            'last-page' . $disable_last,
877
-            esc_attr__('Go to the last page', 'event_espresso'),
878
-            esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)),
879
-            '&raquo;'
880
-        );
881
-
882
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
883
-        // set page class
884
-        if ($total_pages) {
885
-            $page_class = $total_pages < 2 ? ' one-page' : '';
886
-        } else {
887
-            $page_class = ' no-pages';
888
-        }
889
-
890
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
891
-    }
892
-
893
-
894
-    /**
895
-     * @param string $wrap_class
896
-     * @param string $wrap_id
897
-     * @return string
898
-     */
899
-    public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = [])
900
-    {
901
-        $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
902
-        if (
903
-            ! $admin
904
-            && ! apply_filters(
905
-                'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
906
-                EE_Registry::instance()->CFG->admin->show_reg_footer
907
-            )
908
-        ) {
909
-            return '';
910
-        }
911
-        $tag        = $admin ? 'span' : 'div';
912
-        $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
913
-        $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
914
-        $attributes .= ! empty($wrap_class)
915
-            ? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
916
-            : ' class="powered-by-event-espresso-credit"';
917
-        $query_args = array_merge(
918
-            [
919
-                'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
920
-                'utm_source'   => 'powered_by_event_espresso',
921
-                'utm_medium'   => 'link',
922
-                'utm_campaign' => 'powered_by',
923
-            ],
924
-            $query_args
925
-        );
926
-        $powered_by = apply_filters(
927
-            'FHEE__EEH_Template__powered_by_event_espresso_text',
928
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
929
-        );
930
-        $url        = add_query_arg($query_args, 'https://eventespresso.com/');
931
-        $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
932
-        return (string) apply_filters(
933
-            'FHEE__EEH_Template__powered_by_event_espresso__html',
934
-            sprintf(
935
-                esc_html_x(
936
-                    '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
937
-                    'Online event registration and ticketing powered by [link to eventespresso.com]',
938
-                    'event_espresso'
939
-                ),
940
-                "<{$tag}{$attributes}>",
941
-                "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
942
-                $admin ? '' : '<br />'
943
-            ),
944
-            $wrap_class,
945
-            $wrap_id
946
-        );
947
-    }
948
-
949
-
950
-    /**
951
-     * @param string $image_name
952
-     * @return string|null
953
-     * @since   4.10.14.p
954
-     */
955
-    public static function getScreenshotUrl($image_name)
956
-    {
957
-        return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg');
958
-    }
711
+		} else {
712
+			// simple value
713
+			echo esc_html($data);
714
+		}
715
+		return ob_get_clean();
716
+	}
717
+
718
+
719
+	/**
720
+	 * wrapper for self::get_paging_html() that simply echos the generated paging html
721
+	 *
722
+	 * @param        $total_items
723
+	 * @param        $current
724
+	 * @param        $per_page
725
+	 * @param        $url
726
+	 * @param bool   $show_num_field
727
+	 * @param string $paged_arg_name
728
+	 * @param array  $items_label
729
+	 * @see   self:get_paging_html() for argument docs.
730
+	 * @since 4.4.0
731
+	 */
732
+	public static function paging_html(
733
+		$total_items,
734
+		$current,
735
+		$per_page,
736
+		$url,
737
+		$show_num_field = true,
738
+		$paged_arg_name = 'paged',
739
+		$items_label = []
740
+	) {
741
+		echo self::get_paging_html(
742
+			$total_items,
743
+			$current,
744
+			$per_page,
745
+			$url,
746
+			$show_num_field,
747
+			$paged_arg_name,
748
+			$items_label
749
+		);
750
+	}
751
+
752
+
753
+	/**
754
+	 * A method for generating paging similar to WP_List_Table
755
+	 *
756
+	 * @param integer $total_items      How many total items there are to page.
757
+	 * @param integer $current          What the current page is.
758
+	 * @param integer $per_page         How many items per page.
759
+	 * @param string  $url              What the base url for page links is.
760
+	 * @param boolean $show_num_field   Whether to show the input for changing page number.
761
+	 * @param string  $paged_arg_name   The name of the key for the paged query argument.
762
+	 * @param array   $items_label      An array of singular/plural values for the items label:
763
+	 *                                  array(
764
+	 *                                  'single' => 'item',
765
+	 *                                  'plural' => 'items'
766
+	 *                                  )
767
+	 * @return  string
768
+	 * @since    4.4.0
769
+	 * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
770
+	 */
771
+	public static function get_paging_html(
772
+		$total_items,
773
+		$current,
774
+		$per_page,
775
+		$url,
776
+		$show_num_field = true,
777
+		$paged_arg_name = 'paged',
778
+		$items_label = []
779
+	) {
780
+		$page_links     = [];
781
+		$disable_first  = $disable_last = '';
782
+		$total_items    = (int) $total_items;
783
+		$per_page       = (int) $per_page;
784
+		$current        = (int) $current;
785
+		$paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
786
+
787
+		// filter items_label
788
+		$items_label = apply_filters(
789
+			'FHEE__EEH_Template__get_paging_html__items_label',
790
+			$items_label
791
+		);
792
+
793
+		if (
794
+			empty($items_label)
795
+			|| ! is_array($items_label)
796
+			|| ! isset($items_label['single'])
797
+			|| ! isset($items_label['plural'])
798
+		) {
799
+			$items_label = [
800
+				'single' => esc_html__('1 item', 'event_espresso'),
801
+				'plural' => esc_html__('%s items', 'event_espresso'),
802
+			];
803
+		} else {
804
+			$items_label = [
805
+				'single' => '1 ' . esc_html($items_label['single']),
806
+				'plural' => '%s ' . esc_html($items_label['plural']),
807
+			];
808
+		}
809
+
810
+		$total_pages = ceil($total_items / $per_page);
811
+
812
+		if ($total_pages <= 1) {
813
+			return '';
814
+		}
815
+
816
+		$item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
817
+
818
+		$output = '<span class="displaying-num">' . $item_label . '</span>';
819
+
820
+		if ($current === 1) {
821
+			$disable_first = ' disabled';
822
+		}
823
+		if ($current == $total_pages) {
824
+			$disable_last = ' disabled';
825
+		}
826
+
827
+		$page_links[] = sprintf(
828
+			"<a class='%s' title='%s' href='%s'>%s</a>",
829
+			'first-page' . $disable_first,
830
+			esc_attr__('Go to the first page', 'event_espresso'),
831
+			esc_url_raw(remove_query_arg($paged_arg_name, $url)),
832
+			'&laquo;'
833
+		);
834
+
835
+		$page_links[] = sprintf(
836
+			'<a class="%s" title="%s" href="%s">%s</a>',
837
+			'prev-page' . $disable_first,
838
+			esc_attr__('Go to the previous page', 'event_espresso'),
839
+			esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
840
+			'&lsaquo;'
841
+		);
842
+
843
+		if (! $show_num_field) {
844
+			$html_current_page = $current;
845
+		} else {
846
+			$html_current_page = sprintf(
847
+				"<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
848
+				esc_attr__('Current page', 'event_espresso'),
849
+				esc_attr($current),
850
+				strlen($total_pages)
851
+			);
852
+		}
853
+
854
+		$html_total_pages = sprintf(
855
+			'<span class="total-pages">%s</span>',
856
+			number_format_i18n($total_pages)
857
+		);
858
+		$page_links[]     = sprintf(
859
+			_x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
860
+			$html_current_page,
861
+			$html_total_pages,
862
+			'<span class="paging-input">',
863
+			'</span>'
864
+		);
865
+
866
+		$page_links[] = sprintf(
867
+			'<a class="%s" title="%s" href="%s">%s</a>',
868
+			'next-page' . $disable_last,
869
+			esc_attr__('Go to the next page', 'event_espresso'),
870
+			esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
871
+			'&rsaquo;'
872
+		);
873
+
874
+		$page_links[] = sprintf(
875
+			'<a class="%s" title="%s" href="%s">%s</a>',
876
+			'last-page' . $disable_last,
877
+			esc_attr__('Go to the last page', 'event_espresso'),
878
+			esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)),
879
+			'&raquo;'
880
+		);
881
+
882
+		$output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
883
+		// set page class
884
+		if ($total_pages) {
885
+			$page_class = $total_pages < 2 ? ' one-page' : '';
886
+		} else {
887
+			$page_class = ' no-pages';
888
+		}
889
+
890
+		return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
891
+	}
892
+
893
+
894
+	/**
895
+	 * @param string $wrap_class
896
+	 * @param string $wrap_id
897
+	 * @return string
898
+	 */
899
+	public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = [])
900
+	{
901
+		$admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
902
+		if (
903
+			! $admin
904
+			&& ! apply_filters(
905
+				'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
906
+				EE_Registry::instance()->CFG->admin->show_reg_footer
907
+			)
908
+		) {
909
+			return '';
910
+		}
911
+		$tag        = $admin ? 'span' : 'div';
912
+		$attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
913
+		$wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
914
+		$attributes .= ! empty($wrap_class)
915
+			? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
916
+			: ' class="powered-by-event-espresso-credit"';
917
+		$query_args = array_merge(
918
+			[
919
+				'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
920
+				'utm_source'   => 'powered_by_event_espresso',
921
+				'utm_medium'   => 'link',
922
+				'utm_campaign' => 'powered_by',
923
+			],
924
+			$query_args
925
+		);
926
+		$powered_by = apply_filters(
927
+			'FHEE__EEH_Template__powered_by_event_espresso_text',
928
+			$admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
929
+		);
930
+		$url        = add_query_arg($query_args, 'https://eventespresso.com/');
931
+		$url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
932
+		return (string) apply_filters(
933
+			'FHEE__EEH_Template__powered_by_event_espresso__html',
934
+			sprintf(
935
+				esc_html_x(
936
+					'%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s',
937
+					'Online event registration and ticketing powered by [link to eventespresso.com]',
938
+					'event_espresso'
939
+				),
940
+				"<{$tag}{$attributes}>",
941
+				"<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>",
942
+				$admin ? '' : '<br />'
943
+			),
944
+			$wrap_class,
945
+			$wrap_id
946
+		);
947
+	}
948
+
949
+
950
+	/**
951
+	 * @param string $image_name
952
+	 * @return string|null
953
+	 * @since   4.10.14.p
954
+	 */
955
+	public static function getScreenshotUrl($image_name)
956
+	{
957
+		return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg');
958
+	}
959 959
 }
960 960
 
961 961
 
962 962
 if (! function_exists('espresso_pagination')) {
963
-    /**
964
-     *    espresso_pagination
965
-     *
966
-     * @access    public
967
-     * @return    void
968
-     */
969
-    function espresso_pagination()
970
-    {
971
-        global $wp_query;
972
-        $big        = 999999999; // need an unlikely integer
973
-        $pagination = paginate_links(
974
-            [
975
-                'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
976
-                'format'       => '?paged=%#%',
977
-                'current'      => max(1, get_query_var('paged')),
978
-                'total'        => $wp_query->max_num_pages,
979
-                'show_all'     => true,
980
-                'end_size'     => 10,
981
-                'mid_size'     => 6,
982
-                'prev_next'    => true,
983
-                'prev_text'    => esc_html__('&lsaquo; PREV', 'event_espresso'),
984
-                'next_text'    => esc_html__('NEXT &rsaquo;', 'event_espresso'),
985
-                'type'         => 'plain',
986
-                'add_args'     => false,
987
-                'add_fragment' => '',
988
-            ]
989
-        );
990
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
991
-    }
963
+	/**
964
+	 *    espresso_pagination
965
+	 *
966
+	 * @access    public
967
+	 * @return    void
968
+	 */
969
+	function espresso_pagination()
970
+	{
971
+		global $wp_query;
972
+		$big        = 999999999; // need an unlikely integer
973
+		$pagination = paginate_links(
974
+			[
975
+				'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
976
+				'format'       => '?paged=%#%',
977
+				'current'      => max(1, get_query_var('paged')),
978
+				'total'        => $wp_query->max_num_pages,
979
+				'show_all'     => true,
980
+				'end_size'     => 10,
981
+				'mid_size'     => 6,
982
+				'prev_next'    => true,
983
+				'prev_text'    => esc_html__('&lsaquo; PREV', 'event_espresso'),
984
+				'next_text'    => esc_html__('NEXT &rsaquo;', 'event_espresso'),
985
+				'type'         => 'plain',
986
+				'add_args'     => false,
987
+				'add_fragment' => '',
988
+			]
989
+		);
990
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
991
+	}
992 992
 }
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\services\loaders\LoaderFactory;
6 6
 use EventEspresso\core\services\request\RequestInterface;
7 7
 
8
-if (! function_exists('espresso_get_template_part')) {
8
+if ( ! function_exists('espresso_get_template_part')) {
9 9
     /**
10 10
      * espresso_get_template_part
11 11
      * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 }
22 22
 
23 23
 
24
-if (! function_exists('espresso_get_object_css_class')) {
24
+if ( ! function_exists('espresso_get_object_css_class')) {
25 25
     /**
26 26
      * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
27 27
      *
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public static function load_espresso_theme_functions()
74 74
     {
75
-        if (! defined('EE_THEME_FUNCTIONS_LOADED')) {
76
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php')) {
77
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . '/functions.php');
75
+        if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
76
+            if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php')) {
77
+                require_once(EE_PUBLIC.EE_Config::get_current_theme().'/functions.php');
78 78
             }
79 79
         }
80 80
     }
@@ -88,16 +88,16 @@  discard block
 block discarded – undo
88 88
     public static function get_espresso_themes()
89 89
     {
90 90
         if (empty(EEH_Template::$_espresso_themes)) {
91
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
91
+            $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR);
92 92
             if (empty($espresso_themes)) {
93 93
                 return [];
94 94
             }
95 95
             if (($key = array_search('global_assets', $espresso_themes)) !== false) {
96
-                unset($espresso_themes[ $key ]);
96
+                unset($espresso_themes[$key]);
97 97
             }
98 98
             EEH_Template::$_espresso_themes = [];
99 99
             foreach ($espresso_themes as $espresso_theme) {
100
-                EEH_Template::$_espresso_themes[ basename($espresso_theme) ] = $espresso_theme;
100
+                EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
101 101
             }
102 102
         }
103 103
         return EEH_Template::$_espresso_themes;
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
                 // get array of EE Custom Post Types
214 214
                 $EE_CPTs = $custom_post_types->getDefinitions();
215 215
                 // build template name based on request
216
-                if (isset($EE_CPTs[ $post_type ])) {
216
+                if (isset($EE_CPTs[$post_type])) {
217 217
                     $archive_or_single = is_archive() ? 'archive' : '';
218 218
                     $archive_or_single = is_single() ? 'single' : $archive_or_single;
219
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
219
+                    $templates         = $archive_or_single.'-'.$post_type.'.php';
220 220
                 }
221 221
             }
222 222
             // currently active EE template theme
@@ -225,18 +225,18 @@  discard block
 block discarded – undo
225 225
             // array of paths to folders that may contain templates
226 226
             $template_folder_paths = [
227 227
                 // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
228
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
228
+                EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme,
229 229
                 // then in the root of the /wp-content/uploads/espresso/templates/ folder
230 230
                 EVENT_ESPRESSO_TEMPLATE_DIR,
231 231
             ];
232 232
 
233 233
             // add core plugin folders for checking only if we're not $check_if_custom
234
-            if (! $check_if_custom) {
235
-                $core_paths            = [
234
+            if ( ! $check_if_custom) {
235
+                $core_paths = [
236 236
                     // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
237
-                    EE_PUBLIC . $current_theme,
237
+                    EE_PUBLIC.$current_theme,
238 238
                     // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
239
-                    EE_TEMPLATES . $current_theme,
239
+                    EE_TEMPLATES.$current_theme,
240 240
                     // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
241 241
                     EE_PLUGIN_DIR_PATH,
242 242
                 ];
@@ -271,10 +271,10 @@  discard block
 block discarded – undo
271 271
                     );
272 272
                     if ($common_base_path !== '') {
273 273
                         // both paths have a common base, so just tack the filename onto our search path
274
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
274
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name;
275 275
                     } else {
276 276
                         // no common base path, so let's just concatenate
277
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
277
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template;
278 278
                     }
279 279
                     // build up our template locations array by adding our resolved paths
280 280
                     $full_template_paths[] = $resolved_path;
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
                 // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
283 283
                 array_unshift($full_template_paths, $template);
284 284
                 // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
285
-                array_unshift($full_template_paths, get_stylesheet_directory() . '/' . $file_name);
285
+                array_unshift($full_template_paths, get_stylesheet_directory().'/'.$file_name);
286 286
             }
287 287
             // filter final array of full template paths
288 288
             $full_template_paths = apply_filters(
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
                 }
334 334
             }
335 335
             $common_base_path .= $directory;
336
-            $last_offset      = $index + 1;
336
+            $last_offset = $index + 1;
337 337
         }
338 338
         return substr($common_base_path, 0, -1);
339 339
     }
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
         $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
372 372
 
373 373
         // you gimme nuttin - YOU GET NUTTIN !!
374
-        if (! $template_path || ! is_readable($template_path)) {
374
+        if ( ! $template_path || ! is_readable($template_path)) {
375 375
             // ignore whether template is accessible ?
376 376
             if ($throw_exceptions) {
377 377
                 throw new DomainException(
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
             return '';
382 382
         }
383 383
         // if $template_args are not in an array, then make it so
384
-        if (! is_array($template_args) && ! is_object($template_args)) {
384
+        if ( ! is_array($template_args) && ! is_object($template_args)) {
385 385
             $template_args = [$template_args];
386 386
         }
387 387
         extract($template_args, EXTR_SKIP);
@@ -410,11 +410,11 @@  discard block
 block discarded – undo
410 410
     public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
411 411
     {
412 412
         // in the beginning...
413
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
413
+        $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : '';
414 414
         // da muddle
415 415
         $class = '';
416 416
         // the end
417
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
417
+        $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : '';
418 418
         // is the passed object an EE object ?
419 419
         if ($object instanceof EE_Base_Class) {
420 420
             // grab the exact type of object
@@ -424,10 +424,10 @@  discard block
 block discarded – undo
424 424
                 // no specifics just yet...
425 425
                 default:
426 426
                     $class = strtolower(str_replace('_', '-', $obj_class));
427
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
427
+                    $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : '';
428 428
             }
429 429
         }
430
-        return $prefix . $class . $suffix;
430
+        return $prefix.$class.$suffix;
431 431
     }
432 432
 
433 433
 
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
         // filter raw amount (allows 0.00 to be changed to "free" for example)
463 463
         $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
464 464
         // still a number, or was amount converted to a string like "free" ?
465
-        if (! is_float($amount_formatted)) {
465
+        if ( ! is_float($amount_formatted)) {
466 466
             return esc_html($amount_formatted);
467 467
         }
468 468
         try {
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
             $mny = null;
474 474
         }
475 475
         // verify results
476
-        if (! $mny instanceof EE_Currency_Config) {
476
+        if ( ! $mny instanceof EE_Currency_Config) {
477 477
             // set default config country currency settings
478 478
             $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config
479 479
                 ? EE_Registry::instance()->CFG->currency
@@ -482,16 +482,16 @@  discard block
 block discarded – undo
482 482
         // format float
483 483
         $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
484 484
         // add formatting ?
485
-        if (! $return_raw) {
485
+        if ( ! $return_raw) {
486 486
             // add currency sign
487 487
             if ($mny->sign_b4) {
488 488
                 if ($amount >= 0) {
489
-                    $amount_formatted = $mny->sign . $amount_formatted;
489
+                    $amount_formatted = $mny->sign.$amount_formatted;
490 490
                 } else {
491
-                    $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
491
+                    $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted);
492 492
                 }
493 493
             } else {
494
-                $amount_formatted = $amount_formatted . $mny->sign;
494
+                $amount_formatted = $amount_formatted.$mny->sign;
495 495
             }
496 496
 
497 497
             // filter to allow global setting of display_code
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 
503 503
             // add currency code ?
504 504
             $amount_formatted = $display_code
505
-                ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>'
505
+                ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>'
506 506
                 : $amount_formatted;
507 507
         }
508 508
         // filter results
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
             $plural,
539 539
             $schema
540 540
         );
541
-        return $status[ $status_id ];
541
+        return $status[$status_id];
542 542
     }
543 543
 
544 544
 
@@ -555,14 +555,14 @@  discard block
 block discarded – undo
555 555
     public static function get_button_or_link($url, $label, $class = 'button button--primary', $icon = '', $title = '')
556 556
     {
557 557
         $icon_html = '';
558
-        if (! empty($icon)) {
558
+        if ( ! empty($icon)) {
559 559
             $dashicons = preg_split("(ee-icon |dashicons )", $icon);
560 560
             $dashicons = array_filter($dashicons);
561 561
             $count     = count($dashicons);
562 562
             $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
563 563
             foreach ($dashicons as $dashicon) {
564
-                $type      = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
565
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
564
+                $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
565
+                $icon_html .= '<span class="'.$type.$dashicon.'"></span>';
566 566
             }
567 567
             $icon_html .= $count > 1 ? '</span>' : '';
568 568
         }
@@ -602,18 +602,18 @@  discard block
 block discarded – undo
602 602
         $action  = $action ?: $request->getRequestParam('action', 'default', 'key');
603 603
 
604 604
 
605
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
605
+        $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id;
606 606
         $icon      = ! $icon_style ? 'dashicons-editor-help' : $icon_style;
607 607
         $help_text = ! $help_text ? '' : $help_text;
608 608
         return '
609
-        	<a 	id="' . esc_attr($help_tab_lnk) . '" 
610
-        		class="espresso-help-tab-lnk ee-help-btn ee-aria-tooltip dashicons ' . esc_attr($icon) . '" 
609
+        	<a 	id="' . esc_attr($help_tab_lnk).'" 
610
+        		class="espresso-help-tab-lnk ee-help-btn ee-aria-tooltip dashicons ' . esc_attr($icon).'" 
611 611
         		aria-label="' . esc_attr__(
612 612
                         'Click to open the \'Help\' tab for more information about this feature.',
613 613
                         'event_espresso'
614
-                ) . '" 
614
+                ).'" 
615 615
 		    >
616
-		    	' . wp_kses($help_text, $allowedtags) . '
616
+		    	' . wp_kses($help_text, $allowedtags).'
617 617
 			</a>';
618 618
     }
619 619
 
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
      */
635 635
     public static function status_legend($status_array, $active_status = '')
636 636
     {
637
-        if (! is_array($status_array)) {
637
+        if ( ! is_array($status_array)) {
638 638
             throw new EE_Error(
639 639
                 esc_html__(
640 640
                     'The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
@@ -646,17 +646,17 @@  discard block
 block discarded – undo
646 646
         $content = '
647 647
             <div class="ee-list-table-legend-container">
648 648
                 <h4 class="status-legend-title">
649
-                    ' . esc_html__('Status Legend', 'event_espresso') . '
649
+                    ' . esc_html__('Status Legend', 'event_espresso').'
650 650
                 </h4>
651 651
                 <dl class="ee-list-table-legend">';
652 652
 
653 653
         foreach ($status_array as $item => $status) {
654 654
             $active_class = $active_status == $status ? 'class="ee-is-active-status"' : '';
655
-            $content      .= '
656
-                    <dt id="' . esc_attr('ee-legend-item-tooltip-' . $item) . '" ' . $active_class . '>
657
-                        <span class="' . esc_attr('ee-status-legend ee-status-bg--' . $status) . '"></span>
655
+            $content .= '
656
+                    <dt id="' . esc_attr('ee-legend-item-tooltip-'.$item).'" '.$active_class.'>
657
+                        <span class="' . esc_attr('ee-status-legend ee-status-bg--'.$status).'"></span>
658 658
                         <span class="ee-legend-description">
659
-                            ' . EEH_Template::pretty_status($status, false, 'sentence') . '
659
+                            ' . EEH_Template::pretty_status($status, false, 'sentence').'
660 660
                         </span>
661 661
                     </dt>';
662 662
         }
@@ -802,8 +802,8 @@  discard block
 block discarded – undo
802 802
             ];
803 803
         } else {
804 804
             $items_label = [
805
-                'single' => '1 ' . esc_html($items_label['single']),
806
-                'plural' => '%s ' . esc_html($items_label['plural']),
805
+                'single' => '1 '.esc_html($items_label['single']),
806
+                'plural' => '%s '.esc_html($items_label['plural']),
807 807
             ];
808 808
         }
809 809
 
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
 
816 816
         $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
817 817
 
818
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
818
+        $output = '<span class="displaying-num">'.$item_label.'</span>';
819 819
 
820 820
         if ($current === 1) {
821 821
             $disable_first = ' disabled';
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
 
827 827
         $page_links[] = sprintf(
828 828
             "<a class='%s' title='%s' href='%s'>%s</a>",
829
-            'first-page' . $disable_first,
829
+            'first-page'.$disable_first,
830 830
             esc_attr__('Go to the first page', 'event_espresso'),
831 831
             esc_url_raw(remove_query_arg($paged_arg_name, $url)),
832 832
             '&laquo;'
@@ -834,13 +834,13 @@  discard block
 block discarded – undo
834 834
 
835 835
         $page_links[] = sprintf(
836 836
             '<a class="%s" title="%s" href="%s">%s</a>',
837
-            'prev-page' . $disable_first,
837
+            'prev-page'.$disable_first,
838 838
             esc_attr__('Go to the previous page', 'event_espresso'),
839 839
             esc_url_raw(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
840 840
             '&lsaquo;'
841 841
         );
842 842
 
843
-        if (! $show_num_field) {
843
+        if ( ! $show_num_field) {
844 844
             $html_current_page = $current;
845 845
         } else {
846 846
             $html_current_page = sprintf(
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
             '<span class="total-pages">%s</span>',
856 856
             number_format_i18n($total_pages)
857 857
         );
858
-        $page_links[]     = sprintf(
858
+        $page_links[] = sprintf(
859 859
             _x('%3$s%1$s of %2$s%4$s', 'paging', 'event_espresso'),
860 860
             $html_current_page,
861 861
             $html_total_pages,
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
 
866 866
         $page_links[] = sprintf(
867 867
             '<a class="%s" title="%s" href="%s">%s</a>',
868
-            'next-page' . $disable_last,
868
+            'next-page'.$disable_last,
869 869
             esc_attr__('Go to the next page', 'event_espresso'),
870 870
             esc_url_raw(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
871 871
             '&rsaquo;'
@@ -873,13 +873,13 @@  discard block
 block discarded – undo
873 873
 
874 874
         $page_links[] = sprintf(
875 875
             '<a class="%s" title="%s" href="%s">%s</a>',
876
-            'last-page' . $disable_last,
876
+            'last-page'.$disable_last,
877 877
             esc_attr__('Go to the last page', 'event_espresso'),
878 878
             esc_url_raw(add_query_arg($paged_arg_name, $total_pages, $url)),
879 879
             '&raquo;'
880 880
         );
881 881
 
882
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
882
+        $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>';
883 883
         // set page class
884 884
         if ($total_pages) {
885 885
             $page_class = $total_pages < 2 ? ' one-page' : '';
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
             $page_class = ' no-pages';
888 888
         }
889 889
 
890
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
890
+        return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>';
891 891
     }
892 892
 
893 893
 
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
         );
926 926
         $powered_by = apply_filters(
927 927
             'FHEE__EEH_Template__powered_by_event_espresso_text',
928
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'
928
+            $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso'
929 929
         );
930 930
         $url        = add_query_arg($query_args, 'https://eventespresso.com/');
931 931
         $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
@@ -954,12 +954,12 @@  discard block
 block discarded – undo
954 954
      */
955 955
     public static function getScreenshotUrl($image_name)
956 956
     {
957
-        return esc_url_raw(EE_GLOBAL_ASSETS_URL . 'images/screenshots/' . $image_name . '.jpg');
957
+        return esc_url_raw(EE_GLOBAL_ASSETS_URL.'images/screenshots/'.$image_name.'.jpg');
958 958
     }
959 959
 }
960 960
 
961 961
 
962
-if (! function_exists('espresso_pagination')) {
962
+if ( ! function_exists('espresso_pagination')) {
963 963
     /**
964 964
      *    espresso_pagination
965 965
      *
@@ -987,6 +987,6 @@  discard block
 block discarded – undo
987 987
                 'add_fragment' => '',
988 988
             ]
989 989
         );
990
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
990
+        echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : '';
991 991
     }
992 992
 }
Please login to merge, or discard this patch.
admin/extend/registrations/EE_Event_Registrations_List_Table.class.php 2 patches
Indentation   +633 added lines, -633 removed lines patch added patch discarded remove patch
@@ -16,278 +16,278 @@  discard block
 block discarded – undo
16 16
 class EE_Event_Registrations_List_Table extends EE_Admin_List_Table
17 17
 {
18 18
 
19
-    /**
20
-     * @var RequestInterface
21
-     */
22
-    protected $request;
19
+	/**
20
+	 * @var RequestInterface
21
+	 */
22
+	protected $request;
23 23
     
24
-    /**
25
-     * @var Extend_Registrations_Admin_Page
26
-     */
27
-    protected $_admin_page;
28
-
29
-    /**
30
-     * The event ID if one is specified in the request
31
-     *
32
-     * @var int
33
-     */
34
-    protected $event_id = 0;
35
-
36
-    /**
37
-     * This property will hold the related Datetimes on an event IF the event id is included in the request.
38
-     *
39
-     * @var DatetimesForEventCheckIn
40
-     */
41
-    protected $datetimes_for_event = [];
42
-
43
-    /**
44
-     * The DTT_ID if the current view has a specified datetime.
45
-     *
46
-     * @var int
47
-     */
48
-    protected $datetime_id = 0;
49
-
50
-    /**
51
-     * @var EE_Datetime
52
-     */
53
-    protected $datetime;
54
-
55
-    /**
56
-     * @var DatetimesForEventCheckIn
57
-     */
58
-    protected $datetimes_for_current_row;
59
-
60
-
61
-    /**
62
-     * EE_Event_Registrations_List_Table constructor.
63
-     *
64
-     * @param Registrations_Admin_Page $admin_page
65
-     * @throws EE_Error
66
-     * @throws ReflectionException
67
-     */
68
-    public function __construct($admin_page)
69
-    {
70
-        $this->request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
71
-        $this->resolveRequestVars();
72
-        parent::__construct($admin_page);
73
-    }
74
-
75
-
76
-    /**
77
-     * @throws EE_Error
78
-     * @throws ReflectionException
79
-     * @since $VID:$
80
-     */
81
-    private function resolveRequestVars()
82
-    {
83
-        $this->event_id = $this->request->getRequestParam('event_id', 0, 'int');
84
-        $this->datetimes_for_event = DatetimesForEventCheckIn::fromEventID($this->event_id);
85
-        // if we're filtering for a specific event and it only has one datetime, then grab its ID
86
-        $datetime          = $this->datetimes_for_event->getOneActiveDatetimeForEvent();
87
-        $this->datetime_id = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
88
-        // else check the request, but use the above as the default (and hope they match if BOTH exist, LOLZ)
89
-        $this->datetime_id = $this->request->getRequestParam(
90
-            'DTT_ID',
91
-            $this->datetime_id,
92
-            'int'
93
-        );
94
-    }
95
-
96
-
97
-    /**
98
-     * @throws EE_Error
99
-     */
100
-    protected function _setup_data()
101
-    {
102
-        $this->_data = $this->_view !== 'trash'
103
-            ? $this->_admin_page->get_event_attendees($this->_per_page)
104
-            : $this->_admin_page->get_event_attendees($this->_per_page, false, true);
105
-
106
-        $this->_all_data_count = $this->_view !== 'trash'
107
-            ? $this->_admin_page->get_event_attendees($this->_per_page, true)
108
-            : $this->_admin_page->get_event_attendees($this->_per_page, true, true);
109
-    }
110
-
111
-
112
-    protected function _set_properties()
113
-    {
114
-        $this->_wp_list_args = [
115
-            'singular' => esc_html__('registrant', 'event_espresso'),
116
-            'plural'   => esc_html__('registrants', 'event_espresso'),
117
-            'ajax'     => true,
118
-            'screen'   => $this->_admin_page->get_current_screen()->id,
119
-        ];
120
-
121
-        $this->_columns      = [
122
-            'cb' => '<input type="checkbox" />', // Render a checkbox instead of text
123
-            '_REG_att_checked_in' => esc_html__('Check In', 'event_espresso'),
124
-            'ATT_name'            => esc_html__('Registrant', 'event_espresso'),
125
-            'ATT_email'           => esc_html__('Email Address', 'event_espresso'),
126
-            'Event'               => esc_html__('Event', 'event_espresso'),
127
-            'PRC_name'            => esc_html__('TKT Option', 'event_espresso'),
128
-            '_REG_final_price'    => esc_html__('Price', 'event_espresso'),
129
-            'TXN_paid'            => esc_html__('Paid', 'event_espresso'),
130
-            'TXN_total'           => esc_html__('Total', 'event_espresso'),
131
-        ];
132
-        $this->_primary_column = '_REG_att_checked_in';
133
-
134
-        // Add/remove columns when an event has been selected
135
-        if ($this->event_id) {
136
-            // Render a checkbox column
137
-            $this->_columns['cb'] = '<input type="checkbox" />';
138
-            $this->_has_checkbox_column = true;
139
-            // Remove the 'Event' column
140
-            unset($this->_columns['Event']);
141
-            $this->setBottomButtons();
142
-        }
143
-
144
-        $this->_sortable_columns = [
145
-            /**
146
-             * Allows users to change the default sort if they wish.
147
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
148
-             *
149
-             * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
150
-             * change the sorts on any list table involving registration contacts.  If you want to only change the filter
151
-             * for a specific list table you can use the provided reference to this object instance.
152
-             */
153
-            'ATT_name' => [
154
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
155
-                true,
156
-                $this,
157
-            ]
158
-                ? ['ATT_lname' => true]
159
-                : ['ATT_fname' => true],
160
-            'Event'    => ['Event.EVT_name' => false],
161
-        ];
162
-
163
-        $this->_hidden_columns = [];
164
-    }
165
-
166
-
167
-    private function setBottomButtons()
168
-    {
169
-        if (
170
-            ! EE_Registry::instance()->CAP->current_user_can(
171
-                'ee_read_registrations',
172
-                'espresso_registrations_registrations_reports',
173
-                $this->event_id
174
-            )
175
-        ) {
176
-            return;
177
-        }
178
-
179
-        $return_url = $this->getReturnUrl();
180
-        $this->_bottom_buttons = [
181
-            'report' => [
182
-                'route'         => 'registrations_report',
183
-                'extra_request' =>
184
-                    [
185
-                        'EVT_ID'     => $this->event_id,
186
-                        'return_url' => $return_url,
187
-                    ],
188
-            ],
189
-        ];
190
-
191
-        $request_params = $this->request->requestParams();
192
-
193
-        $this->_bottom_buttons['report_filtered'] = [
194
-            'route'         => 'registrations_checkin_report',
195
-            'extra_request' => [
196
-                'use_filters' => true,
197
-                'filters'     => array_merge(
198
-                    [
199
-                        'EVT_ID' => $this->event_id,
200
-                    ],
201
-                    array_diff_key(
202
-                        $request_params,
203
-                        array_flip(
204
-                            [
205
-                                'page',
206
-                                'action',
207
-                                'default_nonce',
208
-                            ]
209
-                        )
210
-                    )
211
-                ),
212
-                'return_url'  => $return_url,
213
-            ],
214
-        ];
215
-    }
216
-
217
-
218
-    /**
219
-     * @param EE_Registration $item
220
-     * @return string
221
-     */
222
-    protected function _get_row_class($item): string
223
-    {
224
-        $class = parent::_get_row_class($item);
225
-        if ($this->_has_checkbox_column) {
226
-            $class .= ' has-checkbox-column';
227
-        }
228
-        return $class;
229
-    }
230
-
231
-
232
-    /**
233
-     * @return array
234
-     * @throws EE_Error
235
-     * @throws ReflectionException
236
-     */
237
-    protected function _get_table_filters(): array
238
-    {
239
-        $filters = [];
240
-        $hide_expired = $this->request->getRequestParam('hide_expired', true, 'bool');
241
-        $hide_upcoming = $this->request->getRequestParam('hide_upcoming', true, 'bool');
242
-        $hide_expired_checked = $hide_expired ? 'checked' : '';
243
-        $hide_upcoming_checked = $hide_upcoming ? 'checked' : '';
244
-        // get datetimes for ALL active events (note possible capability restrictions)
245
-        $events   = $this->datetimes_for_event->getAllActiveDatetimesForAllEvents();
246
-        $event_options[] = [
247
-            'id'   => 0,
248
-            'text' => esc_html__(' - select an event - ', 'event_espresso'),
249
-        ];
250
-        /** @var EE_Event $event */
251
-        foreach ($events as $event) {
252
-            // any registrations for this event?
253
-            if (! $event instanceof EE_Event/* || ! $event->get_count_of_all_registrations()*/) {
254
-                continue;
255
-            }
256
-            $expired_class = $event->is_expired() ? 'ee-expired-event' : '';
257
-            $upcoming_class  = $event->is_upcoming() ? ' ee-upcoming-event' : '';
258
-            $event_options[] = [
259
-                'id'    => $event->ID(),
260
-                'text'  => apply_filters(
261
-                    'FHEE__EE_Event_Registrations___get_table_filters__event_name',
262
-                    $event->name(),
263
-                    $event
264
-                ),
265
-                'class' => $expired_class . $upcoming_class,
266
-            ];
267
-            if ($event->ID() === $this->event_id) {
268
-                $hide_expired = $expired_class === '';
269
-                $hide_expired_checked  = $expired_class === '' ? $hide_expired_checked : '';
270
-                $hide_upcoming = $upcoming_class === '';
271
-                $hide_upcoming_checked = $upcoming_class === '' ? $hide_upcoming_checked : '';
272
-            }
273
-        }
274
-
275
-        $select_class = $hide_expired ? 'ee-hide-expired-events' : '';
276
-        $select_class .= $hide_upcoming ? ' ee-hide-upcoming-events' : '';
277
-
278
-        $filters[] = '
24
+	/**
25
+	 * @var Extend_Registrations_Admin_Page
26
+	 */
27
+	protected $_admin_page;
28
+
29
+	/**
30
+	 * The event ID if one is specified in the request
31
+	 *
32
+	 * @var int
33
+	 */
34
+	protected $event_id = 0;
35
+
36
+	/**
37
+	 * This property will hold the related Datetimes on an event IF the event id is included in the request.
38
+	 *
39
+	 * @var DatetimesForEventCheckIn
40
+	 */
41
+	protected $datetimes_for_event = [];
42
+
43
+	/**
44
+	 * The DTT_ID if the current view has a specified datetime.
45
+	 *
46
+	 * @var int
47
+	 */
48
+	protected $datetime_id = 0;
49
+
50
+	/**
51
+	 * @var EE_Datetime
52
+	 */
53
+	protected $datetime;
54
+
55
+	/**
56
+	 * @var DatetimesForEventCheckIn
57
+	 */
58
+	protected $datetimes_for_current_row;
59
+
60
+
61
+	/**
62
+	 * EE_Event_Registrations_List_Table constructor.
63
+	 *
64
+	 * @param Registrations_Admin_Page $admin_page
65
+	 * @throws EE_Error
66
+	 * @throws ReflectionException
67
+	 */
68
+	public function __construct($admin_page)
69
+	{
70
+		$this->request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
71
+		$this->resolveRequestVars();
72
+		parent::__construct($admin_page);
73
+	}
74
+
75
+
76
+	/**
77
+	 * @throws EE_Error
78
+	 * @throws ReflectionException
79
+	 * @since $VID:$
80
+	 */
81
+	private function resolveRequestVars()
82
+	{
83
+		$this->event_id = $this->request->getRequestParam('event_id', 0, 'int');
84
+		$this->datetimes_for_event = DatetimesForEventCheckIn::fromEventID($this->event_id);
85
+		// if we're filtering for a specific event and it only has one datetime, then grab its ID
86
+		$datetime          = $this->datetimes_for_event->getOneActiveDatetimeForEvent();
87
+		$this->datetime_id = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
88
+		// else check the request, but use the above as the default (and hope they match if BOTH exist, LOLZ)
89
+		$this->datetime_id = $this->request->getRequestParam(
90
+			'DTT_ID',
91
+			$this->datetime_id,
92
+			'int'
93
+		);
94
+	}
95
+
96
+
97
+	/**
98
+	 * @throws EE_Error
99
+	 */
100
+	protected function _setup_data()
101
+	{
102
+		$this->_data = $this->_view !== 'trash'
103
+			? $this->_admin_page->get_event_attendees($this->_per_page)
104
+			: $this->_admin_page->get_event_attendees($this->_per_page, false, true);
105
+
106
+		$this->_all_data_count = $this->_view !== 'trash'
107
+			? $this->_admin_page->get_event_attendees($this->_per_page, true)
108
+			: $this->_admin_page->get_event_attendees($this->_per_page, true, true);
109
+	}
110
+
111
+
112
+	protected function _set_properties()
113
+	{
114
+		$this->_wp_list_args = [
115
+			'singular' => esc_html__('registrant', 'event_espresso'),
116
+			'plural'   => esc_html__('registrants', 'event_espresso'),
117
+			'ajax'     => true,
118
+			'screen'   => $this->_admin_page->get_current_screen()->id,
119
+		];
120
+
121
+		$this->_columns      = [
122
+			'cb' => '<input type="checkbox" />', // Render a checkbox instead of text
123
+			'_REG_att_checked_in' => esc_html__('Check In', 'event_espresso'),
124
+			'ATT_name'            => esc_html__('Registrant', 'event_espresso'),
125
+			'ATT_email'           => esc_html__('Email Address', 'event_espresso'),
126
+			'Event'               => esc_html__('Event', 'event_espresso'),
127
+			'PRC_name'            => esc_html__('TKT Option', 'event_espresso'),
128
+			'_REG_final_price'    => esc_html__('Price', 'event_espresso'),
129
+			'TXN_paid'            => esc_html__('Paid', 'event_espresso'),
130
+			'TXN_total'           => esc_html__('Total', 'event_espresso'),
131
+		];
132
+		$this->_primary_column = '_REG_att_checked_in';
133
+
134
+		// Add/remove columns when an event has been selected
135
+		if ($this->event_id) {
136
+			// Render a checkbox column
137
+			$this->_columns['cb'] = '<input type="checkbox" />';
138
+			$this->_has_checkbox_column = true;
139
+			// Remove the 'Event' column
140
+			unset($this->_columns['Event']);
141
+			$this->setBottomButtons();
142
+		}
143
+
144
+		$this->_sortable_columns = [
145
+			/**
146
+			 * Allows users to change the default sort if they wish.
147
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
148
+			 *
149
+			 * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
150
+			 * change the sorts on any list table involving registration contacts.  If you want to only change the filter
151
+			 * for a specific list table you can use the provided reference to this object instance.
152
+			 */
153
+			'ATT_name' => [
154
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
155
+				true,
156
+				$this,
157
+			]
158
+				? ['ATT_lname' => true]
159
+				: ['ATT_fname' => true],
160
+			'Event'    => ['Event.EVT_name' => false],
161
+		];
162
+
163
+		$this->_hidden_columns = [];
164
+	}
165
+
166
+
167
+	private function setBottomButtons()
168
+	{
169
+		if (
170
+			! EE_Registry::instance()->CAP->current_user_can(
171
+				'ee_read_registrations',
172
+				'espresso_registrations_registrations_reports',
173
+				$this->event_id
174
+			)
175
+		) {
176
+			return;
177
+		}
178
+
179
+		$return_url = $this->getReturnUrl();
180
+		$this->_bottom_buttons = [
181
+			'report' => [
182
+				'route'         => 'registrations_report',
183
+				'extra_request' =>
184
+					[
185
+						'EVT_ID'     => $this->event_id,
186
+						'return_url' => $return_url,
187
+					],
188
+			],
189
+		];
190
+
191
+		$request_params = $this->request->requestParams();
192
+
193
+		$this->_bottom_buttons['report_filtered'] = [
194
+			'route'         => 'registrations_checkin_report',
195
+			'extra_request' => [
196
+				'use_filters' => true,
197
+				'filters'     => array_merge(
198
+					[
199
+						'EVT_ID' => $this->event_id,
200
+					],
201
+					array_diff_key(
202
+						$request_params,
203
+						array_flip(
204
+							[
205
+								'page',
206
+								'action',
207
+								'default_nonce',
208
+							]
209
+						)
210
+					)
211
+				),
212
+				'return_url'  => $return_url,
213
+			],
214
+		];
215
+	}
216
+
217
+
218
+	/**
219
+	 * @param EE_Registration $item
220
+	 * @return string
221
+	 */
222
+	protected function _get_row_class($item): string
223
+	{
224
+		$class = parent::_get_row_class($item);
225
+		if ($this->_has_checkbox_column) {
226
+			$class .= ' has-checkbox-column';
227
+		}
228
+		return $class;
229
+	}
230
+
231
+
232
+	/**
233
+	 * @return array
234
+	 * @throws EE_Error
235
+	 * @throws ReflectionException
236
+	 */
237
+	protected function _get_table_filters(): array
238
+	{
239
+		$filters = [];
240
+		$hide_expired = $this->request->getRequestParam('hide_expired', true, 'bool');
241
+		$hide_upcoming = $this->request->getRequestParam('hide_upcoming', true, 'bool');
242
+		$hide_expired_checked = $hide_expired ? 'checked' : '';
243
+		$hide_upcoming_checked = $hide_upcoming ? 'checked' : '';
244
+		// get datetimes for ALL active events (note possible capability restrictions)
245
+		$events   = $this->datetimes_for_event->getAllActiveDatetimesForAllEvents();
246
+		$event_options[] = [
247
+			'id'   => 0,
248
+			'text' => esc_html__(' - select an event - ', 'event_espresso'),
249
+		];
250
+		/** @var EE_Event $event */
251
+		foreach ($events as $event) {
252
+			// any registrations for this event?
253
+			if (! $event instanceof EE_Event/* || ! $event->get_count_of_all_registrations()*/) {
254
+				continue;
255
+			}
256
+			$expired_class = $event->is_expired() ? 'ee-expired-event' : '';
257
+			$upcoming_class  = $event->is_upcoming() ? ' ee-upcoming-event' : '';
258
+			$event_options[] = [
259
+				'id'    => $event->ID(),
260
+				'text'  => apply_filters(
261
+					'FHEE__EE_Event_Registrations___get_table_filters__event_name',
262
+					$event->name(),
263
+					$event
264
+				),
265
+				'class' => $expired_class . $upcoming_class,
266
+			];
267
+			if ($event->ID() === $this->event_id) {
268
+				$hide_expired = $expired_class === '';
269
+				$hide_expired_checked  = $expired_class === '' ? $hide_expired_checked : '';
270
+				$hide_upcoming = $upcoming_class === '';
271
+				$hide_upcoming_checked = $upcoming_class === '' ? $hide_upcoming_checked : '';
272
+			}
273
+		}
274
+
275
+		$select_class = $hide_expired ? 'ee-hide-expired-events' : '';
276
+		$select_class .= $hide_upcoming ? ' ee-hide-upcoming-events' : '';
277
+
278
+		$filters[] = '
279 279
         <div class="ee-event-filter">
280 280
             <span>
281 281
                 <label for="event_id">
282 282
                     ' . esc_html__('Check-in Status for', 'event_espresso') . '
283 283
                 </label>
284 284
                 ' . EEH_Form_Fields::select_input(
285
-                    'event_id',
286
-                    $event_options,
287
-                    $this->event_id,
288
-                '',
289
-                    $select_class
290
-            ) . '
285
+					'event_id',
286
+					$event_options,
287
+					$this->event_id,
288
+				'',
289
+					$select_class
290
+			) . '
291 291
             </span>
292 292
             <span>
293 293
                 <label for="js-ee-hide-upcoming-events">
@@ -295,11 +295,11 @@  discard block
 block discarded – undo
295 295
                     ' . esc_html__('Hide Upcoming Events', 'event_espresso') . '
296 296
                 </label>
297 297
                 <span class="ee-help-btn dashicons dashicons-editor-help ee-aria-tooltip" aria-label="'
298
-                     . esc_html__(
299
-                         'Will not display events with start dates in the future (ie: have not yet begun)',
300
-                         'event_espresso'
301
-                     )
302
-                     . '"></span>
298
+					 . esc_html__(
299
+						 'Will not display events with start dates in the future (ie: have not yet begun)',
300
+						 'event_espresso'
301
+					 )
302
+					 . '"></span>
303 303
             </span>
304 304
             <span>
305 305
                 <label for="js-ee-hide-expired-events">
@@ -307,386 +307,386 @@  discard block
 block discarded – undo
307 307
                     ' . esc_html__('Hide Expired Events', 'event_espresso') . '
308 308
                 </label>
309 309
                 <span class="ee-help-btn dashicons dashicons-editor-help ee-aria-tooltip" aria-label="'
310
-                     . esc_html__(
311
-                         'Will not display events with end dates in the past (ie: have already finished)',
312
-                         'event_espresso'
313
-                     )
314
-                     . '"></span>
310
+					 . esc_html__(
311
+						 'Will not display events with end dates in the past (ie: have already finished)',
312
+						 'event_espresso'
313
+					 )
314
+					 . '"></span>
315 315
             </span>
316 316
         </div>';
317
-        // DTT datetimes filter
318
-        $datetimes_for_event = $this->datetimes_for_event->getAllActiveDatetimesForEvent($hide_upcoming_checked === 'checked');
319
-        if (count($datetimes_for_event) > 1) {
320
-            $datetimes[0] = esc_html__(' - select a datetime - ', 'event_espresso');
321
-            foreach ($datetimes_for_event as $datetime) {
322
-                $datetime_string              = $datetime->name();
323
-                $datetime_string              = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : '';
324
-                $datetime_string              =
325
-                    $datetime->start_date_and_time() . ' - ' . $datetime->end_date_and_time() . $datetime_string;
326
-                $datetimes[ $datetime->ID() ] = $datetime_string;
327
-            }
328
-            $input     = new EE_Select_Input(
329
-                $datetimes,
330
-                [
331
-                    'html_name' => 'DTT_ID',
332
-                    'html_id'   => 'DTT_ID',
333
-                    'default'   => $this->datetime_id,
334
-                ]
335
-            );
336
-            $filters[] = $input->get_html_for_input();
337
-        }
338
-        return $filters;
339
-    }
340
-
341
-
342
-    /**
343
-     * @throws EE_Error
344
-     * @throws ReflectionException
345
-     */
346
-    protected function _add_view_counts()
347
-    {
348
-        $this->_views['all']['count'] = $this->_get_total_event_attendees();
349
-    }
350
-
351
-
352
-    /**
353
-     * @return int
354
-     * @throws EE_Error
355
-     * @throws ReflectionException
356
-     */
357
-    protected function _get_total_event_attendees(): int
358
-    {
359
-        $query_params      = [];
360
-        if ($this->event_id) {
361
-            $query_params[0]['EVT_ID'] = $this->event_id;
362
-        }
363
-        // if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
364
-        if ($this->datetime_id) {
365
-            $query_params[0]['Ticket.Datetime.DTT_ID'] = $this->datetime_id;
366
-        }
367
-        $status_ids_array          = apply_filters(
368
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
369
-            [EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved]
370
-        );
371
-        $query_params[0]['STS_ID'] = ['IN', $status_ids_array];
372
-        return EEM_Registration::instance()->count($query_params);
373
-    }
374
-
375
-
376
-    /**
377
-     * @param EE_Registration $item
378
-     * @return string
379
-     * @throws EE_Error
380
-     * @throws ReflectionException
381
-     */
382
-    public function column_cb($item): string
383
-    {
384
-        return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
385
-    }
386
-
387
-
388
-    /**
389
-     * column_REG_att_checked_in
390
-     *
391
-     * @param EE_Registration $registration
392
-     * @return string
393
-     * @throws EE_Error
394
-     * @throws InvalidArgumentException
395
-     * @throws InvalidDataTypeException
396
-     * @throws InvalidInterfaceException
397
-     * @throws ReflectionException
398
-     */
399
-    public function column__REG_att_checked_in(EE_Registration $registration): string
400
-    {
401
-        // we need a local variable for the datetime for each row
402
-        // (so that we don't pollute state for the entire table)
403
-        // so let's try to get it from the registration's event
404
-        $this->datetimes_for_current_row = DatetimesForEventCheckIn::fromRegistration($registration);
405
-        $datetime = $this->datetimes_for_current_row->getOneActiveDatetimeForEvent();
406
-
407
-        $DTD_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
408
-
409
-        $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
410
-            $registration,
411
-            $DTD_ID
412
-        );
413
-
414
-        $aria_label = $checkin_status_dashicon->ariaLabel();
415
-        $dashicon_class = $checkin_status_dashicon->cssClasses();
416
-        $attributes = ' onClick="return false"';
417
-        $button_class = 'button button--secondary button--icon-only ee-aria-tooltip ee-aria-tooltip--big-box';
418
-
419
-        if (
420
-            $DTD_ID
421
-            && EE_Registry::instance()->CAP->current_user_can(
422
-                'ee_edit_checkin',
423
-                'espresso_registrations_toggle_checkin_status',
424
-                $registration->ID()
425
-            )
426
-        ) {
427
-            // overwrite the disabled attribute with data attributes for performing checkin
428
-            $attributes = 'data-_regid="' . $registration->ID() . '"';
429
-            $attributes .= ' data-dttid="' . $DTD_ID . '"';
430
-            $attributes .= ' data-nonce="' . wp_create_nonce('checkin_nonce') . '"';
431
-            $button_class .= ' clickable trigger-checkin';
432
-        }
433
-
434
-        $content = '
317
+		// DTT datetimes filter
318
+		$datetimes_for_event = $this->datetimes_for_event->getAllActiveDatetimesForEvent($hide_upcoming_checked === 'checked');
319
+		if (count($datetimes_for_event) > 1) {
320
+			$datetimes[0] = esc_html__(' - select a datetime - ', 'event_espresso');
321
+			foreach ($datetimes_for_event as $datetime) {
322
+				$datetime_string              = $datetime->name();
323
+				$datetime_string              = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : '';
324
+				$datetime_string              =
325
+					$datetime->start_date_and_time() . ' - ' . $datetime->end_date_and_time() . $datetime_string;
326
+				$datetimes[ $datetime->ID() ] = $datetime_string;
327
+			}
328
+			$input     = new EE_Select_Input(
329
+				$datetimes,
330
+				[
331
+					'html_name' => 'DTT_ID',
332
+					'html_id'   => 'DTT_ID',
333
+					'default'   => $this->datetime_id,
334
+				]
335
+			);
336
+			$filters[] = $input->get_html_for_input();
337
+		}
338
+		return $filters;
339
+	}
340
+
341
+
342
+	/**
343
+	 * @throws EE_Error
344
+	 * @throws ReflectionException
345
+	 */
346
+	protected function _add_view_counts()
347
+	{
348
+		$this->_views['all']['count'] = $this->_get_total_event_attendees();
349
+	}
350
+
351
+
352
+	/**
353
+	 * @return int
354
+	 * @throws EE_Error
355
+	 * @throws ReflectionException
356
+	 */
357
+	protected function _get_total_event_attendees(): int
358
+	{
359
+		$query_params      = [];
360
+		if ($this->event_id) {
361
+			$query_params[0]['EVT_ID'] = $this->event_id;
362
+		}
363
+		// if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
364
+		if ($this->datetime_id) {
365
+			$query_params[0]['Ticket.Datetime.DTT_ID'] = $this->datetime_id;
366
+		}
367
+		$status_ids_array          = apply_filters(
368
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
369
+			[EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved]
370
+		);
371
+		$query_params[0]['STS_ID'] = ['IN', $status_ids_array];
372
+		return EEM_Registration::instance()->count($query_params);
373
+	}
374
+
375
+
376
+	/**
377
+	 * @param EE_Registration $item
378
+	 * @return string
379
+	 * @throws EE_Error
380
+	 * @throws ReflectionException
381
+	 */
382
+	public function column_cb($item): string
383
+	{
384
+		return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
385
+	}
386
+
387
+
388
+	/**
389
+	 * column_REG_att_checked_in
390
+	 *
391
+	 * @param EE_Registration $registration
392
+	 * @return string
393
+	 * @throws EE_Error
394
+	 * @throws InvalidArgumentException
395
+	 * @throws InvalidDataTypeException
396
+	 * @throws InvalidInterfaceException
397
+	 * @throws ReflectionException
398
+	 */
399
+	public function column__REG_att_checked_in(EE_Registration $registration): string
400
+	{
401
+		// we need a local variable for the datetime for each row
402
+		// (so that we don't pollute state for the entire table)
403
+		// so let's try to get it from the registration's event
404
+		$this->datetimes_for_current_row = DatetimesForEventCheckIn::fromRegistration($registration);
405
+		$datetime = $this->datetimes_for_current_row->getOneActiveDatetimeForEvent();
406
+
407
+		$DTD_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
408
+
409
+		$checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
410
+			$registration,
411
+			$DTD_ID
412
+		);
413
+
414
+		$aria_label = $checkin_status_dashicon->ariaLabel();
415
+		$dashicon_class = $checkin_status_dashicon->cssClasses();
416
+		$attributes = ' onClick="return false"';
417
+		$button_class = 'button button--secondary button--icon-only ee-aria-tooltip ee-aria-tooltip--big-box';
418
+
419
+		if (
420
+			$DTD_ID
421
+			&& EE_Registry::instance()->CAP->current_user_can(
422
+				'ee_edit_checkin',
423
+				'espresso_registrations_toggle_checkin_status',
424
+				$registration->ID()
425
+			)
426
+		) {
427
+			// overwrite the disabled attribute with data attributes for performing checkin
428
+			$attributes = 'data-_regid="' . $registration->ID() . '"';
429
+			$attributes .= ' data-dttid="' . $DTD_ID . '"';
430
+			$attributes .= ' data-nonce="' . wp_create_nonce('checkin_nonce') . '"';
431
+			$button_class .= ' clickable trigger-checkin';
432
+		}
433
+
434
+		$content = '
435 435
         <button aria-label="' . $aria_label . '" class="' . $button_class . '" ' . $attributes . '>   
436 436
             <span class="' . $dashicon_class . '" ></span>
437 437
         </button>
438 438
         <span class="show-on-mobile-view-only">' . $this->column_ATT_name($registration) . '</span>';
439
-        return $this->columnContent('_REG_att_checked_in', $content, 'center');
440
-    }
441
-
442
-
443
-    /**
444
-     * @param EE_Registration $registration
445
-     * @return string
446
-     * @throws EE_Error
447
-     * @throws ReflectionException
448
-     */
449
-    public function column_ATT_name(EE_Registration $registration): string
450
-    {
451
-        $attendee = $registration->attendee();
452
-        if (! $attendee instanceof EE_Attendee) {
453
-            return esc_html__('No contact record for this registration.', 'event_espresso');
454
-        }
455
-        // edit attendee link
456
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
457
-            ['action' => 'view_registration', '_REG_ID' => $registration->ID()],
458
-            REG_ADMIN_URL
459
-        );
460
-        $name_link    = '
439
+		return $this->columnContent('_REG_att_checked_in', $content, 'center');
440
+	}
441
+
442
+
443
+	/**
444
+	 * @param EE_Registration $registration
445
+	 * @return string
446
+	 * @throws EE_Error
447
+	 * @throws ReflectionException
448
+	 */
449
+	public function column_ATT_name(EE_Registration $registration): string
450
+	{
451
+		$attendee = $registration->attendee();
452
+		if (! $attendee instanceof EE_Attendee) {
453
+			return esc_html__('No contact record for this registration.', 'event_espresso');
454
+		}
455
+		// edit attendee link
456
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
457
+			['action' => 'view_registration', '_REG_ID' => $registration->ID()],
458
+			REG_ADMIN_URL
459
+		);
460
+		$name_link    = '
461 461
             <span class="ee-status-dot ee-status-bg--' . esc_attr($registration->status_ID()) . ' ee-aria-tooltip"
462 462
             aria-label="' . EEH_Template::pretty_status($registration->status_ID(), false, 'sentence') . '">
463 463
             </span>';
464
-        $name_link    .= EE_Registry::instance()->CAP->current_user_can(
465
-            'ee_edit_contacts',
466
-            'espresso_registrations_edit_attendee'
467
-        )
468
-            ? '<a class="ee-aria-tooltip" href="' . $edit_lnk_url . '" aria-label="' . esc_attr__(
469
-                'View Registration Details',
470
-                'event_espresso'
471
-            ) . '">'
472
-              . $registration->attendee()->full_name()
473
-              . '</a>'
474
-            : $registration->attendee()->full_name();
475
-        $name_link    .= $registration->count() === 1
476
-            ? '&nbsp;<sup><div class="dashicons dashicons-star-filled gold-icon"></div></sup>	'
477
-            : '';
478
-        // add group details
479
-        $name_link .= '&nbsp;' . sprintf(
480
-            esc_html__('(%s of %s)', 'event_espresso'),
481
-            $registration->count(),
482
-            $registration->group_size()
483
-        );
484
-        // add regcode
485
-        $link      = EE_Admin_Page::add_query_args_and_nonce(
486
-            ['action' => 'view_registration', '_REG_ID' => $registration->ID()],
487
-            REG_ADMIN_URL
488
-        );
489
-        $name_link .= '<br>';
490
-        $name_link .= EE_Registry::instance()->instance()->CAP->current_user_can(
491
-            'ee_read_registration',
492
-            'view_registration',
493
-            $registration->ID()
494
-        )
495
-            ? '<a class="ee-aria-tooltip" href="' . $link . '" aria-label="' . esc_attr__(
496
-                'View Registration Details',
497
-                'event_espresso'
498
-            ) . '">'
499
-              . $registration->reg_code()
500
-              . '</a>'
501
-            : $registration->reg_code();
502
-
503
-        $actions                 = [];
504
-        if (
505
-            $this->datetime_id
506
-            && EE_Registry::instance()->CAP->current_user_can(
507
-                'ee_read_checkins',
508
-                'espresso_registrations_registration_checkins'
509
-            )
510
-        ) {
511
-            $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
512
-                ['action' => 'registration_checkins', '_REG_ID' => $registration->ID(), 'DTT_ID' => $this->datetime_id],
513
-                REG_ADMIN_URL
514
-            );
515
-            // get the timestamps for this registration's checkins, related to the selected datetime
516
-            /** @var EE_Checkin[] $checkins */
517
-            $checkins = $registration->get_many_related('Checkin', [['DTT_ID' => $this->datetime_id]]);
518
-            if (! empty($checkins)) {
519
-                // get the last timestamp
520
-                $last_checkin = end($checkins);
521
-                // get timestamp string
522
-                $timestamp_string   = $last_checkin->get_datetime('CHK_timestamp');
523
-                $actions['checkin'] = '
464
+		$name_link    .= EE_Registry::instance()->CAP->current_user_can(
465
+			'ee_edit_contacts',
466
+			'espresso_registrations_edit_attendee'
467
+		)
468
+			? '<a class="ee-aria-tooltip" href="' . $edit_lnk_url . '" aria-label="' . esc_attr__(
469
+				'View Registration Details',
470
+				'event_espresso'
471
+			) . '">'
472
+			  . $registration->attendee()->full_name()
473
+			  . '</a>'
474
+			: $registration->attendee()->full_name();
475
+		$name_link    .= $registration->count() === 1
476
+			? '&nbsp;<sup><div class="dashicons dashicons-star-filled gold-icon"></div></sup>	'
477
+			: '';
478
+		// add group details
479
+		$name_link .= '&nbsp;' . sprintf(
480
+			esc_html__('(%s of %s)', 'event_espresso'),
481
+			$registration->count(),
482
+			$registration->group_size()
483
+		);
484
+		// add regcode
485
+		$link      = EE_Admin_Page::add_query_args_and_nonce(
486
+			['action' => 'view_registration', '_REG_ID' => $registration->ID()],
487
+			REG_ADMIN_URL
488
+		);
489
+		$name_link .= '<br>';
490
+		$name_link .= EE_Registry::instance()->instance()->CAP->current_user_can(
491
+			'ee_read_registration',
492
+			'view_registration',
493
+			$registration->ID()
494
+		)
495
+			? '<a class="ee-aria-tooltip" href="' . $link . '" aria-label="' . esc_attr__(
496
+				'View Registration Details',
497
+				'event_espresso'
498
+			) . '">'
499
+			  . $registration->reg_code()
500
+			  . '</a>'
501
+			: $registration->reg_code();
502
+
503
+		$actions                 = [];
504
+		if (
505
+			$this->datetime_id
506
+			&& EE_Registry::instance()->CAP->current_user_can(
507
+				'ee_read_checkins',
508
+				'espresso_registrations_registration_checkins'
509
+			)
510
+		) {
511
+			$checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
512
+				['action' => 'registration_checkins', '_REG_ID' => $registration->ID(), 'DTT_ID' => $this->datetime_id],
513
+				REG_ADMIN_URL
514
+			);
515
+			// get the timestamps for this registration's checkins, related to the selected datetime
516
+			/** @var EE_Checkin[] $checkins */
517
+			$checkins = $registration->get_many_related('Checkin', [['DTT_ID' => $this->datetime_id]]);
518
+			if (! empty($checkins)) {
519
+				// get the last timestamp
520
+				$last_checkin = end($checkins);
521
+				// get timestamp string
522
+				$timestamp_string   = $last_checkin->get_datetime('CHK_timestamp');
523
+				$actions['checkin'] = '
524 524
                     <a  class="ee-aria-tooltip" 
525 525
                         href="' . $checkin_list_url . '" 
526 526
                         aria-label="' . esc_attr__(
527
-                                          'View this registrant\'s check-ins/checkouts for the datetime',
528
-                                          'event_espresso'
529
-                                      ) . '"
527
+										  'View this registrant\'s check-ins/checkouts for the datetime',
528
+										  'event_espresso'
529
+									  ) . '"
530 530
                     >
531 531
                         ' . $last_checkin->getCheckInText() . ': ' . $timestamp_string . '
532 532
                     </a>';
533
-            }
534
-        }
535
-        $content = (! empty($this->datetime_id) && ! empty($checkins))
536
-            ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
537
-            : $name_link;
538
-        return $this->columnContent('ATT_name', $content);
539
-    }
540
-
541
-
542
-    /**
543
-     * @param EE_Registration $registration
544
-     * @return string
545
-     * @throws EE_Error
546
-     * @throws EE_Error
547
-     */
548
-    public function column_ATT_email(EE_Registration $registration): string
549
-    {
550
-        $attendee = $registration->attendee();
551
-        $content = $attendee instanceof EE_Attendee ? $attendee->email() : '';
552
-        return $this->columnContent('ATT_email', $content);
553
-    }
554
-
555
-
556
-    /**
557
-     * @param EE_Registration $registration
558
-     * @return bool|string
559
-     * @throws EE_Error
560
-     * @throws ReflectionException
561
-     */
562
-    public function column_Event(EE_Registration $registration)
563
-    {
564
-        try {
565
-            $event            = $this->_evt instanceof EE_Event ? $this->_evt : $registration->event();
566
-            $checkin_link_url = EE_Admin_Page::add_query_args_and_nonce(
567
-                ['action' => 'event_registrations', 'event_id' => $event->ID()],
568
-                REG_ADMIN_URL
569
-            );
570
-            $content      = EE_Registry::instance()->CAP->current_user_can(
571
-                'ee_read_checkins',
572
-                'espresso_registrations_registration_checkins'
573
-            ) ? '<a class="ee-aria-tooltip" href="' . $checkin_link_url . '" aria-label="'
574
-                . esc_attr__(
575
-                    'View Checkins for this Event',
576
-                    'event_espresso'
577
-                ) . '">' . $event->name() . '</a>' : $event->name();
578
-        } catch (EntityNotFoundException $e) {
579
-            $content = esc_html__('Unknown', 'event_espresso');
580
-        }
581
-        return $this->columnContent('Event', $content);
582
-    }
583
-
584
-
585
-    /**
586
-     * @param EE_Registration $registration
587
-     * @return string
588
-     * @throws EE_Error
589
-     * @throws ReflectionException
590
-     */
591
-    public function column_PRC_name(EE_Registration $registration): string
592
-    {
593
-        $content = $registration->ticket() instanceof EE_Ticket
594
-            ? $registration->ticket()->name()
595
-            : esc_html__(
596
-                "Unknown",
597
-                "event_espresso"
598
-            );
599
-        return $this->columnContent('PRC_name', $content);
600
-    }
601
-
602
-
603
-    /**
604
-     * column_REG_final_price
605
-     *
606
-     * @param EE_Registration $registration
607
-     * @return string
608
-     * @throws EE_Error
609
-     */
610
-    public function column__REG_final_price(EE_Registration $registration): string
611
-    {
612
-        return $this->columnContent('_REG_final_price', $registration->pretty_final_price(), 'end');
613
-    }
614
-
615
-
616
-    /**
617
-     * column_TXN_paid
618
-     *
619
-     * @param EE_Registration $registration
620
-     * @return string
621
-     * @throws EE_Error
622
-     * @throws ReflectionException
623
-     */
624
-    public function column_TXN_paid(EE_Registration $registration): string
625
-    {
626
-        $content = '';
627
-        if ($registration->count() === 1) {
628
-            if ($registration->transaction()->paid() >= $registration->transaction()->total()) {
629
-                return '<div class="dashicons dashicons-yes green-icon"></div>';
630
-            } else {
631
-                $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
632
-                    ['action' => 'view_transaction', 'TXN_ID' => $registration->transaction_ID()],
633
-                    TXN_ADMIN_URL
634
-                );
635
-                $content = EE_Registry::instance()->CAP->current_user_can(
636
-                    'ee_read_transaction',
637
-                    'espresso_transactions_view_transaction'
638
-                ) ? '
533
+			}
534
+		}
535
+		$content = (! empty($this->datetime_id) && ! empty($checkins))
536
+			? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
537
+			: $name_link;
538
+		return $this->columnContent('ATT_name', $content);
539
+	}
540
+
541
+
542
+	/**
543
+	 * @param EE_Registration $registration
544
+	 * @return string
545
+	 * @throws EE_Error
546
+	 * @throws EE_Error
547
+	 */
548
+	public function column_ATT_email(EE_Registration $registration): string
549
+	{
550
+		$attendee = $registration->attendee();
551
+		$content = $attendee instanceof EE_Attendee ? $attendee->email() : '';
552
+		return $this->columnContent('ATT_email', $content);
553
+	}
554
+
555
+
556
+	/**
557
+	 * @param EE_Registration $registration
558
+	 * @return bool|string
559
+	 * @throws EE_Error
560
+	 * @throws ReflectionException
561
+	 */
562
+	public function column_Event(EE_Registration $registration)
563
+	{
564
+		try {
565
+			$event            = $this->_evt instanceof EE_Event ? $this->_evt : $registration->event();
566
+			$checkin_link_url = EE_Admin_Page::add_query_args_and_nonce(
567
+				['action' => 'event_registrations', 'event_id' => $event->ID()],
568
+				REG_ADMIN_URL
569
+			);
570
+			$content      = EE_Registry::instance()->CAP->current_user_can(
571
+				'ee_read_checkins',
572
+				'espresso_registrations_registration_checkins'
573
+			) ? '<a class="ee-aria-tooltip" href="' . $checkin_link_url . '" aria-label="'
574
+				. esc_attr__(
575
+					'View Checkins for this Event',
576
+					'event_espresso'
577
+				) . '">' . $event->name() . '</a>' : $event->name();
578
+		} catch (EntityNotFoundException $e) {
579
+			$content = esc_html__('Unknown', 'event_espresso');
580
+		}
581
+		return $this->columnContent('Event', $content);
582
+	}
583
+
584
+
585
+	/**
586
+	 * @param EE_Registration $registration
587
+	 * @return string
588
+	 * @throws EE_Error
589
+	 * @throws ReflectionException
590
+	 */
591
+	public function column_PRC_name(EE_Registration $registration): string
592
+	{
593
+		$content = $registration->ticket() instanceof EE_Ticket
594
+			? $registration->ticket()->name()
595
+			: esc_html__(
596
+				"Unknown",
597
+				"event_espresso"
598
+			);
599
+		return $this->columnContent('PRC_name', $content);
600
+	}
601
+
602
+
603
+	/**
604
+	 * column_REG_final_price
605
+	 *
606
+	 * @param EE_Registration $registration
607
+	 * @return string
608
+	 * @throws EE_Error
609
+	 */
610
+	public function column__REG_final_price(EE_Registration $registration): string
611
+	{
612
+		return $this->columnContent('_REG_final_price', $registration->pretty_final_price(), 'end');
613
+	}
614
+
615
+
616
+	/**
617
+	 * column_TXN_paid
618
+	 *
619
+	 * @param EE_Registration $registration
620
+	 * @return string
621
+	 * @throws EE_Error
622
+	 * @throws ReflectionException
623
+	 */
624
+	public function column_TXN_paid(EE_Registration $registration): string
625
+	{
626
+		$content = '';
627
+		if ($registration->count() === 1) {
628
+			if ($registration->transaction()->paid() >= $registration->transaction()->total()) {
629
+				return '<div class="dashicons dashicons-yes green-icon"></div>';
630
+			} else {
631
+				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
632
+					['action' => 'view_transaction', 'TXN_ID' => $registration->transaction_ID()],
633
+					TXN_ADMIN_URL
634
+				);
635
+				$content = EE_Registry::instance()->CAP->current_user_can(
636
+					'ee_read_transaction',
637
+					'espresso_transactions_view_transaction'
638
+				) ? '
639 639
 				<a class="ee-aria-tooltip ee-status-color--'
640
-                    . $registration->transaction()->status_ID()
641
-                    . '" href="'
642
-                    . $view_txn_lnk_url
643
-                    . '"  aria-label="'
644
-                    . esc_attr__('View Transaction', 'event_espresso')
645
-                    . '">
640
+					. $registration->transaction()->status_ID()
641
+					. '" href="'
642
+					. $view_txn_lnk_url
643
+					. '"  aria-label="'
644
+					. esc_attr__('View Transaction', 'event_espresso')
645
+					. '">
646 646
 						'
647
-                    . $registration->transaction()->pretty_paid()
648
-                    . '
647
+					. $registration->transaction()->pretty_paid()
648
+					. '
649 649
 					</a>
650 650
 				' : $registration->transaction()->pretty_paid();
651
-            }
652
-        }
653
-        return $this->columnContent('TXN_paid', $content, 'end');
654
-    }
655
-
656
-
657
-    /**
658
-     *        column_TXN_total
659
-     *
660
-     * @param EE_Registration $registration
661
-     * @return string
662
-     * @throws EE_Error
663
-     * @throws ReflectionException
664
-     */
665
-    public function column_TXN_total(EE_Registration $registration): string
666
-    {
667
-        $content = '';
668
-        $txn = $registration->transaction();
669
-        $view_txn_url = add_query_arg(['action' => 'view_transaction', 'TXN_ID' => $txn->ID()], TXN_ADMIN_URL);
670
-        if ($registration->get('REG_count') === 1) {
671
-            $line_total_obj = $txn->total_line_item();
672
-            $txn_total      = $line_total_obj instanceof EE_Line_Item
673
-                ? $line_total_obj->get_pretty('LIN_total')
674
-                : esc_html__(
675
-                    'View Transaction',
676
-                    'event_espresso'
677
-                );
678
-            $content = EE_Registry::instance()->CAP->current_user_can(
679
-                'ee_read_transaction',
680
-                'espresso_transactions_view_transaction'
681
-            ) ? '<a class="ee-aria-tooltip" href="'
682
-                . $view_txn_url
683
-                . '" aria-label="'
684
-                . esc_attr__('View Transaction', 'event_espresso')
685
-                . '">'
686
-                . $txn_total
687
-                . '</a>'
688
-                : $txn_total;
689
-        }
690
-        return $this->columnContent('TXN_total', $content, 'end');
691
-    }
651
+			}
652
+		}
653
+		return $this->columnContent('TXN_paid', $content, 'end');
654
+	}
655
+
656
+
657
+	/**
658
+	 *        column_TXN_total
659
+	 *
660
+	 * @param EE_Registration $registration
661
+	 * @return string
662
+	 * @throws EE_Error
663
+	 * @throws ReflectionException
664
+	 */
665
+	public function column_TXN_total(EE_Registration $registration): string
666
+	{
667
+		$content = '';
668
+		$txn = $registration->transaction();
669
+		$view_txn_url = add_query_arg(['action' => 'view_transaction', 'TXN_ID' => $txn->ID()], TXN_ADMIN_URL);
670
+		if ($registration->get('REG_count') === 1) {
671
+			$line_total_obj = $txn->total_line_item();
672
+			$txn_total      = $line_total_obj instanceof EE_Line_Item
673
+				? $line_total_obj->get_pretty('LIN_total')
674
+				: esc_html__(
675
+					'View Transaction',
676
+					'event_espresso'
677
+				);
678
+			$content = EE_Registry::instance()->CAP->current_user_can(
679
+				'ee_read_transaction',
680
+				'espresso_transactions_view_transaction'
681
+			) ? '<a class="ee-aria-tooltip" href="'
682
+				. $view_txn_url
683
+				. '" aria-label="'
684
+				. esc_attr__('View Transaction', 'event_espresso')
685
+				. '">'
686
+				. $txn_total
687
+				. '</a>'
688
+				: $txn_total;
689
+		}
690
+		return $this->columnContent('TXN_total', $content, 'end');
691
+	}
692 692
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
             'screen'   => $this->_admin_page->get_current_screen()->id,
119 119
         ];
120 120
 
121
-        $this->_columns      = [
121
+        $this->_columns = [
122 122
             'cb' => '<input type="checkbox" />', // Render a checkbox instead of text
123 123
             '_REG_att_checked_in' => esc_html__('Check In', 'event_espresso'),
124 124
             'ATT_name'            => esc_html__('Registrant', 'event_espresso'),
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         $hide_expired_checked = $hide_expired ? 'checked' : '';
243 243
         $hide_upcoming_checked = $hide_upcoming ? 'checked' : '';
244 244
         // get datetimes for ALL active events (note possible capability restrictions)
245
-        $events   = $this->datetimes_for_event->getAllActiveDatetimesForAllEvents();
245
+        $events = $this->datetimes_for_event->getAllActiveDatetimesForAllEvents();
246 246
         $event_options[] = [
247 247
             'id'   => 0,
248 248
             'text' => esc_html__(' - select an event - ', 'event_espresso'),
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
         /** @var EE_Event $event */
251 251
         foreach ($events as $event) {
252 252
             // any registrations for this event?
253
-            if (! $event instanceof EE_Event/* || ! $event->get_count_of_all_registrations()*/) {
253
+            if ( ! $event instanceof EE_Event/* || ! $event->get_count_of_all_registrations()*/) {
254 254
                 continue;
255 255
             }
256 256
             $expired_class = $event->is_expired() ? 'ee-expired-event' : '';
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
                     $event->name(),
263 263
                     $event
264 264
                 ),
265
-                'class' => $expired_class . $upcoming_class,
265
+                'class' => $expired_class.$upcoming_class,
266 266
             ];
267 267
             if ($event->ID() === $this->event_id) {
268 268
                 $hide_expired = $expired_class === '';
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         <div class="ee-event-filter">
280 280
             <span>
281 281
                 <label for="event_id">
282
-                    ' . esc_html__('Check-in Status for', 'event_espresso') . '
282
+                    ' . esc_html__('Check-in Status for', 'event_espresso').'
283 283
                 </label>
284 284
                 ' . EEH_Form_Fields::select_input(
285 285
                     'event_id',
@@ -287,12 +287,12 @@  discard block
 block discarded – undo
287 287
                     $this->event_id,
288 288
                 '',
289 289
                     $select_class
290
-            ) . '
290
+            ).'
291 291
             </span>
292 292
             <span>
293 293
                 <label for="js-ee-hide-upcoming-events">
294
-                    <input type="checkbox" id="js-ee-hide-upcoming-events" name="hide_upcoming" ' . $hide_upcoming_checked . '>
295
-                    ' . esc_html__('Hide Upcoming Events', 'event_espresso') . '
294
+                    <input type="checkbox" id="js-ee-hide-upcoming-events" name="hide_upcoming" ' . $hide_upcoming_checked.'>
295
+                    ' . esc_html__('Hide Upcoming Events', 'event_espresso').'
296 296
                 </label>
297 297
                 <span class="ee-help-btn dashicons dashicons-editor-help ee-aria-tooltip" aria-label="'
298 298
                      . esc_html__(
@@ -303,8 +303,8 @@  discard block
 block discarded – undo
303 303
             </span>
304 304
             <span>
305 305
                 <label for="js-ee-hide-expired-events">
306
-                    <input type="checkbox" id="js-ee-hide-expired-events" name="hide_expired" ' . $hide_expired_checked . '>
307
-                    ' . esc_html__('Hide Expired Events', 'event_espresso') . '
306
+                    <input type="checkbox" id="js-ee-hide-expired-events" name="hide_expired" ' . $hide_expired_checked.'>
307
+                    ' . esc_html__('Hide Expired Events', 'event_espresso').'
308 308
                 </label>
309 309
                 <span class="ee-help-btn dashicons dashicons-editor-help ee-aria-tooltip" aria-label="'
310 310
                      . esc_html__(
@@ -320,12 +320,12 @@  discard block
 block discarded – undo
320 320
             $datetimes[0] = esc_html__(' - select a datetime - ', 'event_espresso');
321 321
             foreach ($datetimes_for_event as $datetime) {
322 322
                 $datetime_string              = $datetime->name();
323
-                $datetime_string              = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : '';
323
+                $datetime_string              = ! empty($datetime_string) ? ' ('.$datetime_string.')' : '';
324 324
                 $datetime_string              =
325
-                    $datetime->start_date_and_time() . ' - ' . $datetime->end_date_and_time() . $datetime_string;
326
-                $datetimes[ $datetime->ID() ] = $datetime_string;
325
+                    $datetime->start_date_and_time().' - '.$datetime->end_date_and_time().$datetime_string;
326
+                $datetimes[$datetime->ID()] = $datetime_string;
327 327
             }
328
-            $input     = new EE_Select_Input(
328
+            $input = new EE_Select_Input(
329 329
                 $datetimes,
330 330
                 [
331 331
                     'html_name' => 'DTT_ID',
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
      */
357 357
     protected function _get_total_event_attendees(): int
358 358
     {
359
-        $query_params      = [];
359
+        $query_params = [];
360 360
         if ($this->event_id) {
361 361
             $query_params[0]['EVT_ID'] = $this->event_id;
362 362
         }
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
         if ($this->datetime_id) {
365 365
             $query_params[0]['Ticket.Datetime.DTT_ID'] = $this->datetime_id;
366 366
         }
367
-        $status_ids_array          = apply_filters(
367
+        $status_ids_array = apply_filters(
368 368
             'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
369 369
             [EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved]
370 370
         );
@@ -425,17 +425,17 @@  discard block
 block discarded – undo
425 425
             )
426 426
         ) {
427 427
             // overwrite the disabled attribute with data attributes for performing checkin
428
-            $attributes = 'data-_regid="' . $registration->ID() . '"';
429
-            $attributes .= ' data-dttid="' . $DTD_ID . '"';
430
-            $attributes .= ' data-nonce="' . wp_create_nonce('checkin_nonce') . '"';
428
+            $attributes = 'data-_regid="'.$registration->ID().'"';
429
+            $attributes .= ' data-dttid="'.$DTD_ID.'"';
430
+            $attributes .= ' data-nonce="'.wp_create_nonce('checkin_nonce').'"';
431 431
             $button_class .= ' clickable trigger-checkin';
432 432
         }
433 433
 
434 434
         $content = '
435
-        <button aria-label="' . $aria_label . '" class="' . $button_class . '" ' . $attributes . '>   
436
-            <span class="' . $dashicon_class . '" ></span>
435
+        <button aria-label="' . $aria_label.'" class="'.$button_class.'" '.$attributes.'>   
436
+            <span class="' . $dashicon_class.'" ></span>
437 437
         </button>
438
-        <span class="show-on-mobile-view-only">' . $this->column_ATT_name($registration) . '</span>';
438
+        <span class="show-on-mobile-view-only">' . $this->column_ATT_name($registration).'</span>';
439 439
         return $this->columnContent('_REG_att_checked_in', $content, 'center');
440 440
     }
441 441
 
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
     public function column_ATT_name(EE_Registration $registration): string
450 450
     {
451 451
         $attendee = $registration->attendee();
452
-        if (! $attendee instanceof EE_Attendee) {
452
+        if ( ! $attendee instanceof EE_Attendee) {
453 453
             return esc_html__('No contact record for this registration.', 'event_espresso');
454 454
         }
455 455
         // edit attendee link
@@ -457,32 +457,32 @@  discard block
 block discarded – undo
457 457
             ['action' => 'view_registration', '_REG_ID' => $registration->ID()],
458 458
             REG_ADMIN_URL
459 459
         );
460
-        $name_link    = '
461
-            <span class="ee-status-dot ee-status-bg--' . esc_attr($registration->status_ID()) . ' ee-aria-tooltip"
462
-            aria-label="' . EEH_Template::pretty_status($registration->status_ID(), false, 'sentence') . '">
460
+        $name_link = '
461
+            <span class="ee-status-dot ee-status-bg--' . esc_attr($registration->status_ID()).' ee-aria-tooltip"
462
+            aria-label="' . EEH_Template::pretty_status($registration->status_ID(), false, 'sentence').'">
463 463
             </span>';
464
-        $name_link    .= EE_Registry::instance()->CAP->current_user_can(
464
+        $name_link .= EE_Registry::instance()->CAP->current_user_can(
465 465
             'ee_edit_contacts',
466 466
             'espresso_registrations_edit_attendee'
467 467
         )
468
-            ? '<a class="ee-aria-tooltip" href="' . $edit_lnk_url . '" aria-label="' . esc_attr__(
468
+            ? '<a class="ee-aria-tooltip" href="'.$edit_lnk_url.'" aria-label="'.esc_attr__(
469 469
                 'View Registration Details',
470 470
                 'event_espresso'
471
-            ) . '">'
471
+            ).'">'
472 472
               . $registration->attendee()->full_name()
473 473
               . '</a>'
474 474
             : $registration->attendee()->full_name();
475
-        $name_link    .= $registration->count() === 1
475
+        $name_link .= $registration->count() === 1
476 476
             ? '&nbsp;<sup><div class="dashicons dashicons-star-filled gold-icon"></div></sup>	'
477 477
             : '';
478 478
         // add group details
479
-        $name_link .= '&nbsp;' . sprintf(
479
+        $name_link .= '&nbsp;'.sprintf(
480 480
             esc_html__('(%s of %s)', 'event_espresso'),
481 481
             $registration->count(),
482 482
             $registration->group_size()
483 483
         );
484 484
         // add regcode
485
-        $link      = EE_Admin_Page::add_query_args_and_nonce(
485
+        $link = EE_Admin_Page::add_query_args_and_nonce(
486 486
             ['action' => 'view_registration', '_REG_ID' => $registration->ID()],
487 487
             REG_ADMIN_URL
488 488
         );
@@ -492,15 +492,15 @@  discard block
 block discarded – undo
492 492
             'view_registration',
493 493
             $registration->ID()
494 494
         )
495
-            ? '<a class="ee-aria-tooltip" href="' . $link . '" aria-label="' . esc_attr__(
495
+            ? '<a class="ee-aria-tooltip" href="'.$link.'" aria-label="'.esc_attr__(
496 496
                 'View Registration Details',
497 497
                 'event_espresso'
498
-            ) . '">'
498
+            ).'">'
499 499
               . $registration->reg_code()
500 500
               . '</a>'
501 501
             : $registration->reg_code();
502 502
 
503
-        $actions                 = [];
503
+        $actions = [];
504 504
         if (
505 505
             $this->datetime_id
506 506
             && EE_Registry::instance()->CAP->current_user_can(
@@ -515,24 +515,24 @@  discard block
 block discarded – undo
515 515
             // get the timestamps for this registration's checkins, related to the selected datetime
516 516
             /** @var EE_Checkin[] $checkins */
517 517
             $checkins = $registration->get_many_related('Checkin', [['DTT_ID' => $this->datetime_id]]);
518
-            if (! empty($checkins)) {
518
+            if ( ! empty($checkins)) {
519 519
                 // get the last timestamp
520 520
                 $last_checkin = end($checkins);
521 521
                 // get timestamp string
522 522
                 $timestamp_string   = $last_checkin->get_datetime('CHK_timestamp');
523 523
                 $actions['checkin'] = '
524 524
                     <a  class="ee-aria-tooltip" 
525
-                        href="' . $checkin_list_url . '" 
525
+                        href="' . $checkin_list_url.'" 
526 526
                         aria-label="' . esc_attr__(
527 527
                                           'View this registrant\'s check-ins/checkouts for the datetime',
528 528
                                           'event_espresso'
529
-                                      ) . '"
529
+                                      ).'"
530 530
                     >
531
-                        ' . $last_checkin->getCheckInText() . ': ' . $timestamp_string . '
531
+                        ' . $last_checkin->getCheckInText().': '.$timestamp_string.'
532 532
                     </a>';
533 533
             }
534 534
         }
535
-        $content = (! empty($this->datetime_id) && ! empty($checkins))
535
+        $content = ( ! empty($this->datetime_id) && ! empty($checkins))
536 536
             ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
537 537
             : $name_link;
538 538
         return $this->columnContent('ATT_name', $content);
@@ -567,14 +567,14 @@  discard block
 block discarded – undo
567 567
                 ['action' => 'event_registrations', 'event_id' => $event->ID()],
568 568
                 REG_ADMIN_URL
569 569
             );
570
-            $content      = EE_Registry::instance()->CAP->current_user_can(
570
+            $content = EE_Registry::instance()->CAP->current_user_can(
571 571
                 'ee_read_checkins',
572 572
                 'espresso_registrations_registration_checkins'
573
-            ) ? '<a class="ee-aria-tooltip" href="' . $checkin_link_url . '" aria-label="'
573
+            ) ? '<a class="ee-aria-tooltip" href="'.$checkin_link_url.'" aria-label="'
574 574
                 . esc_attr__(
575 575
                     'View Checkins for this Event',
576 576
                     'event_espresso'
577
-                ) . '">' . $event->name() . '</a>' : $event->name();
577
+                ).'">'.$event->name().'</a>' : $event->name();
578 578
         } catch (EntityNotFoundException $e) {
579 579
             $content = esc_html__('Unknown', 'event_espresso');
580 580
         }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2892 added lines, -2892 removed lines patch added patch discarded remove patch
@@ -16,2899 +16,2899 @@
 block discarded – undo
16 16
 class Events_Admin_Page extends EE_Admin_Page_CPT
17 17
 {
18 18
 
19
-    /**
20
-     * This will hold the event object for event_details screen.
19
+	/**
20
+	 * This will hold the event object for event_details screen.
21
+	 *
22
+	 * @var EE_Event $_event
23
+	 */
24
+	protected $_event;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var stdClass $_category
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This will hold the event model instance
37
+	 *
38
+	 * @var EEM_Event $_event_model
39
+	 */
40
+	protected $_event_model;
41
+
42
+
43
+	/**
44
+	 * @var EE_Event
45
+	 */
46
+	protected $_cpt_model_obj = false;
47
+
48
+
49
+	/**
50
+	 * @var NodeGroupDao
51
+	 */
52
+	protected $model_obj_node_group_persister;
53
+
54
+
55
+	/**
56
+	 * Initialize page props for this admin page group.
57
+	 */
58
+	protected function _init_page_props()
59
+	{
60
+		$this->page_slug        = EVENTS_PG_SLUG;
61
+		$this->page_label       = EVENTS_LABEL;
62
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
63
+		$this->_admin_base_path = EVENTS_ADMIN;
64
+		$this->_cpt_model_names = [
65
+			'create_new' => 'EEM_Event',
66
+			'edit'       => 'EEM_Event',
67
+		];
68
+		$this->_cpt_edit_routes = [
69
+			'espresso_events' => 'edit',
70
+		];
71
+		add_action(
72
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
73
+			[$this, 'verify_event_edit'],
74
+			10,
75
+			2
76
+		);
77
+	}
78
+
79
+
80
+	/**
81
+	 * Sets the ajax hooks used for this admin page group.
82
+	 */
83
+	protected function _ajax_hooks()
84
+	{
85
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
86
+	}
87
+
88
+
89
+	/**
90
+	 * Sets the page properties for this admin page group.
91
+	 */
92
+	protected function _define_page_props()
93
+	{
94
+		$this->_admin_page_title = EVENTS_LABEL;
95
+		$this->_labels           = [
96
+			'buttons'      => [
97
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
98
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
99
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
100
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
101
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
102
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
103
+			],
104
+			'editor_title' => [
105
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
106
+			],
107
+			'publishbox'   => [
108
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
109
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
110
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
111
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
112
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
113
+			],
114
+		];
115
+	}
116
+
117
+
118
+	/**
119
+	 * Sets the page routes property for this admin page group.
120
+	 */
121
+	protected function _set_page_routes()
122
+	{
123
+		// load formatter helper
124
+		// load field generator helper
125
+		// is there a evt_id in the request?
126
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
127
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
128
+
129
+		$this->_page_routes = [
130
+			'default'                       => [
131
+				'func'       => '_events_overview_list_table',
132
+				'capability' => 'ee_read_events',
133
+			],
134
+			'create_new'                    => [
135
+				'func'       => '_create_new_cpt_item',
136
+				'capability' => 'ee_edit_events',
137
+			],
138
+			'edit'                          => [
139
+				'func'       => '_edit_cpt_item',
140
+				'capability' => 'ee_edit_event',
141
+				'obj_id'     => $EVT_ID,
142
+			],
143
+			'copy_event'                    => [
144
+				'func'       => '_copy_events',
145
+				'capability' => 'ee_edit_event',
146
+				'obj_id'     => $EVT_ID,
147
+				'noheader'   => true,
148
+			],
149
+			'trash_event'                   => [
150
+				'func'       => '_trash_or_restore_event',
151
+				'args'       => ['event_status' => 'trash'],
152
+				'capability' => 'ee_delete_event',
153
+				'obj_id'     => $EVT_ID,
154
+				'noheader'   => true,
155
+			],
156
+			'trash_events'                  => [
157
+				'func'       => '_trash_or_restore_events',
158
+				'args'       => ['event_status' => 'trash'],
159
+				'capability' => 'ee_delete_events',
160
+				'noheader'   => true,
161
+			],
162
+			'restore_event'                 => [
163
+				'func'       => '_trash_or_restore_event',
164
+				'args'       => ['event_status' => 'draft'],
165
+				'capability' => 'ee_delete_event',
166
+				'obj_id'     => $EVT_ID,
167
+				'noheader'   => true,
168
+			],
169
+			'restore_events'                => [
170
+				'func'       => '_trash_or_restore_events',
171
+				'args'       => ['event_status' => 'draft'],
172
+				'capability' => 'ee_delete_events',
173
+				'noheader'   => true,
174
+			],
175
+			'delete_event'                  => [
176
+				'func'       => '_delete_event',
177
+				'capability' => 'ee_delete_event',
178
+				'obj_id'     => $EVT_ID,
179
+				'noheader'   => true,
180
+			],
181
+			'delete_events'                 => [
182
+				'func'       => '_delete_events',
183
+				'capability' => 'ee_delete_events',
184
+				'noheader'   => true,
185
+			],
186
+			'view_report'                   => [
187
+				'func'       => '_view_report',
188
+				'capability' => 'ee_edit_events',
189
+			],
190
+			'default_event_settings'        => [
191
+				'func'       => '_default_event_settings',
192
+				'capability' => 'manage_options',
193
+			],
194
+			'update_default_event_settings' => [
195
+				'func'       => '_update_default_event_settings',
196
+				'capability' => 'manage_options',
197
+				'noheader'   => true,
198
+			],
199
+			'template_settings'             => [
200
+				'func'       => '_template_settings',
201
+				'capability' => 'manage_options',
202
+			],
203
+			// event category tab related
204
+			'add_category'                  => [
205
+				'func'       => '_category_details',
206
+				'capability' => 'ee_edit_event_category',
207
+				'args'       => ['add'],
208
+			],
209
+			'edit_category'                 => [
210
+				'func'       => '_category_details',
211
+				'capability' => 'ee_edit_event_category',
212
+				'args'       => ['edit'],
213
+			],
214
+			'delete_categories'             => [
215
+				'func'       => '_delete_categories',
216
+				'capability' => 'ee_delete_event_category',
217
+				'noheader'   => true,
218
+			],
219
+			'delete_category'               => [
220
+				'func'       => '_delete_categories',
221
+				'capability' => 'ee_delete_event_category',
222
+				'noheader'   => true,
223
+			],
224
+			'insert_category'               => [
225
+				'func'       => '_insert_or_update_category',
226
+				'args'       => ['new_category' => true],
227
+				'capability' => 'ee_edit_event_category',
228
+				'noheader'   => true,
229
+			],
230
+			'update_category'               => [
231
+				'func'       => '_insert_or_update_category',
232
+				'args'       => ['new_category' => false],
233
+				'capability' => 'ee_edit_event_category',
234
+				'noheader'   => true,
235
+			],
236
+			'category_list'                 => [
237
+				'func'       => '_category_list_table',
238
+				'capability' => 'ee_manage_event_categories',
239
+			],
240
+			'preview_deletion'              => [
241
+				'func'       => 'previewDeletion',
242
+				'capability' => 'ee_delete_events',
243
+			],
244
+			'confirm_deletion'              => [
245
+				'func'       => 'confirmDeletion',
246
+				'capability' => 'ee_delete_events',
247
+				'noheader'   => true,
248
+			],
249
+		];
250
+	}
251
+
252
+
253
+	/**
254
+	 * Set the _page_config property for this admin page group.
255
+	 */
256
+	protected function _set_page_config()
257
+	{
258
+		$post_id            = $this->request->getRequestParam('post', 0, 'int');
259
+		$EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
260
+		$this->_page_config = [
261
+			'default'                => [
262
+				'nav'           => [
263
+					'label' => esc_html__('Overview', 'event_espresso'),
264
+					'order' => 10,
265
+				],
266
+				'list_table'    => 'Events_Admin_List_Table',
267
+				'help_tabs'     => [
268
+					'events_overview_help_tab'                       => [
269
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
270
+						'filename' => 'events_overview',
271
+					],
272
+					'events_overview_table_column_headings_help_tab' => [
273
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
+						'filename' => 'events_overview_table_column_headings',
275
+					],
276
+					'events_overview_filters_help_tab'               => [
277
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
+						'filename' => 'events_overview_filters',
279
+					],
280
+					'events_overview_view_help_tab'                  => [
281
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
+						'filename' => 'events_overview_views',
283
+					],
284
+					'events_overview_other_help_tab'                 => [
285
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
+						'filename' => 'events_overview_other',
287
+					],
288
+				],
289
+				'require_nonce' => false,
290
+			],
291
+			'create_new'             => [
292
+				'nav'           => [
293
+					'label'      => esc_html__('Add New Event', 'event_espresso'),
294
+					'order'      => 5,
295
+					'persistent' => false,
296
+				],
297
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
298
+				'help_tabs'     => [
299
+					'event_editor_help_tab'                            => [
300
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
301
+						'filename' => 'event_editor',
302
+					],
303
+					'event_editor_title_richtexteditor_help_tab'       => [
304
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
305
+						'filename' => 'event_editor_title_richtexteditor',
306
+					],
307
+					'event_editor_venue_details_help_tab'              => [
308
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
309
+						'filename' => 'event_editor_venue_details',
310
+					],
311
+					'event_editor_event_datetimes_help_tab'            => [
312
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
313
+						'filename' => 'event_editor_event_datetimes',
314
+					],
315
+					'event_editor_event_tickets_help_tab'              => [
316
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
317
+						'filename' => 'event_editor_event_tickets',
318
+					],
319
+					'event_editor_event_registration_options_help_tab' => [
320
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
321
+						'filename' => 'event_editor_event_registration_options',
322
+					],
323
+					'event_editor_tags_categories_help_tab'            => [
324
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
325
+						'filename' => 'event_editor_tags_categories',
326
+					],
327
+					'event_editor_questions_registrants_help_tab'      => [
328
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
329
+						'filename' => 'event_editor_questions_registrants',
330
+					],
331
+					'event_editor_save_new_event_help_tab'             => [
332
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
333
+						'filename' => 'event_editor_save_new_event',
334
+					],
335
+					'event_editor_other_help_tab'                      => [
336
+						'title'    => esc_html__('Event Other', 'event_espresso'),
337
+						'filename' => 'event_editor_other',
338
+					],
339
+				],
340
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
341
+				'require_nonce' => false,
342
+			],
343
+			'edit'                   => [
344
+				'nav'           => [
345
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
346
+					'order'      => 5,
347
+					'persistent' => false,
348
+					'url'        => $post_id
349
+						? EE_Admin_Page::add_query_args_and_nonce(
350
+							['post' => $post_id, 'action' => 'edit'],
351
+							$this->_current_page_view_url
352
+						)
353
+						: $this->_admin_base_url,
354
+				],
355
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
356
+				'help_tabs'     => [
357
+					'event_editor_help_tab'                            => [
358
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
359
+						'filename' => 'event_editor',
360
+					],
361
+					'event_editor_title_richtexteditor_help_tab'       => [
362
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
363
+						'filename' => 'event_editor_title_richtexteditor',
364
+					],
365
+					'event_editor_venue_details_help_tab'              => [
366
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
367
+						'filename' => 'event_editor_venue_details',
368
+					],
369
+					'event_editor_event_datetimes_help_tab'            => [
370
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
371
+						'filename' => 'event_editor_event_datetimes',
372
+					],
373
+					'event_editor_event_tickets_help_tab'              => [
374
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
375
+						'filename' => 'event_editor_event_tickets',
376
+					],
377
+					'event_editor_event_registration_options_help_tab' => [
378
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
379
+						'filename' => 'event_editor_event_registration_options',
380
+					],
381
+					'event_editor_tags_categories_help_tab'            => [
382
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
383
+						'filename' => 'event_editor_tags_categories',
384
+					],
385
+					'event_editor_questions_registrants_help_tab'      => [
386
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
387
+						'filename' => 'event_editor_questions_registrants',
388
+					],
389
+					'event_editor_save_new_event_help_tab'             => [
390
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
391
+						'filename' => 'event_editor_save_new_event',
392
+					],
393
+					'event_editor_other_help_tab'                      => [
394
+						'title'    => esc_html__('Event Other', 'event_espresso'),
395
+						'filename' => 'event_editor_other',
396
+					],
397
+				],
398
+				'require_nonce' => false,
399
+			],
400
+			'default_event_settings' => [
401
+				'nav'           => [
402
+					'label' => esc_html__('Default Settings', 'event_espresso'),
403
+					'order' => 40,
404
+				],
405
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
406
+				'labels'        => [
407
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
408
+				],
409
+				'help_tabs'     => [
410
+					'default_settings_help_tab'        => [
411
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
412
+						'filename' => 'events_default_settings',
413
+					],
414
+					'default_settings_status_help_tab' => [
415
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
416
+						'filename' => 'events_default_settings_status',
417
+					],
418
+					'default_maximum_tickets_help_tab' => [
419
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
420
+						'filename' => 'events_default_settings_max_tickets',
421
+					],
422
+				],
423
+				'require_nonce' => false,
424
+			],
425
+			// template settings
426
+			'template_settings'      => [
427
+				'nav'           => [
428
+					'label' => esc_html__('Templates', 'event_espresso'),
429
+					'order' => 30,
430
+				],
431
+				'metaboxes'     => $this->_default_espresso_metaboxes,
432
+				'help_tabs'     => [
433
+					'general_settings_templates_help_tab' => [
434
+						'title'    => esc_html__('Templates', 'event_espresso'),
435
+						'filename' => 'general_settings_templates',
436
+					],
437
+				],
438
+				'require_nonce' => false,
439
+			],
440
+			// event category stuff
441
+			'add_category'           => [
442
+				'nav'           => [
443
+					'label'      => esc_html__('Add Category', 'event_espresso'),
444
+					'order'      => 15,
445
+					'persistent' => false,
446
+				],
447
+				'help_tabs'     => [
448
+					'add_category_help_tab' => [
449
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
450
+						'filename' => 'events_add_category',
451
+					],
452
+				],
453
+				'metaboxes'     => ['_publish_post_box'],
454
+				'require_nonce' => false,
455
+			],
456
+			'edit_category'          => [
457
+				'nav'           => [
458
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
459
+					'order'      => 15,
460
+					'persistent' => false,
461
+					'url'        => $EVT_CAT_ID
462
+						? add_query_arg(
463
+							['EVT_CAT_ID' => $EVT_CAT_ID],
464
+							$this->_current_page_view_url
465
+						)
466
+						: $this->_admin_base_url,
467
+				],
468
+				'help_tabs'     => [
469
+					'edit_category_help_tab' => [
470
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
471
+						'filename' => 'events_edit_category',
472
+					],
473
+				],
474
+				'metaboxes'     => ['_publish_post_box'],
475
+				'require_nonce' => false,
476
+			],
477
+			'category_list'          => [
478
+				'nav'           => [
479
+					'label' => esc_html__('Categories', 'event_espresso'),
480
+					'order' => 20,
481
+				],
482
+				'list_table'    => 'Event_Categories_Admin_List_Table',
483
+				'help_tabs'     => [
484
+					'events_categories_help_tab'                       => [
485
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
486
+						'filename' => 'events_categories',
487
+					],
488
+					'events_categories_table_column_headings_help_tab' => [
489
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
490
+						'filename' => 'events_categories_table_column_headings',
491
+					],
492
+					'events_categories_view_help_tab'                  => [
493
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
494
+						'filename' => 'events_categories_views',
495
+					],
496
+					'events_categories_other_help_tab'                 => [
497
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
498
+						'filename' => 'events_categories_other',
499
+					],
500
+				],
501
+				'metaboxes'     => $this->_default_espresso_metaboxes,
502
+				'require_nonce' => false,
503
+			],
504
+			'preview_deletion'       => [
505
+				'nav'           => [
506
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
507
+					'order'      => 15,
508
+					'persistent' => false,
509
+					'url'        => '',
510
+				],
511
+				'require_nonce' => false,
512
+			],
513
+		];
514
+	}
515
+
516
+
517
+	/**
518
+	 * Used to register any global screen options if necessary for every route in this admin page group.
519
+	 */
520
+	protected function _add_screen_options()
521
+	{
522
+	}
523
+
524
+
525
+	/**
526
+	 * Implementing the screen options for the 'default' route.
527
+	 *
528
+	 * @throws InvalidArgumentException
529
+	 * @throws InvalidDataTypeException
530
+	 * @throws InvalidInterfaceException
531
+	 */
532
+	protected function _add_screen_options_default()
533
+	{
534
+		$this->_per_page_screen_option();
535
+	}
536
+
537
+
538
+	/**
539
+	 * Implementing screen options for the category list route.
540
+	 *
541
+	 * @throws InvalidArgumentException
542
+	 * @throws InvalidDataTypeException
543
+	 * @throws InvalidInterfaceException
544
+	 */
545
+	protected function _add_screen_options_category_list()
546
+	{
547
+		$page_title              = $this->_admin_page_title;
548
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
549
+		$this->_per_page_screen_option();
550
+		$this->_admin_page_title = $page_title;
551
+	}
552
+
553
+
554
+	/**
555
+	 * Used to register any global feature pointers for the admin page group.
556
+	 */
557
+	protected function _add_feature_pointers()
558
+	{
559
+	}
560
+
561
+
562
+	/**
563
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
564
+	 */
565
+	public function load_scripts_styles()
566
+	{
567
+		wp_register_style(
568
+			'events-admin-css',
569
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
570
+			[],
571
+			EVENT_ESPRESSO_VERSION
572
+		);
573
+		wp_register_style(
574
+			'ee-cat-admin',
575
+			EVENTS_ASSETS_URL . 'ee-cat-admin.css',
576
+			[],
577
+			EVENT_ESPRESSO_VERSION
578
+		);
579
+		wp_enqueue_style('events-admin-css');
580
+		wp_enqueue_style('ee-cat-admin');
581
+		// scripts
582
+		wp_register_script(
583
+			'event_editor_js',
584
+			EVENTS_ASSETS_URL . 'event_editor.js',
585
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
586
+			EVENT_ESPRESSO_VERSION,
587
+			true
588
+		);
589
+	}
590
+
591
+
592
+	/**
593
+	 * Enqueuing scripts and styles specific to this view
594
+	 */
595
+	public function load_scripts_styles_create_new()
596
+	{
597
+		$this->load_scripts_styles_edit();
598
+	}
599
+
600
+
601
+	/**
602
+	 * Enqueuing scripts and styles specific to this view
603
+	 */
604
+	public function load_scripts_styles_edit()
605
+	{
606
+		// styles
607
+		wp_enqueue_style('espresso-ui-theme');
608
+		wp_register_style(
609
+			'event-editor-css',
610
+			EVENTS_ASSETS_URL . 'event-editor.css',
611
+			['ee-admin-css'],
612
+			EVENT_ESPRESSO_VERSION
613
+		);
614
+		wp_enqueue_style('event-editor-css');
615
+		// scripts
616
+		if (! $this->admin_config->useAdvancedEditor()) {
617
+			wp_register_script(
618
+				'event-datetime-metabox',
619
+				EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
620
+				['event_editor_js', 'ee-datepicker'],
621
+				EVENT_ESPRESSO_VERSION
622
+			);
623
+			wp_enqueue_script('event-datetime-metabox');
624
+		}
625
+	}
626
+
627
+
628
+	/**
629
+	 * Populating the _views property for the category list table view.
630
+	 */
631
+	protected function _set_list_table_views_category_list()
632
+	{
633
+		$this->_views = [
634
+			'all' => [
635
+				'slug'        => 'all',
636
+				'label'       => esc_html__('All', 'event_espresso'),
637
+				'count'       => 0,
638
+				'bulk_action' => [
639
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
640
+				],
641
+			],
642
+		];
643
+	}
644
+
645
+
646
+	/**
647
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
648
+	 */
649
+	public function admin_init()
650
+	{
651
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
652
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
653
+			'event_espresso'
654
+		);
655
+	}
656
+
657
+
658
+	/**
659
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
660
+	 * group.
661
+	 */
662
+	public function admin_notices()
663
+	{
664
+	}
665
+
666
+
667
+	/**
668
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
669
+	 * this admin page group.
670
+	 */
671
+	public function admin_footer_scripts()
672
+	{
673
+	}
674
+
675
+
676
+	/**
677
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
678
+	 * warning (via EE_Error::add_error());
679
+	 *
680
+	 * @param EE_Event $event Event object
681
+	 * @param string   $req_type
682
+	 * @return void
683
+	 * @throws EE_Error
684
+	 * @throws ReflectionException
685
+	 */
686
+	public function verify_event_edit($event = null, $req_type = '')
687
+	{
688
+		// don't need to do this when processing
689
+		if (! empty($req_type)) {
690
+			return;
691
+		}
692
+		// no event?
693
+		if (! $event instanceof EE_Event) {
694
+			$event = $this->_cpt_model_obj;
695
+		}
696
+		// STILL no event?
697
+		if (! $event instanceof EE_Event) {
698
+			return;
699
+		}
700
+		$orig_status = $event->status();
701
+		// first check if event is active.
702
+		if (
703
+			$orig_status === EEM_Event::cancelled
704
+			|| $orig_status === EEM_Event::postponed
705
+			|| $event->is_expired()
706
+			|| $event->is_inactive()
707
+		) {
708
+			return;
709
+		}
710
+		// made it here so it IS active... next check that any of the tickets are sold.
711
+		if ($event->is_sold_out(true)) {
712
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
713
+				EE_Error::add_attention(
714
+					sprintf(
715
+						esc_html__(
716
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
717
+							'event_espresso'
718
+						),
719
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
720
+					)
721
+				);
722
+			}
723
+			return;
724
+		}
725
+		if ($orig_status === EEM_Event::sold_out) {
726
+			EE_Error::add_attention(
727
+				sprintf(
728
+					esc_html__(
729
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
730
+						'event_espresso'
731
+					),
732
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
733
+				)
734
+			);
735
+		}
736
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
737
+		if (! $event->tickets_on_sale()) {
738
+			return;
739
+		}
740
+		// made it here so show warning
741
+		$this->_edit_event_warning();
742
+	}
743
+
744
+
745
+	/**
746
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
747
+	 * When needed, hook this into a EE_Error::add_error() notice.
748
+	 *
749
+	 * @access protected
750
+	 * @return void
751
+	 */
752
+	protected function _edit_event_warning()
753
+	{
754
+		// we don't want to add warnings during these requests
755
+		if ($this->request->getRequestParam('action') === 'editpost') {
756
+			return;
757
+		}
758
+		EE_Error::add_attention(
759
+			sprintf(
760
+				esc_html__(
761
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
762
+					'event_espresso'
763
+				),
764
+				'<a class="espresso-help-tab-lnk ee-help-tab-link">',
765
+				'</a>'
766
+			)
767
+		);
768
+	}
769
+
770
+
771
+	/**
772
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
773
+	 * Otherwise, do the normal logic
774
+	 *
775
+	 * @return void
776
+	 * @throws EE_Error
777
+	 * @throws InvalidArgumentException
778
+	 * @throws InvalidDataTypeException
779
+	 * @throws InvalidInterfaceException
780
+	 */
781
+	protected function _create_new_cpt_item()
782
+	{
783
+		$has_timezone_string = get_option('timezone_string');
784
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
785
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
786
+			EE_Error::add_attention(
787
+				sprintf(
788
+					esc_html__(
789
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
790
+						'event_espresso'
791
+					),
792
+					'<br>',
793
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
794
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
795
+					. '</select>',
796
+					'<button class="button button--secondary timezone-submit">',
797
+					'</button><span class="spinner"></span>'
798
+				),
799
+				__FILE__,
800
+				__FUNCTION__,
801
+				__LINE__
802
+			);
803
+		}
804
+		parent::_create_new_cpt_item();
805
+	}
806
+
807
+
808
+	/**
809
+	 * Sets the _views property for the default route in this admin page group.
810
+	 */
811
+	protected function _set_list_table_views_default()
812
+	{
813
+		$this->_views = [
814
+			'all'   => [
815
+				'slug'        => 'all',
816
+				'label'       => esc_html__('View All Events', 'event_espresso'),
817
+				'count'       => 0,
818
+				'bulk_action' => [
819
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
820
+				],
821
+			],
822
+			'draft' => [
823
+				'slug'        => 'draft',
824
+				'label'       => esc_html__('Draft', 'event_espresso'),
825
+				'count'       => 0,
826
+				'bulk_action' => [
827
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
828
+				],
829
+			],
830
+		];
831
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
832
+			$this->_views['trash'] = [
833
+				'slug'        => 'trash',
834
+				'label'       => esc_html__('Trash', 'event_espresso'),
835
+				'count'       => 0,
836
+				'bulk_action' => [
837
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
838
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
839
+				],
840
+			];
841
+		}
842
+	}
843
+
844
+
845
+	/**
846
+	 * Provides the legend item array for the default list table view.
847
+	 *
848
+	 * @return array
849
+	 * @throws EE_Error
850
+	 * @throws EE_Error
851
+	 */
852
+	protected function _event_legend_items()
853
+	{
854
+		$items    = [
855
+			'view_details'   => [
856
+				'class' => 'dashicons dashicons-visibility',
857
+				'desc'  => esc_html__('View Event', 'event_espresso'),
858
+			],
859
+			'edit_event'     => [
860
+				'class' => 'dashicons dashicons-calendar-alt',
861
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
862
+			],
863
+			'view_attendees' => [
864
+				'class' => 'dashicons dashicons-groups',
865
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
866
+			],
867
+		];
868
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
869
+		$statuses = [
870
+			'sold_out_status'  => [
871
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
872
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
873
+			],
874
+			'active_status'    => [
875
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
876
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
877
+			],
878
+			'upcoming_status'  => [
879
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
880
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
881
+			],
882
+			'postponed_status' => [
883
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
884
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
885
+			],
886
+			'cancelled_status' => [
887
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
888
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
889
+			],
890
+			'expired_status'   => [
891
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
892
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
893
+			],
894
+			'inactive_status'  => [
895
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
896
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
897
+			],
898
+		];
899
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
900
+		return array_merge($items, $statuses);
901
+	}
902
+
903
+
904
+	/**
905
+	 * @return EEM_Event
906
+	 * @throws EE_Error
907
+	 * @throws InvalidArgumentException
908
+	 * @throws InvalidDataTypeException
909
+	 * @throws InvalidInterfaceException
910
+	 * @throws ReflectionException
911
+	 */
912
+	private function _event_model()
913
+	{
914
+		if (! $this->_event_model instanceof EEM_Event) {
915
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
916
+		}
917
+		return $this->_event_model;
918
+	}
919
+
920
+
921
+	/**
922
+	 * Adds extra buttons to the WP CPT permalink field row.
923
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
924
+	 *
925
+	 * @param string $return    the current html
926
+	 * @param int    $id        the post id for the page
927
+	 * @param string $new_title What the title is
928
+	 * @param string $new_slug  what the slug is
929
+	 * @return string            The new html string for the permalink area
930
+	 */
931
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
932
+	{
933
+		// make sure this is only when editing
934
+		if (! empty($id)) {
935
+			$post = get_post($id);
936
+			$return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
937
+					   . esc_html__('Shortcode', 'event_espresso')
938
+					   . '</a> ';
939
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
940
+					   . $post->ID
941
+					   . ']">';
942
+		}
943
+		return $return;
944
+	}
945
+
946
+
947
+	/**
948
+	 * _events_overview_list_table
949
+	 * This contains the logic for showing the events_overview list
950
+	 *
951
+	 * @access protected
952
+	 * @return void
953
+	 * @throws DomainException
954
+	 * @throws EE_Error
955
+	 * @throws InvalidArgumentException
956
+	 * @throws InvalidDataTypeException
957
+	 * @throws InvalidInterfaceException
958
+	 */
959
+	protected function _events_overview_list_table()
960
+	{
961
+		$after_list_table                           = [];
962
+		$links_html = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack');
963
+		$links_html .= EEH_HTML::h3(esc_html__('Links', 'event_espresso'));
964
+		$links_html .= EEH_HTML::div(
965
+			EEH_Template::get_button_or_link(
966
+				get_post_type_archive_link('espresso_events'),
967
+				esc_html__('View Event Archive Page', 'event_espresso'),
968
+				'button button--small button--secondary'
969
+			),
970
+			'',
971
+			'ee-admin-button-row ee-admin-button-row--align-start'
972
+		);
973
+		$links_html .= EEH_HTML::divx();
974
+
975
+		$after_list_table['view_event_list_button'] = $links_html;
976
+
977
+		$after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
978
+		$this->_admin_page_title                    .= ' ' . $this->get_action_link_or_button(
979
+			'create_new',
980
+			'add',
981
+			[],
982
+			'add-new-h2'
983
+		);
984
+
985
+		$this->_template_args['after_list_table']   = array_merge(
986
+			(array) $this->_template_args['after_list_table'],
987
+			$after_list_table
988
+		);
989
+		$this->display_admin_list_table_page_with_no_sidebar();
990
+	}
991
+
992
+
993
+	/**
994
+	 * this allows for extra misc actions in the default WP publish box
995
+	 *
996
+	 * @return void
997
+	 * @throws DomainException
998
+	 * @throws EE_Error
999
+	 * @throws InvalidArgumentException
1000
+	 * @throws InvalidDataTypeException
1001
+	 * @throws InvalidInterfaceException
1002
+	 * @throws ReflectionException
1003
+	 */
1004
+	public function extra_misc_actions_publish_box()
1005
+	{
1006
+		$this->_generate_publish_box_extra_content();
1007
+	}
1008
+
1009
+
1010
+	/**
1011
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1012
+	 * saved.
1013
+	 * Typically you would use this to save any additional data.
1014
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
1015
+	 * ALSO very important.  When a post transitions from scheduled to published,
1016
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1017
+	 * other meta saves. So MAKE sure that you handle this accordingly.
1018
+	 *
1019
+	 * @access protected
1020
+	 * @abstract
1021
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1022
+	 * @param object $post    The post object of the cpt that was saved.
1023
+	 * @return void
1024
+	 * @throws EE_Error
1025
+	 * @throws InvalidArgumentException
1026
+	 * @throws InvalidDataTypeException
1027
+	 * @throws InvalidInterfaceException
1028
+	 * @throws ReflectionException
1029
+	 */
1030
+	protected function _insert_update_cpt_item($post_id, $post)
1031
+	{
1032
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1033
+			// get out we're not processing an event save.
1034
+			return;
1035
+		}
1036
+		$event_values = [
1037
+			'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1038
+			'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1039
+			'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1040
+		];
1041
+		// check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1042
+		if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1043
+			$event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1044
+				'display_ticket_selector',
1045
+				false,
1046
+				'bool'
1047
+			);
1048
+			$event_values['EVT_additional_limit']            = min(
1049
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1050
+				$this->request->getRequestParam('additional_limit', null, 'int')
1051
+			);
1052
+			$event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1053
+				'EVT_default_registration_status',
1054
+				EE_Registry::instance()->CFG->registration->default_STS_ID
1055
+			);
1056
+
1057
+			$event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1058
+			$event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1059
+			$event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool');
1060
+		}
1061
+		// update event
1062
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1063
+		// get event_object for other metaboxes...
1064
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1065
+		// i have to setup where conditions to override the filters in the model
1066
+		// that filter out autodraft and inherit statuses so we GET the inherit id!
1067
+		$event = $this->_event_model()->get_one(
1068
+			[
1069
+				[
1070
+					$this->_event_model()->primary_key_name() => $post_id,
1071
+					'OR'                                      => [
1072
+						'status'   => $post->post_status,
1073
+						// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1074
+						// but the returned object here has a status of "publish", so use the original post status as well
1075
+						'status*1' => $this->request->getRequestParam('original_post_status'),
1076
+					],
1077
+				],
1078
+			]
1079
+		);
1080
+
1081
+		// the following are default callbacks for event attachment updates
1082
+		// that can be overridden by caffeinated functionality and/or addons.
1083
+		$event_update_callbacks = [];
1084
+		if (! $this->admin_config->useAdvancedEditor()) {
1085
+			$event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1086
+			$event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1087
+		}
1088
+		$event_update_callbacks = apply_filters(
1089
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1090
+			$event_update_callbacks
1091
+		);
1092
+
1093
+		$att_success = true;
1094
+		foreach ($event_update_callbacks as $e_callback) {
1095
+			$_success = is_callable($e_callback)
1096
+				? $e_callback($event, $this->request->requestParams())
1097
+				: false;
1098
+			// if ANY of these updates fail then we want the appropriate global error message
1099
+			$att_success = $_success !== false ? $att_success : false;
1100
+		}
1101
+		// any errors?
1102
+		if ($success && $att_success === false) {
1103
+			EE_Error::add_error(
1104
+				esc_html__(
1105
+					'Event Details saved successfully but something went wrong with saving attachments.',
1106
+					'event_espresso'
1107
+				),
1108
+				__FILE__,
1109
+				__FUNCTION__,
1110
+				__LINE__
1111
+			);
1112
+		} elseif ($success === false) {
1113
+			EE_Error::add_error(
1114
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1115
+				__FILE__,
1116
+				__FUNCTION__,
1117
+				__LINE__
1118
+			);
1119
+		}
1120
+	}
1121
+
1122
+
1123
+	/**
1124
+	 * @param int $post_id
1125
+	 * @param int $revision_id
1126
+	 * @throws EE_Error
1127
+	 * @throws EE_Error
1128
+	 * @throws ReflectionException
1129
+	 * @see parent::restore_item()
1130
+	 */
1131
+	protected function _restore_cpt_item($post_id, $revision_id)
1132
+	{
1133
+		// copy existing event meta to new post
1134
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1135
+		if ($post_evt instanceof EE_Event) {
1136
+			// meta revision restore
1137
+			$post_evt->restore_revision($revision_id);
1138
+			// related objs restore
1139
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1140
+		}
1141
+	}
1142
+
1143
+
1144
+	/**
1145
+	 * Attach the venue to the Event
1146
+	 *
1147
+	 * @param EE_Event $event Event Object to add the venue to
1148
+	 * @param array    $data  The request data from the form
1149
+	 * @return bool           Success or fail.
1150
+	 * @throws EE_Error
1151
+	 * @throws ReflectionException
1152
+	 */
1153
+	protected function _default_venue_update(EE_Event $event, $data)
1154
+	{
1155
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1156
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1157
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1158
+		// very important.  If we don't have a venue name...
1159
+		// then we'll get out because not necessary to create empty venue
1160
+		if (empty($data['venue_title'])) {
1161
+			return false;
1162
+		}
1163
+		$venue_array = [
1164
+			'VNU_wp_user'         => $event->get('EVT_wp_user'),
1165
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1166
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1167
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1168
+			'VNU_short_desc'      => ! empty($data['venue_short_description'])
1169
+				? $data['venue_short_description']
1170
+				: null,
1171
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1172
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1173
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1174
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1175
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1176
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1177
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1178
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1179
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1180
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1181
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1182
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1183
+			'status'              => 'publish',
1184
+		];
1185
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1186
+		if (! empty($venue_id)) {
1187
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1188
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1189
+			// we've gotta make sure that the venue is always attached to a revision..
1190
+			// add_relation_to should take care of making sure that the relation is already present.
1191
+			$event->_add_relation_to($venue_id, 'Venue');
1192
+			return $rows_affected > 0;
1193
+		}
1194
+		// we insert the venue
1195
+		$venue_id = $venue_model->insert($venue_array);
1196
+		$event->_add_relation_to($venue_id, 'Venue');
1197
+		return ! empty($venue_id);
1198
+		// when we have the ancestor come in it's already been handled by the revision save.
1199
+	}
1200
+
1201
+
1202
+	/**
1203
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1204
+	 *
1205
+	 * @param EE_Event $event The Event object we're attaching data to
1206
+	 * @param array    $data  The request data from the form
1207
+	 * @return array
1208
+	 * @throws EE_Error
1209
+	 * @throws ReflectionException
1210
+	 * @throws Exception
1211
+	 */
1212
+	protected function _default_tickets_update(EE_Event $event, $data)
1213
+	{
1214
+		if ($this->admin_config->useAdvancedEditor()) {
1215
+			return [];
1216
+		}
1217
+		$datetime       = null;
1218
+		$saved_tickets  = [];
1219
+		$event_timezone = $event->get_timezone();
1220
+		$date_formats   = ['Y-m-d', 'h:i a'];
1221
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1222
+			// trim all values to ensure any excess whitespace is removed.
1223
+			$datetime_data                = array_map('trim', $datetime_data);
1224
+			$datetime_data['DTT_EVT_end'] =
1225
+				isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1226
+					? $datetime_data['DTT_EVT_end']
1227
+					: $datetime_data['DTT_EVT_start'];
1228
+			$datetime_values              = [
1229
+				'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1230
+				'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1231
+				'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1232
+				'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1233
+				'DTT_order'     => $row,
1234
+			];
1235
+			// if we have an id then let's get existing object first and then set the new values.
1236
+			//  Otherwise we instantiate a new object for save.
1237
+			if (! empty($datetime_data['DTT_ID'])) {
1238
+				$datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1239
+				if (! $datetime instanceof EE_Datetime) {
1240
+					throw new RuntimeException(
1241
+						sprintf(
1242
+							esc_html__(
1243
+								'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1244
+								'event_espresso'
1245
+							),
1246
+							$datetime_data['DTT_ID']
1247
+						)
1248
+					);
1249
+				}
1250
+				$datetime->set_date_format($date_formats[0]);
1251
+				$datetime->set_time_format($date_formats[1]);
1252
+				foreach ($datetime_values as $field => $value) {
1253
+					$datetime->set($field, $value);
1254
+				}
1255
+			} else {
1256
+				$datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1257
+			}
1258
+			if (! $datetime instanceof EE_Datetime) {
1259
+				throw new RuntimeException(
1260
+					sprintf(
1261
+						esc_html__(
1262
+							'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1263
+							'event_espresso'
1264
+						),
1265
+						print_r($datetime_values, true)
1266
+					)
1267
+				);
1268
+			}
1269
+			// before going any further make sure our dates are setup correctly
1270
+			// so that the end date is always equal or greater than the start date.
1271
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1272
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1273
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1274
+			}
1275
+			$datetime->save();
1276
+			$event->_add_relation_to($datetime, 'Datetime');
1277
+		}
1278
+		// no datetimes get deleted so we don't do any of that logic here.
1279
+		// update tickets next
1280
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1281
+
1282
+		// set up some default start and end dates in case those are not present in the incoming data
1283
+		$default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1284
+		$default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1285
+		// use the start date of the first datetime for the end date
1286
+		$first_datetime   = $event->first_datetime();
1287
+		$default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1288
+
1289
+		// now process the incoming data
1290
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
1291
+			$update_prices = false;
1292
+			$ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1293
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1294
+				: 0;
1295
+			// trim inputs to ensure any excess whitespace is removed.
1296
+			$ticket_data   = array_map('trim', $ticket_data);
1297
+			$ticket_values = [
1298
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1299
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1300
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1301
+				'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1302
+				'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1303
+					? $ticket_data['TKT_start_date']
1304
+					: $default_start_date,
1305
+				'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1306
+					? $ticket_data['TKT_end_date']
1307
+					: $default_end_date,
1308
+				'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1309
+									 || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1310
+					? $ticket_data['TKT_qty']
1311
+					: EE_INF,
1312
+				'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1313
+									 || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1314
+					? $ticket_data['TKT_uses']
1315
+					: EE_INF,
1316
+				'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1317
+				'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1318
+				'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1319
+				'TKT_price'       => $ticket_price,
1320
+				'TKT_row'         => $row,
1321
+			];
1322
+			// if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1323
+			// which means in turn that the prices will become new prices as well.
1324
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1325
+				$ticket_values['TKT_ID']         = 0;
1326
+				$ticket_values['TKT_is_default'] = 0;
1327
+				$update_prices                   = true;
1328
+			}
1329
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1330
+			// we actually do our saves ahead of adding any relations because its entirely possible that this
1331
+			// ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1332
+			// keep in mind that if the ticket has been sold (and we have changed pricing information),
1333
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1334
+			if (! empty($ticket_data['TKT_ID'])) {
1335
+				$existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1336
+				if (! $existing_ticket instanceof EE_Ticket) {
1337
+					throw new RuntimeException(
1338
+						sprintf(
1339
+							esc_html__(
1340
+								'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1341
+								'event_espresso'
1342
+							),
1343
+							$ticket_data['TKT_ID']
1344
+						)
1345
+					);
1346
+				}
1347
+				$ticket_sold = $existing_ticket->count_related(
1348
+					'Registration',
1349
+					[
1350
+							[
1351
+								'STS_ID' => [
1352
+									'NOT IN',
1353
+									[EEM_Registration::status_id_incomplete],
1354
+								],
1355
+							],
1356
+						]
1357
+				) > 0;
1358
+				// let's just check the total price for the existing ticket and determine if it matches the new total price.
1359
+				// if they are different then we create a new ticket (if $ticket_sold)
1360
+				// if they aren't different then we go ahead and modify existing ticket.
1361
+				$create_new_ticket = $ticket_sold
1362
+									 && $ticket_price !== $existing_ticket->price()
1363
+									 && ! $existing_ticket->deleted();
1364
+				$existing_ticket->set_date_format($date_formats[0]);
1365
+				$existing_ticket->set_time_format($date_formats[1]);
1366
+				// set new values
1367
+				foreach ($ticket_values as $field => $value) {
1368
+					if ($field == 'TKT_qty') {
1369
+						$existing_ticket->set_qty($value);
1370
+					} elseif ($field == 'TKT_price') {
1371
+						$existing_ticket->set('TKT_price', $ticket_price);
1372
+					} else {
1373
+						$existing_ticket->set($field, $value);
1374
+					}
1375
+				}
1376
+				$ticket = $existing_ticket;
1377
+				// if $create_new_ticket is false then we can safely update the existing ticket.
1378
+				//  Otherwise we have to create a new ticket.
1379
+				if ($create_new_ticket) {
1380
+					// archive the old ticket first
1381
+					$existing_ticket->set('TKT_deleted', 1);
1382
+					$existing_ticket->save();
1383
+					// make sure this ticket is still recorded in our $saved_tickets
1384
+					// so we don't run it through the regular trash routine.
1385
+					$saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1386
+					// create new ticket that's a copy of the existing except,
1387
+					// (a new id of course and not archived) AND has the new TKT_price associated with it.
1388
+					$new_ticket = clone $existing_ticket;
1389
+					$new_ticket->set('TKT_ID', 0);
1390
+					$new_ticket->set('TKT_deleted', 0);
1391
+					$new_ticket->set('TKT_sold', 0);
1392
+					// now we need to make sure that $new prices are created as well and attached to new ticket.
1393
+					$update_prices = true;
1394
+					$ticket        = $new_ticket;
1395
+				}
1396
+			} else {
1397
+				// no TKT_id so a new ticket
1398
+				$ticket_values['TKT_price'] = $ticket_price;
1399
+				$ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1400
+				$update_prices              = true;
1401
+			}
1402
+			if (! $ticket instanceof EE_Ticket) {
1403
+				throw new RuntimeException(
1404
+					sprintf(
1405
+						esc_html__(
1406
+							'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1407
+							'event_espresso'
1408
+						),
1409
+						print_r($ticket_values, true)
1410
+					)
1411
+				);
1412
+			}
1413
+			// cap ticket qty by datetime reg limits
1414
+			$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1415
+			// update ticket.
1416
+			$ticket->save();
1417
+			// before going any further make sure our dates are setup correctly
1418
+			// so that the end date is always equal or greater than the start date.
1419
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1420
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1421
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1422
+				$ticket->save();
1423
+			}
1424
+			// initially let's add the ticket to the datetime
1425
+			$datetime->_add_relation_to($ticket, 'Ticket');
1426
+			$saved_tickets[ $ticket->ID() ] = $ticket;
1427
+			// add prices to ticket
1428
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices);
1429
+		}
1430
+		// however now we need to handle permanently deleting tickets via the ui.
1431
+		//  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1432
+		//  However, it does allow for deleting tickets that have no tickets sold,
1433
+		// in which case we want to get rid of permanently because there is no need to save in db.
1434
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1435
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1436
+		foreach ($tickets_removed as $id) {
1437
+			$id = absint($id);
1438
+			// get the ticket for this id
1439
+			$ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1440
+			if (! $ticket_to_remove instanceof EE_Ticket) {
1441
+				continue;
1442
+			}
1443
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1444
+			// (remember this process can ONLY kick off if there are NO tickets sold)
1445
+			$related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1446
+			foreach ($related_datetimes as $related_datetime) {
1447
+				$ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1448
+			}
1449
+			// need to do the same for prices (except these prices can also be deleted because again,
1450
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1451
+			$ticket_to_remove->delete_related_permanently('Price');
1452
+			// finally let's delete this ticket
1453
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1454
+			$ticket_to_remove->delete_permanently();
1455
+		}
1456
+		return [$datetime, $saved_tickets];
1457
+	}
1458
+
1459
+
1460
+	/**
1461
+	 * This attaches a list of given prices to a ticket.
1462
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices)
1463
+	 * because if there is a change in price information on a ticket, a new ticket is created anyways
1464
+	 * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1465
+	 *
1466
+	 * @access  private
1467
+	 * @param array     $prices_data Array of prices from the form.
1468
+	 * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1469
+	 * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1470
+	 * @return  void
1471
+	 * @throws EE_Error
1472
+	 * @throws ReflectionException
1473
+	 */
1474
+	private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1475
+	{
1476
+		$timezone = $ticket->get_timezone();
1477
+		foreach ($prices_data as $row => $price_data) {
1478
+			$price_values = [
1479
+				'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1480
+				'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1481
+				'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1482
+				'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1483
+				'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1484
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1485
+				'PRC_order'      => $row,
1486
+			];
1487
+			if ($new_prices || empty($price_values['PRC_ID'])) {
1488
+				$price_values['PRC_ID'] = 0;
1489
+				$price                  = EE_Price::new_instance($price_values, $timezone);
1490
+			} else {
1491
+				$price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1492
+				// update this price with new values
1493
+				foreach ($price_values as $field => $new_price) {
1494
+					$price->set($field, $new_price);
1495
+				}
1496
+			}
1497
+			if (! $price instanceof EE_Price) {
1498
+				throw new RuntimeException(
1499
+					sprintf(
1500
+						esc_html__(
1501
+							'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1502
+							'event_espresso'
1503
+						),
1504
+						print_r($price_values, true)
1505
+					)
1506
+				);
1507
+			}
1508
+			$price->save();
1509
+			$ticket->_add_relation_to($price, 'Price');
1510
+		}
1511
+	}
1512
+
1513
+
1514
+	/**
1515
+	 * Add in our autosave ajax handlers
1516
+	 *
1517
+	 */
1518
+	protected function _ee_autosave_create_new()
1519
+	{
1520
+	}
1521
+
1522
+
1523
+	/**
1524
+	 * More autosave handlers.
1525
+	 */
1526
+	protected function _ee_autosave_edit()
1527
+	{
1528
+	}
1529
+
1530
+
1531
+	/**
1532
+	 * @throws EE_Error
1533
+	 * @throws ReflectionException
1534
+	 */
1535
+	private function _generate_publish_box_extra_content()
1536
+	{
1537
+		// load formatter helper
1538
+		// args for getting related registrations
1539
+		$approved_query_args        = [
1540
+			[
1541
+				'REG_deleted' => 0,
1542
+				'STS_ID'      => EEM_Registration::status_id_approved,
1543
+			],
1544
+		];
1545
+		$not_approved_query_args    = [
1546
+			[
1547
+				'REG_deleted' => 0,
1548
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1549
+			],
1550
+		];
1551
+		$pending_payment_query_args = [
1552
+			[
1553
+				'REG_deleted' => 0,
1554
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1555
+			],
1556
+		];
1557
+		// publish box
1558
+		$publish_box_extra_args = [
1559
+			'view_approved_reg_url'        => add_query_arg(
1560
+				[
1561
+					'action'      => 'default',
1562
+					'event_id'    => $this->_cpt_model_obj->ID(),
1563
+					'_reg_status' => EEM_Registration::status_id_approved,
1564
+				],
1565
+				REG_ADMIN_URL
1566
+			),
1567
+			'view_not_approved_reg_url'    => add_query_arg(
1568
+				[
1569
+					'action'      => 'default',
1570
+					'event_id'    => $this->_cpt_model_obj->ID(),
1571
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1572
+				],
1573
+				REG_ADMIN_URL
1574
+			),
1575
+			'view_pending_payment_reg_url' => add_query_arg(
1576
+				[
1577
+					'action'      => 'default',
1578
+					'event_id'    => $this->_cpt_model_obj->ID(),
1579
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1580
+				],
1581
+				REG_ADMIN_URL
1582
+			),
1583
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1584
+				'Registration',
1585
+				$approved_query_args
1586
+			),
1587
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1588
+				'Registration',
1589
+				$not_approved_query_args
1590
+			),
1591
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1592
+				'Registration',
1593
+				$pending_payment_query_args
1594
+			),
1595
+			'misc_pub_section_class'       => apply_filters(
1596
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1597
+				'misc-pub-section'
1598
+			),
1599
+		];
1600
+		ob_start();
1601
+		do_action(
1602
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1603
+			$this->_cpt_model_obj
1604
+		);
1605
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1606
+		// load template
1607
+		EEH_Template::display_template(
1608
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1609
+			$publish_box_extra_args
1610
+		);
1611
+	}
1612
+
1613
+
1614
+	/**
1615
+	 * @return EE_Event
1616
+	 */
1617
+	public function get_event_object()
1618
+	{
1619
+		return $this->_cpt_model_obj;
1620
+	}
1621
+
1622
+
1623
+
1624
+
1625
+	/** METABOXES * */
1626
+	/**
1627
+	 * _register_event_editor_meta_boxes
1628
+	 * add all metaboxes related to the event_editor
1629
+	 *
1630
+	 * @return void
1631
+	 * @throws EE_Error
1632
+	 * @throws ReflectionException
1633
+	 */
1634
+	protected function _register_event_editor_meta_boxes()
1635
+	{
1636
+		$this->verify_cpt_object();
1637
+		$use_advanced_editor = $this->admin_config->useAdvancedEditor();
1638
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1639
+		if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1640
+			$this->addMetaBox(
1641
+				'espresso_event_editor_event_options',
1642
+				esc_html__('Event Registration Options', 'event_espresso'),
1643
+				[$this, 'registration_options_meta_box'],
1644
+				$this->page_slug,
1645
+				'side'
1646
+			);
1647
+		}
1648
+		if (! $use_advanced_editor) {
1649
+			$this->addMetaBox(
1650
+				'espresso_event_editor_tickets',
1651
+				esc_html__('Event Datetime & Ticket', 'event_espresso'),
1652
+				[$this, 'ticket_metabox'],
1653
+				$this->page_slug,
1654
+				'normal',
1655
+				'high'
1656
+			);
1657
+		} elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1658
+			add_action(
1659
+				'add_meta_boxes_espresso_events',
1660
+				function () {
1661
+					global $current_screen;
1662
+					remove_meta_box('authordiv', $current_screen, 'normal');
1663
+				},
1664
+				99
1665
+			);
1666
+		}
1667
+		// NOTE: if you're looking for other metaboxes in here,
1668
+		// where a metabox has a related management page in the admin
1669
+		// you will find it setup in the related management page's "_Hooks" file.
1670
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1671
+	}
1672
+
1673
+
1674
+	/**
1675
+	 * @throws DomainException
1676
+	 * @throws EE_Error
1677
+	 * @throws ReflectionException
1678
+	 */
1679
+	public function ticket_metabox()
1680
+	{
1681
+		$existing_datetime_ids = $existing_ticket_ids = [];
1682
+		// defaults for template args
1683
+		$template_args = [
1684
+			'existing_datetime_ids'    => '',
1685
+			'event_datetime_help_link' => '',
1686
+			'ticket_options_help_link' => '',
1687
+			'time'                     => null,
1688
+			'ticket_rows'              => '',
1689
+			'existing_ticket_ids'      => '',
1690
+			'total_ticket_rows'        => 1,
1691
+			'ticket_js_structure'      => '',
1692
+			'trash_icon'               => 'dashicons dashicons-lock',
1693
+			'disabled'                 => '',
1694
+		];
1695
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1696
+		/**
1697
+		 * 1. Start with retrieving Datetimes
1698
+		 * 2. Fore each datetime get related tickets
1699
+		 * 3. For each ticket get related prices
1700
+		 */
1701
+		/** @var EEM_Datetime $datetime_model */
1702
+		$datetime_model = EE_Registry::instance()->load_model('Datetime');
1703
+		/** @var EEM_Ticket $datetime_model */
1704
+		$ticket_model = EE_Registry::instance()->load_model('Ticket');
1705
+		$times        = $datetime_model->get_all_event_dates($event_id);
1706
+		/** @type EE_Datetime $first_datetime */
1707
+		$first_datetime = reset($times);
1708
+		// do we get related tickets?
1709
+		if (
1710
+			$first_datetime instanceof EE_Datetime
1711
+			&& $first_datetime->ID() !== 0
1712
+		) {
1713
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1714
+			$template_args['time']   = $first_datetime;
1715
+			$related_tickets         = $first_datetime->tickets(
1716
+				[
1717
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1718
+					'default_where_conditions' => 'none',
1719
+				]
1720
+			);
1721
+			if (! empty($related_tickets)) {
1722
+				$template_args['total_ticket_rows'] = count($related_tickets);
1723
+				$row                                = 0;
1724
+				foreach ($related_tickets as $ticket) {
1725
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1726
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1727
+					$row++;
1728
+				}
1729
+			} else {
1730
+				$template_args['total_ticket_rows'] = 1;
1731
+				/** @type EE_Ticket $ticket */
1732
+				$ticket                       = $ticket_model->create_default_object();
1733
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1734
+			}
1735
+		} else {
1736
+			$template_args['time'] = $times[0];
1737
+			/** @type EE_Ticket[] $tickets */
1738
+			$tickets                      = $ticket_model->get_all_default_tickets();
1739
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1740
+			// NOTE: we're just sending the first default row
1741
+			// (decaf can't manage default tickets so this should be sufficient);
1742
+		}
1743
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1744
+			'event_editor_event_datetimes_help_tab'
1745
+		);
1746
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1747
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1748
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1749
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1750
+			$ticket_model->create_default_object(),
1751
+			true
1752
+		);
1753
+		$template                                  = apply_filters(
1754
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1755
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1756
+		);
1757
+		EEH_Template::display_template($template, $template_args);
1758
+	}
1759
+
1760
+
1761
+	/**
1762
+	 * Setup an individual ticket form for the decaf event editor page
1763
+	 *
1764
+	 * @access private
1765
+	 * @param EE_Ticket $ticket   the ticket object
1766
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1767
+	 * @param int       $row
1768
+	 * @return string generated html for the ticket row.
1769
+	 * @throws EE_Error
1770
+	 * @throws ReflectionException
1771
+	 */
1772
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1773
+	{
1774
+		$template_args = [
1775
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1776
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1777
+				: '',
1778
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1779
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1780
+			'TKT_name'            => $ticket->get('TKT_name'),
1781
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1782
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1783
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1784
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1785
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1786
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1787
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1788
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1789
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock',
1790
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1791
+				: ' disabled=disabled',
1792
+		];
1793
+		$price         = $ticket->ID() !== 0
1794
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1795
+			: null;
1796
+		$price         = $price instanceof EE_Price
1797
+			? $price
1798
+			: EEM_Price::instance()->create_default_object();
1799
+		$price_args    = [
1800
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1801
+			'PRC_amount'            => $price->get('PRC_amount'),
1802
+			'PRT_ID'                => $price->get('PRT_ID'),
1803
+			'PRC_ID'                => $price->get('PRC_ID'),
1804
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1805
+		];
1806
+		// make sure we have default start and end dates if skeleton
1807
+		// handle rows that should NOT be empty
1808
+		if (empty($template_args['TKT_start_date'])) {
1809
+			// if empty then the start date will be now.
1810
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1811
+		}
1812
+		if (empty($template_args['TKT_end_date'])) {
1813
+			// get the earliest datetime (if present);
1814
+			$earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1815
+				? $this->_cpt_model_obj->get_first_related(
1816
+					'Datetime',
1817
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1818
+				)
1819
+				: null;
1820
+			$template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1821
+				? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1822
+				: date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1823
+		}
1824
+		$template_args = array_merge($template_args, $price_args);
1825
+		$template      = apply_filters(
1826
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1827
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1828
+			$ticket
1829
+		);
1830
+		return EEH_Template::display_template($template, $template_args, true);
1831
+	}
1832
+
1833
+
1834
+	/**
1835
+	 * @throws EE_Error
1836
+	 * @throws ReflectionException
1837
+	 */
1838
+	public function registration_options_meta_box()
1839
+	{
1840
+		$yes_no_values             = [
1841
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1842
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1843
+		];
1844
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1845
+			[
1846
+				EEM_Registration::status_id_cancelled,
1847
+				EEM_Registration::status_id_declined,
1848
+				EEM_Registration::status_id_incomplete,
1849
+			],
1850
+			true
1851
+		);
1852
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1853
+		$template_args['_event']                          = $this->_cpt_model_obj;
1854
+		$template_args['event']                           = $this->_cpt_model_obj;
1855
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1856
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1857
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1858
+			'default_reg_status',
1859
+			$default_reg_status_values,
1860
+			$this->_cpt_model_obj->default_registration_status()
1861
+		);
1862
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1863
+			'display_desc',
1864
+			$yes_no_values,
1865
+			$this->_cpt_model_obj->display_description()
1866
+		);
1867
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1868
+			'display_ticket_selector',
1869
+			$yes_no_values,
1870
+			$this->_cpt_model_obj->display_ticket_selector(),
1871
+			'',
1872
+			'',
1873
+			false
1874
+		);
1875
+		$template_args['additional_registration_options'] = apply_filters(
1876
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1877
+			'',
1878
+			$template_args,
1879
+			$yes_no_values,
1880
+			$default_reg_status_values
1881
+		);
1882
+		EEH_Template::display_template(
1883
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1884
+			$template_args
1885
+		);
1886
+	}
1887
+
1888
+
1889
+	/**
1890
+	 * _get_events()
1891
+	 * This method simply returns all the events (for the given _view and paging)
1892
+	 *
1893
+	 * @access public
1894
+	 * @param int  $per_page     count of items per page (20 default);
1895
+	 * @param int  $current_page what is the current page being viewed.
1896
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1897
+	 *                           If FALSE then we return an array of event objects
1898
+	 *                           that match the given _view and paging parameters.
1899
+	 * @return array|int         an array of event objects or a count of them.
1900
+	 * @throws Exception
1901
+	 */
1902
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1903
+	{
1904
+		$EEM_Event   = $this->_event_model();
1905
+		$offset      = ($current_page - 1) * $per_page;
1906
+		$limit       = $count ? null : $offset . ',' . $per_page;
1907
+		$orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1908
+		$order       = $this->request->getRequestParam('order', 'DESC');
1909
+		$month_range = $this->request->getRequestParam('month_range');
1910
+		if ($month_range) {
1911
+			$pieces = explode(' ', $month_range, 3);
1912
+			// simulate the FIRST day of the month, that fixes issues for months like February
1913
+			// where PHP doesn't know what to assume for date.
1914
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1915
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1916
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1917
+		}
1918
+		$where  = [];
1919
+		$status = $this->request->getRequestParam('status');
1920
+		// determine what post_status our condition will have for the query.
1921
+		switch ($status) {
1922
+			case 'month':
1923
+			case 'today':
1924
+			case null:
1925
+			case 'all':
1926
+				break;
1927
+			case 'draft':
1928
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1929
+				break;
1930
+			default:
1931
+				$where['status'] = $status;
1932
+		}
1933
+		// categories? The default for all categories is -1
1934
+		$category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1935
+		if ($category !== -1) {
1936
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1937
+			$where['Term_Taxonomy.term_id']  = $category;
1938
+		}
1939
+		// date where conditions
1940
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1941
+		if ($month_range) {
1942
+			$DateTime = new DateTime(
1943
+				$year_r . '-' . $month_r . '-01 00:00:00',
1944
+				new DateTimeZone('UTC')
1945
+			);
1946
+			$start    = $DateTime->getTimestamp();
1947
+			// set the datetime to be the end of the month
1948
+			$DateTime->setDate(
1949
+				$year_r,
1950
+				$month_r,
1951
+				$DateTime->format('t')
1952
+			)->setTime(23, 59, 59);
1953
+			$end                             = $DateTime->getTimestamp();
1954
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1955
+		} elseif ($status === 'today') {
1956
+			$DateTime                        =
1957
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1958
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1959
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1960
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1961
+		} elseif ($status === 'month') {
1962
+			$now                             = date('Y-m-01');
1963
+			$DateTime                        =
1964
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1965
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1966
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1967
+														->setTime(23, 59, 59)
1968
+														->format(implode(' ', $start_formats));
1969
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1970
+		}
1971
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1972
+			$where['EVT_wp_user'] = get_current_user_id();
1973
+		} else {
1974
+			if (! isset($where['status'])) {
1975
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1976
+					$where['OR'] = [
1977
+						'status*restrict_private' => ['!=', 'private'],
1978
+						'AND'                     => [
1979
+							'status*inclusive' => ['=', 'private'],
1980
+							'EVT_wp_user'      => get_current_user_id(),
1981
+						],
1982
+					];
1983
+				}
1984
+			}
1985
+		}
1986
+		$wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1987
+		if (
1988
+			$wp_user
1989
+			&& $wp_user !== get_current_user_id()
1990
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1991
+		) {
1992
+			$where['EVT_wp_user'] = $wp_user;
1993
+		}
1994
+		// search query handling
1995
+		$search_term = $this->request->getRequestParam('s');
1996
+		if ($search_term) {
1997
+			$search_term = '%' . $search_term . '%';
1998
+			$where['OR'] = [
1999
+				'EVT_name'       => ['LIKE', $search_term],
2000
+				'EVT_desc'       => ['LIKE', $search_term],
2001
+				'EVT_short_desc' => ['LIKE', $search_term],
2002
+			];
2003
+		}
2004
+		// filter events by venue.
2005
+		$venue = $this->request->getRequestParam('venue', 0, 'int');
2006
+		if ($venue) {
2007
+			$where['Venue.VNU_ID'] = $venue;
2008
+		}
2009
+		$request_params = $this->request->requestParams();
2010
+		$where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2011
+		$query_params   = apply_filters(
2012
+			'FHEE__Events_Admin_Page__get_events__query_params',
2013
+			[
2014
+				$where,
2015
+				'limit'    => $limit,
2016
+				'order_by' => $orderby,
2017
+				'order'    => $order,
2018
+				'group_by' => 'EVT_ID',
2019
+			],
2020
+			$request_params
2021
+		);
2022
+
2023
+		// let's first check if we have special requests coming in.
2024
+		$active_status = $this->request->getRequestParam('active_status');
2025
+		if ($active_status) {
2026
+			switch ($active_status) {
2027
+				case 'upcoming':
2028
+					return $EEM_Event->get_upcoming_events($query_params, $count);
2029
+				case 'expired':
2030
+					return $EEM_Event->get_expired_events($query_params, $count);
2031
+				case 'active':
2032
+					return $EEM_Event->get_active_events($query_params, $count);
2033
+				case 'inactive':
2034
+					return $EEM_Event->get_inactive_events($query_params, $count);
2035
+			}
2036
+		}
2037
+
2038
+		return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2039
+	}
2040
+
2041
+
2042
+	/**
2043
+	 * handling for WordPress CPT actions (trash, restore, delete)
2044
+	 *
2045
+	 * @param string $post_id
2046
+	 * @throws EE_Error
2047
+	 * @throws ReflectionException
2048
+	 */
2049
+	public function trash_cpt_item($post_id)
2050
+	{
2051
+		$this->request->setRequestParam('EVT_ID', $post_id);
2052
+		$this->_trash_or_restore_event('trash', false);
2053
+	}
2054
+
2055
+
2056
+	/**
2057
+	 * @param string $post_id
2058
+	 * @throws EE_Error
2059
+	 * @throws ReflectionException
2060
+	 */
2061
+	public function restore_cpt_item($post_id)
2062
+	{
2063
+		$this->request->setRequestParam('EVT_ID', $post_id);
2064
+		$this->_trash_or_restore_event('draft', false);
2065
+	}
2066
+
2067
+
2068
+	/**
2069
+	 * @param string $post_id
2070
+	 * @throws EE_Error
2071
+	 * @throws EE_Error
2072
+	 */
2073
+	public function delete_cpt_item($post_id)
2074
+	{
2075
+		throw new EE_Error(
2076
+			esc_html__(
2077
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2078
+				'event_espresso'
2079
+			)
2080
+		);
2081
+		// $this->request->setRequestParam('EVT_ID', $post_id);
2082
+		// $this->_delete_event();
2083
+	}
2084
+
2085
+
2086
+	/**
2087
+	 * _trash_or_restore_event
2088
+	 *
2089
+	 * @access protected
2090
+	 * @param string $event_status
2091
+	 * @param bool   $redirect_after
2092
+	 * @throws EE_Error
2093
+	 * @throws EE_Error
2094
+	 * @throws ReflectionException
2095
+	 */
2096
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2097
+	{
2098
+		// determine the event id and set to array.
2099
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2100
+		// loop thru events
2101
+		if ($EVT_ID) {
2102
+			// clean status
2103
+			$event_status = sanitize_key($event_status);
2104
+			// grab status
2105
+			if (! empty($event_status)) {
2106
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2107
+			} else {
2108
+				$success = false;
2109
+				$msg     = esc_html__(
2110
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2111
+					'event_espresso'
2112
+				);
2113
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2114
+			}
2115
+		} else {
2116
+			$success = false;
2117
+			$msg     = esc_html__(
2118
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2119
+				'event_espresso'
2120
+			);
2121
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2122
+		}
2123
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2124
+		if ($redirect_after) {
2125
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2126
+		}
2127
+	}
2128
+
2129
+
2130
+	/**
2131
+	 * _trash_or_restore_events
2132
+	 *
2133
+	 * @access protected
2134
+	 * @param string $event_status
2135
+	 * @return void
2136
+	 * @throws EE_Error
2137
+	 * @throws EE_Error
2138
+	 * @throws ReflectionException
2139
+	 */
2140
+	protected function _trash_or_restore_events($event_status = 'trash')
2141
+	{
2142
+		// clean status
2143
+		$event_status = sanitize_key($event_status);
2144
+		// grab status
2145
+		if (! empty($event_status)) {
2146
+			$success = true;
2147
+			// determine the event id and set to array.
2148
+			$EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2149
+			// loop thru events
2150
+			foreach ($EVT_IDs as $EVT_ID) {
2151
+				if ($EVT_ID = absint($EVT_ID)) {
2152
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2153
+					$success = $results !== false ? $success : false;
2154
+				} else {
2155
+					$msg = sprintf(
2156
+						esc_html__(
2157
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2158
+							'event_espresso'
2159
+						),
2160
+						$EVT_ID
2161
+					);
2162
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2163
+					$success = false;
2164
+				}
2165
+			}
2166
+		} else {
2167
+			$success = false;
2168
+			$msg     = esc_html__(
2169
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2170
+				'event_espresso'
2171
+			);
2172
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2173
+		}
2174
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2175
+		$success = $success ? 2 : false;
2176
+		$action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2177
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2178
+	}
2179
+
2180
+
2181
+	/**
2182
+	 * @param int    $EVT_ID
2183
+	 * @param string $event_status
2184
+	 * @return bool
2185
+	 * @throws EE_Error
2186
+	 * @throws ReflectionException
2187
+	 */
2188
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2189
+	{
2190
+		// grab event id
2191
+		if (! $EVT_ID) {
2192
+			$msg = esc_html__(
2193
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2194
+				'event_espresso'
2195
+			);
2196
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2197
+			return false;
2198
+		}
2199
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2200
+		// clean status
2201
+		$event_status = sanitize_key($event_status);
2202
+		// grab status
2203
+		if (empty($event_status)) {
2204
+			$msg = esc_html__(
2205
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2206
+				'event_espresso'
2207
+			);
2208
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2209
+			return false;
2210
+		}
2211
+		// was event trashed or restored ?
2212
+		switch ($event_status) {
2213
+			case 'draft':
2214
+				$action = 'restored from the trash';
2215
+				$hook   = 'AHEE_event_restored_from_trash';
2216
+				break;
2217
+			case 'trash':
2218
+				$action = 'moved to the trash';
2219
+				$hook   = 'AHEE_event_moved_to_trash';
2220
+				break;
2221
+			default:
2222
+				$action = 'updated';
2223
+				$hook   = false;
2224
+		}
2225
+		// use class to change status
2226
+		$this->_cpt_model_obj->set_status($event_status);
2227
+		$success = $this->_cpt_model_obj->save();
2228
+		if (! $success) {
2229
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2230
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2231
+			return false;
2232
+		}
2233
+		if ($hook) {
2234
+			do_action($hook);
2235
+		}
2236
+		return true;
2237
+	}
2238
+
2239
+
2240
+	/**
2241
+	 * @param array $event_ids
2242
+	 * @return array
2243
+	 * @since   4.10.23.p
2244
+	 */
2245
+	private function cleanEventIds(array $event_ids)
2246
+	{
2247
+		return array_map('absint', $event_ids);
2248
+	}
2249
+
2250
+
2251
+	/**
2252
+	 * @return array
2253
+	 * @since   4.10.23.p
2254
+	 */
2255
+	private function getEventIdsFromRequest()
2256
+	{
2257
+		if ($this->request->requestParamIsSet('EVT_IDs')) {
2258
+			return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2259
+		} else {
2260
+			return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2261
+		}
2262
+	}
2263
+
2264
+
2265
+	/**
2266
+	 * @param bool $preview_delete
2267
+	 * @throws EE_Error
2268
+	 */
2269
+	protected function _delete_event($preview_delete = true)
2270
+	{
2271
+		$this->_delete_events($preview_delete);
2272
+	}
2273
+
2274
+
2275
+	/**
2276
+	 * Gets the tree traversal batch persister.
2277
+	 *
2278
+	 * @return NodeGroupDao
2279
+	 * @throws InvalidArgumentException
2280
+	 * @throws InvalidDataTypeException
2281
+	 * @throws InvalidInterfaceException
2282
+	 * @since 4.10.12.p
2283
+	 */
2284
+	protected function getModelObjNodeGroupPersister()
2285
+	{
2286
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2287
+			$this->model_obj_node_group_persister =
2288
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2289
+		}
2290
+		return $this->model_obj_node_group_persister;
2291
+	}
2292
+
2293
+
2294
+	/**
2295
+	 * @param bool $preview_delete
2296
+	 * @return void
2297
+	 * @throws EE_Error
2298
+	 */
2299
+	protected function _delete_events($preview_delete = true)
2300
+	{
2301
+		$event_ids = $this->getEventIdsFromRequest();
2302
+		if ($preview_delete) {
2303
+			$this->generateDeletionPreview($event_ids);
2304
+		} else {
2305
+			EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2306
+		}
2307
+	}
2308
+
2309
+
2310
+	/**
2311
+	 * @param array $event_ids
2312
+	 */
2313
+	protected function generateDeletionPreview(array $event_ids)
2314
+	{
2315
+		$event_ids = $this->cleanEventIds($event_ids);
2316
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2317
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2318
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2319
+			[
2320
+				'action'            => 'preview_deletion',
2321
+				'deletion_job_code' => $deletion_job_code,
2322
+			],
2323
+			$this->_admin_base_url
2324
+		);
2325
+		EEH_URL::safeRedirectAndExit(
2326
+			EE_Admin_Page::add_query_args_and_nonce(
2327
+				[
2328
+					'page'              => 'espresso_batch',
2329
+					'batch'             => EED_Batch::batch_job,
2330
+					'EVT_IDs'           => $event_ids,
2331
+					'deletion_job_code' => $deletion_job_code,
2332
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2333
+					'return_url'        => urlencode($return_url),
2334
+				],
2335
+				admin_url()
2336
+			)
2337
+		);
2338
+	}
2339
+
2340
+
2341
+	/**
2342
+	 * Checks for a POST submission
2343
+	 *
2344
+	 * @since 4.10.12.p
2345
+	 */
2346
+	protected function confirmDeletion()
2347
+	{
2348
+		$deletion_redirect_logic =
2349
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2350
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2351
+	}
2352
+
2353
+
2354
+	/**
2355
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2356
+	 *
2357
+	 * @throws EE_Error
2358
+	 * @since 4.10.12.p
2359
+	 */
2360
+	protected function previewDeletion()
2361
+	{
2362
+		$preview_deletion_logic =
2363
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2364
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2365
+		$this->display_admin_page_with_no_sidebar();
2366
+	}
2367
+
2368
+
2369
+	/**
2370
+	 * get total number of events
2371
+	 *
2372
+	 * @access public
2373
+	 * @return int
2374
+	 * @throws EE_Error
2375
+	 * @throws EE_Error
2376
+	 */
2377
+	public function total_events()
2378
+	{
2379
+		return EEM_Event::instance()->count(
2380
+			['caps' => 'read_admin'],
2381
+			'EVT_ID',
2382
+			true
2383
+		);
2384
+	}
2385
+
2386
+
2387
+	/**
2388
+	 * get total number of draft events
2389
+	 *
2390
+	 * @access public
2391
+	 * @return int
2392
+	 * @throws EE_Error
2393
+	 * @throws EE_Error
2394
+	 */
2395
+	public function total_events_draft()
2396
+	{
2397
+		return EEM_Event::instance()->count(
2398
+			[
2399
+				['status' => ['IN', ['draft', 'auto-draft']]],
2400
+				'caps' => 'read_admin',
2401
+			],
2402
+			'EVT_ID',
2403
+			true
2404
+		);
2405
+	}
2406
+
2407
+
2408
+	/**
2409
+	 * get total number of trashed events
2410
+	 *
2411
+	 * @access public
2412
+	 * @return int
2413
+	 * @throws EE_Error
2414
+	 * @throws EE_Error
2415
+	 */
2416
+	public function total_trashed_events()
2417
+	{
2418
+		return EEM_Event::instance()->count(
2419
+			[
2420
+				['status' => 'trash'],
2421
+				'caps' => 'read_admin',
2422
+			],
2423
+			'EVT_ID',
2424
+			true
2425
+		);
2426
+	}
2427
+
2428
+
2429
+	/**
2430
+	 *    _default_event_settings
2431
+	 *    This generates the Default Settings Tab
2432
+	 *
2433
+	 * @return void
2434
+	 * @throws DomainException
2435
+	 * @throws EE_Error
2436
+	 * @throws InvalidArgumentException
2437
+	 * @throws InvalidDataTypeException
2438
+	 * @throws InvalidInterfaceException
2439
+	 */
2440
+	protected function _default_event_settings()
2441
+	{
2442
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2443
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2444
+		$this->_template_args['admin_page_content'] = EEH_HTML::div(
2445
+			$this->_default_event_settings_form()->get_html(),
2446
+			'',
2447
+			'padding'
2448
+		);
2449
+		$this->display_admin_page_with_sidebar();
2450
+	}
2451
+
2452
+
2453
+	/**
2454
+	 * Return the form for event settings.
2455
+	 *
2456
+	 * @return EE_Form_Section_Proper
2457
+	 * @throws EE_Error
2458
+	 */
2459
+	protected function _default_event_settings_form()
2460
+	{
2461
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2462
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2463
+		// exclude
2464
+			[
2465
+				EEM_Registration::status_id_cancelled,
2466
+				EEM_Registration::status_id_declined,
2467
+				EEM_Registration::status_id_incomplete,
2468
+				EEM_Registration::status_id_wait_list,
2469
+			],
2470
+			true
2471
+		);
2472
+		return new EE_Form_Section_Proper(
2473
+			[
2474
+				'name'            => 'update_default_event_settings',
2475
+				'html_id'         => 'update_default_event_settings',
2476
+				'html_class'      => 'form-table',
2477
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2478
+				'subsections'     => apply_filters(
2479
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2480
+					[
2481
+						'defaults_section_header' => new EE_Form_Section_HTML(
2482
+							EEH_HTML::h2(
2483
+								esc_html__('Default Settings', 'event_espresso'),
2484
+								'',
2485
+								'ee-admin-settings-hdr'
2486
+							)
2487
+						),
2488
+						'default_reg_status'  => new EE_Select_Input(
2489
+							$registration_stati_for_selection,
2490
+							[
2491
+								'default'         => isset($registration_config->default_STS_ID)
2492
+													 && array_key_exists(
2493
+														 $registration_config->default_STS_ID,
2494
+														 $registration_stati_for_selection
2495
+													 )
2496
+									? sanitize_text_field($registration_config->default_STS_ID)
2497
+									: EEM_Registration::status_id_pending_payment,
2498
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2499
+													 . EEH_Template::get_help_tab_link(
2500
+														 'default_settings_status_help_tab'
2501
+													 ),
2502
+								'html_help_text'  => esc_html__(
2503
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2504
+									'event_espresso'
2505
+								),
2506
+							]
2507
+						),
2508
+						'default_max_tickets' => new EE_Integer_Input(
2509
+							[
2510
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2511
+									? $registration_config->default_maximum_number_of_tickets
2512
+									: EEM_Event::get_default_additional_limit(),
2513
+								'html_label_text' => esc_html__(
2514
+									'Default Maximum Tickets Allowed Per Order:',
2515
+									'event_espresso'
2516
+								)
2517
+													 . EEH_Template::get_help_tab_link(
2518
+														 'default_maximum_tickets_help_tab"'
2519
+													 ),
2520
+								'html_help_text'  => esc_html__(
2521
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2522
+									'event_espresso'
2523
+								),
2524
+							]
2525
+						),
2526
+					]
2527
+				),
2528
+			]
2529
+		);
2530
+	}
2531
+
2532
+
2533
+	/**
2534
+	 * @return void
2535
+	 * @throws EE_Error
2536
+	 * @throws InvalidArgumentException
2537
+	 * @throws InvalidDataTypeException
2538
+	 * @throws InvalidInterfaceException
2539
+	 */
2540
+	protected function _update_default_event_settings()
2541
+	{
2542
+		$form = $this->_default_event_settings_form();
2543
+		if ($form->was_submitted()) {
2544
+			$form->receive_form_submission();
2545
+			if ($form->is_valid()) {
2546
+				$registration_config = EE_Registry::instance()->CFG->registration;
2547
+				$valid_data          = $form->valid_data();
2548
+				if (isset($valid_data['default_reg_status'])) {
2549
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2550
+				}
2551
+				if (isset($valid_data['default_max_tickets'])) {
2552
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2553
+				}
2554
+				do_action(
2555
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2556
+					$valid_data,
2557
+					EE_Registry::instance()->CFG,
2558
+					$this
2559
+				);
2560
+				// update because data was valid!
2561
+				EE_Registry::instance()->CFG->update_espresso_config();
2562
+				EE_Error::overwrite_success();
2563
+				EE_Error::add_success(
2564
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2565
+				);
2566
+			}
2567
+		}
2568
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2569
+	}
2570
+
2571
+
2572
+	/*************        Templates        *************
21 2573
      *
22
-     * @var EE_Event $_event
23
-     */
24
-    protected $_event;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var stdClass $_category
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This will hold the event model instance
37
-     *
38
-     * @var EEM_Event $_event_model
39
-     */
40
-    protected $_event_model;
41
-
42
-
43
-    /**
44
-     * @var EE_Event
45
-     */
46
-    protected $_cpt_model_obj = false;
47
-
48
-
49
-    /**
50
-     * @var NodeGroupDao
51
-     */
52
-    protected $model_obj_node_group_persister;
53
-
54
-
55
-    /**
56
-     * Initialize page props for this admin page group.
57
-     */
58
-    protected function _init_page_props()
59
-    {
60
-        $this->page_slug        = EVENTS_PG_SLUG;
61
-        $this->page_label       = EVENTS_LABEL;
62
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
63
-        $this->_admin_base_path = EVENTS_ADMIN;
64
-        $this->_cpt_model_names = [
65
-            'create_new' => 'EEM_Event',
66
-            'edit'       => 'EEM_Event',
67
-        ];
68
-        $this->_cpt_edit_routes = [
69
-            'espresso_events' => 'edit',
70
-        ];
71
-        add_action(
72
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
73
-            [$this, 'verify_event_edit'],
74
-            10,
75
-            2
76
-        );
77
-    }
78
-
79
-
80
-    /**
81
-     * Sets the ajax hooks used for this admin page group.
82
-     */
83
-    protected function _ajax_hooks()
84
-    {
85
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
86
-    }
87
-
88
-
89
-    /**
90
-     * Sets the page properties for this admin page group.
91
-     */
92
-    protected function _define_page_props()
93
-    {
94
-        $this->_admin_page_title = EVENTS_LABEL;
95
-        $this->_labels           = [
96
-            'buttons'      => [
97
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
98
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
99
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
100
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
101
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
102
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
103
-            ],
104
-            'editor_title' => [
105
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
106
-            ],
107
-            'publishbox'   => [
108
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
109
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
110
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
111
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
112
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
113
-            ],
114
-        ];
115
-    }
116
-
117
-
118
-    /**
119
-     * Sets the page routes property for this admin page group.
120
-     */
121
-    protected function _set_page_routes()
122
-    {
123
-        // load formatter helper
124
-        // load field generator helper
125
-        // is there a evt_id in the request?
126
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
127
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
128
-
129
-        $this->_page_routes = [
130
-            'default'                       => [
131
-                'func'       => '_events_overview_list_table',
132
-                'capability' => 'ee_read_events',
133
-            ],
134
-            'create_new'                    => [
135
-                'func'       => '_create_new_cpt_item',
136
-                'capability' => 'ee_edit_events',
137
-            ],
138
-            'edit'                          => [
139
-                'func'       => '_edit_cpt_item',
140
-                'capability' => 'ee_edit_event',
141
-                'obj_id'     => $EVT_ID,
142
-            ],
143
-            'copy_event'                    => [
144
-                'func'       => '_copy_events',
145
-                'capability' => 'ee_edit_event',
146
-                'obj_id'     => $EVT_ID,
147
-                'noheader'   => true,
148
-            ],
149
-            'trash_event'                   => [
150
-                'func'       => '_trash_or_restore_event',
151
-                'args'       => ['event_status' => 'trash'],
152
-                'capability' => 'ee_delete_event',
153
-                'obj_id'     => $EVT_ID,
154
-                'noheader'   => true,
155
-            ],
156
-            'trash_events'                  => [
157
-                'func'       => '_trash_or_restore_events',
158
-                'args'       => ['event_status' => 'trash'],
159
-                'capability' => 'ee_delete_events',
160
-                'noheader'   => true,
161
-            ],
162
-            'restore_event'                 => [
163
-                'func'       => '_trash_or_restore_event',
164
-                'args'       => ['event_status' => 'draft'],
165
-                'capability' => 'ee_delete_event',
166
-                'obj_id'     => $EVT_ID,
167
-                'noheader'   => true,
168
-            ],
169
-            'restore_events'                => [
170
-                'func'       => '_trash_or_restore_events',
171
-                'args'       => ['event_status' => 'draft'],
172
-                'capability' => 'ee_delete_events',
173
-                'noheader'   => true,
174
-            ],
175
-            'delete_event'                  => [
176
-                'func'       => '_delete_event',
177
-                'capability' => 'ee_delete_event',
178
-                'obj_id'     => $EVT_ID,
179
-                'noheader'   => true,
180
-            ],
181
-            'delete_events'                 => [
182
-                'func'       => '_delete_events',
183
-                'capability' => 'ee_delete_events',
184
-                'noheader'   => true,
185
-            ],
186
-            'view_report'                   => [
187
-                'func'       => '_view_report',
188
-                'capability' => 'ee_edit_events',
189
-            ],
190
-            'default_event_settings'        => [
191
-                'func'       => '_default_event_settings',
192
-                'capability' => 'manage_options',
193
-            ],
194
-            'update_default_event_settings' => [
195
-                'func'       => '_update_default_event_settings',
196
-                'capability' => 'manage_options',
197
-                'noheader'   => true,
198
-            ],
199
-            'template_settings'             => [
200
-                'func'       => '_template_settings',
201
-                'capability' => 'manage_options',
202
-            ],
203
-            // event category tab related
204
-            'add_category'                  => [
205
-                'func'       => '_category_details',
206
-                'capability' => 'ee_edit_event_category',
207
-                'args'       => ['add'],
208
-            ],
209
-            'edit_category'                 => [
210
-                'func'       => '_category_details',
211
-                'capability' => 'ee_edit_event_category',
212
-                'args'       => ['edit'],
213
-            ],
214
-            'delete_categories'             => [
215
-                'func'       => '_delete_categories',
216
-                'capability' => 'ee_delete_event_category',
217
-                'noheader'   => true,
218
-            ],
219
-            'delete_category'               => [
220
-                'func'       => '_delete_categories',
221
-                'capability' => 'ee_delete_event_category',
222
-                'noheader'   => true,
223
-            ],
224
-            'insert_category'               => [
225
-                'func'       => '_insert_or_update_category',
226
-                'args'       => ['new_category' => true],
227
-                'capability' => 'ee_edit_event_category',
228
-                'noheader'   => true,
229
-            ],
230
-            'update_category'               => [
231
-                'func'       => '_insert_or_update_category',
232
-                'args'       => ['new_category' => false],
233
-                'capability' => 'ee_edit_event_category',
234
-                'noheader'   => true,
235
-            ],
236
-            'category_list'                 => [
237
-                'func'       => '_category_list_table',
238
-                'capability' => 'ee_manage_event_categories',
239
-            ],
240
-            'preview_deletion'              => [
241
-                'func'       => 'previewDeletion',
242
-                'capability' => 'ee_delete_events',
243
-            ],
244
-            'confirm_deletion'              => [
245
-                'func'       => 'confirmDeletion',
246
-                'capability' => 'ee_delete_events',
247
-                'noheader'   => true,
248
-            ],
249
-        ];
250
-    }
251
-
252
-
253
-    /**
254
-     * Set the _page_config property for this admin page group.
255
-     */
256
-    protected function _set_page_config()
257
-    {
258
-        $post_id            = $this->request->getRequestParam('post', 0, 'int');
259
-        $EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
260
-        $this->_page_config = [
261
-            'default'                => [
262
-                'nav'           => [
263
-                    'label' => esc_html__('Overview', 'event_espresso'),
264
-                    'order' => 10,
265
-                ],
266
-                'list_table'    => 'Events_Admin_List_Table',
267
-                'help_tabs'     => [
268
-                    'events_overview_help_tab'                       => [
269
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
270
-                        'filename' => 'events_overview',
271
-                    ],
272
-                    'events_overview_table_column_headings_help_tab' => [
273
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
-                        'filename' => 'events_overview_table_column_headings',
275
-                    ],
276
-                    'events_overview_filters_help_tab'               => [
277
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
-                        'filename' => 'events_overview_filters',
279
-                    ],
280
-                    'events_overview_view_help_tab'                  => [
281
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
-                        'filename' => 'events_overview_views',
283
-                    ],
284
-                    'events_overview_other_help_tab'                 => [
285
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
-                        'filename' => 'events_overview_other',
287
-                    ],
288
-                ],
289
-                'require_nonce' => false,
290
-            ],
291
-            'create_new'             => [
292
-                'nav'           => [
293
-                    'label'      => esc_html__('Add New Event', 'event_espresso'),
294
-                    'order'      => 5,
295
-                    'persistent' => false,
296
-                ],
297
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
298
-                'help_tabs'     => [
299
-                    'event_editor_help_tab'                            => [
300
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
301
-                        'filename' => 'event_editor',
302
-                    ],
303
-                    'event_editor_title_richtexteditor_help_tab'       => [
304
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
305
-                        'filename' => 'event_editor_title_richtexteditor',
306
-                    ],
307
-                    'event_editor_venue_details_help_tab'              => [
308
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
309
-                        'filename' => 'event_editor_venue_details',
310
-                    ],
311
-                    'event_editor_event_datetimes_help_tab'            => [
312
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
313
-                        'filename' => 'event_editor_event_datetimes',
314
-                    ],
315
-                    'event_editor_event_tickets_help_tab'              => [
316
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
317
-                        'filename' => 'event_editor_event_tickets',
318
-                    ],
319
-                    'event_editor_event_registration_options_help_tab' => [
320
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
321
-                        'filename' => 'event_editor_event_registration_options',
322
-                    ],
323
-                    'event_editor_tags_categories_help_tab'            => [
324
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
325
-                        'filename' => 'event_editor_tags_categories',
326
-                    ],
327
-                    'event_editor_questions_registrants_help_tab'      => [
328
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
329
-                        'filename' => 'event_editor_questions_registrants',
330
-                    ],
331
-                    'event_editor_save_new_event_help_tab'             => [
332
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
333
-                        'filename' => 'event_editor_save_new_event',
334
-                    ],
335
-                    'event_editor_other_help_tab'                      => [
336
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
337
-                        'filename' => 'event_editor_other',
338
-                    ],
339
-                ],
340
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
341
-                'require_nonce' => false,
342
-            ],
343
-            'edit'                   => [
344
-                'nav'           => [
345
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
346
-                    'order'      => 5,
347
-                    'persistent' => false,
348
-                    'url'        => $post_id
349
-                        ? EE_Admin_Page::add_query_args_and_nonce(
350
-                            ['post' => $post_id, 'action' => 'edit'],
351
-                            $this->_current_page_view_url
352
-                        )
353
-                        : $this->_admin_base_url,
354
-                ],
355
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
356
-                'help_tabs'     => [
357
-                    'event_editor_help_tab'                            => [
358
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
359
-                        'filename' => 'event_editor',
360
-                    ],
361
-                    'event_editor_title_richtexteditor_help_tab'       => [
362
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
363
-                        'filename' => 'event_editor_title_richtexteditor',
364
-                    ],
365
-                    'event_editor_venue_details_help_tab'              => [
366
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
367
-                        'filename' => 'event_editor_venue_details',
368
-                    ],
369
-                    'event_editor_event_datetimes_help_tab'            => [
370
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
371
-                        'filename' => 'event_editor_event_datetimes',
372
-                    ],
373
-                    'event_editor_event_tickets_help_tab'              => [
374
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
375
-                        'filename' => 'event_editor_event_tickets',
376
-                    ],
377
-                    'event_editor_event_registration_options_help_tab' => [
378
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
379
-                        'filename' => 'event_editor_event_registration_options',
380
-                    ],
381
-                    'event_editor_tags_categories_help_tab'            => [
382
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
383
-                        'filename' => 'event_editor_tags_categories',
384
-                    ],
385
-                    'event_editor_questions_registrants_help_tab'      => [
386
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
387
-                        'filename' => 'event_editor_questions_registrants',
388
-                    ],
389
-                    'event_editor_save_new_event_help_tab'             => [
390
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
391
-                        'filename' => 'event_editor_save_new_event',
392
-                    ],
393
-                    'event_editor_other_help_tab'                      => [
394
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
395
-                        'filename' => 'event_editor_other',
396
-                    ],
397
-                ],
398
-                'require_nonce' => false,
399
-            ],
400
-            'default_event_settings' => [
401
-                'nav'           => [
402
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
403
-                    'order' => 40,
404
-                ],
405
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
406
-                'labels'        => [
407
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
408
-                ],
409
-                'help_tabs'     => [
410
-                    'default_settings_help_tab'        => [
411
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
412
-                        'filename' => 'events_default_settings',
413
-                    ],
414
-                    'default_settings_status_help_tab' => [
415
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
416
-                        'filename' => 'events_default_settings_status',
417
-                    ],
418
-                    'default_maximum_tickets_help_tab' => [
419
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
420
-                        'filename' => 'events_default_settings_max_tickets',
421
-                    ],
422
-                ],
423
-                'require_nonce' => false,
424
-            ],
425
-            // template settings
426
-            'template_settings'      => [
427
-                'nav'           => [
428
-                    'label' => esc_html__('Templates', 'event_espresso'),
429
-                    'order' => 30,
430
-                ],
431
-                'metaboxes'     => $this->_default_espresso_metaboxes,
432
-                'help_tabs'     => [
433
-                    'general_settings_templates_help_tab' => [
434
-                        'title'    => esc_html__('Templates', 'event_espresso'),
435
-                        'filename' => 'general_settings_templates',
436
-                    ],
437
-                ],
438
-                'require_nonce' => false,
439
-            ],
440
-            // event category stuff
441
-            'add_category'           => [
442
-                'nav'           => [
443
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
444
-                    'order'      => 15,
445
-                    'persistent' => false,
446
-                ],
447
-                'help_tabs'     => [
448
-                    'add_category_help_tab' => [
449
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
450
-                        'filename' => 'events_add_category',
451
-                    ],
452
-                ],
453
-                'metaboxes'     => ['_publish_post_box'],
454
-                'require_nonce' => false,
455
-            ],
456
-            'edit_category'          => [
457
-                'nav'           => [
458
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
459
-                    'order'      => 15,
460
-                    'persistent' => false,
461
-                    'url'        => $EVT_CAT_ID
462
-                        ? add_query_arg(
463
-                            ['EVT_CAT_ID' => $EVT_CAT_ID],
464
-                            $this->_current_page_view_url
465
-                        )
466
-                        : $this->_admin_base_url,
467
-                ],
468
-                'help_tabs'     => [
469
-                    'edit_category_help_tab' => [
470
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
471
-                        'filename' => 'events_edit_category',
472
-                    ],
473
-                ],
474
-                'metaboxes'     => ['_publish_post_box'],
475
-                'require_nonce' => false,
476
-            ],
477
-            'category_list'          => [
478
-                'nav'           => [
479
-                    'label' => esc_html__('Categories', 'event_espresso'),
480
-                    'order' => 20,
481
-                ],
482
-                'list_table'    => 'Event_Categories_Admin_List_Table',
483
-                'help_tabs'     => [
484
-                    'events_categories_help_tab'                       => [
485
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
486
-                        'filename' => 'events_categories',
487
-                    ],
488
-                    'events_categories_table_column_headings_help_tab' => [
489
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
490
-                        'filename' => 'events_categories_table_column_headings',
491
-                    ],
492
-                    'events_categories_view_help_tab'                  => [
493
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
494
-                        'filename' => 'events_categories_views',
495
-                    ],
496
-                    'events_categories_other_help_tab'                 => [
497
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
498
-                        'filename' => 'events_categories_other',
499
-                    ],
500
-                ],
501
-                'metaboxes'     => $this->_default_espresso_metaboxes,
502
-                'require_nonce' => false,
503
-            ],
504
-            'preview_deletion'       => [
505
-                'nav'           => [
506
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
507
-                    'order'      => 15,
508
-                    'persistent' => false,
509
-                    'url'        => '',
510
-                ],
511
-                'require_nonce' => false,
512
-            ],
513
-        ];
514
-    }
515
-
516
-
517
-    /**
518
-     * Used to register any global screen options if necessary for every route in this admin page group.
519
-     */
520
-    protected function _add_screen_options()
521
-    {
522
-    }
523
-
524
-
525
-    /**
526
-     * Implementing the screen options for the 'default' route.
527
-     *
528
-     * @throws InvalidArgumentException
529
-     * @throws InvalidDataTypeException
530
-     * @throws InvalidInterfaceException
531
-     */
532
-    protected function _add_screen_options_default()
533
-    {
534
-        $this->_per_page_screen_option();
535
-    }
536
-
537
-
538
-    /**
539
-     * Implementing screen options for the category list route.
540
-     *
541
-     * @throws InvalidArgumentException
542
-     * @throws InvalidDataTypeException
543
-     * @throws InvalidInterfaceException
544
-     */
545
-    protected function _add_screen_options_category_list()
546
-    {
547
-        $page_title              = $this->_admin_page_title;
548
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
549
-        $this->_per_page_screen_option();
550
-        $this->_admin_page_title = $page_title;
551
-    }
552
-
553
-
554
-    /**
555
-     * Used to register any global feature pointers for the admin page group.
556
-     */
557
-    protected function _add_feature_pointers()
558
-    {
559
-    }
560
-
561
-
562
-    /**
563
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
564
-     */
565
-    public function load_scripts_styles()
566
-    {
567
-        wp_register_style(
568
-            'events-admin-css',
569
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
570
-            [],
571
-            EVENT_ESPRESSO_VERSION
572
-        );
573
-        wp_register_style(
574
-            'ee-cat-admin',
575
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
576
-            [],
577
-            EVENT_ESPRESSO_VERSION
578
-        );
579
-        wp_enqueue_style('events-admin-css');
580
-        wp_enqueue_style('ee-cat-admin');
581
-        // scripts
582
-        wp_register_script(
583
-            'event_editor_js',
584
-            EVENTS_ASSETS_URL . 'event_editor.js',
585
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
586
-            EVENT_ESPRESSO_VERSION,
587
-            true
588
-        );
589
-    }
590
-
591
-
592
-    /**
593
-     * Enqueuing scripts and styles specific to this view
594
-     */
595
-    public function load_scripts_styles_create_new()
596
-    {
597
-        $this->load_scripts_styles_edit();
598
-    }
599
-
600
-
601
-    /**
602
-     * Enqueuing scripts and styles specific to this view
603
-     */
604
-    public function load_scripts_styles_edit()
605
-    {
606
-        // styles
607
-        wp_enqueue_style('espresso-ui-theme');
608
-        wp_register_style(
609
-            'event-editor-css',
610
-            EVENTS_ASSETS_URL . 'event-editor.css',
611
-            ['ee-admin-css'],
612
-            EVENT_ESPRESSO_VERSION
613
-        );
614
-        wp_enqueue_style('event-editor-css');
615
-        // scripts
616
-        if (! $this->admin_config->useAdvancedEditor()) {
617
-            wp_register_script(
618
-                'event-datetime-metabox',
619
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
620
-                ['event_editor_js', 'ee-datepicker'],
621
-                EVENT_ESPRESSO_VERSION
622
-            );
623
-            wp_enqueue_script('event-datetime-metabox');
624
-        }
625
-    }
626
-
627
-
628
-    /**
629
-     * Populating the _views property for the category list table view.
630
-     */
631
-    protected function _set_list_table_views_category_list()
632
-    {
633
-        $this->_views = [
634
-            'all' => [
635
-                'slug'        => 'all',
636
-                'label'       => esc_html__('All', 'event_espresso'),
637
-                'count'       => 0,
638
-                'bulk_action' => [
639
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
640
-                ],
641
-            ],
642
-        ];
643
-    }
644
-
645
-
646
-    /**
647
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
648
-     */
649
-    public function admin_init()
650
-    {
651
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
652
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
653
-            'event_espresso'
654
-        );
655
-    }
656
-
657
-
658
-    /**
659
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
660
-     * group.
661
-     */
662
-    public function admin_notices()
663
-    {
664
-    }
665
-
666
-
667
-    /**
668
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
669
-     * this admin page group.
670
-     */
671
-    public function admin_footer_scripts()
672
-    {
673
-    }
674
-
675
-
676
-    /**
677
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
678
-     * warning (via EE_Error::add_error());
679
-     *
680
-     * @param EE_Event $event Event object
681
-     * @param string   $req_type
682
-     * @return void
683
-     * @throws EE_Error
684
-     * @throws ReflectionException
685
-     */
686
-    public function verify_event_edit($event = null, $req_type = '')
687
-    {
688
-        // don't need to do this when processing
689
-        if (! empty($req_type)) {
690
-            return;
691
-        }
692
-        // no event?
693
-        if (! $event instanceof EE_Event) {
694
-            $event = $this->_cpt_model_obj;
695
-        }
696
-        // STILL no event?
697
-        if (! $event instanceof EE_Event) {
698
-            return;
699
-        }
700
-        $orig_status = $event->status();
701
-        // first check if event is active.
702
-        if (
703
-            $orig_status === EEM_Event::cancelled
704
-            || $orig_status === EEM_Event::postponed
705
-            || $event->is_expired()
706
-            || $event->is_inactive()
707
-        ) {
708
-            return;
709
-        }
710
-        // made it here so it IS active... next check that any of the tickets are sold.
711
-        if ($event->is_sold_out(true)) {
712
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
713
-                EE_Error::add_attention(
714
-                    sprintf(
715
-                        esc_html__(
716
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
717
-                            'event_espresso'
718
-                        ),
719
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
720
-                    )
721
-                );
722
-            }
723
-            return;
724
-        }
725
-        if ($orig_status === EEM_Event::sold_out) {
726
-            EE_Error::add_attention(
727
-                sprintf(
728
-                    esc_html__(
729
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
730
-                        'event_espresso'
731
-                    ),
732
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
733
-                )
734
-            );
735
-        }
736
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
737
-        if (! $event->tickets_on_sale()) {
738
-            return;
739
-        }
740
-        // made it here so show warning
741
-        $this->_edit_event_warning();
742
-    }
743
-
744
-
745
-    /**
746
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
747
-     * When needed, hook this into a EE_Error::add_error() notice.
748
-     *
749
-     * @access protected
750
-     * @return void
751
-     */
752
-    protected function _edit_event_warning()
753
-    {
754
-        // we don't want to add warnings during these requests
755
-        if ($this->request->getRequestParam('action') === 'editpost') {
756
-            return;
757
-        }
758
-        EE_Error::add_attention(
759
-            sprintf(
760
-                esc_html__(
761
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
762
-                    'event_espresso'
763
-                ),
764
-                '<a class="espresso-help-tab-lnk ee-help-tab-link">',
765
-                '</a>'
766
-            )
767
-        );
768
-    }
769
-
770
-
771
-    /**
772
-     * When a user is creating a new event, notify them if they haven't set their timezone.
773
-     * Otherwise, do the normal logic
774
-     *
775
-     * @return void
776
-     * @throws EE_Error
777
-     * @throws InvalidArgumentException
778
-     * @throws InvalidDataTypeException
779
-     * @throws InvalidInterfaceException
780
-     */
781
-    protected function _create_new_cpt_item()
782
-    {
783
-        $has_timezone_string = get_option('timezone_string');
784
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
785
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
786
-            EE_Error::add_attention(
787
-                sprintf(
788
-                    esc_html__(
789
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
790
-                        'event_espresso'
791
-                    ),
792
-                    '<br>',
793
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
794
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
795
-                    . '</select>',
796
-                    '<button class="button button--secondary timezone-submit">',
797
-                    '</button><span class="spinner"></span>'
798
-                ),
799
-                __FILE__,
800
-                __FUNCTION__,
801
-                __LINE__
802
-            );
803
-        }
804
-        parent::_create_new_cpt_item();
805
-    }
806
-
807
-
808
-    /**
809
-     * Sets the _views property for the default route in this admin page group.
810
-     */
811
-    protected function _set_list_table_views_default()
812
-    {
813
-        $this->_views = [
814
-            'all'   => [
815
-                'slug'        => 'all',
816
-                'label'       => esc_html__('View All Events', 'event_espresso'),
817
-                'count'       => 0,
818
-                'bulk_action' => [
819
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
820
-                ],
821
-            ],
822
-            'draft' => [
823
-                'slug'        => 'draft',
824
-                'label'       => esc_html__('Draft', 'event_espresso'),
825
-                'count'       => 0,
826
-                'bulk_action' => [
827
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
828
-                ],
829
-            ],
830
-        ];
831
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
832
-            $this->_views['trash'] = [
833
-                'slug'        => 'trash',
834
-                'label'       => esc_html__('Trash', 'event_espresso'),
835
-                'count'       => 0,
836
-                'bulk_action' => [
837
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
838
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
839
-                ],
840
-            ];
841
-        }
842
-    }
843
-
844
-
845
-    /**
846
-     * Provides the legend item array for the default list table view.
847
-     *
848
-     * @return array
849
-     * @throws EE_Error
850
-     * @throws EE_Error
851
-     */
852
-    protected function _event_legend_items()
853
-    {
854
-        $items    = [
855
-            'view_details'   => [
856
-                'class' => 'dashicons dashicons-visibility',
857
-                'desc'  => esc_html__('View Event', 'event_espresso'),
858
-            ],
859
-            'edit_event'     => [
860
-                'class' => 'dashicons dashicons-calendar-alt',
861
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
862
-            ],
863
-            'view_attendees' => [
864
-                'class' => 'dashicons dashicons-groups',
865
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
866
-            ],
867
-        ];
868
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
869
-        $statuses = [
870
-            'sold_out_status'  => [
871
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
872
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
873
-            ],
874
-            'active_status'    => [
875
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
876
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
877
-            ],
878
-            'upcoming_status'  => [
879
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
880
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
881
-            ],
882
-            'postponed_status' => [
883
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
884
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
885
-            ],
886
-            'cancelled_status' => [
887
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
888
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
889
-            ],
890
-            'expired_status'   => [
891
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
892
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
893
-            ],
894
-            'inactive_status'  => [
895
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
896
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
897
-            ],
898
-        ];
899
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
900
-        return array_merge($items, $statuses);
901
-    }
902
-
903
-
904
-    /**
905
-     * @return EEM_Event
906
-     * @throws EE_Error
907
-     * @throws InvalidArgumentException
908
-     * @throws InvalidDataTypeException
909
-     * @throws InvalidInterfaceException
910
-     * @throws ReflectionException
911
-     */
912
-    private function _event_model()
913
-    {
914
-        if (! $this->_event_model instanceof EEM_Event) {
915
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
916
-        }
917
-        return $this->_event_model;
918
-    }
919
-
920
-
921
-    /**
922
-     * Adds extra buttons to the WP CPT permalink field row.
923
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
924
-     *
925
-     * @param string $return    the current html
926
-     * @param int    $id        the post id for the page
927
-     * @param string $new_title What the title is
928
-     * @param string $new_slug  what the slug is
929
-     * @return string            The new html string for the permalink area
930
-     */
931
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
932
-    {
933
-        // make sure this is only when editing
934
-        if (! empty($id)) {
935
-            $post = get_post($id);
936
-            $return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
937
-                       . esc_html__('Shortcode', 'event_espresso')
938
-                       . '</a> ';
939
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
940
-                       . $post->ID
941
-                       . ']">';
942
-        }
943
-        return $return;
944
-    }
945
-
946
-
947
-    /**
948
-     * _events_overview_list_table
949
-     * This contains the logic for showing the events_overview list
950
-     *
951
-     * @access protected
952
-     * @return void
953
-     * @throws DomainException
954
-     * @throws EE_Error
955
-     * @throws InvalidArgumentException
956
-     * @throws InvalidDataTypeException
957
-     * @throws InvalidInterfaceException
958
-     */
959
-    protected function _events_overview_list_table()
960
-    {
961
-        $after_list_table                           = [];
962
-        $links_html = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack');
963
-        $links_html .= EEH_HTML::h3(esc_html__('Links', 'event_espresso'));
964
-        $links_html .= EEH_HTML::div(
965
-            EEH_Template::get_button_or_link(
966
-                get_post_type_archive_link('espresso_events'),
967
-                esc_html__('View Event Archive Page', 'event_espresso'),
968
-                'button button--small button--secondary'
969
-            ),
970
-            '',
971
-            'ee-admin-button-row ee-admin-button-row--align-start'
972
-        );
973
-        $links_html .= EEH_HTML::divx();
974
-
975
-        $after_list_table['view_event_list_button'] = $links_html;
976
-
977
-        $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
978
-        $this->_admin_page_title                    .= ' ' . $this->get_action_link_or_button(
979
-            'create_new',
980
-            'add',
981
-            [],
982
-            'add-new-h2'
983
-        );
984
-
985
-        $this->_template_args['after_list_table']   = array_merge(
986
-            (array) $this->_template_args['after_list_table'],
987
-            $after_list_table
988
-        );
989
-        $this->display_admin_list_table_page_with_no_sidebar();
990
-    }
991
-
992
-
993
-    /**
994
-     * this allows for extra misc actions in the default WP publish box
995
-     *
996
-     * @return void
997
-     * @throws DomainException
998
-     * @throws EE_Error
999
-     * @throws InvalidArgumentException
1000
-     * @throws InvalidDataTypeException
1001
-     * @throws InvalidInterfaceException
1002
-     * @throws ReflectionException
1003
-     */
1004
-    public function extra_misc_actions_publish_box()
1005
-    {
1006
-        $this->_generate_publish_box_extra_content();
1007
-    }
1008
-
1009
-
1010
-    /**
1011
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1012
-     * saved.
1013
-     * Typically you would use this to save any additional data.
1014
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
1015
-     * ALSO very important.  When a post transitions from scheduled to published,
1016
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1017
-     * other meta saves. So MAKE sure that you handle this accordingly.
1018
-     *
1019
-     * @access protected
1020
-     * @abstract
1021
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1022
-     * @param object $post    The post object of the cpt that was saved.
1023
-     * @return void
1024
-     * @throws EE_Error
1025
-     * @throws InvalidArgumentException
1026
-     * @throws InvalidDataTypeException
1027
-     * @throws InvalidInterfaceException
1028
-     * @throws ReflectionException
1029
-     */
1030
-    protected function _insert_update_cpt_item($post_id, $post)
1031
-    {
1032
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1033
-            // get out we're not processing an event save.
1034
-            return;
1035
-        }
1036
-        $event_values = [
1037
-            'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1038
-            'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1039
-            'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1040
-        ];
1041
-        // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1042
-        if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1043
-            $event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1044
-                'display_ticket_selector',
1045
-                false,
1046
-                'bool'
1047
-            );
1048
-            $event_values['EVT_additional_limit']            = min(
1049
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1050
-                $this->request->getRequestParam('additional_limit', null, 'int')
1051
-            );
1052
-            $event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1053
-                'EVT_default_registration_status',
1054
-                EE_Registry::instance()->CFG->registration->default_STS_ID
1055
-            );
1056
-
1057
-            $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1058
-            $event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1059
-            $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool');
1060
-        }
1061
-        // update event
1062
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1063
-        // get event_object for other metaboxes...
1064
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1065
-        // i have to setup where conditions to override the filters in the model
1066
-        // that filter out autodraft and inherit statuses so we GET the inherit id!
1067
-        $event = $this->_event_model()->get_one(
1068
-            [
1069
-                [
1070
-                    $this->_event_model()->primary_key_name() => $post_id,
1071
-                    'OR'                                      => [
1072
-                        'status'   => $post->post_status,
1073
-                        // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1074
-                        // but the returned object here has a status of "publish", so use the original post status as well
1075
-                        'status*1' => $this->request->getRequestParam('original_post_status'),
1076
-                    ],
1077
-                ],
1078
-            ]
1079
-        );
1080
-
1081
-        // the following are default callbacks for event attachment updates
1082
-        // that can be overridden by caffeinated functionality and/or addons.
1083
-        $event_update_callbacks = [];
1084
-        if (! $this->admin_config->useAdvancedEditor()) {
1085
-            $event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1086
-            $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1087
-        }
1088
-        $event_update_callbacks = apply_filters(
1089
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1090
-            $event_update_callbacks
1091
-        );
1092
-
1093
-        $att_success = true;
1094
-        foreach ($event_update_callbacks as $e_callback) {
1095
-            $_success = is_callable($e_callback)
1096
-                ? $e_callback($event, $this->request->requestParams())
1097
-                : false;
1098
-            // if ANY of these updates fail then we want the appropriate global error message
1099
-            $att_success = $_success !== false ? $att_success : false;
1100
-        }
1101
-        // any errors?
1102
-        if ($success && $att_success === false) {
1103
-            EE_Error::add_error(
1104
-                esc_html__(
1105
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1106
-                    'event_espresso'
1107
-                ),
1108
-                __FILE__,
1109
-                __FUNCTION__,
1110
-                __LINE__
1111
-            );
1112
-        } elseif ($success === false) {
1113
-            EE_Error::add_error(
1114
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1115
-                __FILE__,
1116
-                __FUNCTION__,
1117
-                __LINE__
1118
-            );
1119
-        }
1120
-    }
1121
-
1122
-
1123
-    /**
1124
-     * @param int $post_id
1125
-     * @param int $revision_id
1126
-     * @throws EE_Error
1127
-     * @throws EE_Error
1128
-     * @throws ReflectionException
1129
-     * @see parent::restore_item()
1130
-     */
1131
-    protected function _restore_cpt_item($post_id, $revision_id)
1132
-    {
1133
-        // copy existing event meta to new post
1134
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1135
-        if ($post_evt instanceof EE_Event) {
1136
-            // meta revision restore
1137
-            $post_evt->restore_revision($revision_id);
1138
-            // related objs restore
1139
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1140
-        }
1141
-    }
1142
-
1143
-
1144
-    /**
1145
-     * Attach the venue to the Event
1146
-     *
1147
-     * @param EE_Event $event Event Object to add the venue to
1148
-     * @param array    $data  The request data from the form
1149
-     * @return bool           Success or fail.
1150
-     * @throws EE_Error
1151
-     * @throws ReflectionException
1152
-     */
1153
-    protected function _default_venue_update(EE_Event $event, $data)
1154
-    {
1155
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1156
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1157
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1158
-        // very important.  If we don't have a venue name...
1159
-        // then we'll get out because not necessary to create empty venue
1160
-        if (empty($data['venue_title'])) {
1161
-            return false;
1162
-        }
1163
-        $venue_array = [
1164
-            'VNU_wp_user'         => $event->get('EVT_wp_user'),
1165
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1166
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1167
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1168
-            'VNU_short_desc'      => ! empty($data['venue_short_description'])
1169
-                ? $data['venue_short_description']
1170
-                : null,
1171
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1172
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1173
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1174
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1175
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1176
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1177
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1178
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1179
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1180
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1181
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1182
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1183
-            'status'              => 'publish',
1184
-        ];
1185
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1186
-        if (! empty($venue_id)) {
1187
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1188
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1189
-            // we've gotta make sure that the venue is always attached to a revision..
1190
-            // add_relation_to should take care of making sure that the relation is already present.
1191
-            $event->_add_relation_to($venue_id, 'Venue');
1192
-            return $rows_affected > 0;
1193
-        }
1194
-        // we insert the venue
1195
-        $venue_id = $venue_model->insert($venue_array);
1196
-        $event->_add_relation_to($venue_id, 'Venue');
1197
-        return ! empty($venue_id);
1198
-        // when we have the ancestor come in it's already been handled by the revision save.
1199
-    }
1200
-
1201
-
1202
-    /**
1203
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1204
-     *
1205
-     * @param EE_Event $event The Event object we're attaching data to
1206
-     * @param array    $data  The request data from the form
1207
-     * @return array
1208
-     * @throws EE_Error
1209
-     * @throws ReflectionException
1210
-     * @throws Exception
1211
-     */
1212
-    protected function _default_tickets_update(EE_Event $event, $data)
1213
-    {
1214
-        if ($this->admin_config->useAdvancedEditor()) {
1215
-            return [];
1216
-        }
1217
-        $datetime       = null;
1218
-        $saved_tickets  = [];
1219
-        $event_timezone = $event->get_timezone();
1220
-        $date_formats   = ['Y-m-d', 'h:i a'];
1221
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1222
-            // trim all values to ensure any excess whitespace is removed.
1223
-            $datetime_data                = array_map('trim', $datetime_data);
1224
-            $datetime_data['DTT_EVT_end'] =
1225
-                isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1226
-                    ? $datetime_data['DTT_EVT_end']
1227
-                    : $datetime_data['DTT_EVT_start'];
1228
-            $datetime_values              = [
1229
-                'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1230
-                'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1231
-                'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1232
-                'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1233
-                'DTT_order'     => $row,
1234
-            ];
1235
-            // if we have an id then let's get existing object first and then set the new values.
1236
-            //  Otherwise we instantiate a new object for save.
1237
-            if (! empty($datetime_data['DTT_ID'])) {
1238
-                $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1239
-                if (! $datetime instanceof EE_Datetime) {
1240
-                    throw new RuntimeException(
1241
-                        sprintf(
1242
-                            esc_html__(
1243
-                                'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1244
-                                'event_espresso'
1245
-                            ),
1246
-                            $datetime_data['DTT_ID']
1247
-                        )
1248
-                    );
1249
-                }
1250
-                $datetime->set_date_format($date_formats[0]);
1251
-                $datetime->set_time_format($date_formats[1]);
1252
-                foreach ($datetime_values as $field => $value) {
1253
-                    $datetime->set($field, $value);
1254
-                }
1255
-            } else {
1256
-                $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1257
-            }
1258
-            if (! $datetime instanceof EE_Datetime) {
1259
-                throw new RuntimeException(
1260
-                    sprintf(
1261
-                        esc_html__(
1262
-                            'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1263
-                            'event_espresso'
1264
-                        ),
1265
-                        print_r($datetime_values, true)
1266
-                    )
1267
-                );
1268
-            }
1269
-            // before going any further make sure our dates are setup correctly
1270
-            // so that the end date is always equal or greater than the start date.
1271
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1272
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1273
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1274
-            }
1275
-            $datetime->save();
1276
-            $event->_add_relation_to($datetime, 'Datetime');
1277
-        }
1278
-        // no datetimes get deleted so we don't do any of that logic here.
1279
-        // update tickets next
1280
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1281
-
1282
-        // set up some default start and end dates in case those are not present in the incoming data
1283
-        $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1284
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1285
-        // use the start date of the first datetime for the end date
1286
-        $first_datetime   = $event->first_datetime();
1287
-        $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1288
-
1289
-        // now process the incoming data
1290
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
1291
-            $update_prices = false;
1292
-            $ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1293
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1294
-                : 0;
1295
-            // trim inputs to ensure any excess whitespace is removed.
1296
-            $ticket_data   = array_map('trim', $ticket_data);
1297
-            $ticket_values = [
1298
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1299
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1300
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1301
-                'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1302
-                'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1303
-                    ? $ticket_data['TKT_start_date']
1304
-                    : $default_start_date,
1305
-                'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1306
-                    ? $ticket_data['TKT_end_date']
1307
-                    : $default_end_date,
1308
-                'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1309
-                                     || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1310
-                    ? $ticket_data['TKT_qty']
1311
-                    : EE_INF,
1312
-                'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1313
-                                     || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1314
-                    ? $ticket_data['TKT_uses']
1315
-                    : EE_INF,
1316
-                'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1317
-                'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1318
-                'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1319
-                'TKT_price'       => $ticket_price,
1320
-                'TKT_row'         => $row,
1321
-            ];
1322
-            // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1323
-            // which means in turn that the prices will become new prices as well.
1324
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1325
-                $ticket_values['TKT_ID']         = 0;
1326
-                $ticket_values['TKT_is_default'] = 0;
1327
-                $update_prices                   = true;
1328
-            }
1329
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1330
-            // we actually do our saves ahead of adding any relations because its entirely possible that this
1331
-            // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1332
-            // keep in mind that if the ticket has been sold (and we have changed pricing information),
1333
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1334
-            if (! empty($ticket_data['TKT_ID'])) {
1335
-                $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1336
-                if (! $existing_ticket instanceof EE_Ticket) {
1337
-                    throw new RuntimeException(
1338
-                        sprintf(
1339
-                            esc_html__(
1340
-                                'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1341
-                                'event_espresso'
1342
-                            ),
1343
-                            $ticket_data['TKT_ID']
1344
-                        )
1345
-                    );
1346
-                }
1347
-                $ticket_sold = $existing_ticket->count_related(
1348
-                    'Registration',
1349
-                    [
1350
-                            [
1351
-                                'STS_ID' => [
1352
-                                    'NOT IN',
1353
-                                    [EEM_Registration::status_id_incomplete],
1354
-                                ],
1355
-                            ],
1356
-                        ]
1357
-                ) > 0;
1358
-                // let's just check the total price for the existing ticket and determine if it matches the new total price.
1359
-                // if they are different then we create a new ticket (if $ticket_sold)
1360
-                // if they aren't different then we go ahead and modify existing ticket.
1361
-                $create_new_ticket = $ticket_sold
1362
-                                     && $ticket_price !== $existing_ticket->price()
1363
-                                     && ! $existing_ticket->deleted();
1364
-                $existing_ticket->set_date_format($date_formats[0]);
1365
-                $existing_ticket->set_time_format($date_formats[1]);
1366
-                // set new values
1367
-                foreach ($ticket_values as $field => $value) {
1368
-                    if ($field == 'TKT_qty') {
1369
-                        $existing_ticket->set_qty($value);
1370
-                    } elseif ($field == 'TKT_price') {
1371
-                        $existing_ticket->set('TKT_price', $ticket_price);
1372
-                    } else {
1373
-                        $existing_ticket->set($field, $value);
1374
-                    }
1375
-                }
1376
-                $ticket = $existing_ticket;
1377
-                // if $create_new_ticket is false then we can safely update the existing ticket.
1378
-                //  Otherwise we have to create a new ticket.
1379
-                if ($create_new_ticket) {
1380
-                    // archive the old ticket first
1381
-                    $existing_ticket->set('TKT_deleted', 1);
1382
-                    $existing_ticket->save();
1383
-                    // make sure this ticket is still recorded in our $saved_tickets
1384
-                    // so we don't run it through the regular trash routine.
1385
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1386
-                    // create new ticket that's a copy of the existing except,
1387
-                    // (a new id of course and not archived) AND has the new TKT_price associated with it.
1388
-                    $new_ticket = clone $existing_ticket;
1389
-                    $new_ticket->set('TKT_ID', 0);
1390
-                    $new_ticket->set('TKT_deleted', 0);
1391
-                    $new_ticket->set('TKT_sold', 0);
1392
-                    // now we need to make sure that $new prices are created as well and attached to new ticket.
1393
-                    $update_prices = true;
1394
-                    $ticket        = $new_ticket;
1395
-                }
1396
-            } else {
1397
-                // no TKT_id so a new ticket
1398
-                $ticket_values['TKT_price'] = $ticket_price;
1399
-                $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1400
-                $update_prices              = true;
1401
-            }
1402
-            if (! $ticket instanceof EE_Ticket) {
1403
-                throw new RuntimeException(
1404
-                    sprintf(
1405
-                        esc_html__(
1406
-                            'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1407
-                            'event_espresso'
1408
-                        ),
1409
-                        print_r($ticket_values, true)
1410
-                    )
1411
-                );
1412
-            }
1413
-            // cap ticket qty by datetime reg limits
1414
-            $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1415
-            // update ticket.
1416
-            $ticket->save();
1417
-            // before going any further make sure our dates are setup correctly
1418
-            // so that the end date is always equal or greater than the start date.
1419
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1420
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1421
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1422
-                $ticket->save();
1423
-            }
1424
-            // initially let's add the ticket to the datetime
1425
-            $datetime->_add_relation_to($ticket, 'Ticket');
1426
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1427
-            // add prices to ticket
1428
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices);
1429
-        }
1430
-        // however now we need to handle permanently deleting tickets via the ui.
1431
-        //  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1432
-        //  However, it does allow for deleting tickets that have no tickets sold,
1433
-        // in which case we want to get rid of permanently because there is no need to save in db.
1434
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1435
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1436
-        foreach ($tickets_removed as $id) {
1437
-            $id = absint($id);
1438
-            // get the ticket for this id
1439
-            $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1440
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1441
-                continue;
1442
-            }
1443
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1444
-            // (remember this process can ONLY kick off if there are NO tickets sold)
1445
-            $related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1446
-            foreach ($related_datetimes as $related_datetime) {
1447
-                $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1448
-            }
1449
-            // need to do the same for prices (except these prices can also be deleted because again,
1450
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1451
-            $ticket_to_remove->delete_related_permanently('Price');
1452
-            // finally let's delete this ticket
1453
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1454
-            $ticket_to_remove->delete_permanently();
1455
-        }
1456
-        return [$datetime, $saved_tickets];
1457
-    }
1458
-
1459
-
1460
-    /**
1461
-     * This attaches a list of given prices to a ticket.
1462
-     * Note we dont' have to worry about ever removing relationships (or archiving prices)
1463
-     * because if there is a change in price information on a ticket, a new ticket is created anyways
1464
-     * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1465
-     *
1466
-     * @access  private
1467
-     * @param array     $prices_data Array of prices from the form.
1468
-     * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1469
-     * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1470
-     * @return  void
1471
-     * @throws EE_Error
1472
-     * @throws ReflectionException
1473
-     */
1474
-    private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1475
-    {
1476
-        $timezone = $ticket->get_timezone();
1477
-        foreach ($prices_data as $row => $price_data) {
1478
-            $price_values = [
1479
-                'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1480
-                'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1481
-                'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1482
-                'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1483
-                'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1484
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1485
-                'PRC_order'      => $row,
1486
-            ];
1487
-            if ($new_prices || empty($price_values['PRC_ID'])) {
1488
-                $price_values['PRC_ID'] = 0;
1489
-                $price                  = EE_Price::new_instance($price_values, $timezone);
1490
-            } else {
1491
-                $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1492
-                // update this price with new values
1493
-                foreach ($price_values as $field => $new_price) {
1494
-                    $price->set($field, $new_price);
1495
-                }
1496
-            }
1497
-            if (! $price instanceof EE_Price) {
1498
-                throw new RuntimeException(
1499
-                    sprintf(
1500
-                        esc_html__(
1501
-                            'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1502
-                            'event_espresso'
1503
-                        ),
1504
-                        print_r($price_values, true)
1505
-                    )
1506
-                );
1507
-            }
1508
-            $price->save();
1509
-            $ticket->_add_relation_to($price, 'Price');
1510
-        }
1511
-    }
1512
-
1513
-
1514
-    /**
1515
-     * Add in our autosave ajax handlers
1516
-     *
1517
-     */
1518
-    protected function _ee_autosave_create_new()
1519
-    {
1520
-    }
1521
-
1522
-
1523
-    /**
1524
-     * More autosave handlers.
1525
-     */
1526
-    protected function _ee_autosave_edit()
1527
-    {
1528
-    }
1529
-
1530
-
1531
-    /**
1532
-     * @throws EE_Error
1533
-     * @throws ReflectionException
1534
-     */
1535
-    private function _generate_publish_box_extra_content()
1536
-    {
1537
-        // load formatter helper
1538
-        // args for getting related registrations
1539
-        $approved_query_args        = [
1540
-            [
1541
-                'REG_deleted' => 0,
1542
-                'STS_ID'      => EEM_Registration::status_id_approved,
1543
-            ],
1544
-        ];
1545
-        $not_approved_query_args    = [
1546
-            [
1547
-                'REG_deleted' => 0,
1548
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1549
-            ],
1550
-        ];
1551
-        $pending_payment_query_args = [
1552
-            [
1553
-                'REG_deleted' => 0,
1554
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1555
-            ],
1556
-        ];
1557
-        // publish box
1558
-        $publish_box_extra_args = [
1559
-            'view_approved_reg_url'        => add_query_arg(
1560
-                [
1561
-                    'action'      => 'default',
1562
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1563
-                    '_reg_status' => EEM_Registration::status_id_approved,
1564
-                ],
1565
-                REG_ADMIN_URL
1566
-            ),
1567
-            'view_not_approved_reg_url'    => add_query_arg(
1568
-                [
1569
-                    'action'      => 'default',
1570
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1571
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1572
-                ],
1573
-                REG_ADMIN_URL
1574
-            ),
1575
-            'view_pending_payment_reg_url' => add_query_arg(
1576
-                [
1577
-                    'action'      => 'default',
1578
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1579
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1580
-                ],
1581
-                REG_ADMIN_URL
1582
-            ),
1583
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1584
-                'Registration',
1585
-                $approved_query_args
1586
-            ),
1587
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1588
-                'Registration',
1589
-                $not_approved_query_args
1590
-            ),
1591
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1592
-                'Registration',
1593
-                $pending_payment_query_args
1594
-            ),
1595
-            'misc_pub_section_class'       => apply_filters(
1596
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1597
-                'misc-pub-section'
1598
-            ),
1599
-        ];
1600
-        ob_start();
1601
-        do_action(
1602
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1603
-            $this->_cpt_model_obj
1604
-        );
1605
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1606
-        // load template
1607
-        EEH_Template::display_template(
1608
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1609
-            $publish_box_extra_args
1610
-        );
1611
-    }
1612
-
1613
-
1614
-    /**
1615
-     * @return EE_Event
1616
-     */
1617
-    public function get_event_object()
1618
-    {
1619
-        return $this->_cpt_model_obj;
1620
-    }
1621
-
1622
-
1623
-
1624
-
1625
-    /** METABOXES * */
1626
-    /**
1627
-     * _register_event_editor_meta_boxes
1628
-     * add all metaboxes related to the event_editor
1629
-     *
1630
-     * @return void
1631
-     * @throws EE_Error
1632
-     * @throws ReflectionException
1633
-     */
1634
-    protected function _register_event_editor_meta_boxes()
1635
-    {
1636
-        $this->verify_cpt_object();
1637
-        $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1638
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1639
-        if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1640
-            $this->addMetaBox(
1641
-                'espresso_event_editor_event_options',
1642
-                esc_html__('Event Registration Options', 'event_espresso'),
1643
-                [$this, 'registration_options_meta_box'],
1644
-                $this->page_slug,
1645
-                'side'
1646
-            );
1647
-        }
1648
-        if (! $use_advanced_editor) {
1649
-            $this->addMetaBox(
1650
-                'espresso_event_editor_tickets',
1651
-                esc_html__('Event Datetime & Ticket', 'event_espresso'),
1652
-                [$this, 'ticket_metabox'],
1653
-                $this->page_slug,
1654
-                'normal',
1655
-                'high'
1656
-            );
1657
-        } elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1658
-            add_action(
1659
-                'add_meta_boxes_espresso_events',
1660
-                function () {
1661
-                    global $current_screen;
1662
-                    remove_meta_box('authordiv', $current_screen, 'normal');
1663
-                },
1664
-                99
1665
-            );
1666
-        }
1667
-        // NOTE: if you're looking for other metaboxes in here,
1668
-        // where a metabox has a related management page in the admin
1669
-        // you will find it setup in the related management page's "_Hooks" file.
1670
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1671
-    }
1672
-
1673
-
1674
-    /**
1675
-     * @throws DomainException
1676
-     * @throws EE_Error
1677
-     * @throws ReflectionException
1678
-     */
1679
-    public function ticket_metabox()
1680
-    {
1681
-        $existing_datetime_ids = $existing_ticket_ids = [];
1682
-        // defaults for template args
1683
-        $template_args = [
1684
-            'existing_datetime_ids'    => '',
1685
-            'event_datetime_help_link' => '',
1686
-            'ticket_options_help_link' => '',
1687
-            'time'                     => null,
1688
-            'ticket_rows'              => '',
1689
-            'existing_ticket_ids'      => '',
1690
-            'total_ticket_rows'        => 1,
1691
-            'ticket_js_structure'      => '',
1692
-            'trash_icon'               => 'dashicons dashicons-lock',
1693
-            'disabled'                 => '',
1694
-        ];
1695
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1696
-        /**
1697
-         * 1. Start with retrieving Datetimes
1698
-         * 2. Fore each datetime get related tickets
1699
-         * 3. For each ticket get related prices
1700
-         */
1701
-        /** @var EEM_Datetime $datetime_model */
1702
-        $datetime_model = EE_Registry::instance()->load_model('Datetime');
1703
-        /** @var EEM_Ticket $datetime_model */
1704
-        $ticket_model = EE_Registry::instance()->load_model('Ticket');
1705
-        $times        = $datetime_model->get_all_event_dates($event_id);
1706
-        /** @type EE_Datetime $first_datetime */
1707
-        $first_datetime = reset($times);
1708
-        // do we get related tickets?
1709
-        if (
1710
-            $first_datetime instanceof EE_Datetime
1711
-            && $first_datetime->ID() !== 0
1712
-        ) {
1713
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1714
-            $template_args['time']   = $first_datetime;
1715
-            $related_tickets         = $first_datetime->tickets(
1716
-                [
1717
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1718
-                    'default_where_conditions' => 'none',
1719
-                ]
1720
-            );
1721
-            if (! empty($related_tickets)) {
1722
-                $template_args['total_ticket_rows'] = count($related_tickets);
1723
-                $row                                = 0;
1724
-                foreach ($related_tickets as $ticket) {
1725
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1726
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1727
-                    $row++;
1728
-                }
1729
-            } else {
1730
-                $template_args['total_ticket_rows'] = 1;
1731
-                /** @type EE_Ticket $ticket */
1732
-                $ticket                       = $ticket_model->create_default_object();
1733
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1734
-            }
1735
-        } else {
1736
-            $template_args['time'] = $times[0];
1737
-            /** @type EE_Ticket[] $tickets */
1738
-            $tickets                      = $ticket_model->get_all_default_tickets();
1739
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1740
-            // NOTE: we're just sending the first default row
1741
-            // (decaf can't manage default tickets so this should be sufficient);
1742
-        }
1743
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1744
-            'event_editor_event_datetimes_help_tab'
1745
-        );
1746
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1747
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1748
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1749
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1750
-            $ticket_model->create_default_object(),
1751
-            true
1752
-        );
1753
-        $template                                  = apply_filters(
1754
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1755
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1756
-        );
1757
-        EEH_Template::display_template($template, $template_args);
1758
-    }
1759
-
1760
-
1761
-    /**
1762
-     * Setup an individual ticket form for the decaf event editor page
1763
-     *
1764
-     * @access private
1765
-     * @param EE_Ticket $ticket   the ticket object
1766
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1767
-     * @param int       $row
1768
-     * @return string generated html for the ticket row.
1769
-     * @throws EE_Error
1770
-     * @throws ReflectionException
1771
-     */
1772
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1773
-    {
1774
-        $template_args = [
1775
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1776
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1777
-                : '',
1778
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1779
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1780
-            'TKT_name'            => $ticket->get('TKT_name'),
1781
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1782
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1783
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1784
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1785
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1786
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1787
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1788
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1789
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock',
1790
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1791
-                : ' disabled=disabled',
1792
-        ];
1793
-        $price         = $ticket->ID() !== 0
1794
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1795
-            : null;
1796
-        $price         = $price instanceof EE_Price
1797
-            ? $price
1798
-            : EEM_Price::instance()->create_default_object();
1799
-        $price_args    = [
1800
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1801
-            'PRC_amount'            => $price->get('PRC_amount'),
1802
-            'PRT_ID'                => $price->get('PRT_ID'),
1803
-            'PRC_ID'                => $price->get('PRC_ID'),
1804
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1805
-        ];
1806
-        // make sure we have default start and end dates if skeleton
1807
-        // handle rows that should NOT be empty
1808
-        if (empty($template_args['TKT_start_date'])) {
1809
-            // if empty then the start date will be now.
1810
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1811
-        }
1812
-        if (empty($template_args['TKT_end_date'])) {
1813
-            // get the earliest datetime (if present);
1814
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1815
-                ? $this->_cpt_model_obj->get_first_related(
1816
-                    'Datetime',
1817
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1818
-                )
1819
-                : null;
1820
-            $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1821
-                ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1822
-                : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1823
-        }
1824
-        $template_args = array_merge($template_args, $price_args);
1825
-        $template      = apply_filters(
1826
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1827
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1828
-            $ticket
1829
-        );
1830
-        return EEH_Template::display_template($template, $template_args, true);
1831
-    }
1832
-
1833
-
1834
-    /**
1835
-     * @throws EE_Error
1836
-     * @throws ReflectionException
1837
-     */
1838
-    public function registration_options_meta_box()
1839
-    {
1840
-        $yes_no_values             = [
1841
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1842
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1843
-        ];
1844
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1845
-            [
1846
-                EEM_Registration::status_id_cancelled,
1847
-                EEM_Registration::status_id_declined,
1848
-                EEM_Registration::status_id_incomplete,
1849
-            ],
1850
-            true
1851
-        );
1852
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1853
-        $template_args['_event']                          = $this->_cpt_model_obj;
1854
-        $template_args['event']                           = $this->_cpt_model_obj;
1855
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1856
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1857
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1858
-            'default_reg_status',
1859
-            $default_reg_status_values,
1860
-            $this->_cpt_model_obj->default_registration_status()
1861
-        );
1862
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1863
-            'display_desc',
1864
-            $yes_no_values,
1865
-            $this->_cpt_model_obj->display_description()
1866
-        );
1867
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1868
-            'display_ticket_selector',
1869
-            $yes_no_values,
1870
-            $this->_cpt_model_obj->display_ticket_selector(),
1871
-            '',
1872
-            '',
1873
-            false
1874
-        );
1875
-        $template_args['additional_registration_options'] = apply_filters(
1876
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1877
-            '',
1878
-            $template_args,
1879
-            $yes_no_values,
1880
-            $default_reg_status_values
1881
-        );
1882
-        EEH_Template::display_template(
1883
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1884
-            $template_args
1885
-        );
1886
-    }
1887
-
1888
-
1889
-    /**
1890
-     * _get_events()
1891
-     * This method simply returns all the events (for the given _view and paging)
1892
-     *
1893
-     * @access public
1894
-     * @param int  $per_page     count of items per page (20 default);
1895
-     * @param int  $current_page what is the current page being viewed.
1896
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1897
-     *                           If FALSE then we return an array of event objects
1898
-     *                           that match the given _view and paging parameters.
1899
-     * @return array|int         an array of event objects or a count of them.
1900
-     * @throws Exception
1901
-     */
1902
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1903
-    {
1904
-        $EEM_Event   = $this->_event_model();
1905
-        $offset      = ($current_page - 1) * $per_page;
1906
-        $limit       = $count ? null : $offset . ',' . $per_page;
1907
-        $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1908
-        $order       = $this->request->getRequestParam('order', 'DESC');
1909
-        $month_range = $this->request->getRequestParam('month_range');
1910
-        if ($month_range) {
1911
-            $pieces = explode(' ', $month_range, 3);
1912
-            // simulate the FIRST day of the month, that fixes issues for months like February
1913
-            // where PHP doesn't know what to assume for date.
1914
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1915
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1916
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1917
-        }
1918
-        $where  = [];
1919
-        $status = $this->request->getRequestParam('status');
1920
-        // determine what post_status our condition will have for the query.
1921
-        switch ($status) {
1922
-            case 'month':
1923
-            case 'today':
1924
-            case null:
1925
-            case 'all':
1926
-                break;
1927
-            case 'draft':
1928
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1929
-                break;
1930
-            default:
1931
-                $where['status'] = $status;
1932
-        }
1933
-        // categories? The default for all categories is -1
1934
-        $category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1935
-        if ($category !== -1) {
1936
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1937
-            $where['Term_Taxonomy.term_id']  = $category;
1938
-        }
1939
-        // date where conditions
1940
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1941
-        if ($month_range) {
1942
-            $DateTime = new DateTime(
1943
-                $year_r . '-' . $month_r . '-01 00:00:00',
1944
-                new DateTimeZone('UTC')
1945
-            );
1946
-            $start    = $DateTime->getTimestamp();
1947
-            // set the datetime to be the end of the month
1948
-            $DateTime->setDate(
1949
-                $year_r,
1950
-                $month_r,
1951
-                $DateTime->format('t')
1952
-            )->setTime(23, 59, 59);
1953
-            $end                             = $DateTime->getTimestamp();
1954
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1955
-        } elseif ($status === 'today') {
1956
-            $DateTime                        =
1957
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1958
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1959
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1960
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1961
-        } elseif ($status === 'month') {
1962
-            $now                             = date('Y-m-01');
1963
-            $DateTime                        =
1964
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1965
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1966
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1967
-                                                        ->setTime(23, 59, 59)
1968
-                                                        ->format(implode(' ', $start_formats));
1969
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1970
-        }
1971
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1972
-            $where['EVT_wp_user'] = get_current_user_id();
1973
-        } else {
1974
-            if (! isset($where['status'])) {
1975
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1976
-                    $where['OR'] = [
1977
-                        'status*restrict_private' => ['!=', 'private'],
1978
-                        'AND'                     => [
1979
-                            'status*inclusive' => ['=', 'private'],
1980
-                            'EVT_wp_user'      => get_current_user_id(),
1981
-                        ],
1982
-                    ];
1983
-                }
1984
-            }
1985
-        }
1986
-        $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1987
-        if (
1988
-            $wp_user
1989
-            && $wp_user !== get_current_user_id()
1990
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1991
-        ) {
1992
-            $where['EVT_wp_user'] = $wp_user;
1993
-        }
1994
-        // search query handling
1995
-        $search_term = $this->request->getRequestParam('s');
1996
-        if ($search_term) {
1997
-            $search_term = '%' . $search_term . '%';
1998
-            $where['OR'] = [
1999
-                'EVT_name'       => ['LIKE', $search_term],
2000
-                'EVT_desc'       => ['LIKE', $search_term],
2001
-                'EVT_short_desc' => ['LIKE', $search_term],
2002
-            ];
2003
-        }
2004
-        // filter events by venue.
2005
-        $venue = $this->request->getRequestParam('venue', 0, 'int');
2006
-        if ($venue) {
2007
-            $where['Venue.VNU_ID'] = $venue;
2008
-        }
2009
-        $request_params = $this->request->requestParams();
2010
-        $where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2011
-        $query_params   = apply_filters(
2012
-            'FHEE__Events_Admin_Page__get_events__query_params',
2013
-            [
2014
-                $where,
2015
-                'limit'    => $limit,
2016
-                'order_by' => $orderby,
2017
-                'order'    => $order,
2018
-                'group_by' => 'EVT_ID',
2019
-            ],
2020
-            $request_params
2021
-        );
2022
-
2023
-        // let's first check if we have special requests coming in.
2024
-        $active_status = $this->request->getRequestParam('active_status');
2025
-        if ($active_status) {
2026
-            switch ($active_status) {
2027
-                case 'upcoming':
2028
-                    return $EEM_Event->get_upcoming_events($query_params, $count);
2029
-                case 'expired':
2030
-                    return $EEM_Event->get_expired_events($query_params, $count);
2031
-                case 'active':
2032
-                    return $EEM_Event->get_active_events($query_params, $count);
2033
-                case 'inactive':
2034
-                    return $EEM_Event->get_inactive_events($query_params, $count);
2035
-            }
2036
-        }
2037
-
2038
-        return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2039
-    }
2040
-
2041
-
2042
-    /**
2043
-     * handling for WordPress CPT actions (trash, restore, delete)
2044
-     *
2045
-     * @param string $post_id
2046
-     * @throws EE_Error
2047
-     * @throws ReflectionException
2048
-     */
2049
-    public function trash_cpt_item($post_id)
2050
-    {
2051
-        $this->request->setRequestParam('EVT_ID', $post_id);
2052
-        $this->_trash_or_restore_event('trash', false);
2053
-    }
2054
-
2055
-
2056
-    /**
2057
-     * @param string $post_id
2058
-     * @throws EE_Error
2059
-     * @throws ReflectionException
2060
-     */
2061
-    public function restore_cpt_item($post_id)
2062
-    {
2063
-        $this->request->setRequestParam('EVT_ID', $post_id);
2064
-        $this->_trash_or_restore_event('draft', false);
2065
-    }
2066
-
2067
-
2068
-    /**
2069
-     * @param string $post_id
2070
-     * @throws EE_Error
2071
-     * @throws EE_Error
2072
-     */
2073
-    public function delete_cpt_item($post_id)
2074
-    {
2075
-        throw new EE_Error(
2076
-            esc_html__(
2077
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2078
-                'event_espresso'
2079
-            )
2080
-        );
2081
-        // $this->request->setRequestParam('EVT_ID', $post_id);
2082
-        // $this->_delete_event();
2083
-    }
2084
-
2085
-
2086
-    /**
2087
-     * _trash_or_restore_event
2088
-     *
2089
-     * @access protected
2090
-     * @param string $event_status
2091
-     * @param bool   $redirect_after
2092
-     * @throws EE_Error
2093
-     * @throws EE_Error
2094
-     * @throws ReflectionException
2095
-     */
2096
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2097
-    {
2098
-        // determine the event id and set to array.
2099
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2100
-        // loop thru events
2101
-        if ($EVT_ID) {
2102
-            // clean status
2103
-            $event_status = sanitize_key($event_status);
2104
-            // grab status
2105
-            if (! empty($event_status)) {
2106
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2107
-            } else {
2108
-                $success = false;
2109
-                $msg     = esc_html__(
2110
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2111
-                    'event_espresso'
2112
-                );
2113
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2114
-            }
2115
-        } else {
2116
-            $success = false;
2117
-            $msg     = esc_html__(
2118
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2119
-                'event_espresso'
2120
-            );
2121
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2122
-        }
2123
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2124
-        if ($redirect_after) {
2125
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2126
-        }
2127
-    }
2128
-
2129
-
2130
-    /**
2131
-     * _trash_or_restore_events
2132
-     *
2133
-     * @access protected
2134
-     * @param string $event_status
2135
-     * @return void
2136
-     * @throws EE_Error
2137
-     * @throws EE_Error
2138
-     * @throws ReflectionException
2139
-     */
2140
-    protected function _trash_or_restore_events($event_status = 'trash')
2141
-    {
2142
-        // clean status
2143
-        $event_status = sanitize_key($event_status);
2144
-        // grab status
2145
-        if (! empty($event_status)) {
2146
-            $success = true;
2147
-            // determine the event id and set to array.
2148
-            $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2149
-            // loop thru events
2150
-            foreach ($EVT_IDs as $EVT_ID) {
2151
-                if ($EVT_ID = absint($EVT_ID)) {
2152
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2153
-                    $success = $results !== false ? $success : false;
2154
-                } else {
2155
-                    $msg = sprintf(
2156
-                        esc_html__(
2157
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2158
-                            'event_espresso'
2159
-                        ),
2160
-                        $EVT_ID
2161
-                    );
2162
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2163
-                    $success = false;
2164
-                }
2165
-            }
2166
-        } else {
2167
-            $success = false;
2168
-            $msg     = esc_html__(
2169
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2170
-                'event_espresso'
2171
-            );
2172
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2173
-        }
2174
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2175
-        $success = $success ? 2 : false;
2176
-        $action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2177
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2178
-    }
2179
-
2180
-
2181
-    /**
2182
-     * @param int    $EVT_ID
2183
-     * @param string $event_status
2184
-     * @return bool
2185
-     * @throws EE_Error
2186
-     * @throws ReflectionException
2187
-     */
2188
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2189
-    {
2190
-        // grab event id
2191
-        if (! $EVT_ID) {
2192
-            $msg = esc_html__(
2193
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2194
-                'event_espresso'
2195
-            );
2196
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2197
-            return false;
2198
-        }
2199
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2200
-        // clean status
2201
-        $event_status = sanitize_key($event_status);
2202
-        // grab status
2203
-        if (empty($event_status)) {
2204
-            $msg = esc_html__(
2205
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2206
-                'event_espresso'
2207
-            );
2208
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2209
-            return false;
2210
-        }
2211
-        // was event trashed or restored ?
2212
-        switch ($event_status) {
2213
-            case 'draft':
2214
-                $action = 'restored from the trash';
2215
-                $hook   = 'AHEE_event_restored_from_trash';
2216
-                break;
2217
-            case 'trash':
2218
-                $action = 'moved to the trash';
2219
-                $hook   = 'AHEE_event_moved_to_trash';
2220
-                break;
2221
-            default:
2222
-                $action = 'updated';
2223
-                $hook   = false;
2224
-        }
2225
-        // use class to change status
2226
-        $this->_cpt_model_obj->set_status($event_status);
2227
-        $success = $this->_cpt_model_obj->save();
2228
-        if (! $success) {
2229
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2230
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2231
-            return false;
2232
-        }
2233
-        if ($hook) {
2234
-            do_action($hook);
2235
-        }
2236
-        return true;
2237
-    }
2238
-
2239
-
2240
-    /**
2241
-     * @param array $event_ids
2242
-     * @return array
2243
-     * @since   4.10.23.p
2244
-     */
2245
-    private function cleanEventIds(array $event_ids)
2246
-    {
2247
-        return array_map('absint', $event_ids);
2248
-    }
2249
-
2250
-
2251
-    /**
2252
-     * @return array
2253
-     * @since   4.10.23.p
2254
-     */
2255
-    private function getEventIdsFromRequest()
2256
-    {
2257
-        if ($this->request->requestParamIsSet('EVT_IDs')) {
2258
-            return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2259
-        } else {
2260
-            return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2261
-        }
2262
-    }
2263
-
2264
-
2265
-    /**
2266
-     * @param bool $preview_delete
2267
-     * @throws EE_Error
2268
-     */
2269
-    protected function _delete_event($preview_delete = true)
2270
-    {
2271
-        $this->_delete_events($preview_delete);
2272
-    }
2273
-
2274
-
2275
-    /**
2276
-     * Gets the tree traversal batch persister.
2277
-     *
2278
-     * @return NodeGroupDao
2279
-     * @throws InvalidArgumentException
2280
-     * @throws InvalidDataTypeException
2281
-     * @throws InvalidInterfaceException
2282
-     * @since 4.10.12.p
2283
-     */
2284
-    protected function getModelObjNodeGroupPersister()
2285
-    {
2286
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2287
-            $this->model_obj_node_group_persister =
2288
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2289
-        }
2290
-        return $this->model_obj_node_group_persister;
2291
-    }
2292
-
2293
-
2294
-    /**
2295
-     * @param bool $preview_delete
2296
-     * @return void
2297
-     * @throws EE_Error
2298
-     */
2299
-    protected function _delete_events($preview_delete = true)
2300
-    {
2301
-        $event_ids = $this->getEventIdsFromRequest();
2302
-        if ($preview_delete) {
2303
-            $this->generateDeletionPreview($event_ids);
2304
-        } else {
2305
-            EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2306
-        }
2307
-    }
2308
-
2309
-
2310
-    /**
2311
-     * @param array $event_ids
2312
-     */
2313
-    protected function generateDeletionPreview(array $event_ids)
2314
-    {
2315
-        $event_ids = $this->cleanEventIds($event_ids);
2316
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2317
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2318
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2319
-            [
2320
-                'action'            => 'preview_deletion',
2321
-                'deletion_job_code' => $deletion_job_code,
2322
-            ],
2323
-            $this->_admin_base_url
2324
-        );
2325
-        EEH_URL::safeRedirectAndExit(
2326
-            EE_Admin_Page::add_query_args_and_nonce(
2327
-                [
2328
-                    'page'              => 'espresso_batch',
2329
-                    'batch'             => EED_Batch::batch_job,
2330
-                    'EVT_IDs'           => $event_ids,
2331
-                    'deletion_job_code' => $deletion_job_code,
2332
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2333
-                    'return_url'        => urlencode($return_url),
2334
-                ],
2335
-                admin_url()
2336
-            )
2337
-        );
2338
-    }
2339
-
2340
-
2341
-    /**
2342
-     * Checks for a POST submission
2343
-     *
2344
-     * @since 4.10.12.p
2345
-     */
2346
-    protected function confirmDeletion()
2347
-    {
2348
-        $deletion_redirect_logic =
2349
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2350
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2351
-    }
2352
-
2353
-
2354
-    /**
2355
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2356
-     *
2357
-     * @throws EE_Error
2358
-     * @since 4.10.12.p
2359
-     */
2360
-    protected function previewDeletion()
2361
-    {
2362
-        $preview_deletion_logic =
2363
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2364
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2365
-        $this->display_admin_page_with_no_sidebar();
2366
-    }
2367
-
2368
-
2369
-    /**
2370
-     * get total number of events
2371
-     *
2372
-     * @access public
2373
-     * @return int
2374
-     * @throws EE_Error
2375
-     * @throws EE_Error
2376
-     */
2377
-    public function total_events()
2378
-    {
2379
-        return EEM_Event::instance()->count(
2380
-            ['caps' => 'read_admin'],
2381
-            'EVT_ID',
2382
-            true
2383
-        );
2384
-    }
2385
-
2386
-
2387
-    /**
2388
-     * get total number of draft events
2389
-     *
2390
-     * @access public
2391
-     * @return int
2392
-     * @throws EE_Error
2393
-     * @throws EE_Error
2394
-     */
2395
-    public function total_events_draft()
2396
-    {
2397
-        return EEM_Event::instance()->count(
2398
-            [
2399
-                ['status' => ['IN', ['draft', 'auto-draft']]],
2400
-                'caps' => 'read_admin',
2401
-            ],
2402
-            'EVT_ID',
2403
-            true
2404
-        );
2405
-    }
2406
-
2407
-
2408
-    /**
2409
-     * get total number of trashed events
2410
-     *
2411
-     * @access public
2412
-     * @return int
2413
-     * @throws EE_Error
2414
-     * @throws EE_Error
2415
-     */
2416
-    public function total_trashed_events()
2417
-    {
2418
-        return EEM_Event::instance()->count(
2419
-            [
2420
-                ['status' => 'trash'],
2421
-                'caps' => 'read_admin',
2422
-            ],
2423
-            'EVT_ID',
2424
-            true
2425
-        );
2426
-    }
2427
-
2428
-
2429
-    /**
2430
-     *    _default_event_settings
2431
-     *    This generates the Default Settings Tab
2432
-     *
2433
-     * @return void
2434
-     * @throws DomainException
2435
-     * @throws EE_Error
2436
-     * @throws InvalidArgumentException
2437
-     * @throws InvalidDataTypeException
2438
-     * @throws InvalidInterfaceException
2439
-     */
2440
-    protected function _default_event_settings()
2441
-    {
2442
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2443
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2444
-        $this->_template_args['admin_page_content'] = EEH_HTML::div(
2445
-            $this->_default_event_settings_form()->get_html(),
2446
-            '',
2447
-            'padding'
2448
-        );
2449
-        $this->display_admin_page_with_sidebar();
2450
-    }
2451
-
2452
-
2453
-    /**
2454
-     * Return the form for event settings.
2455
-     *
2456
-     * @return EE_Form_Section_Proper
2457
-     * @throws EE_Error
2458
-     */
2459
-    protected function _default_event_settings_form()
2460
-    {
2461
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2462
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2463
-        // exclude
2464
-            [
2465
-                EEM_Registration::status_id_cancelled,
2466
-                EEM_Registration::status_id_declined,
2467
-                EEM_Registration::status_id_incomplete,
2468
-                EEM_Registration::status_id_wait_list,
2469
-            ],
2470
-            true
2471
-        );
2472
-        return new EE_Form_Section_Proper(
2473
-            [
2474
-                'name'            => 'update_default_event_settings',
2475
-                'html_id'         => 'update_default_event_settings',
2476
-                'html_class'      => 'form-table',
2477
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2478
-                'subsections'     => apply_filters(
2479
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2480
-                    [
2481
-                        'defaults_section_header' => new EE_Form_Section_HTML(
2482
-                            EEH_HTML::h2(
2483
-                                esc_html__('Default Settings', 'event_espresso'),
2484
-                                '',
2485
-                                'ee-admin-settings-hdr'
2486
-                            )
2487
-                        ),
2488
-                        'default_reg_status'  => new EE_Select_Input(
2489
-                            $registration_stati_for_selection,
2490
-                            [
2491
-                                'default'         => isset($registration_config->default_STS_ID)
2492
-                                                     && array_key_exists(
2493
-                                                         $registration_config->default_STS_ID,
2494
-                                                         $registration_stati_for_selection
2495
-                                                     )
2496
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2497
-                                    : EEM_Registration::status_id_pending_payment,
2498
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2499
-                                                     . EEH_Template::get_help_tab_link(
2500
-                                                         'default_settings_status_help_tab'
2501
-                                                     ),
2502
-                                'html_help_text'  => esc_html__(
2503
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2504
-                                    'event_espresso'
2505
-                                ),
2506
-                            ]
2507
-                        ),
2508
-                        'default_max_tickets' => new EE_Integer_Input(
2509
-                            [
2510
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2511
-                                    ? $registration_config->default_maximum_number_of_tickets
2512
-                                    : EEM_Event::get_default_additional_limit(),
2513
-                                'html_label_text' => esc_html__(
2514
-                                    'Default Maximum Tickets Allowed Per Order:',
2515
-                                    'event_espresso'
2516
-                                )
2517
-                                                     . EEH_Template::get_help_tab_link(
2518
-                                                         'default_maximum_tickets_help_tab"'
2519
-                                                     ),
2520
-                                'html_help_text'  => esc_html__(
2521
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2522
-                                    'event_espresso'
2523
-                                ),
2524
-                            ]
2525
-                        ),
2526
-                    ]
2527
-                ),
2528
-            ]
2529
-        );
2530
-    }
2531
-
2532
-
2533
-    /**
2534
-     * @return void
2535
-     * @throws EE_Error
2536
-     * @throws InvalidArgumentException
2537
-     * @throws InvalidDataTypeException
2538
-     * @throws InvalidInterfaceException
2539
-     */
2540
-    protected function _update_default_event_settings()
2541
-    {
2542
-        $form = $this->_default_event_settings_form();
2543
-        if ($form->was_submitted()) {
2544
-            $form->receive_form_submission();
2545
-            if ($form->is_valid()) {
2546
-                $registration_config = EE_Registry::instance()->CFG->registration;
2547
-                $valid_data          = $form->valid_data();
2548
-                if (isset($valid_data['default_reg_status'])) {
2549
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2550
-                }
2551
-                if (isset($valid_data['default_max_tickets'])) {
2552
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2553
-                }
2554
-                do_action(
2555
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2556
-                    $valid_data,
2557
-                    EE_Registry::instance()->CFG,
2558
-                    $this
2559
-                );
2560
-                // update because data was valid!
2561
-                EE_Registry::instance()->CFG->update_espresso_config();
2562
-                EE_Error::overwrite_success();
2563
-                EE_Error::add_success(
2564
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2565
-                );
2566
-            }
2567
-        }
2568
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2569
-    }
2570
-
2571
-
2572
-    /*************        Templates        *************
2573
-     *
2574
-     * @throws EE_Error
2575
-     */
2576
-    protected function _template_settings()
2577
-    {
2578
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2579
-        $this->_template_args['preview_img']  = '<img src="'
2580
-                                                . EVENTS_ASSETS_URL
2581
-                                                . '/images/'
2582
-                                                . 'caffeinated_template_features.jpg" alt="'
2583
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2584
-                                                . '" />';
2585
-        $this->_template_args['preview_text'] = '<strong>'
2586
-                                                . esc_html__(
2587
-                                                    'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2588
-                                                    'event_espresso'
2589
-                                                ) . '</strong>';
2590
-        $this->display_admin_caf_preview_page('template_settings_tab');
2591
-    }
2592
-
2593
-
2594
-    /** Event Category Stuff **/
2595
-    /**
2596
-     * set the _category property with the category object for the loaded page.
2597
-     *
2598
-     * @access private
2599
-     * @return void
2600
-     */
2601
-    private function _set_category_object()
2602
-    {
2603
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2604
-            return;
2605
-        } //already have the category object so get out.
2606
-        // set default category object
2607
-        $this->_set_empty_category_object();
2608
-        // only set if we've got an id
2609
-        $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2610
-        if (! $category_ID) {
2611
-            return;
2612
-        }
2613
-        $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2614
-        if (! empty($term)) {
2615
-            $this->_category->category_name       = $term->name;
2616
-            $this->_category->category_identifier = $term->slug;
2617
-            $this->_category->category_desc       = $term->description;
2618
-            $this->_category->id                  = $term->term_id;
2619
-            $this->_category->parent              = $term->parent;
2620
-        }
2621
-    }
2622
-
2623
-
2624
-    /**
2625
-     * Clears out category properties.
2626
-     */
2627
-    private function _set_empty_category_object()
2628
-    {
2629
-        $this->_category                = new stdClass();
2630
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2631
-        $this->_category->id            = $this->_category->parent = 0;
2632
-    }
2633
-
2634
-
2635
-    /**
2636
-     * @throws DomainException
2637
-     * @throws EE_Error
2638
-     * @throws InvalidArgumentException
2639
-     * @throws InvalidDataTypeException
2640
-     * @throws InvalidInterfaceException
2641
-     */
2642
-    protected function _category_list_table()
2643
-    {
2644
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2645
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2646
-        $this->_admin_page_title .= ' ';
2647
-        $this->_admin_page_title .= $this->get_action_link_or_button(
2648
-            'add_category',
2649
-            'add_category',
2650
-            [],
2651
-            'add-new-h2'
2652
-        );
2653
-        $this->display_admin_list_table_page_with_sidebar();
2654
-    }
2655
-
2656
-
2657
-    /**
2658
-     * Output category details view.
2659
-     *
2660
-     * @throws EE_Error
2661
-     * @throws EE_Error
2662
-     */
2663
-    protected function _category_details($view)
2664
-    {
2665
-        // load formatter helper
2666
-        // load field generator helper
2667
-        $route = $view === 'edit' ? 'update_category' : 'insert_category';
2668
-        $this->_set_add_edit_form_tags($route);
2669
-        $this->_set_category_object();
2670
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2671
-        $delete_action = 'delete_category';
2672
-        // custom redirect
2673
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2674
-            ['action' => 'category_list'],
2675
-            $this->_admin_base_url
2676
-        );
2677
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2678
-        // take care of contents
2679
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2680
-        $this->display_admin_page_with_sidebar();
2681
-    }
2682
-
2683
-
2684
-    /**
2685
-     * Output category details content.
2686
-     *
2687
-     * @throws DomainException
2688
-     */
2689
-    protected function _category_details_content()
2690
-    {
2691
-        $editor_args['category_desc'] = [
2692
-            'type'          => 'wp_editor',
2693
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2694
-            'class'         => 'my_editor_custom',
2695
-            'wpeditor_args' => ['media_buttons' => false],
2696
-        ];
2697
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2698
-        $all_terms                    = get_terms(
2699
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2700
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2701
-        );
2702
-        // setup category select for term parents.
2703
-        $category_select_values[] = [
2704
-            'text' => esc_html__('No Parent', 'event_espresso'),
2705
-            'id'   => 0,
2706
-        ];
2707
-        foreach ($all_terms as $term) {
2708
-            $category_select_values[] = [
2709
-                'text' => $term->name,
2710
-                'id'   => $term->term_id,
2711
-            ];
2712
-        }
2713
-        $category_select = EEH_Form_Fields::select_input(
2714
-            'category_parent',
2715
-            $category_select_values,
2716
-            $this->_category->parent
2717
-        );
2718
-        $template_args   = [
2719
-            'category'                 => $this->_category,
2720
-            'category_select'          => $category_select,
2721
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2722
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2723
-            'disable'                  => '',
2724
-            'disabled_message'         => false,
2725
-        ];
2726
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2727
-        return EEH_Template::display_template($template, $template_args, true);
2728
-    }
2729
-
2730
-
2731
-    /**
2732
-     * Handles deleting categories.
2733
-     *
2734
-     * @throws EE_Error
2735
-     */
2736
-    protected function _delete_categories()
2737
-    {
2738
-        $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2739
-        foreach ($category_IDs as $category_ID) {
2740
-            $this->_delete_category($category_ID);
2741
-        }
2742
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2743
-        $query_args = [
2744
-            'action' => 'category_list',
2745
-        ];
2746
-        $this->_redirect_after_action(0, '', '', $query_args);
2747
-    }
2748
-
2749
-
2750
-    /**
2751
-     * Handles deleting specific category.
2752
-     *
2753
-     * @param int $cat_id
2754
-     */
2755
-    protected function _delete_category($cat_id)
2756
-    {
2757
-        $cat_id = absint($cat_id);
2758
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2759
-    }
2760
-
2761
-
2762
-    /**
2763
-     * Handles triggering the update or insertion of a new category.
2764
-     *
2765
-     * @param bool $new_category true means we're triggering the insert of a new category.
2766
-     * @throws EE_Error
2767
-     * @throws EE_Error
2768
-     */
2769
-    protected function _insert_or_update_category($new_category)
2770
-    {
2771
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2772
-        $success = 0; // we already have a success message so lets not send another.
2773
-        if ($cat_id) {
2774
-            $query_args = [
2775
-                'action'     => 'edit_category',
2776
-                'EVT_CAT_ID' => $cat_id,
2777
-            ];
2778
-        } else {
2779
-            $query_args = ['action' => 'add_category'];
2780
-        }
2781
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2782
-    }
2783
-
2784
-
2785
-    /**
2786
-     * Inserts or updates category
2787
-     *
2788
-     * @param bool $update (true indicates we're updating a category).
2789
-     * @return bool|mixed|string
2790
-     */
2791
-    private function _insert_category($update = false)
2792
-    {
2793
-        $category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2794
-        $category_name       = $this->request->getRequestParam('category_name', '');
2795
-        $category_desc       = $this->request->getRequestParam('category_desc', '');
2796
-        $category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2797
-        $category_identifier = $this->request->getRequestParam('category_identifier', '');
2798
-
2799
-        if (empty($category_name)) {
2800
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2801
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2802
-            return false;
2803
-        }
2804
-        $term_args = [
2805
-            'name'        => $category_name,
2806
-            'description' => $category_desc,
2807
-            'parent'      => $category_parent,
2808
-        ];
2809
-        // was the category_identifier input disabled?
2810
-        if ($category_identifier) {
2811
-            $term_args['slug'] = $category_identifier;
2812
-        }
2813
-        $insert_ids = $update
2814
-            ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2815
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2816
-        if (! is_array($insert_ids)) {
2817
-            $msg = esc_html__(
2818
-                'An error occurred and the category has not been saved to the database.',
2819
-                'event_espresso'
2820
-            );
2821
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2822
-        } else {
2823
-            $category_ID = $insert_ids['term_id'];
2824
-            $msg         = sprintf(
2825
-                esc_html__('The category %s was successfully saved', 'event_espresso'),
2826
-                $category_name
2827
-            );
2828
-            EE_Error::add_success($msg);
2829
-        }
2830
-        return $category_ID;
2831
-    }
2832
-
2833
-
2834
-    /**
2835
-     * Gets categories or count of categories matching the arguments in the request.
2836
-     *
2837
-     * @param int  $per_page
2838
-     * @param int  $current_page
2839
-     * @param bool $count
2840
-     * @return EE_Term_Taxonomy[]|int
2841
-     * @throws EE_Error
2842
-     */
2843
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2844
-    {
2845
-        // testing term stuff
2846
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2847
-        $order       = $this->request->getRequestParam('order', 'DESC');
2848
-        $limit       = ($current_page - 1) * $per_page;
2849
-        $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2850
-        $search_term = $this->request->getRequestParam('s');
2851
-        if ($search_term) {
2852
-            $search_term = '%' . $search_term . '%';
2853
-            $where['OR'] = [
2854
-                'Term.name'   => ['LIKE', $search_term],
2855
-                'description' => ['LIKE', $search_term],
2856
-            ];
2857
-        }
2858
-        $query_params = [
2859
-            $where,
2860
-            'order_by'   => [$orderby => $order],
2861
-            'limit'      => $limit . ',' . $per_page,
2862
-            'force_join' => ['Term'],
2863
-        ];
2864
-        return $count
2865
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2866
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2867
-    }
2868
-
2869
-    /* end category stuff */
2870
-
2871
-
2872
-    /**************/
2873
-
2874
-
2875
-    /**
2876
-     * Callback for the `ee_save_timezone_setting` ajax action.
2877
-     *
2878
-     * @throws EE_Error
2879
-     * @throws InvalidArgumentException
2880
-     * @throws InvalidDataTypeException
2881
-     * @throws InvalidInterfaceException
2882
-     */
2883
-    public function saveTimezoneString()
2884
-    {
2885
-        $timezone_string = $this->request->getRequestParam('timezone_selected');
2886
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2887
-            EE_Error::add_error(
2888
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2889
-                __FILE__,
2890
-                __FUNCTION__,
2891
-                __LINE__
2892
-            );
2893
-            $this->_template_args['error'] = true;
2894
-            $this->_return_json();
2895
-        }
2896
-
2897
-        update_option('timezone_string', $timezone_string);
2898
-        EE_Error::add_success(
2899
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2900
-        );
2901
-        $this->_template_args['success'] = true;
2902
-        $this->_return_json(true, ['action' => 'create_new']);
2903
-    }
2904
-
2905
-
2906
-    /**
2907 2574
      * @throws EE_Error
2908
-     * @deprecated 4.10.25.p
2909 2575
      */
2910
-    public function save_timezonestring_setting()
2911
-    {
2912
-        $this->saveTimezoneString();
2913
-    }
2576
+	protected function _template_settings()
2577
+	{
2578
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2579
+		$this->_template_args['preview_img']  = '<img src="'
2580
+												. EVENTS_ASSETS_URL
2581
+												. '/images/'
2582
+												. 'caffeinated_template_features.jpg" alt="'
2583
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2584
+												. '" />';
2585
+		$this->_template_args['preview_text'] = '<strong>'
2586
+												. esc_html__(
2587
+													'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2588
+													'event_espresso'
2589
+												) . '</strong>';
2590
+		$this->display_admin_caf_preview_page('template_settings_tab');
2591
+	}
2592
+
2593
+
2594
+	/** Event Category Stuff **/
2595
+	/**
2596
+	 * set the _category property with the category object for the loaded page.
2597
+	 *
2598
+	 * @access private
2599
+	 * @return void
2600
+	 */
2601
+	private function _set_category_object()
2602
+	{
2603
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2604
+			return;
2605
+		} //already have the category object so get out.
2606
+		// set default category object
2607
+		$this->_set_empty_category_object();
2608
+		// only set if we've got an id
2609
+		$category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2610
+		if (! $category_ID) {
2611
+			return;
2612
+		}
2613
+		$term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2614
+		if (! empty($term)) {
2615
+			$this->_category->category_name       = $term->name;
2616
+			$this->_category->category_identifier = $term->slug;
2617
+			$this->_category->category_desc       = $term->description;
2618
+			$this->_category->id                  = $term->term_id;
2619
+			$this->_category->parent              = $term->parent;
2620
+		}
2621
+	}
2622
+
2623
+
2624
+	/**
2625
+	 * Clears out category properties.
2626
+	 */
2627
+	private function _set_empty_category_object()
2628
+	{
2629
+		$this->_category                = new stdClass();
2630
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2631
+		$this->_category->id            = $this->_category->parent = 0;
2632
+	}
2633
+
2634
+
2635
+	/**
2636
+	 * @throws DomainException
2637
+	 * @throws EE_Error
2638
+	 * @throws InvalidArgumentException
2639
+	 * @throws InvalidDataTypeException
2640
+	 * @throws InvalidInterfaceException
2641
+	 */
2642
+	protected function _category_list_table()
2643
+	{
2644
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2645
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2646
+		$this->_admin_page_title .= ' ';
2647
+		$this->_admin_page_title .= $this->get_action_link_or_button(
2648
+			'add_category',
2649
+			'add_category',
2650
+			[],
2651
+			'add-new-h2'
2652
+		);
2653
+		$this->display_admin_list_table_page_with_sidebar();
2654
+	}
2655
+
2656
+
2657
+	/**
2658
+	 * Output category details view.
2659
+	 *
2660
+	 * @throws EE_Error
2661
+	 * @throws EE_Error
2662
+	 */
2663
+	protected function _category_details($view)
2664
+	{
2665
+		// load formatter helper
2666
+		// load field generator helper
2667
+		$route = $view === 'edit' ? 'update_category' : 'insert_category';
2668
+		$this->_set_add_edit_form_tags($route);
2669
+		$this->_set_category_object();
2670
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2671
+		$delete_action = 'delete_category';
2672
+		// custom redirect
2673
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2674
+			['action' => 'category_list'],
2675
+			$this->_admin_base_url
2676
+		);
2677
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2678
+		// take care of contents
2679
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2680
+		$this->display_admin_page_with_sidebar();
2681
+	}
2682
+
2683
+
2684
+	/**
2685
+	 * Output category details content.
2686
+	 *
2687
+	 * @throws DomainException
2688
+	 */
2689
+	protected function _category_details_content()
2690
+	{
2691
+		$editor_args['category_desc'] = [
2692
+			'type'          => 'wp_editor',
2693
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2694
+			'class'         => 'my_editor_custom',
2695
+			'wpeditor_args' => ['media_buttons' => false],
2696
+		];
2697
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2698
+		$all_terms                    = get_terms(
2699
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2700
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2701
+		);
2702
+		// setup category select for term parents.
2703
+		$category_select_values[] = [
2704
+			'text' => esc_html__('No Parent', 'event_espresso'),
2705
+			'id'   => 0,
2706
+		];
2707
+		foreach ($all_terms as $term) {
2708
+			$category_select_values[] = [
2709
+				'text' => $term->name,
2710
+				'id'   => $term->term_id,
2711
+			];
2712
+		}
2713
+		$category_select = EEH_Form_Fields::select_input(
2714
+			'category_parent',
2715
+			$category_select_values,
2716
+			$this->_category->parent
2717
+		);
2718
+		$template_args   = [
2719
+			'category'                 => $this->_category,
2720
+			'category_select'          => $category_select,
2721
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2722
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2723
+			'disable'                  => '',
2724
+			'disabled_message'         => false,
2725
+		];
2726
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2727
+		return EEH_Template::display_template($template, $template_args, true);
2728
+	}
2729
+
2730
+
2731
+	/**
2732
+	 * Handles deleting categories.
2733
+	 *
2734
+	 * @throws EE_Error
2735
+	 */
2736
+	protected function _delete_categories()
2737
+	{
2738
+		$category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2739
+		foreach ($category_IDs as $category_ID) {
2740
+			$this->_delete_category($category_ID);
2741
+		}
2742
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2743
+		$query_args = [
2744
+			'action' => 'category_list',
2745
+		];
2746
+		$this->_redirect_after_action(0, '', '', $query_args);
2747
+	}
2748
+
2749
+
2750
+	/**
2751
+	 * Handles deleting specific category.
2752
+	 *
2753
+	 * @param int $cat_id
2754
+	 */
2755
+	protected function _delete_category($cat_id)
2756
+	{
2757
+		$cat_id = absint($cat_id);
2758
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2759
+	}
2760
+
2761
+
2762
+	/**
2763
+	 * Handles triggering the update or insertion of a new category.
2764
+	 *
2765
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2766
+	 * @throws EE_Error
2767
+	 * @throws EE_Error
2768
+	 */
2769
+	protected function _insert_or_update_category($new_category)
2770
+	{
2771
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2772
+		$success = 0; // we already have a success message so lets not send another.
2773
+		if ($cat_id) {
2774
+			$query_args = [
2775
+				'action'     => 'edit_category',
2776
+				'EVT_CAT_ID' => $cat_id,
2777
+			];
2778
+		} else {
2779
+			$query_args = ['action' => 'add_category'];
2780
+		}
2781
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2782
+	}
2783
+
2784
+
2785
+	/**
2786
+	 * Inserts or updates category
2787
+	 *
2788
+	 * @param bool $update (true indicates we're updating a category).
2789
+	 * @return bool|mixed|string
2790
+	 */
2791
+	private function _insert_category($update = false)
2792
+	{
2793
+		$category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2794
+		$category_name       = $this->request->getRequestParam('category_name', '');
2795
+		$category_desc       = $this->request->getRequestParam('category_desc', '');
2796
+		$category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2797
+		$category_identifier = $this->request->getRequestParam('category_identifier', '');
2798
+
2799
+		if (empty($category_name)) {
2800
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2801
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2802
+			return false;
2803
+		}
2804
+		$term_args = [
2805
+			'name'        => $category_name,
2806
+			'description' => $category_desc,
2807
+			'parent'      => $category_parent,
2808
+		];
2809
+		// was the category_identifier input disabled?
2810
+		if ($category_identifier) {
2811
+			$term_args['slug'] = $category_identifier;
2812
+		}
2813
+		$insert_ids = $update
2814
+			? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2815
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2816
+		if (! is_array($insert_ids)) {
2817
+			$msg = esc_html__(
2818
+				'An error occurred and the category has not been saved to the database.',
2819
+				'event_espresso'
2820
+			);
2821
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2822
+		} else {
2823
+			$category_ID = $insert_ids['term_id'];
2824
+			$msg         = sprintf(
2825
+				esc_html__('The category %s was successfully saved', 'event_espresso'),
2826
+				$category_name
2827
+			);
2828
+			EE_Error::add_success($msg);
2829
+		}
2830
+		return $category_ID;
2831
+	}
2832
+
2833
+
2834
+	/**
2835
+	 * Gets categories or count of categories matching the arguments in the request.
2836
+	 *
2837
+	 * @param int  $per_page
2838
+	 * @param int  $current_page
2839
+	 * @param bool $count
2840
+	 * @return EE_Term_Taxonomy[]|int
2841
+	 * @throws EE_Error
2842
+	 */
2843
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2844
+	{
2845
+		// testing term stuff
2846
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2847
+		$order       = $this->request->getRequestParam('order', 'DESC');
2848
+		$limit       = ($current_page - 1) * $per_page;
2849
+		$where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2850
+		$search_term = $this->request->getRequestParam('s');
2851
+		if ($search_term) {
2852
+			$search_term = '%' . $search_term . '%';
2853
+			$where['OR'] = [
2854
+				'Term.name'   => ['LIKE', $search_term],
2855
+				'description' => ['LIKE', $search_term],
2856
+			];
2857
+		}
2858
+		$query_params = [
2859
+			$where,
2860
+			'order_by'   => [$orderby => $order],
2861
+			'limit'      => $limit . ',' . $per_page,
2862
+			'force_join' => ['Term'],
2863
+		];
2864
+		return $count
2865
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2866
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2867
+	}
2868
+
2869
+	/* end category stuff */
2870
+
2871
+
2872
+	/**************/
2873
+
2874
+
2875
+	/**
2876
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2877
+	 *
2878
+	 * @throws EE_Error
2879
+	 * @throws InvalidArgumentException
2880
+	 * @throws InvalidDataTypeException
2881
+	 * @throws InvalidInterfaceException
2882
+	 */
2883
+	public function saveTimezoneString()
2884
+	{
2885
+		$timezone_string = $this->request->getRequestParam('timezone_selected');
2886
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2887
+			EE_Error::add_error(
2888
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2889
+				__FILE__,
2890
+				__FUNCTION__,
2891
+				__LINE__
2892
+			);
2893
+			$this->_template_args['error'] = true;
2894
+			$this->_return_json();
2895
+		}
2896
+
2897
+		update_option('timezone_string', $timezone_string);
2898
+		EE_Error::add_success(
2899
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2900
+		);
2901
+		$this->_template_args['success'] = true;
2902
+		$this->_return_json(true, ['action' => 'create_new']);
2903
+	}
2904
+
2905
+
2906
+	/**
2907
+	 * @throws EE_Error
2908
+	 * @deprecated 4.10.25.p
2909
+	 */
2910
+	public function save_timezonestring_setting()
2911
+	{
2912
+		$this->saveTimezoneString();
2913
+	}
2914 2914
 }
Please login to merge, or discard this patch.