Completed
Branch master (830cdc)
by
unknown
13:06 queued 10:49
created
core/helpers/EEH_Template.helper.php 2 patches
Indentation   +926 added lines, -926 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-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
-        $label = esc_html($label);
575
-        return "<a id='{$id}' href='{$url}' class='{$class}' title='{$title}'>{$icon_html}{$label}</a>";
576
-    }
577
-
578
-
579
-    /**
580
-     * This returns a generated link that will load the related help tab on admin pages.
581
-     *
582
-     * @param string      $help_tab_id the id for the connected help tab
583
-     * @param bool|string $page        The page identifier for the page the help tab is on
584
-     * @param bool|string $action      The action (route) for the admin page the help tab is on.
585
-     * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
586
-     * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
587
-     * @return string              generated link
588
-     */
589
-    public static function get_help_tab_link(
590
-        $help_tab_id,
591
-        $page = false,
592
-        $action = false,
593
-        $icon_style = false,
594
-        $help_text = false
595
-    ) {
596
-        global $allowedtags;
597
-        /** @var RequestInterface $request */
598
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
599
-        $page    = $page ?: $request->getRequestParam('page', '', 'key');
600
-        $action  = $action ?: $request->getRequestParam('action', 'default', 'key');
601
-
602
-
603
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
604
-        $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
605
-        $help_text    = ! $help_text ? '' : $help_text;
606
-        return '<a id="'
607
-               . esc_attr($help_tab_lnk)
608
-               . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'
609
-               . esc_attr($icon)
610
-               . '" title="'
611
-               . esc_attr__(
612
-                   'Click to open the \'Help\' tab for more information about this feature.',
613
-                   'event_espresso'
614
-               )
615
-               . '" > '
616
-               . wp_kses($help_text, $allowedtags)
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 = '
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-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
+		$label = esc_html($label);
575
+		return "<a id='{$id}' href='{$url}' class='{$class}' title='{$title}'>{$icon_html}{$label}</a>";
576
+	}
577
+
578
+
579
+	/**
580
+	 * This returns a generated link that will load the related help tab on admin pages.
581
+	 *
582
+	 * @param string      $help_tab_id the id for the connected help tab
583
+	 * @param bool|string $page        The page identifier for the page the help tab is on
584
+	 * @param bool|string $action      The action (route) for the admin page the help tab is on.
585
+	 * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
586
+	 * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
587
+	 * @return string              generated link
588
+	 */
589
+	public static function get_help_tab_link(
590
+		$help_tab_id,
591
+		$page = false,
592
+		$action = false,
593
+		$icon_style = false,
594
+		$help_text = false
595
+	) {
596
+		global $allowedtags;
597
+		/** @var RequestInterface $request */
598
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
599
+		$page    = $page ?: $request->getRequestParam('page', '', 'key');
600
+		$action  = $action ?: $request->getRequestParam('action', 'default', 'key');
601
+
602
+
603
+		$help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
604
+		$icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
605
+		$help_text    = ! $help_text ? '' : $help_text;
606
+		return '<a id="'
607
+			   . esc_attr($help_tab_lnk)
608
+			   . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'
609
+			   . esc_attr($icon)
610
+			   . '" title="'
611
+			   . esc_attr__(
612
+				   'Click to open the \'Help\' tab for more information about this feature.',
613
+				   'event_espresso'
614
+			   )
615
+			   . '" > '
616
+			   . wp_kses($help_text, $allowedtags)
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 = '
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-legend-' . $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
 }
993 993
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 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-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
         }
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
         $action  = $action ?: $request->getRequestParam('action', 'default', 'key');
601 601
 
602 602
 
603
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
603
+        $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id;
604 604
         $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
605 605
         $help_text    = ! $help_text ? '' : $help_text;
606 606
         return '<a id="'
@@ -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-legend-' . $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-legend-'.$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
 }
993 993
\ No newline at end of file
Please login to merge, or discard this patch.
core/EE_Config.core.php 1 patch
Indentation   +3178 added lines, -3178 removed lines patch added patch discarded remove patch
@@ -19,2546 +19,2546 @@  discard block
 block discarded – undo
19 19
 final class EE_Config implements ResettableInterface
20 20
 {
21 21
 
22
-    const OPTION_NAME = 'ee_config';
23
-
24
-    const LOG_NAME = 'ee_config_log';
25
-
26
-    const LOG_LENGTH = 100;
27
-
28
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
29
-
30
-    /**
31
-     *    instance of the EE_Config object
32
-     *
33
-     * @var    EE_Config $_instance
34
-     * @access    private
35
-     */
36
-    private static $_instance;
37
-
38
-    /**
39
-     * @var boolean $_logging_enabled
40
-     */
41
-    private static $_logging_enabled = false;
42
-
43
-    /**
44
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
45
-     */
46
-    private $legacy_shortcodes_manager;
47
-
48
-    /**
49
-     * An StdClass whose property names are addon slugs,
50
-     * and values are their config classes
51
-     *
52
-     * @var StdClass
53
-     */
54
-    public $addons;
55
-
56
-    /**
57
-     * @var EE_Admin_Config
58
-     */
59
-    public $admin;
60
-
61
-    /**
62
-     * @var EE_Core_Config
63
-     */
64
-    public $core;
65
-
66
-    /**
67
-     * @var EE_Currency_Config
68
-     */
69
-    public $currency;
70
-
71
-    /**
72
-     * @var EE_Organization_Config
73
-     */
74
-    public $organization;
75
-
76
-    /**
77
-     * @var EE_Registration_Config
78
-     */
79
-    public $registration;
80
-
81
-    /**
82
-     * @var EE_Template_Config
83
-     */
84
-    public $template_settings;
85
-
86
-    /**
87
-     * Holds EE environment values.
88
-     *
89
-     * @var EE_Environment_Config
90
-     */
91
-    public $environment;
92
-
93
-    /**
94
-     * settings pertaining to Google maps
95
-     *
96
-     * @var EE_Map_Config
97
-     */
98
-    public $map_settings;
99
-
100
-    /**
101
-     * settings pertaining to Taxes
102
-     *
103
-     * @var EE_Tax_Config
104
-     */
105
-    public $tax_settings;
106
-
107
-    /**
108
-     * Settings pertaining to global messages settings.
109
-     *
110
-     * @var EE_Messages_Config
111
-     */
112
-    public $messages;
113
-
114
-    /**
115
-     * @deprecated
116
-     * @var EE_Gateway_Config
117
-     */
118
-    public $gateway;
119
-
120
-    /**
121
-     * @var    array $_addon_option_names
122
-     * @access    private
123
-     */
124
-    private $_addon_option_names = array();
125
-
126
-    /**
127
-     * @var    array $_module_route_map
128
-     * @access    private
129
-     */
130
-    private static $_module_route_map = array();
131
-
132
-    /**
133
-     * @var    array $_module_forward_map
134
-     * @access    private
135
-     */
136
-    private static $_module_forward_map = array();
137
-
138
-    /**
139
-     * @var    array $_module_view_map
140
-     * @access    private
141
-     */
142
-    private static $_module_view_map = array();
143
-
144
-
145
-    /**
146
-     * @singleton method used to instantiate class object
147
-     * @access    public
148
-     * @return EE_Config instance
149
-     */
150
-    public static function instance()
151
-    {
152
-        // check if class object is instantiated, and instantiated properly
153
-        if (! self::$_instance instanceof EE_Config) {
154
-            self::$_instance = new self();
155
-        }
156
-        return self::$_instance;
157
-    }
158
-
159
-
160
-    /**
161
-     * Resets the config
162
-     *
163
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
164
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
165
-     *                               reflect its state in the database
166
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
167
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
168
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
169
-     *                               site was put into maintenance mode)
170
-     * @return EE_Config
171
-     */
172
-    public static function reset($hard_reset = false, $reinstantiate = true)
173
-    {
174
-        if (self::$_instance instanceof EE_Config) {
175
-            if ($hard_reset) {
176
-                self::$_instance->legacy_shortcodes_manager = null;
177
-                self::$_instance->_addon_option_names = array();
178
-                self::$_instance->_initialize_config();
179
-                self::$_instance->update_espresso_config();
180
-            }
181
-            self::$_instance->update_addon_option_names();
182
-        }
183
-        self::$_instance = null;
184
-        // we don't need to reset the static properties imo because those should
185
-        // only change when a module is added or removed. Currently we don't
186
-        // support removing a module during a request when it previously existed
187
-        if ($reinstantiate) {
188
-            return self::instance();
189
-        } else {
190
-            return null;
191
-        }
192
-    }
193
-
194
-
195
-    /**
196
-     *    class constructor
197
-     *
198
-     * @access    private
199
-     */
200
-    private function __construct()
201
-    {
202
-        do_action('AHEE__EE_Config__construct__begin', $this);
203
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
204
-        // setup empty config classes
205
-        $this->_initialize_config();
206
-        // load existing EE site settings
207
-        $this->_load_core_config();
208
-        // confirm everything loaded correctly and set filtered defaults if not
209
-        $this->_verify_config();
210
-        //  register shortcodes and modules
211
-        add_action(
212
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
213
-            array($this, 'register_shortcodes_and_modules'),
214
-            999
215
-        );
216
-        //  initialize shortcodes and modules
217
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
218
-        // register widgets
219
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
220
-        // shutdown
221
-        add_action('shutdown', array($this, 'shutdown'), 10);
222
-        // construct__end hook
223
-        do_action('AHEE__EE_Config__construct__end', $this);
224
-        // hardcoded hack
225
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
226
-    }
227
-
228
-
229
-    /**
230
-     * @return boolean
231
-     */
232
-    public static function logging_enabled()
233
-    {
234
-        return self::$_logging_enabled;
235
-    }
236
-
237
-
238
-    /**
239
-     * use to get the current theme if needed from static context
240
-     *
241
-     * @return string current theme set.
242
-     */
243
-    public static function get_current_theme()
244
-    {
245
-        return isset(self::$_instance->template_settings->current_espresso_theme)
246
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
247
-    }
248
-
249
-
250
-    /**
251
-     *        _initialize_config
252
-     *
253
-     * @access private
254
-     * @return void
255
-     */
256
-    private function _initialize_config()
257
-    {
258
-        EE_Config::trim_log();
259
-        // set defaults
260
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
261
-        $this->addons = new stdClass();
262
-        // set _module_route_map
263
-        EE_Config::$_module_route_map = array();
264
-        // set _module_forward_map
265
-        EE_Config::$_module_forward_map = array();
266
-        // set _module_view_map
267
-        EE_Config::$_module_view_map = array();
268
-    }
269
-
270
-
271
-    /**
272
-     *        load core plugin configuration
273
-     *
274
-     * @access private
275
-     * @return void
276
-     */
277
-    private function _load_core_config()
278
-    {
279
-        // load_core_config__start hook
280
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
281
-        $espresso_config = $this->get_espresso_config();
282
-        foreach ($espresso_config as $config => $settings) {
283
-            // load_core_config__start hook
284
-            $settings = apply_filters(
285
-                'FHEE__EE_Config___load_core_config__config_settings',
286
-                $settings,
287
-                $config,
288
-                $this
289
-            );
290
-            if (is_object($settings) && property_exists($this, $config)) {
291
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
292
-                // call configs populate method to ensure any defaults are set for empty values.
293
-                if (method_exists($settings, 'populate')) {
294
-                    $this->{$config}->populate();
295
-                }
296
-                if (method_exists($settings, 'do_hooks')) {
297
-                    $this->{$config}->do_hooks();
298
-                }
299
-            }
300
-        }
301
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
302
-            $this->update_espresso_config();
303
-        }
304
-        // load_core_config__end hook
305
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
306
-    }
307
-
308
-
309
-    /**
310
-     *    _verify_config
311
-     *
312
-     * @access    protected
313
-     * @return    void
314
-     */
315
-    protected function _verify_config()
316
-    {
317
-        $this->core = $this->core instanceof EE_Core_Config
318
-            ? $this->core
319
-            : new EE_Core_Config();
320
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
321
-        $this->organization = $this->organization instanceof EE_Organization_Config
322
-            ? $this->organization
323
-            : new EE_Organization_Config();
324
-        $this->organization = apply_filters(
325
-            'FHEE__EE_Config___initialize_config__organization',
326
-            $this->organization
327
-        );
328
-        $this->currency = $this->currency instanceof EE_Currency_Config
329
-            ? $this->currency
330
-            : new EE_Currency_Config();
331
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
332
-        $this->registration = $this->registration instanceof EE_Registration_Config
333
-            ? $this->registration
334
-            : new EE_Registration_Config();
335
-        $this->registration = apply_filters(
336
-            'FHEE__EE_Config___initialize_config__registration',
337
-            $this->registration
338
-        );
339
-        $this->admin = $this->admin instanceof EE_Admin_Config
340
-            ? $this->admin
341
-            : new EE_Admin_Config();
342
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
343
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
344
-            ? $this->template_settings
345
-            : new EE_Template_Config();
346
-        $this->template_settings = apply_filters(
347
-            'FHEE__EE_Config___initialize_config__template_settings',
348
-            $this->template_settings
349
-        );
350
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
351
-            ? $this->map_settings
352
-            : new EE_Map_Config();
353
-        $this->map_settings = apply_filters(
354
-            'FHEE__EE_Config___initialize_config__map_settings',
355
-            $this->map_settings
356
-        );
357
-        $this->environment = $this->environment instanceof EE_Environment_Config
358
-            ? $this->environment
359
-            : new EE_Environment_Config();
360
-        $this->environment = apply_filters(
361
-            'FHEE__EE_Config___initialize_config__environment',
362
-            $this->environment
363
-        );
364
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
365
-            ? $this->tax_settings
366
-            : new EE_Tax_Config();
367
-        $this->tax_settings = apply_filters(
368
-            'FHEE__EE_Config___initialize_config__tax_settings',
369
-            $this->tax_settings
370
-        );
371
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
372
-        $this->messages = $this->messages instanceof EE_Messages_Config
373
-            ? $this->messages
374
-            : new EE_Messages_Config();
375
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
376
-            ? $this->gateway
377
-            : new EE_Gateway_Config();
378
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
379
-        $this->legacy_shortcodes_manager = null;
380
-    }
381
-
382
-
383
-    /**
384
-     *    get_espresso_config
385
-     *
386
-     * @access    public
387
-     * @return    array of espresso config stuff
388
-     */
389
-    public function get_espresso_config()
390
-    {
391
-        // grab espresso configuration
392
-        return apply_filters(
393
-            'FHEE__EE_Config__get_espresso_config__CFG',
394
-            get_option(EE_Config::OPTION_NAME, array())
395
-        );
396
-    }
397
-
398
-
399
-    /**
400
-     *    double_check_config_comparison
401
-     *
402
-     * @access    public
403
-     * @param string $option
404
-     * @param        $old_value
405
-     * @param        $value
406
-     */
407
-    public function double_check_config_comparison($option = '', $old_value, $value)
408
-    {
409
-        // make sure we're checking the ee config
410
-        if ($option === EE_Config::OPTION_NAME) {
411
-            // run a loose comparison of the old value against the new value for type and properties,
412
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
413
-            if ($value != $old_value) {
414
-                // if they are NOT the same, then remove the hook,
415
-                // which means the subsequent update results will be based solely on the update query results
416
-                // the reason we do this is because, as stated above,
417
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
418
-                // this happens PRIOR to serialization and any subsequent update.
419
-                // If values are found to match their previous old value,
420
-                // then WP bails before performing any update.
421
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
422
-                // it just pulled from the db, with the one being passed to it (which will not match).
423
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
424
-                // MySQL MAY ALSO NOT perform the update because
425
-                // the string it sees in the db looks the same as the new one it has been passed!!!
426
-                // This results in the query returning an "affected rows" value of ZERO,
427
-                // which gets returned immediately by WP update_option and looks like an error.
428
-                remove_action('update_option', array($this, 'check_config_updated'));
429
-            }
430
-        }
431
-    }
432
-
433
-
434
-    /**
435
-     *    update_espresso_config
436
-     *
437
-     * @access   public
438
-     */
439
-    protected function _reset_espresso_addon_config()
440
-    {
441
-        $this->_addon_option_names = array();
442
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
443
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
444
-            if ($addon_config_obj instanceof EE_Config_Base) {
445
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
446
-            }
447
-            $this->addons->{$addon_name} = null;
448
-        }
449
-    }
450
-
451
-
452
-    /**
453
-     *    update_espresso_config
454
-     *
455
-     * @access   public
456
-     * @param   bool $add_success
457
-     * @param   bool $add_error
458
-     * @return   bool
459
-     */
460
-    public function update_espresso_config($add_success = false, $add_error = true)
461
-    {
462
-        // don't allow config updates during WP heartbeats
463
-        /** @var RequestInterface $request */
464
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
465
-        if ($request->isWordPressHeartbeat()) {
466
-            return false;
467
-        }
468
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
469
-        // $clone = clone( self::$_instance );
470
-        // self::$_instance = NULL;
471
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
472
-        $this->_reset_espresso_addon_config();
473
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
474
-        // but BEFORE the actual update occurs
475
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
476
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
477
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
478
-        $this->legacy_shortcodes_manager = null;
479
-        // now update "ee_config"
480
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
481
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
482
-        EE_Config::log(EE_Config::OPTION_NAME);
483
-        // if not saved... check if the hook we just added still exists;
484
-        // if it does, it means one of two things:
485
-        // that update_option bailed at the($value === $old_value) conditional,
486
-        // or...
487
-        // the db update query returned 0 rows affected
488
-        // (probably because the data  value was the same from it's perspective)
489
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
490
-        // but just means no update occurred, so don't display an error to the user.
491
-        // BUT... if update_option returns FALSE, AND the hook is missing,
492
-        // then it means that something truly went wrong
493
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
494
-        // remove our action since we don't want it in the system anymore
495
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
496
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
497
-        // self::$_instance = $clone;
498
-        // unset( $clone );
499
-        // if config remains the same or was updated successfully
500
-        if ($saved) {
501
-            if ($add_success) {
502
-                EE_Error::add_success(
503
-                    esc_html__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
504
-                    __FILE__,
505
-                    __FUNCTION__,
506
-                    __LINE__
507
-                );
508
-            }
509
-            return true;
510
-        } else {
511
-            if ($add_error) {
512
-                EE_Error::add_error(
513
-                    esc_html__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
514
-                    __FILE__,
515
-                    __FUNCTION__,
516
-                    __LINE__
517
-                );
518
-            }
519
-            return false;
520
-        }
521
-    }
522
-
523
-
524
-    /**
525
-     *    _verify_config_params
526
-     *
527
-     * @access    private
528
-     * @param    string         $section
529
-     * @param    string         $name
530
-     * @param    string         $config_class
531
-     * @param    EE_Config_Base $config_obj
532
-     * @param    array          $tests_to_run
533
-     * @param    bool           $display_errors
534
-     * @return    bool    TRUE on success, FALSE on fail
535
-     */
536
-    private function _verify_config_params(
537
-        $section = '',
538
-        $name = '',
539
-        $config_class = '',
540
-        $config_obj = null,
541
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
542
-        $display_errors = true
543
-    ) {
544
-        try {
545
-            foreach ($tests_to_run as $test) {
546
-                switch ($test) {
547
-                    // TEST #1 : check that section was set
548
-                    case 1:
549
-                        if (empty($section)) {
550
-                            if ($display_errors) {
551
-                                throw new EE_Error(
552
-                                    sprintf(
553
-                                        esc_html__(
554
-                                            'No configuration section has been provided while attempting to save "%s".',
555
-                                            'event_espresso'
556
-                                        ),
557
-                                        $config_class
558
-                                    )
559
-                                );
560
-                            }
561
-                            return false;
562
-                        }
563
-                        break;
564
-                    // TEST #2 : check that settings section exists
565
-                    case 2:
566
-                        if (! isset($this->{$section})) {
567
-                            if ($display_errors) {
568
-                                throw new EE_Error(
569
-                                    sprintf(
570
-                                        esc_html__('The "%s" configuration section does not exist.', 'event_espresso'),
571
-                                        $section
572
-                                    )
573
-                                );
574
-                            }
575
-                            return false;
576
-                        }
577
-                        break;
578
-                    // TEST #3 : check that section is the proper format
579
-                    case 3:
580
-                        if (
581
-                            ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
582
-                        ) {
583
-                            if ($display_errors) {
584
-                                throw new EE_Error(
585
-                                    sprintf(
586
-                                        esc_html__(
587
-                                            'The "%s" configuration settings have not been formatted correctly.',
588
-                                            'event_espresso'
589
-                                        ),
590
-                                        $section
591
-                                    )
592
-                                );
593
-                            }
594
-                            return false;
595
-                        }
596
-                        break;
597
-                    // TEST #4 : check that config section name has been set
598
-                    case 4:
599
-                        if (empty($name)) {
600
-                            if ($display_errors) {
601
-                                throw new EE_Error(
602
-                                    esc_html__(
603
-                                        'No name has been provided for the specific configuration section.',
604
-                                        'event_espresso'
605
-                                    )
606
-                                );
607
-                            }
608
-                            return false;
609
-                        }
610
-                        break;
611
-                    // TEST #5 : check that a config class name has been set
612
-                    case 5:
613
-                        if (empty($config_class)) {
614
-                            if ($display_errors) {
615
-                                throw new EE_Error(
616
-                                    esc_html__(
617
-                                        'No class name has been provided for the specific configuration section.',
618
-                                        'event_espresso'
619
-                                    )
620
-                                );
621
-                            }
622
-                            return false;
623
-                        }
624
-                        break;
625
-                    // TEST #6 : verify config class is accessible
626
-                    case 6:
627
-                        if (! class_exists($config_class)) {
628
-                            if ($display_errors) {
629
-                                throw new EE_Error(
630
-                                    sprintf(
631
-                                        esc_html__(
632
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
633
-                                            'event_espresso'
634
-                                        ),
635
-                                        $config_class
636
-                                    )
637
-                                );
638
-                            }
639
-                            return false;
640
-                        }
641
-                        break;
642
-                    // TEST #7 : check that config has even been set
643
-                    case 7:
644
-                        if (! isset($this->{$section}->{$name})) {
645
-                            if ($display_errors) {
646
-                                throw new EE_Error(
647
-                                    sprintf(
648
-                                        esc_html__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
649
-                                        $section,
650
-                                        $name
651
-                                    )
652
-                                );
653
-                            }
654
-                            return false;
655
-                        } else {
656
-                            // and make sure it's not serialized
657
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
658
-                        }
659
-                        break;
660
-                    // TEST #8 : check that config is the requested type
661
-                    case 8:
662
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
663
-                            if ($display_errors) {
664
-                                throw new EE_Error(
665
-                                    sprintf(
666
-                                        esc_html__(
667
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
668
-                                            'event_espresso'
669
-                                        ),
670
-                                        $section,
671
-                                        $name,
672
-                                        $config_class
673
-                                    )
674
-                                );
675
-                            }
676
-                            return false;
677
-                        }
678
-                        break;
679
-                    // TEST #9 : verify config object
680
-                    case 9:
681
-                        if (! $config_obj instanceof EE_Config_Base) {
682
-                            if ($display_errors) {
683
-                                throw new EE_Error(
684
-                                    sprintf(
685
-                                        esc_html__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
686
-                                        print_r($config_obj, true)
687
-                                    )
688
-                                );
689
-                            }
690
-                            return false;
691
-                        }
692
-                        break;
693
-                }
694
-            }
695
-        } catch (EE_Error $e) {
696
-            $e->get_error();
697
-        }
698
-        // you have successfully run the gauntlet
699
-        return true;
700
-    }
701
-
702
-
703
-    /**
704
-     *    _generate_config_option_name
705
-     *
706
-     * @access        protected
707
-     * @param        string $section
708
-     * @param        string $name
709
-     * @return        string
710
-     */
711
-    private function _generate_config_option_name($section = '', $name = '')
712
-    {
713
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
714
-    }
715
-
716
-
717
-    /**
718
-     *    _set_config_class
719
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
720
-     *
721
-     * @access    private
722
-     * @param    string $config_class
723
-     * @param    string $name
724
-     * @return    string
725
-     */
726
-    private function _set_config_class($config_class = '', $name = '')
727
-    {
728
-        return ! empty($config_class)
729
-            ? $config_class
730
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
731
-    }
732
-
733
-
734
-    /**
735
-     *    set_config
736
-     *
737
-     * @access    protected
738
-     * @param    string         $section
739
-     * @param    string         $name
740
-     * @param    string         $config_class
741
-     * @param    EE_Config_Base $config_obj
742
-     * @return    EE_Config_Base
743
-     */
744
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
745
-    {
746
-        // ensure config class is set to something
747
-        $config_class = $this->_set_config_class($config_class, $name);
748
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
749
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
750
-            return null;
751
-        }
752
-        $config_option_name = $this->_generate_config_option_name($section, $name);
753
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
754
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
755
-            $this->_addon_option_names[ $config_option_name ] = $config_class;
756
-            $this->update_addon_option_names();
757
-        }
758
-        // verify the incoming config object but suppress errors
759
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
760
-            $config_obj = new $config_class();
761
-        }
762
-        if (get_option($config_option_name)) {
763
-            EE_Config::log($config_option_name);
764
-            update_option($config_option_name, $config_obj);
765
-            $this->{$section}->{$name} = $config_obj;
766
-            return $this->{$section}->{$name};
767
-        } else {
768
-            // create a wp-option for this config
769
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
770
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
771
-                return $this->{$section}->{$name};
772
-            } else {
773
-                EE_Error::add_error(
774
-                    sprintf(esc_html__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
775
-                    __FILE__,
776
-                    __FUNCTION__,
777
-                    __LINE__
778
-                );
779
-                return null;
780
-            }
781
-        }
782
-    }
783
-
784
-
785
-    /**
786
-     *    update_config
787
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
788
-     *
789
-     * @access    public
790
-     * @param    string                $section
791
-     * @param    string                $name
792
-     * @param    EE_Config_Base|string $config_obj
793
-     * @param    bool                  $throw_errors
794
-     * @return    bool
795
-     */
796
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
797
-    {
798
-        // don't allow config updates during WP heartbeats
799
-        /** @var RequestInterface $request */
800
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
801
-        if ($request->isWordPressHeartbeat()) {
802
-            return false;
803
-        }
804
-        $config_obj = maybe_unserialize($config_obj);
805
-        // get class name of the incoming object
806
-        $config_class = get_class($config_obj);
807
-        // run tests 1-5 and 9 to verify config
808
-        if (
809
-            ! $this->_verify_config_params(
810
-                $section,
811
-                $name,
812
-                $config_class,
813
-                $config_obj,
814
-                array(1, 2, 3, 4, 7, 9)
815
-            )
816
-        ) {
817
-            return false;
818
-        }
819
-        $config_option_name = $this->_generate_config_option_name($section, $name);
820
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
821
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
822
-            // save new config to db
823
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
824
-                return true;
825
-            }
826
-        } else {
827
-            // first check if the record already exists
828
-            $existing_config = get_option($config_option_name);
829
-            $config_obj = serialize($config_obj);
830
-            // just return if db record is already up to date (NOT type safe comparison)
831
-            if ($existing_config == $config_obj) {
832
-                $this->{$section}->{$name} = $config_obj;
833
-                return true;
834
-            } elseif (update_option($config_option_name, $config_obj)) {
835
-                EE_Config::log($config_option_name);
836
-                // update wp-option for this config class
837
-                $this->{$section}->{$name} = $config_obj;
838
-                return true;
839
-            } elseif ($throw_errors) {
840
-                EE_Error::add_error(
841
-                    sprintf(
842
-                        esc_html__(
843
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
844
-                            'event_espresso'
845
-                        ),
846
-                        $config_class,
847
-                        'EE_Config->' . $section . '->' . $name
848
-                    ),
849
-                    __FILE__,
850
-                    __FUNCTION__,
851
-                    __LINE__
852
-                );
853
-            }
854
-        }
855
-        return false;
856
-    }
857
-
858
-
859
-    /**
860
-     *    get_config
861
-     *
862
-     * @access    public
863
-     * @param    string $section
864
-     * @param    string $name
865
-     * @param    string $config_class
866
-     * @return    mixed EE_Config_Base | NULL
867
-     */
868
-    public function get_config($section = '', $name = '', $config_class = '')
869
-    {
870
-        // ensure config class is set to something
871
-        $config_class = $this->_set_config_class($config_class, $name);
872
-        // run tests 1-4, 6 and 7 to verify that all params have been set
873
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
874
-            return null;
875
-        }
876
-        // now test if the requested config object exists, but suppress errors
877
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
878
-            // config already exists, so pass it back
879
-            return $this->{$section}->{$name};
880
-        }
881
-        // load config option from db if it exists
882
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
883
-        // verify the newly retrieved config object, but suppress errors
884
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
885
-            // config is good, so set it and pass it back
886
-            $this->{$section}->{$name} = $config_obj;
887
-            return $this->{$section}->{$name};
888
-        }
889
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
890
-        $config_obj = $this->set_config($section, $name, $config_class);
891
-        // verify the newly created config object
892
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
893
-            return $this->{$section}->{$name};
894
-        } else {
895
-            EE_Error::add_error(
896
-                sprintf(esc_html__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
897
-                __FILE__,
898
-                __FUNCTION__,
899
-                __LINE__
900
-            );
901
-        }
902
-        return null;
903
-    }
904
-
905
-
906
-    /**
907
-     *    get_config_option
908
-     *
909
-     * @access    public
910
-     * @param    string $config_option_name
911
-     * @return    mixed EE_Config_Base | FALSE
912
-     */
913
-    public function get_config_option($config_option_name = '')
914
-    {
915
-        // retrieve the wp-option for this config class.
916
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
917
-        if (empty($config_option)) {
918
-            EE_Config::log($config_option_name . '-NOT-FOUND');
919
-        }
920
-        return $config_option;
921
-    }
922
-
923
-
924
-    /**
925
-     * log
926
-     *
927
-     * @param string $config_option_name
928
-     */
929
-    public static function log($config_option_name = '')
930
-    {
931
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
932
-            $config_log = get_option(EE_Config::LOG_NAME, array());
933
-            /** @var RequestParams $request */
934
-            $request = LoaderFactory::getLoader()->getShared(RequestParams::class);
935
-            $config_log[ (string) microtime(true) ] = array(
936
-                'config_name' => $config_option_name,
937
-                'request'     => $request->requestParams(),
938
-            );
939
-            update_option(EE_Config::LOG_NAME, $config_log);
940
-        }
941
-    }
942
-
943
-
944
-    /**
945
-     * trim_log
946
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
947
-     */
948
-    public static function trim_log()
949
-    {
950
-        if (! EE_Config::logging_enabled()) {
951
-            return;
952
-        }
953
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
954
-        $log_length = count($config_log);
955
-        if ($log_length > EE_Config::LOG_LENGTH) {
956
-            ksort($config_log);
957
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
958
-            update_option(EE_Config::LOG_NAME, $config_log);
959
-        }
960
-    }
961
-
962
-
963
-    /**
964
-     *    get_page_for_posts
965
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
966
-     *    wp-option "page_for_posts", or "posts" if no page is selected
967
-     *
968
-     * @access    public
969
-     * @return    string
970
-     */
971
-    public static function get_page_for_posts()
972
-    {
973
-        $page_for_posts = get_option('page_for_posts');
974
-        if (! $page_for_posts) {
975
-            return 'posts';
976
-        }
977
-        global $wpdb;
978
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
979
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
980
-    }
981
-
982
-
983
-    /**
984
-     *    register_shortcodes_and_modules.
985
-     *    At this point, it's too early to tell if we're maintenance mode or not.
986
-     *    In fact, this is where we give modules a chance to let core know they exist
987
-     *    so they can help trigger maintenance mode if it's needed
988
-     *
989
-     * @access    public
990
-     * @return    void
991
-     */
992
-    public function register_shortcodes_and_modules()
993
-    {
994
-        // allow modules to set hooks for the rest of the system
995
-        EE_Registry::instance()->modules = $this->_register_modules();
996
-    }
997
-
998
-
999
-    /**
1000
-     *    initialize_shortcodes_and_modules
1001
-     *    meaning they can start adding their hooks to get stuff done
1002
-     *
1003
-     * @access    public
1004
-     * @return    void
1005
-     */
1006
-    public function initialize_shortcodes_and_modules()
1007
-    {
1008
-        // allow modules to set hooks for the rest of the system
1009
-        $this->_initialize_modules();
1010
-    }
1011
-
1012
-
1013
-    /**
1014
-     *    widgets_init
1015
-     *
1016
-     * @access private
1017
-     * @return void
1018
-     */
1019
-    public function widgets_init()
1020
-    {
1021
-        // only init widgets on admin pages when not in complete maintenance, and
1022
-        // on frontend when not in any maintenance mode
1023
-        if (
1024
-            ! EE_Maintenance_Mode::instance()->level()
1025
-            || (
1026
-                is_admin()
1027
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1028
-            )
1029
-        ) {
1030
-            // grab list of installed widgets
1031
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1032
-            // filter list of modules to register
1033
-            $widgets_to_register = apply_filters(
1034
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1035
-                $widgets_to_register
1036
-            );
1037
-            if (! empty($widgets_to_register)) {
1038
-                // cycle thru widget folders
1039
-                foreach ($widgets_to_register as $widget_path) {
1040
-                    // add to list of installed widget modules
1041
-                    EE_Config::register_ee_widget($widget_path);
1042
-                }
1043
-            }
1044
-            // filter list of installed modules
1045
-            EE_Registry::instance()->widgets = apply_filters(
1046
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1047
-                EE_Registry::instance()->widgets
1048
-            );
1049
-        }
1050
-    }
1051
-
1052
-
1053
-    /**
1054
-     *    register_ee_widget - makes core aware of this widget
1055
-     *
1056
-     * @access    public
1057
-     * @param    string $widget_path - full path up to and including widget folder
1058
-     * @return    void
1059
-     */
1060
-    public static function register_ee_widget($widget_path = null)
1061
-    {
1062
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1063
-        $widget_ext = '.widget.php';
1064
-        // make all separators match
1065
-        $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1066
-        // does the file path INCLUDE the actual file name as part of the path ?
1067
-        if (strpos($widget_path, $widget_ext) !== false) {
1068
-            // grab and shortcode file name from directory name and break apart at dots
1069
-            $file_name = explode('.', basename($widget_path));
1070
-            // take first segment from file name pieces and remove class prefix if it exists
1071
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1072
-            // sanitize shortcode directory name
1073
-            $widget = sanitize_key($widget);
1074
-            // now we need to rebuild the shortcode path
1075
-            $widget_path = explode('/', $widget_path);
1076
-            // remove last segment
1077
-            array_pop($widget_path);
1078
-            // glue it back together
1079
-            $widget_path = implode(DS, $widget_path);
1080
-        } else {
1081
-            // grab and sanitize widget directory name
1082
-            $widget = sanitize_key(basename($widget_path));
1083
-        }
1084
-        // create classname from widget directory name
1085
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1086
-        // add class prefix
1087
-        $widget_class = 'EEW_' . $widget;
1088
-        // does the widget exist ?
1089
-        if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1090
-            $msg = sprintf(
1091
-                esc_html__(
1092
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1093
-                    'event_espresso'
1094
-                ),
1095
-                $widget_class,
1096
-                $widget_path . '/' . $widget_class . $widget_ext
1097
-            );
1098
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1099
-            return;
1100
-        }
1101
-        // load the widget class file
1102
-        require_once($widget_path . '/' . $widget_class . $widget_ext);
1103
-        // verify that class exists
1104
-        if (! class_exists($widget_class)) {
1105
-            $msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1106
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1107
-            return;
1108
-        }
1109
-        register_widget($widget_class);
1110
-        // add to array of registered widgets
1111
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1112
-    }
1113
-
1114
-
1115
-    /**
1116
-     *        _register_modules
1117
-     *
1118
-     * @access private
1119
-     * @return array
1120
-     */
1121
-    private function _register_modules()
1122
-    {
1123
-        // grab list of installed modules
1124
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1125
-        // filter list of modules to register
1126
-        $modules_to_register = apply_filters(
1127
-            'FHEE__EE_Config__register_modules__modules_to_register',
1128
-            $modules_to_register
1129
-        );
1130
-        if (! empty($modules_to_register)) {
1131
-            // loop through folders
1132
-            foreach ($modules_to_register as $module_path) {
1133
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1134
-                if (
1135
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1136
-                    && $module_path !== EE_MODULES . 'gateways'
1137
-                ) {
1138
-                    // add to list of installed modules
1139
-                    EE_Config::register_module($module_path);
1140
-                }
1141
-            }
1142
-        }
1143
-        // filter list of installed modules
1144
-        return apply_filters(
1145
-            'FHEE__EE_Config___register_modules__installed_modules',
1146
-            EE_Registry::instance()->modules
1147
-        );
1148
-    }
1149
-
1150
-
1151
-    /**
1152
-     *    register_module - makes core aware of this module
1153
-     *
1154
-     * @access    public
1155
-     * @param    string $module_path - full path up to and including module folder
1156
-     * @return    bool
1157
-     */
1158
-    public static function register_module($module_path = null)
1159
-    {
1160
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1161
-        $module_ext = '.module.php';
1162
-        // make all separators match
1163
-        $module_path = str_replace(array('\\', '/'), '/', $module_path);
1164
-        // does the file path INCLUDE the actual file name as part of the path ?
1165
-        if (strpos($module_path, $module_ext) !== false) {
1166
-            // grab and shortcode file name from directory name and break apart at dots
1167
-            $module_file = explode('.', basename($module_path));
1168
-            // now we need to rebuild the shortcode path
1169
-            $module_path = explode('/', $module_path);
1170
-            // remove last segment
1171
-            array_pop($module_path);
1172
-            // glue it back together
1173
-            $module_path = implode('/', $module_path) . '/';
1174
-            // take first segment from file name pieces and sanitize it
1175
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1176
-            // ensure class prefix is added
1177
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1178
-        } else {
1179
-            // we need to generate the filename based off of the folder name
1180
-            // grab and sanitize module name
1181
-            $module = strtolower(basename($module_path));
1182
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1183
-            // like trailingslashit()
1184
-            $module_path = rtrim($module_path, '/') . '/';
1185
-            // create classname from module directory name
1186
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1187
-            // add class prefix
1188
-            $module_class = 'EED_' . $module;
1189
-        }
1190
-        // does the module exist ?
1191
-        if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1192
-            $msg = sprintf(
1193
-                esc_html__(
1194
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1195
-                    'event_espresso'
1196
-                ),
1197
-                $module
1198
-            );
1199
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1200
-            return false;
1201
-        }
1202
-        // load the module class file
1203
-        require_once($module_path . $module_class . $module_ext);
1204
-        // verify that class exists
1205
-        if (! class_exists($module_class)) {
1206
-            $msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1207
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1208
-            return false;
1209
-        }
1210
-        // add to array of registered modules
1211
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1212
-        do_action(
1213
-            'AHEE__EE_Config__register_module__complete',
1214
-            $module_class,
1215
-            EE_Registry::instance()->modules->{$module_class}
1216
-        );
1217
-        return true;
1218
-    }
1219
-
1220
-
1221
-    /**
1222
-     *    _initialize_modules
1223
-     *    allow modules to set hooks for the rest of the system
1224
-     *
1225
-     * @access private
1226
-     * @return void
1227
-     */
1228
-    private function _initialize_modules()
1229
-    {
1230
-        // cycle thru shortcode folders
1231
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1232
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1233
-            // which set hooks ?
1234
-            if (is_admin()) {
1235
-                // fire immediately
1236
-                call_user_func(array($module_class, 'set_hooks_admin'));
1237
-            } else {
1238
-                // delay until other systems are online
1239
-                add_action(
1240
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1241
-                    array($module_class, 'set_hooks')
1242
-                );
1243
-            }
1244
-        }
1245
-    }
1246
-
1247
-
1248
-    /**
1249
-     *    register_route - adds module method routes to route_map
1250
-     *
1251
-     * @access    public
1252
-     * @param    string $route       - "pretty" public alias for module method
1253
-     * @param    string $module      - module name (classname without EED_ prefix)
1254
-     * @param    string $method_name - the actual module method to be routed to
1255
-     * @param    string $key         - url param key indicating a route is being called
1256
-     * @return    bool
1257
-     */
1258
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1259
-    {
1260
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1261
-        $module = str_replace('EED_', '', $module);
1262
-        $module_class = 'EED_' . $module;
1263
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1264
-            $msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module);
1265
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1266
-            return false;
1267
-        }
1268
-        if (empty($route)) {
1269
-            $msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route);
1270
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1271
-            return false;
1272
-        }
1273
-        if (! method_exists('EED_' . $module, $method_name)) {
1274
-            $msg = sprintf(
1275
-                esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1276
-                $route
1277
-            );
1278
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1279
-            return false;
1280
-        }
1281
-        EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1282
-        return true;
1283
-    }
1284
-
1285
-
1286
-    /**
1287
-     *    get_route - get module method route
1288
-     *
1289
-     * @access    public
1290
-     * @param    string $route - "pretty" public alias for module method
1291
-     * @param    string $key   - url param key indicating a route is being called
1292
-     * @return    string
1293
-     */
1294
-    public static function get_route($route = null, $key = 'ee')
1295
-    {
1296
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1297
-        $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1298
-        if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1299
-            return EE_Config::$_module_route_map[ $key ][ $route ];
1300
-        }
1301
-        return null;
1302
-    }
1303
-
1304
-
1305
-    /**
1306
-     *    get_routes - get ALL module method routes
1307
-     *
1308
-     * @access    public
1309
-     * @return    array
1310
-     */
1311
-    public static function get_routes()
1312
-    {
1313
-        return EE_Config::$_module_route_map;
1314
-    }
1315
-
1316
-
1317
-    /**
1318
-     *    register_forward - allows modules to forward request to another module for further processing
1319
-     *
1320
-     * @access    public
1321
-     * @param    string       $route   - "pretty" public alias for module method
1322
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1323
-     *                                 class, allows different forwards to be served based on status
1324
-     * @param    array|string $forward - function name or array( class, method )
1325
-     * @param    string       $key     - url param key indicating a route is being called
1326
-     * @return    bool
1327
-     */
1328
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1329
-    {
1330
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1331
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1332
-            $msg = sprintf(
1333
-                esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'),
1334
-                $route
1335
-            );
1336
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1337
-            return false;
1338
-        }
1339
-        if (empty($forward)) {
1340
-            $msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route);
1341
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1342
-            return false;
1343
-        }
1344
-        if (is_array($forward)) {
1345
-            if (! isset($forward[1])) {
1346
-                $msg = sprintf(
1347
-                    esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1348
-                    $route
1349
-                );
1350
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1351
-                return false;
1352
-            }
1353
-            if (! method_exists($forward[0], $forward[1])) {
1354
-                $msg = sprintf(
1355
-                    esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1356
-                    $forward[1],
1357
-                    $route
1358
-                );
1359
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1360
-                return false;
1361
-            }
1362
-        } elseif (! function_exists($forward)) {
1363
-            $msg = sprintf(
1364
-                esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1365
-                $forward,
1366
-                $route
1367
-            );
1368
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1369
-            return false;
1370
-        }
1371
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1372
-        return true;
1373
-    }
1374
-
1375
-
1376
-    /**
1377
-     *    get_forward - get forwarding route
1378
-     *
1379
-     * @access    public
1380
-     * @param    string  $route  - "pretty" public alias for module method
1381
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1382
-     *                           allows different forwards to be served based on status
1383
-     * @param    string  $key    - url param key indicating a route is being called
1384
-     * @return    string
1385
-     */
1386
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1387
-    {
1388
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1389
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1390
-            return apply_filters(
1391
-                'FHEE__EE_Config__get_forward',
1392
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1393
-                $route,
1394
-                $status
1395
-            );
1396
-        }
1397
-        return null;
1398
-    }
1399
-
1400
-
1401
-    /**
1402
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1403
-     *    results
1404
-     *
1405
-     * @access    public
1406
-     * @param    string  $route  - "pretty" public alias for module method
1407
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1408
-     *                           allows different views to be served based on status
1409
-     * @param    string  $view
1410
-     * @param    string  $key    - url param key indicating a route is being called
1411
-     * @return    bool
1412
-     */
1413
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1414
-    {
1415
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1416
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1417
-            $msg = sprintf(
1418
-                esc_html__('The module route %s for this view has not been registered.', 'event_espresso'),
1419
-                $route
1420
-            );
1421
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1422
-            return false;
1423
-        }
1424
-        if (! is_readable($view)) {
1425
-            $msg = sprintf(
1426
-                esc_html__(
1427
-                    'The %s view file could not be found or is not readable due to file permissions.',
1428
-                    'event_espresso'
1429
-                ),
1430
-                $view
1431
-            );
1432
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1433
-            return false;
1434
-        }
1435
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1436
-        return true;
1437
-    }
1438
-
1439
-
1440
-    /**
1441
-     *    get_view - get view for route and status
1442
-     *
1443
-     * @access    public
1444
-     * @param    string  $route  - "pretty" public alias for module method
1445
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1446
-     *                           allows different views to be served based on status
1447
-     * @param    string  $key    - url param key indicating a route is being called
1448
-     * @return    string
1449
-     */
1450
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1451
-    {
1452
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1453
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1454
-            return apply_filters(
1455
-                'FHEE__EE_Config__get_view',
1456
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1457
-                $route,
1458
-                $status
1459
-            );
1460
-        }
1461
-        return null;
1462
-    }
1463
-
1464
-
1465
-    public function update_addon_option_names()
1466
-    {
1467
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1468
-    }
1469
-
1470
-
1471
-    public function shutdown()
1472
-    {
1473
-        $this->update_addon_option_names();
1474
-    }
1475
-
1476
-
1477
-    /**
1478
-     * @return LegacyShortcodesManager
1479
-     */
1480
-    public static function getLegacyShortcodesManager()
1481
-    {
1482
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1483
-            EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared(
1484
-                LegacyShortcodesManager::class
1485
-            );
1486
-        }
1487
-        return EE_Config::instance()->legacy_shortcodes_manager;
1488
-    }
1489
-
1490
-
1491
-    /**
1492
-     * register_shortcode - makes core aware of this shortcode
1493
-     *
1494
-     * @deprecated 4.9.26
1495
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1496
-     * @return    bool
1497
-     */
1498
-    public static function register_shortcode($shortcode_path = null)
1499
-    {
1500
-        EE_Error::doing_it_wrong(
1501
-            __METHOD__,
1502
-            esc_html__(
1503
-                'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1504
-                'event_espresso'
1505
-            ),
1506
-            '4.9.26'
1507
-        );
1508
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1509
-    }
1510
-}
1511
-
1512
-/**
1513
- * Base class used for config classes. These classes should generally not have
1514
- * magic functions in use, except we'll allow them to magically set and get stuff...
1515
- * basically, they should just be well-defined stdClasses
1516
- */
1517
-class EE_Config_Base
1518
-{
1519
-
1520
-    /**
1521
-     * Utility function for escaping the value of a property and returning.
1522
-     *
1523
-     * @param string $property property name (checks to see if exists).
1524
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1525
-     * @throws EE_Error
1526
-     */
1527
-    public function get_pretty($property)
1528
-    {
1529
-        if (! property_exists($this, $property)) {
1530
-            throw new EE_Error(
1531
-                sprintf(
1532
-                    esc_html__(
1533
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1534
-                        'event_espresso'
1535
-                    ),
1536
-                    get_class($this),
1537
-                    $property
1538
-                )
1539
-            );
1540
-        }
1541
-        // just handling escaping of strings for now.
1542
-        if (is_string($this->{$property})) {
1543
-            return stripslashes($this->{$property});
1544
-        }
1545
-        return $this->{$property};
1546
-    }
1547
-
1548
-
1549
-    public function populate()
1550
-    {
1551
-        // grab defaults via a new instance of this class.
1552
-        $class_name = get_class($this);
1553
-        $defaults = new $class_name();
1554
-        // loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1555
-        // default from our $defaults object.
1556
-        foreach (get_object_vars($defaults) as $property => $value) {
1557
-            if ($this->{$property} === null) {
1558
-                $this->{$property} = $value;
1559
-            }
1560
-        }
1561
-        // cleanup
1562
-        unset($defaults);
1563
-    }
1564
-
1565
-
1566
-    /**
1567
-     *        __isset
1568
-     *
1569
-     * @param $a
1570
-     * @return bool
1571
-     */
1572
-    public function __isset($a)
1573
-    {
1574
-        return false;
1575
-    }
1576
-
1577
-
1578
-    /**
1579
-     *        __unset
1580
-     *
1581
-     * @param $a
1582
-     * @return bool
1583
-     */
1584
-    public function __unset($a)
1585
-    {
1586
-        return false;
1587
-    }
1588
-
1589
-
1590
-    /**
1591
-     *        __clone
1592
-     */
1593
-    public function __clone()
1594
-    {
1595
-    }
1596
-
1597
-
1598
-    /**
1599
-     *        __wakeup
1600
-     */
1601
-    public function __wakeup()
1602
-    {
1603
-    }
1604
-
1605
-
1606
-    /**
1607
-     *        __destruct
1608
-     */
1609
-    public function __destruct()
1610
-    {
1611
-    }
1612
-}
1613
-
1614
-/**
1615
- * Class for defining what's in the EE_Config relating to registration settings
1616
- */
1617
-class EE_Core_Config extends EE_Config_Base
1618
-{
1619
-
1620
-    const OPTION_NAME_UXIP = 'ee_ueip_optin';
1621
-
1622
-
1623
-    public $current_blog_id;
1624
-
1625
-    public $ee_ueip_optin;
1626
-
1627
-    public $ee_ueip_has_notified;
1628
-
1629
-    /**
1630
-     * Not to be confused with the 4 critical page variables (See
1631
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1632
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1633
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1634
-     *
1635
-     * @var array
1636
-     */
1637
-    public $post_shortcodes;
1638
-
1639
-    public $module_route_map;
1640
-
1641
-    public $module_forward_map;
1642
-
1643
-    public $module_view_map;
1644
-
1645
-    /**
1646
-     * The next 4 vars are the IDs of critical EE pages.
1647
-     *
1648
-     * @var int
1649
-     */
1650
-    public $reg_page_id;
1651
-
1652
-    public $txn_page_id;
1653
-
1654
-    public $thank_you_page_id;
1655
-
1656
-    public $cancel_page_id;
1657
-
1658
-    /**
1659
-     * The next 4 vars are the URLs of critical EE pages.
1660
-     *
1661
-     * @var int
1662
-     */
1663
-    public $reg_page_url;
1664
-
1665
-    public $txn_page_url;
1666
-
1667
-    public $thank_you_page_url;
1668
-
1669
-    public $cancel_page_url;
1670
-
1671
-    /**
1672
-     * The next vars relate to the custom slugs for EE CPT routes
1673
-     */
1674
-    public $event_cpt_slug;
1675
-
1676
-    /**
1677
-     * This caches the _ee_ueip_option in case this config is reset in the same
1678
-     * request across blog switches in a multisite context.
1679
-     * Avoids extra queries to the db for this option.
1680
-     *
1681
-     * @var bool
1682
-     */
1683
-    public static $ee_ueip_option;
1684
-
1685
-
1686
-    /**
1687
-     *    class constructor
1688
-     *
1689
-     * @access    public
1690
-     */
1691
-    public function __construct()
1692
-    {
1693
-        // set default organization settings
1694
-        $this->current_blog_id = get_current_blog_id();
1695
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1696
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1697
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1698
-        $this->post_shortcodes = array();
1699
-        $this->module_route_map = array();
1700
-        $this->module_forward_map = array();
1701
-        $this->module_view_map = array();
1702
-        // critical EE page IDs
1703
-        $this->reg_page_id = 0;
1704
-        $this->txn_page_id = 0;
1705
-        $this->thank_you_page_id = 0;
1706
-        $this->cancel_page_id = 0;
1707
-        // critical EE page URLs
1708
-        $this->reg_page_url = '';
1709
-        $this->txn_page_url = '';
1710
-        $this->thank_you_page_url = '';
1711
-        $this->cancel_page_url = '';
1712
-        // cpt slugs
1713
-        $this->event_cpt_slug = esc_html__('events', 'event_espresso');
1714
-        // ueip constant check
1715
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1716
-            $this->ee_ueip_optin = false;
1717
-            $this->ee_ueip_has_notified = true;
1718
-        }
1719
-    }
1720
-
1721
-
1722
-    /**
1723
-     * @return array
1724
-     */
1725
-    public function get_critical_pages_array()
1726
-    {
1727
-        return array(
1728
-            $this->reg_page_id,
1729
-            $this->txn_page_id,
1730
-            $this->thank_you_page_id,
1731
-            $this->cancel_page_id,
1732
-        );
1733
-    }
1734
-
1735
-
1736
-    /**
1737
-     * @return array
1738
-     */
1739
-    public function get_critical_pages_shortcodes_array()
1740
-    {
1741
-        return array(
1742
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1743
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1744
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1745
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1746
-        );
1747
-    }
1748
-
1749
-
1750
-    /**
1751
-     *  gets/returns URL for EE reg_page
1752
-     *
1753
-     * @access    public
1754
-     * @return    string
1755
-     */
1756
-    public function reg_page_url()
1757
-    {
1758
-        if (! $this->reg_page_url) {
1759
-            $this->reg_page_url = add_query_arg(
1760
-                array('uts' => time()),
1761
-                get_permalink($this->reg_page_id)
1762
-            ) . '#checkout';
1763
-        }
1764
-        return $this->reg_page_url;
1765
-    }
1766
-
1767
-
1768
-    /**
1769
-     *  gets/returns URL for EE txn_page
1770
-     *
1771
-     * @param array $query_args like what gets passed to
1772
-     *                          add_query_arg() as the first argument
1773
-     * @access    public
1774
-     * @return    string
1775
-     */
1776
-    public function txn_page_url($query_args = array())
1777
-    {
1778
-        if (! $this->txn_page_url) {
1779
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1780
-        }
1781
-        if ($query_args) {
1782
-            return add_query_arg($query_args, $this->txn_page_url);
1783
-        } else {
1784
-            return $this->txn_page_url;
1785
-        }
1786
-    }
1787
-
1788
-
1789
-    /**
1790
-     *  gets/returns URL for EE thank_you_page
1791
-     *
1792
-     * @param array $query_args like what gets passed to
1793
-     *                          add_query_arg() as the first argument
1794
-     * @access    public
1795
-     * @return    string
1796
-     */
1797
-    public function thank_you_page_url($query_args = array())
1798
-    {
1799
-        if (! $this->thank_you_page_url) {
1800
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1801
-        }
1802
-        if ($query_args) {
1803
-            return add_query_arg($query_args, $this->thank_you_page_url);
1804
-        } else {
1805
-            return $this->thank_you_page_url;
1806
-        }
1807
-    }
1808
-
1809
-
1810
-    /**
1811
-     *  gets/returns URL for EE cancel_page
1812
-     *
1813
-     * @access    public
1814
-     * @return    string
1815
-     */
1816
-    public function cancel_page_url()
1817
-    {
1818
-        if (! $this->cancel_page_url) {
1819
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1820
-        }
1821
-        return $this->cancel_page_url;
1822
-    }
1823
-
1824
-
1825
-    /**
1826
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1827
-     *
1828
-     * @since 4.7.5
1829
-     */
1830
-    protected function _reset_urls()
1831
-    {
1832
-        $this->reg_page_url = '';
1833
-        $this->txn_page_url = '';
1834
-        $this->cancel_page_url = '';
1835
-        $this->thank_you_page_url = '';
1836
-    }
1837
-
1838
-
1839
-    /**
1840
-     * Used to return what the optin value is set for the EE User Experience Program.
1841
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1842
-     * on the main site only.
1843
-     *
1844
-     * @return bool
1845
-     */
1846
-    protected function _get_main_ee_ueip_optin()
1847
-    {
1848
-        // if this is the main site then we can just bypass our direct query.
1849
-        if (is_main_site()) {
1850
-            return get_option(self::OPTION_NAME_UXIP, false);
1851
-        }
1852
-        // is this already cached for this request?  If so use it.
1853
-        if (EE_Core_Config::$ee_ueip_option !== null) {
1854
-            return EE_Core_Config::$ee_ueip_option;
1855
-        }
1856
-        global $wpdb;
1857
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1858
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1859
-        $option = self::OPTION_NAME_UXIP;
1860
-        // set correct table for query
1861
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1862
-        // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1863
-        // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1864
-        // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1865
-        // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1866
-        // for the purpose of caching.
1867
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1868
-        if (false !== $pre) {
1869
-            EE_Core_Config::$ee_ueip_option = $pre;
1870
-            return EE_Core_Config::$ee_ueip_option;
1871
-        }
1872
-        $row = $wpdb->get_row(
1873
-            $wpdb->prepare(
1874
-                "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1875
-                $option
1876
-            )
1877
-        );
1878
-        if (is_object($row)) {
1879
-            $value = $row->option_value;
1880
-        } else { // option does not exist so use default.
1881
-            EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1882
-            return EE_Core_Config::$ee_ueip_option;
1883
-        }
1884
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1885
-        return EE_Core_Config::$ee_ueip_option;
1886
-    }
1887
-
1888
-
1889
-    /**
1890
-     * Utility function for escaping the value of a property and returning.
1891
-     *
1892
-     * @param string $property property name (checks to see if exists).
1893
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1894
-     * @throws EE_Error
1895
-     */
1896
-    public function get_pretty($property)
1897
-    {
1898
-        if ($property === self::OPTION_NAME_UXIP) {
1899
-            return $this->ee_ueip_optin ? 'yes' : 'no';
1900
-        }
1901
-        return parent::get_pretty($property);
1902
-    }
1903
-
1904
-
1905
-    /**
1906
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1907
-     * on the object.
1908
-     *
1909
-     * @return array
1910
-     */
1911
-    public function __sleep()
1912
-    {
1913
-        // reset all url properties
1914
-        $this->_reset_urls();
1915
-        // return what to save to db
1916
-        return array_keys(get_object_vars($this));
1917
-    }
1918
-}
1919
-
1920
-/**
1921
- * Config class for storing info on the Organization
1922
- */
1923
-class EE_Organization_Config extends EE_Config_Base
1924
-{
1925
-
1926
-    /**
1927
-     * @var string $name
1928
-     * eg EE4.1
1929
-     */
1930
-    public $name;
1931
-
1932
-    /**
1933
-     * @var string $address_1
1934
-     * eg 123 Onna Road
1935
-     */
1936
-    public $address_1 = '';
1937
-
1938
-    /**
1939
-     * @var string $address_2
1940
-     * eg PO Box 123
1941
-     */
1942
-    public $address_2 = '';
1943
-
1944
-    /**
1945
-     * @var string $city
1946
-     * eg Inna City
1947
-     */
1948
-    public $city = '';
1949
-
1950
-    /**
1951
-     * @var int $STA_ID
1952
-     * eg 4
1953
-     */
1954
-    public $STA_ID = 0;
1955
-
1956
-    /**
1957
-     * @var string $CNT_ISO
1958
-     * eg US
1959
-     */
1960
-    public $CNT_ISO = '';
1961
-
1962
-    /**
1963
-     * @var string $zip
1964
-     * eg 12345  or V1A 2B3
1965
-     */
1966
-    public $zip = '';
1967
-
1968
-    /**
1969
-     * @var string $email
1970
-     * eg [email protected]
1971
-     */
1972
-    public $email;
1973
-
1974
-    /**
1975
-     * @var string $phone
1976
-     * eg. 111-111-1111
1977
-     */
1978
-    public $phone = '';
1979
-
1980
-    /**
1981
-     * @var string $vat
1982
-     * VAT/Tax Number
1983
-     */
1984
-    public $vat = '';
1985
-
1986
-    /**
1987
-     * @var string $logo_url
1988
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1989
-     */
1990
-    public $logo_url = '';
1991
-
1992
-    /**
1993
-     * The below are all various properties for holding links to organization social network profiles
1994
-     *
1995
-     * @var string
1996
-     */
1997
-    /**
1998
-     * facebook (facebook.com/profile.name)
1999
-     *
2000
-     * @var string
2001
-     */
2002
-    public $facebook = '';
2003
-
2004
-    /**
2005
-     * twitter (twitter.com/twitter_handle)
2006
-     *
2007
-     * @var string
2008
-     */
2009
-    public $twitter = '';
2010
-
2011
-    /**
2012
-     * linkedin (linkedin.com/in/profile_name)
2013
-     *
2014
-     * @var string
2015
-     */
2016
-    public $linkedin = '';
2017
-
2018
-    /**
2019
-     * pinterest (www.pinterest.com/profile_name)
2020
-     *
2021
-     * @var string
2022
-     */
2023
-    public $pinterest = '';
2024
-
2025
-    /**
2026
-     * google+ (google.com/+profileName)
2027
-     *
2028
-     * @var string
2029
-     */
2030
-    public $google = '';
2031
-
2032
-    /**
2033
-     * instagram (instagram.com/handle)
2034
-     *
2035
-     * @var string
2036
-     */
2037
-    public $instagram = '';
2038
-
2039
-
2040
-    /**
2041
-     *    class constructor
2042
-     *
2043
-     * @access    public
2044
-     */
2045
-    public function __construct()
2046
-    {
2047
-        // set default organization settings
2048
-        // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2049
-        $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2050
-        $this->email = get_bloginfo('admin_email');
2051
-    }
2052
-}
2053
-
2054
-/**
2055
- * Class for defining what's in the EE_Config relating to currency
2056
- */
2057
-class EE_Currency_Config extends EE_Config_Base
2058
-{
2059
-
2060
-    /**
2061
-     * @var string $code
2062
-     * eg 'US'
2063
-     */
2064
-    public $code;
2065
-
2066
-    /**
2067
-     * @var string $name
2068
-     * eg 'Dollar'
2069
-     */
2070
-    public $name;
2071
-
2072
-    /**
2073
-     * plural name
2074
-     *
2075
-     * @var string $plural
2076
-     * eg 'Dollars'
2077
-     */
2078
-    public $plural;
2079
-
2080
-    /**
2081
-     * currency sign
2082
-     *
2083
-     * @var string $sign
2084
-     * eg '$'
2085
-     */
2086
-    public $sign;
2087
-
2088
-    /**
2089
-     * Whether the currency sign should come before the number or not
2090
-     *
2091
-     * @var boolean $sign_b4
2092
-     */
2093
-    public $sign_b4;
2094
-
2095
-    /**
2096
-     * How many digits should come after the decimal place
2097
-     *
2098
-     * @var int $dec_plc
2099
-     */
2100
-    public $dec_plc;
2101
-
2102
-    /**
2103
-     * Symbol to use for decimal mark
2104
-     *
2105
-     * @var string $dec_mrk
2106
-     * eg '.'
2107
-     */
2108
-    public $dec_mrk;
2109
-
2110
-    /**
2111
-     * Symbol to use for thousands
2112
-     *
2113
-     * @var string $thsnds
2114
-     * eg ','
2115
-     */
2116
-    public $thsnds;
2117
-
2118
-
2119
-    /**
2120
-     *    class constructor
2121
-     *
2122
-     * @access    public
2123
-     * @param string $CNT_ISO
2124
-     * @throws EE_Error
2125
-     * @throws ReflectionException
2126
-     */
2127
-    public function __construct($CNT_ISO = '')
2128
-    {
2129
-        /** @var TableAnalysis $table_analysis */
2130
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2131
-        // get country code from organization settings or use default
2132
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2133
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2134
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2135
-            : '';
2136
-        // but override if requested
2137
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2138
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2139
-        if (
2140
-            ! empty($CNT_ISO)
2141
-            && EE_Maintenance_Mode::instance()->models_can_query()
2142
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2143
-        ) {
2144
-            // retrieve the country settings from the db, just in case they have been customized
2145
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2146
-            if ($country instanceof EE_Country) {
2147
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2148
-                $this->name = $country->currency_name_single();    // Dollar
2149
-                $this->plural = $country->currency_name_plural();    // Dollars
2150
-                $this->sign = $country->currency_sign();            // currency sign: $
2151
-                $this->sign_b4 = $country->currency_sign_before(
2152
-                );        // currency sign before or after: $TRUE  or  FALSE$
2153
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2154
-                $this->dec_mrk = $country->currency_decimal_mark(
2155
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2156
-                $this->thsnds = $country->currency_thousands_separator(
2157
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2158
-            }
2159
-        }
2160
-        // fallback to hardcoded defaults, in case the above failed
2161
-        if (empty($this->code)) {
2162
-            // set default currency settings
2163
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2164
-            $this->name = esc_html__('Dollar', 'event_espresso');    // Dollar
2165
-            $this->plural = esc_html__('Dollars', 'event_espresso');    // Dollars
2166
-            $this->sign = '$';    // currency sign: $
2167
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2168
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2169
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2170
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2171
-        }
2172
-    }
2173
-}
2174
-
2175
-/**
2176
- * Class for defining what's in the EE_Config relating to registration settings
2177
- */
2178
-class EE_Registration_Config extends EE_Config_Base
2179
-{
2180
-
2181
-    /**
2182
-     * Default registration status
2183
-     *
2184
-     * @var string $default_STS_ID
2185
-     * eg 'RPP'
2186
-     */
2187
-    public $default_STS_ID;
2188
-
2189
-    /**
2190
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2191
-     * registrations)
2192
-     *
2193
-     * @var int
2194
-     */
2195
-    public $default_maximum_number_of_tickets;
2196
-
2197
-    /**
2198
-     * level of validation to apply to email addresses
2199
-     *
2200
-     * @var string $email_validation_level
2201
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2202
-     */
2203
-    public $email_validation_level;
2204
-
2205
-    /**
2206
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2207
-     *
2208
-     * @var boolean $show_pending_payment_options
2209
-     */
2210
-    public $show_pending_payment_options;
2211
-
2212
-    /**
2213
-     * Whether to skip the registration confirmation page
2214
-     *
2215
-     * @var boolean $skip_reg_confirmation
2216
-     */
2217
-    public $skip_reg_confirmation;
2218
-
2219
-    /**
2220
-     * an array of SPCO reg steps where:
2221
-     *        the keys denotes the reg step order
2222
-     *        each element consists of an array with the following elements:
2223
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2224
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2225
-     *            "slug" => the URL param used to trigger the reg step
2226
-     *
2227
-     * @var array $reg_steps
2228
-     */
2229
-    public $reg_steps;
2230
-
2231
-    /**
2232
-     * Whether registration confirmation should be the last page of SPCO
2233
-     *
2234
-     * @var boolean $reg_confirmation_last
2235
-     */
2236
-    public $reg_confirmation_last;
2237
-
2238
-    /**
2239
-     * Whether or not to enable the EE Bot Trap
2240
-     *
2241
-     * @var boolean $use_bot_trap
2242
-     */
2243
-    public $use_bot_trap;
2244
-
2245
-    /**
2246
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2247
-     *
2248
-     * @var boolean $use_encryption
2249
-     */
2250
-    public $use_encryption;
2251
-
2252
-    /**
2253
-     * Whether or not to use ReCaptcha
2254
-     *
2255
-     * @var boolean $use_captcha
2256
-     */
2257
-    public $use_captcha;
2258
-
2259
-    /**
2260
-     * ReCaptcha Theme
2261
-     *
2262
-     * @var string $recaptcha_theme
2263
-     *    options: 'dark', 'light', 'invisible'
2264
-     */
2265
-    public $recaptcha_theme;
2266
-
2267
-    /**
2268
-     * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2269
-     *
2270
-     * @var string $recaptcha_badge
2271
-     *    options: 'bottomright', 'bottomleft', 'inline'
2272
-     */
2273
-    public $recaptcha_badge;
22
+	const OPTION_NAME = 'ee_config';
23
+
24
+	const LOG_NAME = 'ee_config_log';
25
+
26
+	const LOG_LENGTH = 100;
27
+
28
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
29
+
30
+	/**
31
+	 *    instance of the EE_Config object
32
+	 *
33
+	 * @var    EE_Config $_instance
34
+	 * @access    private
35
+	 */
36
+	private static $_instance;
37
+
38
+	/**
39
+	 * @var boolean $_logging_enabled
40
+	 */
41
+	private static $_logging_enabled = false;
42
+
43
+	/**
44
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
45
+	 */
46
+	private $legacy_shortcodes_manager;
47
+
48
+	/**
49
+	 * An StdClass whose property names are addon slugs,
50
+	 * and values are their config classes
51
+	 *
52
+	 * @var StdClass
53
+	 */
54
+	public $addons;
55
+
56
+	/**
57
+	 * @var EE_Admin_Config
58
+	 */
59
+	public $admin;
60
+
61
+	/**
62
+	 * @var EE_Core_Config
63
+	 */
64
+	public $core;
65
+
66
+	/**
67
+	 * @var EE_Currency_Config
68
+	 */
69
+	public $currency;
70
+
71
+	/**
72
+	 * @var EE_Organization_Config
73
+	 */
74
+	public $organization;
75
+
76
+	/**
77
+	 * @var EE_Registration_Config
78
+	 */
79
+	public $registration;
80
+
81
+	/**
82
+	 * @var EE_Template_Config
83
+	 */
84
+	public $template_settings;
85
+
86
+	/**
87
+	 * Holds EE environment values.
88
+	 *
89
+	 * @var EE_Environment_Config
90
+	 */
91
+	public $environment;
92
+
93
+	/**
94
+	 * settings pertaining to Google maps
95
+	 *
96
+	 * @var EE_Map_Config
97
+	 */
98
+	public $map_settings;
99
+
100
+	/**
101
+	 * settings pertaining to Taxes
102
+	 *
103
+	 * @var EE_Tax_Config
104
+	 */
105
+	public $tax_settings;
106
+
107
+	/**
108
+	 * Settings pertaining to global messages settings.
109
+	 *
110
+	 * @var EE_Messages_Config
111
+	 */
112
+	public $messages;
113
+
114
+	/**
115
+	 * @deprecated
116
+	 * @var EE_Gateway_Config
117
+	 */
118
+	public $gateway;
119
+
120
+	/**
121
+	 * @var    array $_addon_option_names
122
+	 * @access    private
123
+	 */
124
+	private $_addon_option_names = array();
125
+
126
+	/**
127
+	 * @var    array $_module_route_map
128
+	 * @access    private
129
+	 */
130
+	private static $_module_route_map = array();
131
+
132
+	/**
133
+	 * @var    array $_module_forward_map
134
+	 * @access    private
135
+	 */
136
+	private static $_module_forward_map = array();
137
+
138
+	/**
139
+	 * @var    array $_module_view_map
140
+	 * @access    private
141
+	 */
142
+	private static $_module_view_map = array();
143
+
144
+
145
+	/**
146
+	 * @singleton method used to instantiate class object
147
+	 * @access    public
148
+	 * @return EE_Config instance
149
+	 */
150
+	public static function instance()
151
+	{
152
+		// check if class object is instantiated, and instantiated properly
153
+		if (! self::$_instance instanceof EE_Config) {
154
+			self::$_instance = new self();
155
+		}
156
+		return self::$_instance;
157
+	}
158
+
159
+
160
+	/**
161
+	 * Resets the config
162
+	 *
163
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
164
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
165
+	 *                               reflect its state in the database
166
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
167
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
168
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
169
+	 *                               site was put into maintenance mode)
170
+	 * @return EE_Config
171
+	 */
172
+	public static function reset($hard_reset = false, $reinstantiate = true)
173
+	{
174
+		if (self::$_instance instanceof EE_Config) {
175
+			if ($hard_reset) {
176
+				self::$_instance->legacy_shortcodes_manager = null;
177
+				self::$_instance->_addon_option_names = array();
178
+				self::$_instance->_initialize_config();
179
+				self::$_instance->update_espresso_config();
180
+			}
181
+			self::$_instance->update_addon_option_names();
182
+		}
183
+		self::$_instance = null;
184
+		// we don't need to reset the static properties imo because those should
185
+		// only change when a module is added or removed. Currently we don't
186
+		// support removing a module during a request when it previously existed
187
+		if ($reinstantiate) {
188
+			return self::instance();
189
+		} else {
190
+			return null;
191
+		}
192
+	}
193
+
194
+
195
+	/**
196
+	 *    class constructor
197
+	 *
198
+	 * @access    private
199
+	 */
200
+	private function __construct()
201
+	{
202
+		do_action('AHEE__EE_Config__construct__begin', $this);
203
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
204
+		// setup empty config classes
205
+		$this->_initialize_config();
206
+		// load existing EE site settings
207
+		$this->_load_core_config();
208
+		// confirm everything loaded correctly and set filtered defaults if not
209
+		$this->_verify_config();
210
+		//  register shortcodes and modules
211
+		add_action(
212
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
213
+			array($this, 'register_shortcodes_and_modules'),
214
+			999
215
+		);
216
+		//  initialize shortcodes and modules
217
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
218
+		// register widgets
219
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
220
+		// shutdown
221
+		add_action('shutdown', array($this, 'shutdown'), 10);
222
+		// construct__end hook
223
+		do_action('AHEE__EE_Config__construct__end', $this);
224
+		// hardcoded hack
225
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
226
+	}
227
+
228
+
229
+	/**
230
+	 * @return boolean
231
+	 */
232
+	public static function logging_enabled()
233
+	{
234
+		return self::$_logging_enabled;
235
+	}
236
+
237
+
238
+	/**
239
+	 * use to get the current theme if needed from static context
240
+	 *
241
+	 * @return string current theme set.
242
+	 */
243
+	public static function get_current_theme()
244
+	{
245
+		return isset(self::$_instance->template_settings->current_espresso_theme)
246
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
247
+	}
248
+
249
+
250
+	/**
251
+	 *        _initialize_config
252
+	 *
253
+	 * @access private
254
+	 * @return void
255
+	 */
256
+	private function _initialize_config()
257
+	{
258
+		EE_Config::trim_log();
259
+		// set defaults
260
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
261
+		$this->addons = new stdClass();
262
+		// set _module_route_map
263
+		EE_Config::$_module_route_map = array();
264
+		// set _module_forward_map
265
+		EE_Config::$_module_forward_map = array();
266
+		// set _module_view_map
267
+		EE_Config::$_module_view_map = array();
268
+	}
269
+
270
+
271
+	/**
272
+	 *        load core plugin configuration
273
+	 *
274
+	 * @access private
275
+	 * @return void
276
+	 */
277
+	private function _load_core_config()
278
+	{
279
+		// load_core_config__start hook
280
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
281
+		$espresso_config = $this->get_espresso_config();
282
+		foreach ($espresso_config as $config => $settings) {
283
+			// load_core_config__start hook
284
+			$settings = apply_filters(
285
+				'FHEE__EE_Config___load_core_config__config_settings',
286
+				$settings,
287
+				$config,
288
+				$this
289
+			);
290
+			if (is_object($settings) && property_exists($this, $config)) {
291
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
292
+				// call configs populate method to ensure any defaults are set for empty values.
293
+				if (method_exists($settings, 'populate')) {
294
+					$this->{$config}->populate();
295
+				}
296
+				if (method_exists($settings, 'do_hooks')) {
297
+					$this->{$config}->do_hooks();
298
+				}
299
+			}
300
+		}
301
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
302
+			$this->update_espresso_config();
303
+		}
304
+		// load_core_config__end hook
305
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
306
+	}
307
+
308
+
309
+	/**
310
+	 *    _verify_config
311
+	 *
312
+	 * @access    protected
313
+	 * @return    void
314
+	 */
315
+	protected function _verify_config()
316
+	{
317
+		$this->core = $this->core instanceof EE_Core_Config
318
+			? $this->core
319
+			: new EE_Core_Config();
320
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
321
+		$this->organization = $this->organization instanceof EE_Organization_Config
322
+			? $this->organization
323
+			: new EE_Organization_Config();
324
+		$this->organization = apply_filters(
325
+			'FHEE__EE_Config___initialize_config__organization',
326
+			$this->organization
327
+		);
328
+		$this->currency = $this->currency instanceof EE_Currency_Config
329
+			? $this->currency
330
+			: new EE_Currency_Config();
331
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
332
+		$this->registration = $this->registration instanceof EE_Registration_Config
333
+			? $this->registration
334
+			: new EE_Registration_Config();
335
+		$this->registration = apply_filters(
336
+			'FHEE__EE_Config___initialize_config__registration',
337
+			$this->registration
338
+		);
339
+		$this->admin = $this->admin instanceof EE_Admin_Config
340
+			? $this->admin
341
+			: new EE_Admin_Config();
342
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
343
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
344
+			? $this->template_settings
345
+			: new EE_Template_Config();
346
+		$this->template_settings = apply_filters(
347
+			'FHEE__EE_Config___initialize_config__template_settings',
348
+			$this->template_settings
349
+		);
350
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
351
+			? $this->map_settings
352
+			: new EE_Map_Config();
353
+		$this->map_settings = apply_filters(
354
+			'FHEE__EE_Config___initialize_config__map_settings',
355
+			$this->map_settings
356
+		);
357
+		$this->environment = $this->environment instanceof EE_Environment_Config
358
+			? $this->environment
359
+			: new EE_Environment_Config();
360
+		$this->environment = apply_filters(
361
+			'FHEE__EE_Config___initialize_config__environment',
362
+			$this->environment
363
+		);
364
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
365
+			? $this->tax_settings
366
+			: new EE_Tax_Config();
367
+		$this->tax_settings = apply_filters(
368
+			'FHEE__EE_Config___initialize_config__tax_settings',
369
+			$this->tax_settings
370
+		);
371
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
372
+		$this->messages = $this->messages instanceof EE_Messages_Config
373
+			? $this->messages
374
+			: new EE_Messages_Config();
375
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
376
+			? $this->gateway
377
+			: new EE_Gateway_Config();
378
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
379
+		$this->legacy_shortcodes_manager = null;
380
+	}
381
+
382
+
383
+	/**
384
+	 *    get_espresso_config
385
+	 *
386
+	 * @access    public
387
+	 * @return    array of espresso config stuff
388
+	 */
389
+	public function get_espresso_config()
390
+	{
391
+		// grab espresso configuration
392
+		return apply_filters(
393
+			'FHEE__EE_Config__get_espresso_config__CFG',
394
+			get_option(EE_Config::OPTION_NAME, array())
395
+		);
396
+	}
397
+
398
+
399
+	/**
400
+	 *    double_check_config_comparison
401
+	 *
402
+	 * @access    public
403
+	 * @param string $option
404
+	 * @param        $old_value
405
+	 * @param        $value
406
+	 */
407
+	public function double_check_config_comparison($option = '', $old_value, $value)
408
+	{
409
+		// make sure we're checking the ee config
410
+		if ($option === EE_Config::OPTION_NAME) {
411
+			// run a loose comparison of the old value against the new value for type and properties,
412
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
413
+			if ($value != $old_value) {
414
+				// if they are NOT the same, then remove the hook,
415
+				// which means the subsequent update results will be based solely on the update query results
416
+				// the reason we do this is because, as stated above,
417
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
418
+				// this happens PRIOR to serialization and any subsequent update.
419
+				// If values are found to match their previous old value,
420
+				// then WP bails before performing any update.
421
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
422
+				// it just pulled from the db, with the one being passed to it (which will not match).
423
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
424
+				// MySQL MAY ALSO NOT perform the update because
425
+				// the string it sees in the db looks the same as the new one it has been passed!!!
426
+				// This results in the query returning an "affected rows" value of ZERO,
427
+				// which gets returned immediately by WP update_option and looks like an error.
428
+				remove_action('update_option', array($this, 'check_config_updated'));
429
+			}
430
+		}
431
+	}
432
+
433
+
434
+	/**
435
+	 *    update_espresso_config
436
+	 *
437
+	 * @access   public
438
+	 */
439
+	protected function _reset_espresso_addon_config()
440
+	{
441
+		$this->_addon_option_names = array();
442
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
443
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
444
+			if ($addon_config_obj instanceof EE_Config_Base) {
445
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
446
+			}
447
+			$this->addons->{$addon_name} = null;
448
+		}
449
+	}
450
+
451
+
452
+	/**
453
+	 *    update_espresso_config
454
+	 *
455
+	 * @access   public
456
+	 * @param   bool $add_success
457
+	 * @param   bool $add_error
458
+	 * @return   bool
459
+	 */
460
+	public function update_espresso_config($add_success = false, $add_error = true)
461
+	{
462
+		// don't allow config updates during WP heartbeats
463
+		/** @var RequestInterface $request */
464
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
465
+		if ($request->isWordPressHeartbeat()) {
466
+			return false;
467
+		}
468
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
469
+		// $clone = clone( self::$_instance );
470
+		// self::$_instance = NULL;
471
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
472
+		$this->_reset_espresso_addon_config();
473
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
474
+		// but BEFORE the actual update occurs
475
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
476
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
477
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
478
+		$this->legacy_shortcodes_manager = null;
479
+		// now update "ee_config"
480
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
481
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
482
+		EE_Config::log(EE_Config::OPTION_NAME);
483
+		// if not saved... check if the hook we just added still exists;
484
+		// if it does, it means one of two things:
485
+		// that update_option bailed at the($value === $old_value) conditional,
486
+		// or...
487
+		// the db update query returned 0 rows affected
488
+		// (probably because the data  value was the same from it's perspective)
489
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
490
+		// but just means no update occurred, so don't display an error to the user.
491
+		// BUT... if update_option returns FALSE, AND the hook is missing,
492
+		// then it means that something truly went wrong
493
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
494
+		// remove our action since we don't want it in the system anymore
495
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
496
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
497
+		// self::$_instance = $clone;
498
+		// unset( $clone );
499
+		// if config remains the same or was updated successfully
500
+		if ($saved) {
501
+			if ($add_success) {
502
+				EE_Error::add_success(
503
+					esc_html__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
504
+					__FILE__,
505
+					__FUNCTION__,
506
+					__LINE__
507
+				);
508
+			}
509
+			return true;
510
+		} else {
511
+			if ($add_error) {
512
+				EE_Error::add_error(
513
+					esc_html__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
514
+					__FILE__,
515
+					__FUNCTION__,
516
+					__LINE__
517
+				);
518
+			}
519
+			return false;
520
+		}
521
+	}
522
+
523
+
524
+	/**
525
+	 *    _verify_config_params
526
+	 *
527
+	 * @access    private
528
+	 * @param    string         $section
529
+	 * @param    string         $name
530
+	 * @param    string         $config_class
531
+	 * @param    EE_Config_Base $config_obj
532
+	 * @param    array          $tests_to_run
533
+	 * @param    bool           $display_errors
534
+	 * @return    bool    TRUE on success, FALSE on fail
535
+	 */
536
+	private function _verify_config_params(
537
+		$section = '',
538
+		$name = '',
539
+		$config_class = '',
540
+		$config_obj = null,
541
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
542
+		$display_errors = true
543
+	) {
544
+		try {
545
+			foreach ($tests_to_run as $test) {
546
+				switch ($test) {
547
+					// TEST #1 : check that section was set
548
+					case 1:
549
+						if (empty($section)) {
550
+							if ($display_errors) {
551
+								throw new EE_Error(
552
+									sprintf(
553
+										esc_html__(
554
+											'No configuration section has been provided while attempting to save "%s".',
555
+											'event_espresso'
556
+										),
557
+										$config_class
558
+									)
559
+								);
560
+							}
561
+							return false;
562
+						}
563
+						break;
564
+					// TEST #2 : check that settings section exists
565
+					case 2:
566
+						if (! isset($this->{$section})) {
567
+							if ($display_errors) {
568
+								throw new EE_Error(
569
+									sprintf(
570
+										esc_html__('The "%s" configuration section does not exist.', 'event_espresso'),
571
+										$section
572
+									)
573
+								);
574
+							}
575
+							return false;
576
+						}
577
+						break;
578
+					// TEST #3 : check that section is the proper format
579
+					case 3:
580
+						if (
581
+							! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
582
+						) {
583
+							if ($display_errors) {
584
+								throw new EE_Error(
585
+									sprintf(
586
+										esc_html__(
587
+											'The "%s" configuration settings have not been formatted correctly.',
588
+											'event_espresso'
589
+										),
590
+										$section
591
+									)
592
+								);
593
+							}
594
+							return false;
595
+						}
596
+						break;
597
+					// TEST #4 : check that config section name has been set
598
+					case 4:
599
+						if (empty($name)) {
600
+							if ($display_errors) {
601
+								throw new EE_Error(
602
+									esc_html__(
603
+										'No name has been provided for the specific configuration section.',
604
+										'event_espresso'
605
+									)
606
+								);
607
+							}
608
+							return false;
609
+						}
610
+						break;
611
+					// TEST #5 : check that a config class name has been set
612
+					case 5:
613
+						if (empty($config_class)) {
614
+							if ($display_errors) {
615
+								throw new EE_Error(
616
+									esc_html__(
617
+										'No class name has been provided for the specific configuration section.',
618
+										'event_espresso'
619
+									)
620
+								);
621
+							}
622
+							return false;
623
+						}
624
+						break;
625
+					// TEST #6 : verify config class is accessible
626
+					case 6:
627
+						if (! class_exists($config_class)) {
628
+							if ($display_errors) {
629
+								throw new EE_Error(
630
+									sprintf(
631
+										esc_html__(
632
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
633
+											'event_espresso'
634
+										),
635
+										$config_class
636
+									)
637
+								);
638
+							}
639
+							return false;
640
+						}
641
+						break;
642
+					// TEST #7 : check that config has even been set
643
+					case 7:
644
+						if (! isset($this->{$section}->{$name})) {
645
+							if ($display_errors) {
646
+								throw new EE_Error(
647
+									sprintf(
648
+										esc_html__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
649
+										$section,
650
+										$name
651
+									)
652
+								);
653
+							}
654
+							return false;
655
+						} else {
656
+							// and make sure it's not serialized
657
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
658
+						}
659
+						break;
660
+					// TEST #8 : check that config is the requested type
661
+					case 8:
662
+						if (! $this->{$section}->{$name} instanceof $config_class) {
663
+							if ($display_errors) {
664
+								throw new EE_Error(
665
+									sprintf(
666
+										esc_html__(
667
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
668
+											'event_espresso'
669
+										),
670
+										$section,
671
+										$name,
672
+										$config_class
673
+									)
674
+								);
675
+							}
676
+							return false;
677
+						}
678
+						break;
679
+					// TEST #9 : verify config object
680
+					case 9:
681
+						if (! $config_obj instanceof EE_Config_Base) {
682
+							if ($display_errors) {
683
+								throw new EE_Error(
684
+									sprintf(
685
+										esc_html__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
686
+										print_r($config_obj, true)
687
+									)
688
+								);
689
+							}
690
+							return false;
691
+						}
692
+						break;
693
+				}
694
+			}
695
+		} catch (EE_Error $e) {
696
+			$e->get_error();
697
+		}
698
+		// you have successfully run the gauntlet
699
+		return true;
700
+	}
701
+
702
+
703
+	/**
704
+	 *    _generate_config_option_name
705
+	 *
706
+	 * @access        protected
707
+	 * @param        string $section
708
+	 * @param        string $name
709
+	 * @return        string
710
+	 */
711
+	private function _generate_config_option_name($section = '', $name = '')
712
+	{
713
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
714
+	}
715
+
716
+
717
+	/**
718
+	 *    _set_config_class
719
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
720
+	 *
721
+	 * @access    private
722
+	 * @param    string $config_class
723
+	 * @param    string $name
724
+	 * @return    string
725
+	 */
726
+	private function _set_config_class($config_class = '', $name = '')
727
+	{
728
+		return ! empty($config_class)
729
+			? $config_class
730
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
731
+	}
732
+
733
+
734
+	/**
735
+	 *    set_config
736
+	 *
737
+	 * @access    protected
738
+	 * @param    string         $section
739
+	 * @param    string         $name
740
+	 * @param    string         $config_class
741
+	 * @param    EE_Config_Base $config_obj
742
+	 * @return    EE_Config_Base
743
+	 */
744
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
745
+	{
746
+		// ensure config class is set to something
747
+		$config_class = $this->_set_config_class($config_class, $name);
748
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
749
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
750
+			return null;
751
+		}
752
+		$config_option_name = $this->_generate_config_option_name($section, $name);
753
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
754
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
755
+			$this->_addon_option_names[ $config_option_name ] = $config_class;
756
+			$this->update_addon_option_names();
757
+		}
758
+		// verify the incoming config object but suppress errors
759
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
760
+			$config_obj = new $config_class();
761
+		}
762
+		if (get_option($config_option_name)) {
763
+			EE_Config::log($config_option_name);
764
+			update_option($config_option_name, $config_obj);
765
+			$this->{$section}->{$name} = $config_obj;
766
+			return $this->{$section}->{$name};
767
+		} else {
768
+			// create a wp-option for this config
769
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
770
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
771
+				return $this->{$section}->{$name};
772
+			} else {
773
+				EE_Error::add_error(
774
+					sprintf(esc_html__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
775
+					__FILE__,
776
+					__FUNCTION__,
777
+					__LINE__
778
+				);
779
+				return null;
780
+			}
781
+		}
782
+	}
783
+
784
+
785
+	/**
786
+	 *    update_config
787
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
788
+	 *
789
+	 * @access    public
790
+	 * @param    string                $section
791
+	 * @param    string                $name
792
+	 * @param    EE_Config_Base|string $config_obj
793
+	 * @param    bool                  $throw_errors
794
+	 * @return    bool
795
+	 */
796
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
797
+	{
798
+		// don't allow config updates during WP heartbeats
799
+		/** @var RequestInterface $request */
800
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
801
+		if ($request->isWordPressHeartbeat()) {
802
+			return false;
803
+		}
804
+		$config_obj = maybe_unserialize($config_obj);
805
+		// get class name of the incoming object
806
+		$config_class = get_class($config_obj);
807
+		// run tests 1-5 and 9 to verify config
808
+		if (
809
+			! $this->_verify_config_params(
810
+				$section,
811
+				$name,
812
+				$config_class,
813
+				$config_obj,
814
+				array(1, 2, 3, 4, 7, 9)
815
+			)
816
+		) {
817
+			return false;
818
+		}
819
+		$config_option_name = $this->_generate_config_option_name($section, $name);
820
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
821
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
822
+			// save new config to db
823
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
824
+				return true;
825
+			}
826
+		} else {
827
+			// first check if the record already exists
828
+			$existing_config = get_option($config_option_name);
829
+			$config_obj = serialize($config_obj);
830
+			// just return if db record is already up to date (NOT type safe comparison)
831
+			if ($existing_config == $config_obj) {
832
+				$this->{$section}->{$name} = $config_obj;
833
+				return true;
834
+			} elseif (update_option($config_option_name, $config_obj)) {
835
+				EE_Config::log($config_option_name);
836
+				// update wp-option for this config class
837
+				$this->{$section}->{$name} = $config_obj;
838
+				return true;
839
+			} elseif ($throw_errors) {
840
+				EE_Error::add_error(
841
+					sprintf(
842
+						esc_html__(
843
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
844
+							'event_espresso'
845
+						),
846
+						$config_class,
847
+						'EE_Config->' . $section . '->' . $name
848
+					),
849
+					__FILE__,
850
+					__FUNCTION__,
851
+					__LINE__
852
+				);
853
+			}
854
+		}
855
+		return false;
856
+	}
857
+
858
+
859
+	/**
860
+	 *    get_config
861
+	 *
862
+	 * @access    public
863
+	 * @param    string $section
864
+	 * @param    string $name
865
+	 * @param    string $config_class
866
+	 * @return    mixed EE_Config_Base | NULL
867
+	 */
868
+	public function get_config($section = '', $name = '', $config_class = '')
869
+	{
870
+		// ensure config class is set to something
871
+		$config_class = $this->_set_config_class($config_class, $name);
872
+		// run tests 1-4, 6 and 7 to verify that all params have been set
873
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
874
+			return null;
875
+		}
876
+		// now test if the requested config object exists, but suppress errors
877
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
878
+			// config already exists, so pass it back
879
+			return $this->{$section}->{$name};
880
+		}
881
+		// load config option from db if it exists
882
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
883
+		// verify the newly retrieved config object, but suppress errors
884
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
885
+			// config is good, so set it and pass it back
886
+			$this->{$section}->{$name} = $config_obj;
887
+			return $this->{$section}->{$name};
888
+		}
889
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
890
+		$config_obj = $this->set_config($section, $name, $config_class);
891
+		// verify the newly created config object
892
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
893
+			return $this->{$section}->{$name};
894
+		} else {
895
+			EE_Error::add_error(
896
+				sprintf(esc_html__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
897
+				__FILE__,
898
+				__FUNCTION__,
899
+				__LINE__
900
+			);
901
+		}
902
+		return null;
903
+	}
904
+
905
+
906
+	/**
907
+	 *    get_config_option
908
+	 *
909
+	 * @access    public
910
+	 * @param    string $config_option_name
911
+	 * @return    mixed EE_Config_Base | FALSE
912
+	 */
913
+	public function get_config_option($config_option_name = '')
914
+	{
915
+		// retrieve the wp-option for this config class.
916
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
917
+		if (empty($config_option)) {
918
+			EE_Config::log($config_option_name . '-NOT-FOUND');
919
+		}
920
+		return $config_option;
921
+	}
922
+
923
+
924
+	/**
925
+	 * log
926
+	 *
927
+	 * @param string $config_option_name
928
+	 */
929
+	public static function log($config_option_name = '')
930
+	{
931
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
932
+			$config_log = get_option(EE_Config::LOG_NAME, array());
933
+			/** @var RequestParams $request */
934
+			$request = LoaderFactory::getLoader()->getShared(RequestParams::class);
935
+			$config_log[ (string) microtime(true) ] = array(
936
+				'config_name' => $config_option_name,
937
+				'request'     => $request->requestParams(),
938
+			);
939
+			update_option(EE_Config::LOG_NAME, $config_log);
940
+		}
941
+	}
942
+
943
+
944
+	/**
945
+	 * trim_log
946
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
947
+	 */
948
+	public static function trim_log()
949
+	{
950
+		if (! EE_Config::logging_enabled()) {
951
+			return;
952
+		}
953
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
954
+		$log_length = count($config_log);
955
+		if ($log_length > EE_Config::LOG_LENGTH) {
956
+			ksort($config_log);
957
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
958
+			update_option(EE_Config::LOG_NAME, $config_log);
959
+		}
960
+	}
961
+
962
+
963
+	/**
964
+	 *    get_page_for_posts
965
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
966
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
967
+	 *
968
+	 * @access    public
969
+	 * @return    string
970
+	 */
971
+	public static function get_page_for_posts()
972
+	{
973
+		$page_for_posts = get_option('page_for_posts');
974
+		if (! $page_for_posts) {
975
+			return 'posts';
976
+		}
977
+		global $wpdb;
978
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
979
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
980
+	}
981
+
982
+
983
+	/**
984
+	 *    register_shortcodes_and_modules.
985
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
986
+	 *    In fact, this is where we give modules a chance to let core know they exist
987
+	 *    so they can help trigger maintenance mode if it's needed
988
+	 *
989
+	 * @access    public
990
+	 * @return    void
991
+	 */
992
+	public function register_shortcodes_and_modules()
993
+	{
994
+		// allow modules to set hooks for the rest of the system
995
+		EE_Registry::instance()->modules = $this->_register_modules();
996
+	}
997
+
998
+
999
+	/**
1000
+	 *    initialize_shortcodes_and_modules
1001
+	 *    meaning they can start adding their hooks to get stuff done
1002
+	 *
1003
+	 * @access    public
1004
+	 * @return    void
1005
+	 */
1006
+	public function initialize_shortcodes_and_modules()
1007
+	{
1008
+		// allow modules to set hooks for the rest of the system
1009
+		$this->_initialize_modules();
1010
+	}
1011
+
1012
+
1013
+	/**
1014
+	 *    widgets_init
1015
+	 *
1016
+	 * @access private
1017
+	 * @return void
1018
+	 */
1019
+	public function widgets_init()
1020
+	{
1021
+		// only init widgets on admin pages when not in complete maintenance, and
1022
+		// on frontend when not in any maintenance mode
1023
+		if (
1024
+			! EE_Maintenance_Mode::instance()->level()
1025
+			|| (
1026
+				is_admin()
1027
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1028
+			)
1029
+		) {
1030
+			// grab list of installed widgets
1031
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1032
+			// filter list of modules to register
1033
+			$widgets_to_register = apply_filters(
1034
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1035
+				$widgets_to_register
1036
+			);
1037
+			if (! empty($widgets_to_register)) {
1038
+				// cycle thru widget folders
1039
+				foreach ($widgets_to_register as $widget_path) {
1040
+					// add to list of installed widget modules
1041
+					EE_Config::register_ee_widget($widget_path);
1042
+				}
1043
+			}
1044
+			// filter list of installed modules
1045
+			EE_Registry::instance()->widgets = apply_filters(
1046
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1047
+				EE_Registry::instance()->widgets
1048
+			);
1049
+		}
1050
+	}
1051
+
1052
+
1053
+	/**
1054
+	 *    register_ee_widget - makes core aware of this widget
1055
+	 *
1056
+	 * @access    public
1057
+	 * @param    string $widget_path - full path up to and including widget folder
1058
+	 * @return    void
1059
+	 */
1060
+	public static function register_ee_widget($widget_path = null)
1061
+	{
1062
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1063
+		$widget_ext = '.widget.php';
1064
+		// make all separators match
1065
+		$widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1066
+		// does the file path INCLUDE the actual file name as part of the path ?
1067
+		if (strpos($widget_path, $widget_ext) !== false) {
1068
+			// grab and shortcode file name from directory name and break apart at dots
1069
+			$file_name = explode('.', basename($widget_path));
1070
+			// take first segment from file name pieces and remove class prefix if it exists
1071
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1072
+			// sanitize shortcode directory name
1073
+			$widget = sanitize_key($widget);
1074
+			// now we need to rebuild the shortcode path
1075
+			$widget_path = explode('/', $widget_path);
1076
+			// remove last segment
1077
+			array_pop($widget_path);
1078
+			// glue it back together
1079
+			$widget_path = implode(DS, $widget_path);
1080
+		} else {
1081
+			// grab and sanitize widget directory name
1082
+			$widget = sanitize_key(basename($widget_path));
1083
+		}
1084
+		// create classname from widget directory name
1085
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1086
+		// add class prefix
1087
+		$widget_class = 'EEW_' . $widget;
1088
+		// does the widget exist ?
1089
+		if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1090
+			$msg = sprintf(
1091
+				esc_html__(
1092
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1093
+					'event_espresso'
1094
+				),
1095
+				$widget_class,
1096
+				$widget_path . '/' . $widget_class . $widget_ext
1097
+			);
1098
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1099
+			return;
1100
+		}
1101
+		// load the widget class file
1102
+		require_once($widget_path . '/' . $widget_class . $widget_ext);
1103
+		// verify that class exists
1104
+		if (! class_exists($widget_class)) {
1105
+			$msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1106
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1107
+			return;
1108
+		}
1109
+		register_widget($widget_class);
1110
+		// add to array of registered widgets
1111
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1112
+	}
1113
+
1114
+
1115
+	/**
1116
+	 *        _register_modules
1117
+	 *
1118
+	 * @access private
1119
+	 * @return array
1120
+	 */
1121
+	private function _register_modules()
1122
+	{
1123
+		// grab list of installed modules
1124
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1125
+		// filter list of modules to register
1126
+		$modules_to_register = apply_filters(
1127
+			'FHEE__EE_Config__register_modules__modules_to_register',
1128
+			$modules_to_register
1129
+		);
1130
+		if (! empty($modules_to_register)) {
1131
+			// loop through folders
1132
+			foreach ($modules_to_register as $module_path) {
1133
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1134
+				if (
1135
+					$module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1136
+					&& $module_path !== EE_MODULES . 'gateways'
1137
+				) {
1138
+					// add to list of installed modules
1139
+					EE_Config::register_module($module_path);
1140
+				}
1141
+			}
1142
+		}
1143
+		// filter list of installed modules
1144
+		return apply_filters(
1145
+			'FHEE__EE_Config___register_modules__installed_modules',
1146
+			EE_Registry::instance()->modules
1147
+		);
1148
+	}
1149
+
1150
+
1151
+	/**
1152
+	 *    register_module - makes core aware of this module
1153
+	 *
1154
+	 * @access    public
1155
+	 * @param    string $module_path - full path up to and including module folder
1156
+	 * @return    bool
1157
+	 */
1158
+	public static function register_module($module_path = null)
1159
+	{
1160
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1161
+		$module_ext = '.module.php';
1162
+		// make all separators match
1163
+		$module_path = str_replace(array('\\', '/'), '/', $module_path);
1164
+		// does the file path INCLUDE the actual file name as part of the path ?
1165
+		if (strpos($module_path, $module_ext) !== false) {
1166
+			// grab and shortcode file name from directory name and break apart at dots
1167
+			$module_file = explode('.', basename($module_path));
1168
+			// now we need to rebuild the shortcode path
1169
+			$module_path = explode('/', $module_path);
1170
+			// remove last segment
1171
+			array_pop($module_path);
1172
+			// glue it back together
1173
+			$module_path = implode('/', $module_path) . '/';
1174
+			// take first segment from file name pieces and sanitize it
1175
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1176
+			// ensure class prefix is added
1177
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1178
+		} else {
1179
+			// we need to generate the filename based off of the folder name
1180
+			// grab and sanitize module name
1181
+			$module = strtolower(basename($module_path));
1182
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1183
+			// like trailingslashit()
1184
+			$module_path = rtrim($module_path, '/') . '/';
1185
+			// create classname from module directory name
1186
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1187
+			// add class prefix
1188
+			$module_class = 'EED_' . $module;
1189
+		}
1190
+		// does the module exist ?
1191
+		if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1192
+			$msg = sprintf(
1193
+				esc_html__(
1194
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1195
+					'event_espresso'
1196
+				),
1197
+				$module
1198
+			);
1199
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1200
+			return false;
1201
+		}
1202
+		// load the module class file
1203
+		require_once($module_path . $module_class . $module_ext);
1204
+		// verify that class exists
1205
+		if (! class_exists($module_class)) {
1206
+			$msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1207
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1208
+			return false;
1209
+		}
1210
+		// add to array of registered modules
1211
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1212
+		do_action(
1213
+			'AHEE__EE_Config__register_module__complete',
1214
+			$module_class,
1215
+			EE_Registry::instance()->modules->{$module_class}
1216
+		);
1217
+		return true;
1218
+	}
1219
+
1220
+
1221
+	/**
1222
+	 *    _initialize_modules
1223
+	 *    allow modules to set hooks for the rest of the system
1224
+	 *
1225
+	 * @access private
1226
+	 * @return void
1227
+	 */
1228
+	private function _initialize_modules()
1229
+	{
1230
+		// cycle thru shortcode folders
1231
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1232
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1233
+			// which set hooks ?
1234
+			if (is_admin()) {
1235
+				// fire immediately
1236
+				call_user_func(array($module_class, 'set_hooks_admin'));
1237
+			} else {
1238
+				// delay until other systems are online
1239
+				add_action(
1240
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1241
+					array($module_class, 'set_hooks')
1242
+				);
1243
+			}
1244
+		}
1245
+	}
1246
+
1247
+
1248
+	/**
1249
+	 *    register_route - adds module method routes to route_map
1250
+	 *
1251
+	 * @access    public
1252
+	 * @param    string $route       - "pretty" public alias for module method
1253
+	 * @param    string $module      - module name (classname without EED_ prefix)
1254
+	 * @param    string $method_name - the actual module method to be routed to
1255
+	 * @param    string $key         - url param key indicating a route is being called
1256
+	 * @return    bool
1257
+	 */
1258
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1259
+	{
1260
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1261
+		$module = str_replace('EED_', '', $module);
1262
+		$module_class = 'EED_' . $module;
1263
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1264
+			$msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module);
1265
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1266
+			return false;
1267
+		}
1268
+		if (empty($route)) {
1269
+			$msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route);
1270
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1271
+			return false;
1272
+		}
1273
+		if (! method_exists('EED_' . $module, $method_name)) {
1274
+			$msg = sprintf(
1275
+				esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1276
+				$route
1277
+			);
1278
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1279
+			return false;
1280
+		}
1281
+		EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1282
+		return true;
1283
+	}
1284
+
1285
+
1286
+	/**
1287
+	 *    get_route - get module method route
1288
+	 *
1289
+	 * @access    public
1290
+	 * @param    string $route - "pretty" public alias for module method
1291
+	 * @param    string $key   - url param key indicating a route is being called
1292
+	 * @return    string
1293
+	 */
1294
+	public static function get_route($route = null, $key = 'ee')
1295
+	{
1296
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1297
+		$route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1298
+		if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1299
+			return EE_Config::$_module_route_map[ $key ][ $route ];
1300
+		}
1301
+		return null;
1302
+	}
1303
+
1304
+
1305
+	/**
1306
+	 *    get_routes - get ALL module method routes
1307
+	 *
1308
+	 * @access    public
1309
+	 * @return    array
1310
+	 */
1311
+	public static function get_routes()
1312
+	{
1313
+		return EE_Config::$_module_route_map;
1314
+	}
1315
+
1316
+
1317
+	/**
1318
+	 *    register_forward - allows modules to forward request to another module for further processing
1319
+	 *
1320
+	 * @access    public
1321
+	 * @param    string       $route   - "pretty" public alias for module method
1322
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1323
+	 *                                 class, allows different forwards to be served based on status
1324
+	 * @param    array|string $forward - function name or array( class, method )
1325
+	 * @param    string       $key     - url param key indicating a route is being called
1326
+	 * @return    bool
1327
+	 */
1328
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1329
+	{
1330
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1331
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1332
+			$msg = sprintf(
1333
+				esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'),
1334
+				$route
1335
+			);
1336
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1337
+			return false;
1338
+		}
1339
+		if (empty($forward)) {
1340
+			$msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route);
1341
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1342
+			return false;
1343
+		}
1344
+		if (is_array($forward)) {
1345
+			if (! isset($forward[1])) {
1346
+				$msg = sprintf(
1347
+					esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1348
+					$route
1349
+				);
1350
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1351
+				return false;
1352
+			}
1353
+			if (! method_exists($forward[0], $forward[1])) {
1354
+				$msg = sprintf(
1355
+					esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1356
+					$forward[1],
1357
+					$route
1358
+				);
1359
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1360
+				return false;
1361
+			}
1362
+		} elseif (! function_exists($forward)) {
1363
+			$msg = sprintf(
1364
+				esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1365
+				$forward,
1366
+				$route
1367
+			);
1368
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1369
+			return false;
1370
+		}
1371
+		EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1372
+		return true;
1373
+	}
1374
+
1375
+
1376
+	/**
1377
+	 *    get_forward - get forwarding route
1378
+	 *
1379
+	 * @access    public
1380
+	 * @param    string  $route  - "pretty" public alias for module method
1381
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1382
+	 *                           allows different forwards to be served based on status
1383
+	 * @param    string  $key    - url param key indicating a route is being called
1384
+	 * @return    string
1385
+	 */
1386
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1387
+	{
1388
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1389
+		if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1390
+			return apply_filters(
1391
+				'FHEE__EE_Config__get_forward',
1392
+				EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1393
+				$route,
1394
+				$status
1395
+			);
1396
+		}
1397
+		return null;
1398
+	}
1399
+
1400
+
1401
+	/**
1402
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1403
+	 *    results
1404
+	 *
1405
+	 * @access    public
1406
+	 * @param    string  $route  - "pretty" public alias for module method
1407
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1408
+	 *                           allows different views to be served based on status
1409
+	 * @param    string  $view
1410
+	 * @param    string  $key    - url param key indicating a route is being called
1411
+	 * @return    bool
1412
+	 */
1413
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1414
+	{
1415
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1416
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1417
+			$msg = sprintf(
1418
+				esc_html__('The module route %s for this view has not been registered.', 'event_espresso'),
1419
+				$route
1420
+			);
1421
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1422
+			return false;
1423
+		}
1424
+		if (! is_readable($view)) {
1425
+			$msg = sprintf(
1426
+				esc_html__(
1427
+					'The %s view file could not be found or is not readable due to file permissions.',
1428
+					'event_espresso'
1429
+				),
1430
+				$view
1431
+			);
1432
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1433
+			return false;
1434
+		}
1435
+		EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1436
+		return true;
1437
+	}
1438
+
1439
+
1440
+	/**
1441
+	 *    get_view - get view for route and status
1442
+	 *
1443
+	 * @access    public
1444
+	 * @param    string  $route  - "pretty" public alias for module method
1445
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1446
+	 *                           allows different views to be served based on status
1447
+	 * @param    string  $key    - url param key indicating a route is being called
1448
+	 * @return    string
1449
+	 */
1450
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1451
+	{
1452
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1453
+		if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1454
+			return apply_filters(
1455
+				'FHEE__EE_Config__get_view',
1456
+				EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1457
+				$route,
1458
+				$status
1459
+			);
1460
+		}
1461
+		return null;
1462
+	}
1463
+
1464
+
1465
+	public function update_addon_option_names()
1466
+	{
1467
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1468
+	}
1469
+
1470
+
1471
+	public function shutdown()
1472
+	{
1473
+		$this->update_addon_option_names();
1474
+	}
1475
+
1476
+
1477
+	/**
1478
+	 * @return LegacyShortcodesManager
1479
+	 */
1480
+	public static function getLegacyShortcodesManager()
1481
+	{
1482
+		if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1483
+			EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared(
1484
+				LegacyShortcodesManager::class
1485
+			);
1486
+		}
1487
+		return EE_Config::instance()->legacy_shortcodes_manager;
1488
+	}
1489
+
1490
+
1491
+	/**
1492
+	 * register_shortcode - makes core aware of this shortcode
1493
+	 *
1494
+	 * @deprecated 4.9.26
1495
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1496
+	 * @return    bool
1497
+	 */
1498
+	public static function register_shortcode($shortcode_path = null)
1499
+	{
1500
+		EE_Error::doing_it_wrong(
1501
+			__METHOD__,
1502
+			esc_html__(
1503
+				'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1504
+				'event_espresso'
1505
+			),
1506
+			'4.9.26'
1507
+		);
1508
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1509
+	}
1510
+}
2274 1511
 
2275
-    /**
2276
-     * ReCaptcha Type
2277
-     *
2278
-     * @var string $recaptcha_type
2279
-     *    options: 'audio', 'image'
2280
-     */
2281
-    public $recaptcha_type;
1512
+/**
1513
+ * Base class used for config classes. These classes should generally not have
1514
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1515
+ * basically, they should just be well-defined stdClasses
1516
+ */
1517
+class EE_Config_Base
1518
+{
2282 1519
 
2283
-    /**
2284
-     * ReCaptcha language
2285
-     *
2286
-     * @var string $recaptcha_language
2287
-     * eg 'en'
2288
-     */
2289
-    public $recaptcha_language;
1520
+	/**
1521
+	 * Utility function for escaping the value of a property and returning.
1522
+	 *
1523
+	 * @param string $property property name (checks to see if exists).
1524
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1525
+	 * @throws EE_Error
1526
+	 */
1527
+	public function get_pretty($property)
1528
+	{
1529
+		if (! property_exists($this, $property)) {
1530
+			throw new EE_Error(
1531
+				sprintf(
1532
+					esc_html__(
1533
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1534
+						'event_espresso'
1535
+					),
1536
+					get_class($this),
1537
+					$property
1538
+				)
1539
+			);
1540
+		}
1541
+		// just handling escaping of strings for now.
1542
+		if (is_string($this->{$property})) {
1543
+			return stripslashes($this->{$property});
1544
+		}
1545
+		return $this->{$property};
1546
+	}
1547
+
1548
+
1549
+	public function populate()
1550
+	{
1551
+		// grab defaults via a new instance of this class.
1552
+		$class_name = get_class($this);
1553
+		$defaults = new $class_name();
1554
+		// loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1555
+		// default from our $defaults object.
1556
+		foreach (get_object_vars($defaults) as $property => $value) {
1557
+			if ($this->{$property} === null) {
1558
+				$this->{$property} = $value;
1559
+			}
1560
+		}
1561
+		// cleanup
1562
+		unset($defaults);
1563
+	}
1564
+
1565
+
1566
+	/**
1567
+	 *        __isset
1568
+	 *
1569
+	 * @param $a
1570
+	 * @return bool
1571
+	 */
1572
+	public function __isset($a)
1573
+	{
1574
+		return false;
1575
+	}
1576
+
1577
+
1578
+	/**
1579
+	 *        __unset
1580
+	 *
1581
+	 * @param $a
1582
+	 * @return bool
1583
+	 */
1584
+	public function __unset($a)
1585
+	{
1586
+		return false;
1587
+	}
1588
+
1589
+
1590
+	/**
1591
+	 *        __clone
1592
+	 */
1593
+	public function __clone()
1594
+	{
1595
+	}
1596
+
1597
+
1598
+	/**
1599
+	 *        __wakeup
1600
+	 */
1601
+	public function __wakeup()
1602
+	{
1603
+	}
1604
+
1605
+
1606
+	/**
1607
+	 *        __destruct
1608
+	 */
1609
+	public function __destruct()
1610
+	{
1611
+	}
1612
+}
2290 1613
 
2291
-    /**
2292
-     * ReCaptcha public key
2293
-     *
2294
-     * @var string $recaptcha_publickey
2295
-     */
2296
-    public $recaptcha_publickey;
1614
+/**
1615
+ * Class for defining what's in the EE_Config relating to registration settings
1616
+ */
1617
+class EE_Core_Config extends EE_Config_Base
1618
+{
2297 1619
 
2298
-    /**
2299
-     * ReCaptcha private key
2300
-     *
2301
-     * @var string $recaptcha_privatekey
2302
-     */
2303
-    public $recaptcha_privatekey;
1620
+	const OPTION_NAME_UXIP = 'ee_ueip_optin';
1621
+
1622
+
1623
+	public $current_blog_id;
1624
+
1625
+	public $ee_ueip_optin;
1626
+
1627
+	public $ee_ueip_has_notified;
1628
+
1629
+	/**
1630
+	 * Not to be confused with the 4 critical page variables (See
1631
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1632
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1633
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1634
+	 *
1635
+	 * @var array
1636
+	 */
1637
+	public $post_shortcodes;
1638
+
1639
+	public $module_route_map;
1640
+
1641
+	public $module_forward_map;
1642
+
1643
+	public $module_view_map;
1644
+
1645
+	/**
1646
+	 * The next 4 vars are the IDs of critical EE pages.
1647
+	 *
1648
+	 * @var int
1649
+	 */
1650
+	public $reg_page_id;
1651
+
1652
+	public $txn_page_id;
1653
+
1654
+	public $thank_you_page_id;
1655
+
1656
+	public $cancel_page_id;
1657
+
1658
+	/**
1659
+	 * The next 4 vars are the URLs of critical EE pages.
1660
+	 *
1661
+	 * @var int
1662
+	 */
1663
+	public $reg_page_url;
1664
+
1665
+	public $txn_page_url;
1666
+
1667
+	public $thank_you_page_url;
1668
+
1669
+	public $cancel_page_url;
1670
+
1671
+	/**
1672
+	 * The next vars relate to the custom slugs for EE CPT routes
1673
+	 */
1674
+	public $event_cpt_slug;
1675
+
1676
+	/**
1677
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1678
+	 * request across blog switches in a multisite context.
1679
+	 * Avoids extra queries to the db for this option.
1680
+	 *
1681
+	 * @var bool
1682
+	 */
1683
+	public static $ee_ueip_option;
1684
+
1685
+
1686
+	/**
1687
+	 *    class constructor
1688
+	 *
1689
+	 * @access    public
1690
+	 */
1691
+	public function __construct()
1692
+	{
1693
+		// set default organization settings
1694
+		$this->current_blog_id = get_current_blog_id();
1695
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1696
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1697
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1698
+		$this->post_shortcodes = array();
1699
+		$this->module_route_map = array();
1700
+		$this->module_forward_map = array();
1701
+		$this->module_view_map = array();
1702
+		// critical EE page IDs
1703
+		$this->reg_page_id = 0;
1704
+		$this->txn_page_id = 0;
1705
+		$this->thank_you_page_id = 0;
1706
+		$this->cancel_page_id = 0;
1707
+		// critical EE page URLs
1708
+		$this->reg_page_url = '';
1709
+		$this->txn_page_url = '';
1710
+		$this->thank_you_page_url = '';
1711
+		$this->cancel_page_url = '';
1712
+		// cpt slugs
1713
+		$this->event_cpt_slug = esc_html__('events', 'event_espresso');
1714
+		// ueip constant check
1715
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1716
+			$this->ee_ueip_optin = false;
1717
+			$this->ee_ueip_has_notified = true;
1718
+		}
1719
+	}
1720
+
1721
+
1722
+	/**
1723
+	 * @return array
1724
+	 */
1725
+	public function get_critical_pages_array()
1726
+	{
1727
+		return array(
1728
+			$this->reg_page_id,
1729
+			$this->txn_page_id,
1730
+			$this->thank_you_page_id,
1731
+			$this->cancel_page_id,
1732
+		);
1733
+	}
1734
+
1735
+
1736
+	/**
1737
+	 * @return array
1738
+	 */
1739
+	public function get_critical_pages_shortcodes_array()
1740
+	{
1741
+		return array(
1742
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1743
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1744
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1745
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1746
+		);
1747
+	}
1748
+
1749
+
1750
+	/**
1751
+	 *  gets/returns URL for EE reg_page
1752
+	 *
1753
+	 * @access    public
1754
+	 * @return    string
1755
+	 */
1756
+	public function reg_page_url()
1757
+	{
1758
+		if (! $this->reg_page_url) {
1759
+			$this->reg_page_url = add_query_arg(
1760
+				array('uts' => time()),
1761
+				get_permalink($this->reg_page_id)
1762
+			) . '#checkout';
1763
+		}
1764
+		return $this->reg_page_url;
1765
+	}
1766
+
1767
+
1768
+	/**
1769
+	 *  gets/returns URL for EE txn_page
1770
+	 *
1771
+	 * @param array $query_args like what gets passed to
1772
+	 *                          add_query_arg() as the first argument
1773
+	 * @access    public
1774
+	 * @return    string
1775
+	 */
1776
+	public function txn_page_url($query_args = array())
1777
+	{
1778
+		if (! $this->txn_page_url) {
1779
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1780
+		}
1781
+		if ($query_args) {
1782
+			return add_query_arg($query_args, $this->txn_page_url);
1783
+		} else {
1784
+			return $this->txn_page_url;
1785
+		}
1786
+	}
1787
+
1788
+
1789
+	/**
1790
+	 *  gets/returns URL for EE thank_you_page
1791
+	 *
1792
+	 * @param array $query_args like what gets passed to
1793
+	 *                          add_query_arg() as the first argument
1794
+	 * @access    public
1795
+	 * @return    string
1796
+	 */
1797
+	public function thank_you_page_url($query_args = array())
1798
+	{
1799
+		if (! $this->thank_you_page_url) {
1800
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1801
+		}
1802
+		if ($query_args) {
1803
+			return add_query_arg($query_args, $this->thank_you_page_url);
1804
+		} else {
1805
+			return $this->thank_you_page_url;
1806
+		}
1807
+	}
1808
+
1809
+
1810
+	/**
1811
+	 *  gets/returns URL for EE cancel_page
1812
+	 *
1813
+	 * @access    public
1814
+	 * @return    string
1815
+	 */
1816
+	public function cancel_page_url()
1817
+	{
1818
+		if (! $this->cancel_page_url) {
1819
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1820
+		}
1821
+		return $this->cancel_page_url;
1822
+	}
1823
+
1824
+
1825
+	/**
1826
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1827
+	 *
1828
+	 * @since 4.7.5
1829
+	 */
1830
+	protected function _reset_urls()
1831
+	{
1832
+		$this->reg_page_url = '';
1833
+		$this->txn_page_url = '';
1834
+		$this->cancel_page_url = '';
1835
+		$this->thank_you_page_url = '';
1836
+	}
1837
+
1838
+
1839
+	/**
1840
+	 * Used to return what the optin value is set for the EE User Experience Program.
1841
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1842
+	 * on the main site only.
1843
+	 *
1844
+	 * @return bool
1845
+	 */
1846
+	protected function _get_main_ee_ueip_optin()
1847
+	{
1848
+		// if this is the main site then we can just bypass our direct query.
1849
+		if (is_main_site()) {
1850
+			return get_option(self::OPTION_NAME_UXIP, false);
1851
+		}
1852
+		// is this already cached for this request?  If so use it.
1853
+		if (EE_Core_Config::$ee_ueip_option !== null) {
1854
+			return EE_Core_Config::$ee_ueip_option;
1855
+		}
1856
+		global $wpdb;
1857
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1858
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1859
+		$option = self::OPTION_NAME_UXIP;
1860
+		// set correct table for query
1861
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1862
+		// rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1863
+		// get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1864
+		// re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1865
+		// this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1866
+		// for the purpose of caching.
1867
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1868
+		if (false !== $pre) {
1869
+			EE_Core_Config::$ee_ueip_option = $pre;
1870
+			return EE_Core_Config::$ee_ueip_option;
1871
+		}
1872
+		$row = $wpdb->get_row(
1873
+			$wpdb->prepare(
1874
+				"SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1875
+				$option
1876
+			)
1877
+		);
1878
+		if (is_object($row)) {
1879
+			$value = $row->option_value;
1880
+		} else { // option does not exist so use default.
1881
+			EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1882
+			return EE_Core_Config::$ee_ueip_option;
1883
+		}
1884
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1885
+		return EE_Core_Config::$ee_ueip_option;
1886
+	}
1887
+
1888
+
1889
+	/**
1890
+	 * Utility function for escaping the value of a property and returning.
1891
+	 *
1892
+	 * @param string $property property name (checks to see if exists).
1893
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1894
+	 * @throws EE_Error
1895
+	 */
1896
+	public function get_pretty($property)
1897
+	{
1898
+		if ($property === self::OPTION_NAME_UXIP) {
1899
+			return $this->ee_ueip_optin ? 'yes' : 'no';
1900
+		}
1901
+		return parent::get_pretty($property);
1902
+	}
1903
+
1904
+
1905
+	/**
1906
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1907
+	 * on the object.
1908
+	 *
1909
+	 * @return array
1910
+	 */
1911
+	public function __sleep()
1912
+	{
1913
+		// reset all url properties
1914
+		$this->_reset_urls();
1915
+		// return what to save to db
1916
+		return array_keys(get_object_vars($this));
1917
+	}
1918
+}
2304 1919
 
2305
-    /**
2306
-     * array of form names protected by ReCaptcha
2307
-     *
2308
-     * @var array $recaptcha_protected_forms
2309
-     */
2310
-    public $recaptcha_protected_forms;
1920
+/**
1921
+ * Config class for storing info on the Organization
1922
+ */
1923
+class EE_Organization_Config extends EE_Config_Base
1924
+{
2311 1925
 
2312
-    /**
2313
-     * ReCaptcha width
2314
-     *
2315
-     * @var int $recaptcha_width
2316
-     * @deprecated
2317
-     */
2318
-    public $recaptcha_width;
1926
+	/**
1927
+	 * @var string $name
1928
+	 * eg EE4.1
1929
+	 */
1930
+	public $name;
1931
+
1932
+	/**
1933
+	 * @var string $address_1
1934
+	 * eg 123 Onna Road
1935
+	 */
1936
+	public $address_1 = '';
1937
+
1938
+	/**
1939
+	 * @var string $address_2
1940
+	 * eg PO Box 123
1941
+	 */
1942
+	public $address_2 = '';
1943
+
1944
+	/**
1945
+	 * @var string $city
1946
+	 * eg Inna City
1947
+	 */
1948
+	public $city = '';
1949
+
1950
+	/**
1951
+	 * @var int $STA_ID
1952
+	 * eg 4
1953
+	 */
1954
+	public $STA_ID = 0;
1955
+
1956
+	/**
1957
+	 * @var string $CNT_ISO
1958
+	 * eg US
1959
+	 */
1960
+	public $CNT_ISO = '';
1961
+
1962
+	/**
1963
+	 * @var string $zip
1964
+	 * eg 12345  or V1A 2B3
1965
+	 */
1966
+	public $zip = '';
1967
+
1968
+	/**
1969
+	 * @var string $email
1970
+	 * eg [email protected]
1971
+	 */
1972
+	public $email;
1973
+
1974
+	/**
1975
+	 * @var string $phone
1976
+	 * eg. 111-111-1111
1977
+	 */
1978
+	public $phone = '';
1979
+
1980
+	/**
1981
+	 * @var string $vat
1982
+	 * VAT/Tax Number
1983
+	 */
1984
+	public $vat = '';
1985
+
1986
+	/**
1987
+	 * @var string $logo_url
1988
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1989
+	 */
1990
+	public $logo_url = '';
1991
+
1992
+	/**
1993
+	 * The below are all various properties for holding links to organization social network profiles
1994
+	 *
1995
+	 * @var string
1996
+	 */
1997
+	/**
1998
+	 * facebook (facebook.com/profile.name)
1999
+	 *
2000
+	 * @var string
2001
+	 */
2002
+	public $facebook = '';
2003
+
2004
+	/**
2005
+	 * twitter (twitter.com/twitter_handle)
2006
+	 *
2007
+	 * @var string
2008
+	 */
2009
+	public $twitter = '';
2010
+
2011
+	/**
2012
+	 * linkedin (linkedin.com/in/profile_name)
2013
+	 *
2014
+	 * @var string
2015
+	 */
2016
+	public $linkedin = '';
2017
+
2018
+	/**
2019
+	 * pinterest (www.pinterest.com/profile_name)
2020
+	 *
2021
+	 * @var string
2022
+	 */
2023
+	public $pinterest = '';
2024
+
2025
+	/**
2026
+	 * google+ (google.com/+profileName)
2027
+	 *
2028
+	 * @var string
2029
+	 */
2030
+	public $google = '';
2031
+
2032
+	/**
2033
+	 * instagram (instagram.com/handle)
2034
+	 *
2035
+	 * @var string
2036
+	 */
2037
+	public $instagram = '';
2038
+
2039
+
2040
+	/**
2041
+	 *    class constructor
2042
+	 *
2043
+	 * @access    public
2044
+	 */
2045
+	public function __construct()
2046
+	{
2047
+		// set default organization settings
2048
+		// decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2049
+		$this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2050
+		$this->email = get_bloginfo('admin_email');
2051
+	}
2052
+}
2319 2053
 
2320
-    /**
2321
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2322
-     *
2323
-     * @var boolean $track_invalid_checkout_access
2324
-     */
2325
-    protected $track_invalid_checkout_access = true;
2054
+/**
2055
+ * Class for defining what's in the EE_Config relating to currency
2056
+ */
2057
+class EE_Currency_Config extends EE_Config_Base
2058
+{
2326 2059
 
2327
-    /**
2328
-     * Whether or not to show the privacy policy consent checkbox
2329
-     *
2330
-     * @var bool
2331
-     */
2332
-    public $consent_checkbox_enabled;
2060
+	/**
2061
+	 * @var string $code
2062
+	 * eg 'US'
2063
+	 */
2064
+	public $code;
2065
+
2066
+	/**
2067
+	 * @var string $name
2068
+	 * eg 'Dollar'
2069
+	 */
2070
+	public $name;
2071
+
2072
+	/**
2073
+	 * plural name
2074
+	 *
2075
+	 * @var string $plural
2076
+	 * eg 'Dollars'
2077
+	 */
2078
+	public $plural;
2079
+
2080
+	/**
2081
+	 * currency sign
2082
+	 *
2083
+	 * @var string $sign
2084
+	 * eg '$'
2085
+	 */
2086
+	public $sign;
2087
+
2088
+	/**
2089
+	 * Whether the currency sign should come before the number or not
2090
+	 *
2091
+	 * @var boolean $sign_b4
2092
+	 */
2093
+	public $sign_b4;
2094
+
2095
+	/**
2096
+	 * How many digits should come after the decimal place
2097
+	 *
2098
+	 * @var int $dec_plc
2099
+	 */
2100
+	public $dec_plc;
2101
+
2102
+	/**
2103
+	 * Symbol to use for decimal mark
2104
+	 *
2105
+	 * @var string $dec_mrk
2106
+	 * eg '.'
2107
+	 */
2108
+	public $dec_mrk;
2109
+
2110
+	/**
2111
+	 * Symbol to use for thousands
2112
+	 *
2113
+	 * @var string $thsnds
2114
+	 * eg ','
2115
+	 */
2116
+	public $thsnds;
2117
+
2118
+
2119
+	/**
2120
+	 *    class constructor
2121
+	 *
2122
+	 * @access    public
2123
+	 * @param string $CNT_ISO
2124
+	 * @throws EE_Error
2125
+	 * @throws ReflectionException
2126
+	 */
2127
+	public function __construct($CNT_ISO = '')
2128
+	{
2129
+		/** @var TableAnalysis $table_analysis */
2130
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2131
+		// get country code from organization settings or use default
2132
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2133
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2134
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2135
+			: '';
2136
+		// but override if requested
2137
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2138
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2139
+		if (
2140
+			! empty($CNT_ISO)
2141
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2142
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2143
+		) {
2144
+			// retrieve the country settings from the db, just in case they have been customized
2145
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2146
+			if ($country instanceof EE_Country) {
2147
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2148
+				$this->name = $country->currency_name_single();    // Dollar
2149
+				$this->plural = $country->currency_name_plural();    // Dollars
2150
+				$this->sign = $country->currency_sign();            // currency sign: $
2151
+				$this->sign_b4 = $country->currency_sign_before(
2152
+				);        // currency sign before or after: $TRUE  or  FALSE$
2153
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2154
+				$this->dec_mrk = $country->currency_decimal_mark(
2155
+				);    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2156
+				$this->thsnds = $country->currency_thousands_separator(
2157
+				);    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2158
+			}
2159
+		}
2160
+		// fallback to hardcoded defaults, in case the above failed
2161
+		if (empty($this->code)) {
2162
+			// set default currency settings
2163
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2164
+			$this->name = esc_html__('Dollar', 'event_espresso');    // Dollar
2165
+			$this->plural = esc_html__('Dollars', 'event_espresso');    // Dollars
2166
+			$this->sign = '$';    // currency sign: $
2167
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2168
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2169
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2170
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2171
+		}
2172
+	}
2173
+}
2333 2174
 
2334
-    /**
2335
-     * Label text to show on the checkbox
2336
-     *
2337
-     * @var string
2338
-     */
2339
-    public $consent_checkbox_label_text;
2175
+/**
2176
+ * Class for defining what's in the EE_Config relating to registration settings
2177
+ */
2178
+class EE_Registration_Config extends EE_Config_Base
2179
+{
2340 2180
 
2341
-    /*
2181
+	/**
2182
+	 * Default registration status
2183
+	 *
2184
+	 * @var string $default_STS_ID
2185
+	 * eg 'RPP'
2186
+	 */
2187
+	public $default_STS_ID;
2188
+
2189
+	/**
2190
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2191
+	 * registrations)
2192
+	 *
2193
+	 * @var int
2194
+	 */
2195
+	public $default_maximum_number_of_tickets;
2196
+
2197
+	/**
2198
+	 * level of validation to apply to email addresses
2199
+	 *
2200
+	 * @var string $email_validation_level
2201
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2202
+	 */
2203
+	public $email_validation_level;
2204
+
2205
+	/**
2206
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2207
+	 *
2208
+	 * @var boolean $show_pending_payment_options
2209
+	 */
2210
+	public $show_pending_payment_options;
2211
+
2212
+	/**
2213
+	 * Whether to skip the registration confirmation page
2214
+	 *
2215
+	 * @var boolean $skip_reg_confirmation
2216
+	 */
2217
+	public $skip_reg_confirmation;
2218
+
2219
+	/**
2220
+	 * an array of SPCO reg steps where:
2221
+	 *        the keys denotes the reg step order
2222
+	 *        each element consists of an array with the following elements:
2223
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2224
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2225
+	 *            "slug" => the URL param used to trigger the reg step
2226
+	 *
2227
+	 * @var array $reg_steps
2228
+	 */
2229
+	public $reg_steps;
2230
+
2231
+	/**
2232
+	 * Whether registration confirmation should be the last page of SPCO
2233
+	 *
2234
+	 * @var boolean $reg_confirmation_last
2235
+	 */
2236
+	public $reg_confirmation_last;
2237
+
2238
+	/**
2239
+	 * Whether or not to enable the EE Bot Trap
2240
+	 *
2241
+	 * @var boolean $use_bot_trap
2242
+	 */
2243
+	public $use_bot_trap;
2244
+
2245
+	/**
2246
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2247
+	 *
2248
+	 * @var boolean $use_encryption
2249
+	 */
2250
+	public $use_encryption;
2251
+
2252
+	/**
2253
+	 * Whether or not to use ReCaptcha
2254
+	 *
2255
+	 * @var boolean $use_captcha
2256
+	 */
2257
+	public $use_captcha;
2258
+
2259
+	/**
2260
+	 * ReCaptcha Theme
2261
+	 *
2262
+	 * @var string $recaptcha_theme
2263
+	 *    options: 'dark', 'light', 'invisible'
2264
+	 */
2265
+	public $recaptcha_theme;
2266
+
2267
+	/**
2268
+	 * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2269
+	 *
2270
+	 * @var string $recaptcha_badge
2271
+	 *    options: 'bottomright', 'bottomleft', 'inline'
2272
+	 */
2273
+	public $recaptcha_badge;
2274
+
2275
+	/**
2276
+	 * ReCaptcha Type
2277
+	 *
2278
+	 * @var string $recaptcha_type
2279
+	 *    options: 'audio', 'image'
2280
+	 */
2281
+	public $recaptcha_type;
2282
+
2283
+	/**
2284
+	 * ReCaptcha language
2285
+	 *
2286
+	 * @var string $recaptcha_language
2287
+	 * eg 'en'
2288
+	 */
2289
+	public $recaptcha_language;
2290
+
2291
+	/**
2292
+	 * ReCaptcha public key
2293
+	 *
2294
+	 * @var string $recaptcha_publickey
2295
+	 */
2296
+	public $recaptcha_publickey;
2297
+
2298
+	/**
2299
+	 * ReCaptcha private key
2300
+	 *
2301
+	 * @var string $recaptcha_privatekey
2302
+	 */
2303
+	public $recaptcha_privatekey;
2304
+
2305
+	/**
2306
+	 * array of form names protected by ReCaptcha
2307
+	 *
2308
+	 * @var array $recaptcha_protected_forms
2309
+	 */
2310
+	public $recaptcha_protected_forms;
2311
+
2312
+	/**
2313
+	 * ReCaptcha width
2314
+	 *
2315
+	 * @var int $recaptcha_width
2316
+	 * @deprecated
2317
+	 */
2318
+	public $recaptcha_width;
2319
+
2320
+	/**
2321
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2322
+	 *
2323
+	 * @var boolean $track_invalid_checkout_access
2324
+	 */
2325
+	protected $track_invalid_checkout_access = true;
2326
+
2327
+	/**
2328
+	 * Whether or not to show the privacy policy consent checkbox
2329
+	 *
2330
+	 * @var bool
2331
+	 */
2332
+	public $consent_checkbox_enabled;
2333
+
2334
+	/**
2335
+	 * Label text to show on the checkbox
2336
+	 *
2337
+	 * @var string
2338
+	 */
2339
+	public $consent_checkbox_label_text;
2340
+
2341
+	/*
2342 2342
      * String describing how long to keep payment logs. Passed into DateTime constructor
2343 2343
      * @var string
2344 2344
      */
2345
-    public $gateway_log_lifespan = '1 week';
2346
-
2347
-    /**
2348
-     * Enable copy attendee info at form
2349
-     *
2350
-     * @var boolean $enable_copy_attendee
2351
-     */
2352
-    protected $copy_attendee_info = true;
2353
-
2354
-
2355
-    /**
2356
-     *    class constructor
2357
-     *
2358
-     * @access    public
2359
-     */
2360
-    public function __construct()
2361
-    {
2362
-        // set default registration settings
2363
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2364
-        $this->email_validation_level = 'wp_default';
2365
-        $this->show_pending_payment_options = true;
2366
-        $this->skip_reg_confirmation = true;
2367
-        $this->reg_steps = array();
2368
-        $this->reg_confirmation_last = false;
2369
-        $this->use_bot_trap = true;
2370
-        $this->use_encryption = true;
2371
-        $this->use_captcha = false;
2372
-        $this->recaptcha_theme = 'light';
2373
-        $this->recaptcha_badge = 'bottomleft';
2374
-        $this->recaptcha_type = 'image';
2375
-        $this->recaptcha_language = 'en';
2376
-        $this->recaptcha_publickey = null;
2377
-        $this->recaptcha_privatekey = null;
2378
-        $this->recaptcha_protected_forms = array();
2379
-        $this->recaptcha_width = 500;
2380
-        $this->default_maximum_number_of_tickets = 10;
2381
-        $this->consent_checkbox_enabled = false;
2382
-        $this->consent_checkbox_label_text = '';
2383
-        $this->gateway_log_lifespan = '7 days';
2384
-        $this->copy_attendee_info = true;
2385
-    }
2386
-
2387
-
2388
-    /**
2389
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2390
-     *
2391
-     * @since 4.8.8.rc.019
2392
-     */
2393
-    public function do_hooks()
2394
-    {
2395
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2396
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2397
-        add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2398
-    }
2399
-
2400
-
2401
-    /**
2402
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2403
-     * EVT_default_registration_status field matches the config setting for default_STS_ID.
2404
-     */
2405
-    public function set_default_reg_status_on_EEM_Event()
2406
-    {
2407
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2408
-    }
2409
-
2410
-
2411
-    /**
2412
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2413
-     * for Events matches the config setting for default_maximum_number_of_tickets
2414
-     */
2415
-    public function set_default_max_ticket_on_EEM_Event()
2416
-    {
2417
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2418
-    }
2419
-
2420
-
2421
-    /**
2422
-     * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2423
-     * constructed because that happens before we can get the privacy policy page's permalink.
2424
-     *
2425
-     * @throws InvalidArgumentException
2426
-     * @throws InvalidDataTypeException
2427
-     * @throws InvalidInterfaceException
2428
-     */
2429
-    public function setDefaultCheckboxLabelText()
2430
-    {
2431
-        if (
2432
-            $this->getConsentCheckboxLabelText() === null
2433
-            || $this->getConsentCheckboxLabelText() === ''
2434
-        ) {
2435
-            $opening_a_tag = '';
2436
-            $closing_a_tag = '';
2437
-            if (function_exists('get_privacy_policy_url')) {
2438
-                $privacy_page_url = get_privacy_policy_url();
2439
-                if (! empty($privacy_page_url)) {
2440
-                    $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2441
-                    $closing_a_tag = '</a>';
2442
-                }
2443
-            }
2444
-            $loader = LoaderFactory::getLoader();
2445
-            $org_config = $loader->getShared('EE_Organization_Config');
2446
-            /**
2447
-             * @var $org_config EE_Organization_Config
2448
-             */
2449
-
2450
-            $this->setConsentCheckboxLabelText(
2451
-                sprintf(
2452
-                    esc_html__(
2453
-                        'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2454
-                        'event_espresso'
2455
-                    ),
2456
-                    $org_config->name,
2457
-                    $opening_a_tag,
2458
-                    $closing_a_tag
2459
-                )
2460
-            );
2461
-        }
2462
-    }
2463
-
2464
-
2465
-    /**
2466
-     * @return boolean
2467
-     */
2468
-    public function track_invalid_checkout_access()
2469
-    {
2470
-        return $this->track_invalid_checkout_access;
2471
-    }
2472
-
2473
-
2474
-    /**
2475
-     * @param boolean $track_invalid_checkout_access
2476
-     */
2477
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2478
-    {
2479
-        $this->track_invalid_checkout_access = filter_var(
2480
-            $track_invalid_checkout_access,
2481
-            FILTER_VALIDATE_BOOLEAN
2482
-        );
2483
-    }
2484
-
2485
-    /**
2486
-     * @return boolean
2487
-     */
2488
-    public function copyAttendeeInfo()
2489
-    {
2490
-        return $this->copy_attendee_info;
2491
-    }
2492
-
2493
-
2494
-    /**
2495
-     * @param boolean $copy_attendee_info
2496
-     */
2497
-    public function setCopyAttendeeInfo($copy_attendee_info)
2498
-    {
2499
-        $this->copy_attendee_info = filter_var(
2500
-            $copy_attendee_info,
2501
-            FILTER_VALIDATE_BOOLEAN
2502
-        );
2503
-    }
2504
-
2505
-
2506
-    /**
2507
-     * Gets the options to make availalbe for the gateway log lifespan
2508
-     * @return array
2509
-     */
2510
-    public function gatewayLogLifespanOptions()
2511
-    {
2512
-        return (array) apply_filters(
2513
-            'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2514
-            array(
2515
-                '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2516
-                '1 day' => esc_html__('1 Day', 'event_espresso'),
2517
-                '7 days' => esc_html__('7 Days', 'event_espresso'),
2518
-                '14 days' => esc_html__('14 Days', 'event_espresso'),
2519
-                '30 days' => esc_html__('30 Days', 'event_espresso')
2520
-            )
2521
-        );
2522
-    }
2523
-
2524
-
2525
-    /**
2526
-     * @return bool
2527
-     */
2528
-    public function isConsentCheckboxEnabled()
2529
-    {
2530
-        return $this->consent_checkbox_enabled;
2531
-    }
2532
-
2533
-
2534
-    /**
2535
-     * @param bool $consent_checkbox_enabled
2536
-     */
2537
-    public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2538
-    {
2539
-        $this->consent_checkbox_enabled = filter_var(
2540
-            $consent_checkbox_enabled,
2541
-            FILTER_VALIDATE_BOOLEAN
2542
-        );
2543
-    }
2544
-
2545
-
2546
-    /**
2547
-     * @return string
2548
-     */
2549
-    public function getConsentCheckboxLabelText()
2550
-    {
2551
-        return $this->consent_checkbox_label_text;
2552
-    }
2553
-
2554
-
2555
-    /**
2556
-     * @param string $consent_checkbox_label_text
2557
-     */
2558
-    public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2559
-    {
2560
-        $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2561
-    }
2345
+	public $gateway_log_lifespan = '1 week';
2346
+
2347
+	/**
2348
+	 * Enable copy attendee info at form
2349
+	 *
2350
+	 * @var boolean $enable_copy_attendee
2351
+	 */
2352
+	protected $copy_attendee_info = true;
2353
+
2354
+
2355
+	/**
2356
+	 *    class constructor
2357
+	 *
2358
+	 * @access    public
2359
+	 */
2360
+	public function __construct()
2361
+	{
2362
+		// set default registration settings
2363
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2364
+		$this->email_validation_level = 'wp_default';
2365
+		$this->show_pending_payment_options = true;
2366
+		$this->skip_reg_confirmation = true;
2367
+		$this->reg_steps = array();
2368
+		$this->reg_confirmation_last = false;
2369
+		$this->use_bot_trap = true;
2370
+		$this->use_encryption = true;
2371
+		$this->use_captcha = false;
2372
+		$this->recaptcha_theme = 'light';
2373
+		$this->recaptcha_badge = 'bottomleft';
2374
+		$this->recaptcha_type = 'image';
2375
+		$this->recaptcha_language = 'en';
2376
+		$this->recaptcha_publickey = null;
2377
+		$this->recaptcha_privatekey = null;
2378
+		$this->recaptcha_protected_forms = array();
2379
+		$this->recaptcha_width = 500;
2380
+		$this->default_maximum_number_of_tickets = 10;
2381
+		$this->consent_checkbox_enabled = false;
2382
+		$this->consent_checkbox_label_text = '';
2383
+		$this->gateway_log_lifespan = '7 days';
2384
+		$this->copy_attendee_info = true;
2385
+	}
2386
+
2387
+
2388
+	/**
2389
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2390
+	 *
2391
+	 * @since 4.8.8.rc.019
2392
+	 */
2393
+	public function do_hooks()
2394
+	{
2395
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2396
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2397
+		add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2398
+	}
2399
+
2400
+
2401
+	/**
2402
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2403
+	 * EVT_default_registration_status field matches the config setting for default_STS_ID.
2404
+	 */
2405
+	public function set_default_reg_status_on_EEM_Event()
2406
+	{
2407
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2408
+	}
2409
+
2410
+
2411
+	/**
2412
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2413
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2414
+	 */
2415
+	public function set_default_max_ticket_on_EEM_Event()
2416
+	{
2417
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2418
+	}
2419
+
2420
+
2421
+	/**
2422
+	 * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2423
+	 * constructed because that happens before we can get the privacy policy page's permalink.
2424
+	 *
2425
+	 * @throws InvalidArgumentException
2426
+	 * @throws InvalidDataTypeException
2427
+	 * @throws InvalidInterfaceException
2428
+	 */
2429
+	public function setDefaultCheckboxLabelText()
2430
+	{
2431
+		if (
2432
+			$this->getConsentCheckboxLabelText() === null
2433
+			|| $this->getConsentCheckboxLabelText() === ''
2434
+		) {
2435
+			$opening_a_tag = '';
2436
+			$closing_a_tag = '';
2437
+			if (function_exists('get_privacy_policy_url')) {
2438
+				$privacy_page_url = get_privacy_policy_url();
2439
+				if (! empty($privacy_page_url)) {
2440
+					$opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2441
+					$closing_a_tag = '</a>';
2442
+				}
2443
+			}
2444
+			$loader = LoaderFactory::getLoader();
2445
+			$org_config = $loader->getShared('EE_Organization_Config');
2446
+			/**
2447
+			 * @var $org_config EE_Organization_Config
2448
+			 */
2449
+
2450
+			$this->setConsentCheckboxLabelText(
2451
+				sprintf(
2452
+					esc_html__(
2453
+						'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2454
+						'event_espresso'
2455
+					),
2456
+					$org_config->name,
2457
+					$opening_a_tag,
2458
+					$closing_a_tag
2459
+				)
2460
+			);
2461
+		}
2462
+	}
2463
+
2464
+
2465
+	/**
2466
+	 * @return boolean
2467
+	 */
2468
+	public function track_invalid_checkout_access()
2469
+	{
2470
+		return $this->track_invalid_checkout_access;
2471
+	}
2472
+
2473
+
2474
+	/**
2475
+	 * @param boolean $track_invalid_checkout_access
2476
+	 */
2477
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2478
+	{
2479
+		$this->track_invalid_checkout_access = filter_var(
2480
+			$track_invalid_checkout_access,
2481
+			FILTER_VALIDATE_BOOLEAN
2482
+		);
2483
+	}
2484
+
2485
+	/**
2486
+	 * @return boolean
2487
+	 */
2488
+	public function copyAttendeeInfo()
2489
+	{
2490
+		return $this->copy_attendee_info;
2491
+	}
2492
+
2493
+
2494
+	/**
2495
+	 * @param boolean $copy_attendee_info
2496
+	 */
2497
+	public function setCopyAttendeeInfo($copy_attendee_info)
2498
+	{
2499
+		$this->copy_attendee_info = filter_var(
2500
+			$copy_attendee_info,
2501
+			FILTER_VALIDATE_BOOLEAN
2502
+		);
2503
+	}
2504
+
2505
+
2506
+	/**
2507
+	 * Gets the options to make availalbe for the gateway log lifespan
2508
+	 * @return array
2509
+	 */
2510
+	public function gatewayLogLifespanOptions()
2511
+	{
2512
+		return (array) apply_filters(
2513
+			'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2514
+			array(
2515
+				'1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2516
+				'1 day' => esc_html__('1 Day', 'event_espresso'),
2517
+				'7 days' => esc_html__('7 Days', 'event_espresso'),
2518
+				'14 days' => esc_html__('14 Days', 'event_espresso'),
2519
+				'30 days' => esc_html__('30 Days', 'event_espresso')
2520
+			)
2521
+		);
2522
+	}
2523
+
2524
+
2525
+	/**
2526
+	 * @return bool
2527
+	 */
2528
+	public function isConsentCheckboxEnabled()
2529
+	{
2530
+		return $this->consent_checkbox_enabled;
2531
+	}
2532
+
2533
+
2534
+	/**
2535
+	 * @param bool $consent_checkbox_enabled
2536
+	 */
2537
+	public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2538
+	{
2539
+		$this->consent_checkbox_enabled = filter_var(
2540
+			$consent_checkbox_enabled,
2541
+			FILTER_VALIDATE_BOOLEAN
2542
+		);
2543
+	}
2544
+
2545
+
2546
+	/**
2547
+	 * @return string
2548
+	 */
2549
+	public function getConsentCheckboxLabelText()
2550
+	{
2551
+		return $this->consent_checkbox_label_text;
2552
+	}
2553
+
2554
+
2555
+	/**
2556
+	 * @param string $consent_checkbox_label_text
2557
+	 */
2558
+	public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2559
+	{
2560
+		$this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2561
+	}
2562 2562
 }
2563 2563
 
2564 2564
 /**
@@ -2567,143 +2567,143 @@  discard block
 block discarded – undo
2567 2567
 class EE_Admin_Config extends EE_Config_Base
2568 2568
 {
2569 2569
 
2570
-    /**
2571
-     * @var boolean $use_personnel_manager
2572
-     */
2573
-    public $use_personnel_manager;
2574
-
2575
-    /**
2576
-     * @var boolean $use_dashboard_widget
2577
-     */
2578
-    public $use_dashboard_widget;
2579
-
2580
-    /**
2581
-     * @var int $events_in_dashboard
2582
-     */
2583
-    public $events_in_dashboard;
2584
-
2585
-    /**
2586
-     * @var boolean $use_event_timezones
2587
-     */
2588
-    public $use_event_timezones;
2589
-
2590
-    /**
2591
-     * @var string $log_file_name
2592
-     */
2593
-    public $log_file_name;
2594
-
2595
-    /**
2596
-     * @var string $debug_file_name
2597
-     */
2598
-    public $debug_file_name;
2599
-
2600
-    /**
2601
-     * @var boolean $use_remote_logging
2602
-     */
2603
-    public $use_remote_logging;
2604
-
2605
-    /**
2606
-     * @var string $remote_logging_url
2607
-     */
2608
-    public $remote_logging_url;
2609
-
2610
-    /**
2611
-     * @var boolean $show_reg_footer
2612
-     */
2613
-    public $show_reg_footer;
2614
-
2615
-    /**
2616
-     * @var string $affiliate_id
2617
-     */
2618
-    public $affiliate_id;
2619
-
2620
-    /**
2621
-     * adds extra layer of encoding to session data to prevent serialization errors
2622
-     * but is incompatible with some server configuration errors
2623
-     * if you get "500 internal server errors" during registration, try turning this on
2624
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2625
-     *
2626
-     * @var boolean $encode_session_data
2627
-     */
2628
-    private $encode_session_data = false;
2629
-
2630
-
2631
-    /**
2632
-     *    class constructor
2633
-     *
2634
-     * @access    public
2635
-     */
2636
-    public function __construct()
2637
-    {
2638
-        // set default general admin settings
2639
-        $this->use_personnel_manager = true;
2640
-        $this->use_dashboard_widget = true;
2641
-        $this->events_in_dashboard = 30;
2642
-        $this->use_event_timezones = false;
2643
-        $this->use_remote_logging = false;
2644
-        $this->remote_logging_url = null;
2645
-        $this->show_reg_footer = apply_filters(
2646
-            'FHEE__EE_Admin_Config__show_reg_footer__default',
2647
-            false
2648
-        );
2649
-        $this->affiliate_id = 'default';
2650
-        $this->encode_session_data = false;
2651
-    }
2652
-
2653
-
2654
-    /**
2655
-     * @param bool $reset
2656
-     * @return string
2657
-     */
2658
-    public function log_file_name($reset = false)
2659
-    {
2660
-        if (empty($this->log_file_name) || $reset) {
2661
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2662
-            EE_Config::instance()->update_espresso_config(false, false);
2663
-        }
2664
-        return $this->log_file_name;
2665
-    }
2666
-
2667
-
2668
-    /**
2669
-     * @param bool $reset
2670
-     * @return string
2671
-     */
2672
-    public function debug_file_name($reset = false)
2673
-    {
2674
-        if (empty($this->debug_file_name) || $reset) {
2675
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2676
-            EE_Config::instance()->update_espresso_config(false, false);
2677
-        }
2678
-        return $this->debug_file_name;
2679
-    }
2680
-
2681
-
2682
-    /**
2683
-     * @return string
2684
-     */
2685
-    public function affiliate_id()
2686
-    {
2687
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2688
-    }
2689
-
2690
-
2691
-    /**
2692
-     * @return boolean
2693
-     */
2694
-    public function encode_session_data()
2695
-    {
2696
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2697
-    }
2698
-
2699
-
2700
-    /**
2701
-     * @param boolean $encode_session_data
2702
-     */
2703
-    public function set_encode_session_data($encode_session_data)
2704
-    {
2705
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2706
-    }
2570
+	/**
2571
+	 * @var boolean $use_personnel_manager
2572
+	 */
2573
+	public $use_personnel_manager;
2574
+
2575
+	/**
2576
+	 * @var boolean $use_dashboard_widget
2577
+	 */
2578
+	public $use_dashboard_widget;
2579
+
2580
+	/**
2581
+	 * @var int $events_in_dashboard
2582
+	 */
2583
+	public $events_in_dashboard;
2584
+
2585
+	/**
2586
+	 * @var boolean $use_event_timezones
2587
+	 */
2588
+	public $use_event_timezones;
2589
+
2590
+	/**
2591
+	 * @var string $log_file_name
2592
+	 */
2593
+	public $log_file_name;
2594
+
2595
+	/**
2596
+	 * @var string $debug_file_name
2597
+	 */
2598
+	public $debug_file_name;
2599
+
2600
+	/**
2601
+	 * @var boolean $use_remote_logging
2602
+	 */
2603
+	public $use_remote_logging;
2604
+
2605
+	/**
2606
+	 * @var string $remote_logging_url
2607
+	 */
2608
+	public $remote_logging_url;
2609
+
2610
+	/**
2611
+	 * @var boolean $show_reg_footer
2612
+	 */
2613
+	public $show_reg_footer;
2614
+
2615
+	/**
2616
+	 * @var string $affiliate_id
2617
+	 */
2618
+	public $affiliate_id;
2619
+
2620
+	/**
2621
+	 * adds extra layer of encoding to session data to prevent serialization errors
2622
+	 * but is incompatible with some server configuration errors
2623
+	 * if you get "500 internal server errors" during registration, try turning this on
2624
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2625
+	 *
2626
+	 * @var boolean $encode_session_data
2627
+	 */
2628
+	private $encode_session_data = false;
2629
+
2630
+
2631
+	/**
2632
+	 *    class constructor
2633
+	 *
2634
+	 * @access    public
2635
+	 */
2636
+	public function __construct()
2637
+	{
2638
+		// set default general admin settings
2639
+		$this->use_personnel_manager = true;
2640
+		$this->use_dashboard_widget = true;
2641
+		$this->events_in_dashboard = 30;
2642
+		$this->use_event_timezones = false;
2643
+		$this->use_remote_logging = false;
2644
+		$this->remote_logging_url = null;
2645
+		$this->show_reg_footer = apply_filters(
2646
+			'FHEE__EE_Admin_Config__show_reg_footer__default',
2647
+			false
2648
+		);
2649
+		$this->affiliate_id = 'default';
2650
+		$this->encode_session_data = false;
2651
+	}
2652
+
2653
+
2654
+	/**
2655
+	 * @param bool $reset
2656
+	 * @return string
2657
+	 */
2658
+	public function log_file_name($reset = false)
2659
+	{
2660
+		if (empty($this->log_file_name) || $reset) {
2661
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2662
+			EE_Config::instance()->update_espresso_config(false, false);
2663
+		}
2664
+		return $this->log_file_name;
2665
+	}
2666
+
2667
+
2668
+	/**
2669
+	 * @param bool $reset
2670
+	 * @return string
2671
+	 */
2672
+	public function debug_file_name($reset = false)
2673
+	{
2674
+		if (empty($this->debug_file_name) || $reset) {
2675
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2676
+			EE_Config::instance()->update_espresso_config(false, false);
2677
+		}
2678
+		return $this->debug_file_name;
2679
+	}
2680
+
2681
+
2682
+	/**
2683
+	 * @return string
2684
+	 */
2685
+	public function affiliate_id()
2686
+	{
2687
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2688
+	}
2689
+
2690
+
2691
+	/**
2692
+	 * @return boolean
2693
+	 */
2694
+	public function encode_session_data()
2695
+	{
2696
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2697
+	}
2698
+
2699
+
2700
+	/**
2701
+	 * @param boolean $encode_session_data
2702
+	 */
2703
+	public function set_encode_session_data($encode_session_data)
2704
+	{
2705
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2706
+	}
2707 2707
 }
2708 2708
 
2709 2709
 /**
@@ -2712,70 +2712,70 @@  discard block
 block discarded – undo
2712 2712
 class EE_Template_Config extends EE_Config_Base
2713 2713
 {
2714 2714
 
2715
-    /**
2716
-     * @var boolean $enable_default_style
2717
-     */
2718
-    public $enable_default_style;
2719
-
2720
-    /**
2721
-     * @var string $custom_style_sheet
2722
-     */
2723
-    public $custom_style_sheet;
2724
-
2725
-    /**
2726
-     * @var boolean $display_address_in_regform
2727
-     */
2728
-    public $display_address_in_regform;
2729
-
2730
-    /**
2731
-     * @var int $display_description_on_multi_reg_page
2732
-     */
2733
-    public $display_description_on_multi_reg_page;
2734
-
2735
-    /**
2736
-     * @var boolean $use_custom_templates
2737
-     */
2738
-    public $use_custom_templates;
2739
-
2740
-    /**
2741
-     * @var string $current_espresso_theme
2742
-     */
2743
-    public $current_espresso_theme;
2744
-
2745
-    /**
2746
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2747
-     */
2748
-    public $EED_Ticket_Selector;
2749
-
2750
-    /**
2751
-     * @var EE_Event_Single_Config $EED_Event_Single
2752
-     */
2753
-    public $EED_Event_Single;
2754
-
2755
-    /**
2756
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2757
-     */
2758
-    public $EED_Events_Archive;
2759
-
2760
-
2761
-    /**
2762
-     *    class constructor
2763
-     *
2764
-     * @access    public
2765
-     */
2766
-    public function __construct()
2767
-    {
2768
-        // set default template settings
2769
-        $this->enable_default_style = true;
2770
-        $this->custom_style_sheet = null;
2771
-        $this->display_address_in_regform = true;
2772
-        $this->display_description_on_multi_reg_page = false;
2773
-        $this->use_custom_templates = false;
2774
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2775
-        $this->EED_Event_Single = null;
2776
-        $this->EED_Events_Archive = null;
2777
-        $this->EED_Ticket_Selector = null;
2778
-    }
2715
+	/**
2716
+	 * @var boolean $enable_default_style
2717
+	 */
2718
+	public $enable_default_style;
2719
+
2720
+	/**
2721
+	 * @var string $custom_style_sheet
2722
+	 */
2723
+	public $custom_style_sheet;
2724
+
2725
+	/**
2726
+	 * @var boolean $display_address_in_regform
2727
+	 */
2728
+	public $display_address_in_regform;
2729
+
2730
+	/**
2731
+	 * @var int $display_description_on_multi_reg_page
2732
+	 */
2733
+	public $display_description_on_multi_reg_page;
2734
+
2735
+	/**
2736
+	 * @var boolean $use_custom_templates
2737
+	 */
2738
+	public $use_custom_templates;
2739
+
2740
+	/**
2741
+	 * @var string $current_espresso_theme
2742
+	 */
2743
+	public $current_espresso_theme;
2744
+
2745
+	/**
2746
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2747
+	 */
2748
+	public $EED_Ticket_Selector;
2749
+
2750
+	/**
2751
+	 * @var EE_Event_Single_Config $EED_Event_Single
2752
+	 */
2753
+	public $EED_Event_Single;
2754
+
2755
+	/**
2756
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2757
+	 */
2758
+	public $EED_Events_Archive;
2759
+
2760
+
2761
+	/**
2762
+	 *    class constructor
2763
+	 *
2764
+	 * @access    public
2765
+	 */
2766
+	public function __construct()
2767
+	{
2768
+		// set default template settings
2769
+		$this->enable_default_style = true;
2770
+		$this->custom_style_sheet = null;
2771
+		$this->display_address_in_regform = true;
2772
+		$this->display_description_on_multi_reg_page = false;
2773
+		$this->use_custom_templates = false;
2774
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2775
+		$this->EED_Event_Single = null;
2776
+		$this->EED_Events_Archive = null;
2777
+		$this->EED_Ticket_Selector = null;
2778
+	}
2779 2779
 }
2780 2780
 
2781 2781
 /**
@@ -2784,114 +2784,114 @@  discard block
 block discarded – undo
2784 2784
 class EE_Map_Config extends EE_Config_Base
2785 2785
 {
2786 2786
 
2787
-    /**
2788
-     * @var boolean $use_google_maps
2789
-     */
2790
-    public $use_google_maps;
2791
-
2792
-    /**
2793
-     * @var string $api_key
2794
-     */
2795
-    public $google_map_api_key;
2796
-
2797
-    /**
2798
-     * @var int $event_details_map_width
2799
-     */
2800
-    public $event_details_map_width;
2801
-
2802
-    /**
2803
-     * @var int $event_details_map_height
2804
-     */
2805
-    public $event_details_map_height;
2806
-
2807
-    /**
2808
-     * @var int $event_details_map_zoom
2809
-     */
2810
-    public $event_details_map_zoom;
2811
-
2812
-    /**
2813
-     * @var boolean $event_details_display_nav
2814
-     */
2815
-    public $event_details_display_nav;
2816
-
2817
-    /**
2818
-     * @var boolean $event_details_nav_size
2819
-     */
2820
-    public $event_details_nav_size;
2821
-
2822
-    /**
2823
-     * @var string $event_details_control_type
2824
-     */
2825
-    public $event_details_control_type;
2826
-
2827
-    /**
2828
-     * @var string $event_details_map_align
2829
-     */
2830
-    public $event_details_map_align;
2831
-
2832
-    /**
2833
-     * @var int $event_list_map_width
2834
-     */
2835
-    public $event_list_map_width;
2836
-
2837
-    /**
2838
-     * @var int $event_list_map_height
2839
-     */
2840
-    public $event_list_map_height;
2841
-
2842
-    /**
2843
-     * @var int $event_list_map_zoom
2844
-     */
2845
-    public $event_list_map_zoom;
2846
-
2847
-    /**
2848
-     * @var boolean $event_list_display_nav
2849
-     */
2850
-    public $event_list_display_nav;
2851
-
2852
-    /**
2853
-     * @var boolean $event_list_nav_size
2854
-     */
2855
-    public $event_list_nav_size;
2856
-
2857
-    /**
2858
-     * @var string $event_list_control_type
2859
-     */
2860
-    public $event_list_control_type;
2861
-
2862
-    /**
2863
-     * @var string $event_list_map_align
2864
-     */
2865
-    public $event_list_map_align;
2866
-
2867
-
2868
-    /**
2869
-     *    class constructor
2870
-     *
2871
-     * @access    public
2872
-     */
2873
-    public function __construct()
2874
-    {
2875
-        // set default map settings
2876
-        $this->use_google_maps = true;
2877
-        $this->google_map_api_key = '';
2878
-        // for event details pages (reg page)
2879
-        $this->event_details_map_width = 585;            // ee_map_width_single
2880
-        $this->event_details_map_height = 362;            // ee_map_height_single
2881
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2882
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2883
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2884
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2885
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2886
-        // for event list pages
2887
-        $this->event_list_map_width = 300;            // ee_map_width
2888
-        $this->event_list_map_height = 185;        // ee_map_height
2889
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2890
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2891
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2892
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2893
-        $this->event_list_map_align = 'center';            // ee_map_align
2894
-    }
2787
+	/**
2788
+	 * @var boolean $use_google_maps
2789
+	 */
2790
+	public $use_google_maps;
2791
+
2792
+	/**
2793
+	 * @var string $api_key
2794
+	 */
2795
+	public $google_map_api_key;
2796
+
2797
+	/**
2798
+	 * @var int $event_details_map_width
2799
+	 */
2800
+	public $event_details_map_width;
2801
+
2802
+	/**
2803
+	 * @var int $event_details_map_height
2804
+	 */
2805
+	public $event_details_map_height;
2806
+
2807
+	/**
2808
+	 * @var int $event_details_map_zoom
2809
+	 */
2810
+	public $event_details_map_zoom;
2811
+
2812
+	/**
2813
+	 * @var boolean $event_details_display_nav
2814
+	 */
2815
+	public $event_details_display_nav;
2816
+
2817
+	/**
2818
+	 * @var boolean $event_details_nav_size
2819
+	 */
2820
+	public $event_details_nav_size;
2821
+
2822
+	/**
2823
+	 * @var string $event_details_control_type
2824
+	 */
2825
+	public $event_details_control_type;
2826
+
2827
+	/**
2828
+	 * @var string $event_details_map_align
2829
+	 */
2830
+	public $event_details_map_align;
2831
+
2832
+	/**
2833
+	 * @var int $event_list_map_width
2834
+	 */
2835
+	public $event_list_map_width;
2836
+
2837
+	/**
2838
+	 * @var int $event_list_map_height
2839
+	 */
2840
+	public $event_list_map_height;
2841
+
2842
+	/**
2843
+	 * @var int $event_list_map_zoom
2844
+	 */
2845
+	public $event_list_map_zoom;
2846
+
2847
+	/**
2848
+	 * @var boolean $event_list_display_nav
2849
+	 */
2850
+	public $event_list_display_nav;
2851
+
2852
+	/**
2853
+	 * @var boolean $event_list_nav_size
2854
+	 */
2855
+	public $event_list_nav_size;
2856
+
2857
+	/**
2858
+	 * @var string $event_list_control_type
2859
+	 */
2860
+	public $event_list_control_type;
2861
+
2862
+	/**
2863
+	 * @var string $event_list_map_align
2864
+	 */
2865
+	public $event_list_map_align;
2866
+
2867
+
2868
+	/**
2869
+	 *    class constructor
2870
+	 *
2871
+	 * @access    public
2872
+	 */
2873
+	public function __construct()
2874
+	{
2875
+		// set default map settings
2876
+		$this->use_google_maps = true;
2877
+		$this->google_map_api_key = '';
2878
+		// for event details pages (reg page)
2879
+		$this->event_details_map_width = 585;            // ee_map_width_single
2880
+		$this->event_details_map_height = 362;            // ee_map_height_single
2881
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2882
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2883
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2884
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2885
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2886
+		// for event list pages
2887
+		$this->event_list_map_width = 300;            // ee_map_width
2888
+		$this->event_list_map_height = 185;        // ee_map_height
2889
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2890
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2891
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2892
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2893
+		$this->event_list_map_align = 'center';            // ee_map_align
2894
+	}
2895 2895
 }
2896 2896
 
2897 2897
 /**
@@ -2900,46 +2900,46 @@  discard block
 block discarded – undo
2900 2900
 class EE_Events_Archive_Config extends EE_Config_Base
2901 2901
 {
2902 2902
 
2903
-    public $display_status_banner;
2903
+	public $display_status_banner;
2904 2904
 
2905
-    public $display_description;
2905
+	public $display_description;
2906 2906
 
2907
-    public $display_ticket_selector;
2907
+	public $display_ticket_selector;
2908 2908
 
2909
-    public $display_datetimes;
2909
+	public $display_datetimes;
2910 2910
 
2911
-    public $display_venue;
2911
+	public $display_venue;
2912 2912
 
2913
-    public $display_expired_events;
2913
+	public $display_expired_events;
2914 2914
 
2915
-    public $use_sortable_display_order;
2915
+	public $use_sortable_display_order;
2916 2916
 
2917
-    public $display_order_tickets;
2917
+	public $display_order_tickets;
2918 2918
 
2919
-    public $display_order_datetimes;
2919
+	public $display_order_datetimes;
2920 2920
 
2921
-    public $display_order_event;
2921
+	public $display_order_event;
2922 2922
 
2923
-    public $display_order_venue;
2923
+	public $display_order_venue;
2924 2924
 
2925 2925
 
2926
-    /**
2927
-     *    class constructor
2928
-     */
2929
-    public function __construct()
2930
-    {
2931
-        $this->display_status_banner = 0;
2932
-        $this->display_description = 1;
2933
-        $this->display_ticket_selector = 0;
2934
-        $this->display_datetimes = 1;
2935
-        $this->display_venue = 0;
2936
-        $this->display_expired_events = 0;
2937
-        $this->use_sortable_display_order = false;
2938
-        $this->display_order_tickets = 100;
2939
-        $this->display_order_datetimes = 110;
2940
-        $this->display_order_event = 120;
2941
-        $this->display_order_venue = 130;
2942
-    }
2926
+	/**
2927
+	 *    class constructor
2928
+	 */
2929
+	public function __construct()
2930
+	{
2931
+		$this->display_status_banner = 0;
2932
+		$this->display_description = 1;
2933
+		$this->display_ticket_selector = 0;
2934
+		$this->display_datetimes = 1;
2935
+		$this->display_venue = 0;
2936
+		$this->display_expired_events = 0;
2937
+		$this->use_sortable_display_order = false;
2938
+		$this->display_order_tickets = 100;
2939
+		$this->display_order_datetimes = 110;
2940
+		$this->display_order_event = 120;
2941
+		$this->display_order_venue = 130;
2942
+	}
2943 2943
 }
2944 2944
 
2945 2945
 /**
@@ -2948,34 +2948,34 @@  discard block
 block discarded – undo
2948 2948
 class EE_Event_Single_Config extends EE_Config_Base
2949 2949
 {
2950 2950
 
2951
-    public $display_status_banner_single;
2951
+	public $display_status_banner_single;
2952 2952
 
2953
-    public $display_venue;
2953
+	public $display_venue;
2954 2954
 
2955
-    public $use_sortable_display_order;
2955
+	public $use_sortable_display_order;
2956 2956
 
2957
-    public $display_order_tickets;
2957
+	public $display_order_tickets;
2958 2958
 
2959
-    public $display_order_datetimes;
2959
+	public $display_order_datetimes;
2960 2960
 
2961
-    public $display_order_event;
2961
+	public $display_order_event;
2962 2962
 
2963
-    public $display_order_venue;
2963
+	public $display_order_venue;
2964 2964
 
2965 2965
 
2966
-    /**
2967
-     *    class constructor
2968
-     */
2969
-    public function __construct()
2970
-    {
2971
-        $this->display_status_banner_single = 0;
2972
-        $this->display_venue = 1;
2973
-        $this->use_sortable_display_order = false;
2974
-        $this->display_order_tickets = 100;
2975
-        $this->display_order_datetimes = 110;
2976
-        $this->display_order_event = 120;
2977
-        $this->display_order_venue = 130;
2978
-    }
2966
+	/**
2967
+	 *    class constructor
2968
+	 */
2969
+	public function __construct()
2970
+	{
2971
+		$this->display_status_banner_single = 0;
2972
+		$this->display_venue = 1;
2973
+		$this->use_sortable_display_order = false;
2974
+		$this->display_order_tickets = 100;
2975
+		$this->display_order_datetimes = 110;
2976
+		$this->display_order_event = 120;
2977
+		$this->display_order_venue = 130;
2978
+	}
2979 2979
 }
2980 2980
 
2981 2981
 /**
@@ -2984,172 +2984,172 @@  discard block
 block discarded – undo
2984 2984
 class EE_Ticket_Selector_Config extends EE_Config_Base
2985 2985
 {
2986 2986
 
2987
-    /**
2988
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2989
-     */
2990
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2991
-
2992
-    /**
2993
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2994
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2995
-     */
2996
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2997
-
2998
-    /**
2999
-     * @var boolean $show_ticket_sale_columns
3000
-     */
3001
-    public $show_ticket_sale_columns;
3002
-
3003
-    /**
3004
-     * @var boolean $show_ticket_details
3005
-     */
3006
-    public $show_ticket_details;
3007
-
3008
-    /**
3009
-     * @var boolean $show_expired_tickets
3010
-     */
3011
-    public $show_expired_tickets;
3012
-
3013
-    /**
3014
-     * whether or not to display a dropdown box populated with event datetimes
3015
-     * that toggles which tickets are displayed for a ticket selector.
3016
-     * uses one of the *_DATETIME_SELECTOR constants defined above
3017
-     *
3018
-     * @var string $show_datetime_selector
3019
-     */
3020
-    private $show_datetime_selector = 'no_datetime_selector';
3021
-
3022
-    /**
3023
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
3024
-     *
3025
-     * @var int $datetime_selector_threshold
3026
-     */
3027
-    private $datetime_selector_threshold = 3;
3028
-
3029
-    /**
3030
-     * determines the maximum number of "checked" dates in the date and time filter
3031
-     *
3032
-     * @var int $datetime_selector_checked
3033
-     */
3034
-    private $datetime_selector_max_checked = 10;
3035
-
3036
-
3037
-    /**
3038
-     *    class constructor
3039
-     */
3040
-    public function __construct()
3041
-    {
3042
-        $this->show_ticket_sale_columns = true;
3043
-        $this->show_ticket_details = true;
3044
-        $this->show_expired_tickets = true;
3045
-        $this->show_datetime_selector = EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3046
-        $this->datetime_selector_threshold = 3;
3047
-        $this->datetime_selector_max_checked = 10;
3048
-    }
3049
-
3050
-
3051
-    /**
3052
-     * returns true if a datetime selector should be displayed
3053
-     *
3054
-     * @param array $datetimes
3055
-     * @return bool
3056
-     */
3057
-    public function showDatetimeSelector(array $datetimes)
3058
-    {
3059
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
3060
-        return ! (
3061
-            $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3062
-            || (
3063
-                $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3064
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
3065
-            )
3066
-        );
3067
-    }
3068
-
3069
-
3070
-    /**
3071
-     * @return string
3072
-     */
3073
-    public function getShowDatetimeSelector()
3074
-    {
3075
-        return $this->show_datetime_selector;
3076
-    }
3077
-
3078
-
3079
-    /**
3080
-     * @param bool $keys_only
3081
-     * @return array
3082
-     */
3083
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3084
-    {
3085
-        return $keys_only
3086
-            ? array(
3087
-                EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3088
-                EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3089
-            )
3090
-            : array(
3091
-                EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3092
-                    'Do not show date & time filter',
3093
-                    'event_espresso'
3094
-                ),
3095
-                EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3096
-                    'Maybe show date & time filter',
3097
-                    'event_espresso'
3098
-                ),
3099
-            );
3100
-    }
3101
-
3102
-
3103
-    /**
3104
-     * @param string $show_datetime_selector
3105
-     */
3106
-    public function setShowDatetimeSelector($show_datetime_selector)
3107
-    {
3108
-        $this->show_datetime_selector = in_array(
3109
-            $show_datetime_selector,
3110
-            $this->getShowDatetimeSelectorOptions(),
3111
-            true
3112
-        )
3113
-            ? $show_datetime_selector
3114
-            : EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3115
-    }
3116
-
3117
-
3118
-    /**
3119
-     * @return int
3120
-     */
3121
-    public function getDatetimeSelectorThreshold()
3122
-    {
3123
-        return $this->datetime_selector_threshold;
3124
-    }
3125
-
3126
-
3127
-    /**
3128
-     * @param int $datetime_selector_threshold
3129
-     */
3130
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3131
-    {
3132
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3133
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3134
-    }
3135
-
3136
-
3137
-    /**
3138
-     * @return int
3139
-     */
3140
-    public function getDatetimeSelectorMaxChecked()
3141
-    {
3142
-        return $this->datetime_selector_max_checked;
3143
-    }
3144
-
3145
-
3146
-    /**
3147
-     * @param int $datetime_selector_max_checked
3148
-     */
3149
-    public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3150
-    {
3151
-        $this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3152
-    }
2987
+	/**
2988
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2989
+	 */
2990
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2991
+
2992
+	/**
2993
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2994
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2995
+	 */
2996
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2997
+
2998
+	/**
2999
+	 * @var boolean $show_ticket_sale_columns
3000
+	 */
3001
+	public $show_ticket_sale_columns;
3002
+
3003
+	/**
3004
+	 * @var boolean $show_ticket_details
3005
+	 */
3006
+	public $show_ticket_details;
3007
+
3008
+	/**
3009
+	 * @var boolean $show_expired_tickets
3010
+	 */
3011
+	public $show_expired_tickets;
3012
+
3013
+	/**
3014
+	 * whether or not to display a dropdown box populated with event datetimes
3015
+	 * that toggles which tickets are displayed for a ticket selector.
3016
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
3017
+	 *
3018
+	 * @var string $show_datetime_selector
3019
+	 */
3020
+	private $show_datetime_selector = 'no_datetime_selector';
3021
+
3022
+	/**
3023
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
3024
+	 *
3025
+	 * @var int $datetime_selector_threshold
3026
+	 */
3027
+	private $datetime_selector_threshold = 3;
3028
+
3029
+	/**
3030
+	 * determines the maximum number of "checked" dates in the date and time filter
3031
+	 *
3032
+	 * @var int $datetime_selector_checked
3033
+	 */
3034
+	private $datetime_selector_max_checked = 10;
3035
+
3036
+
3037
+	/**
3038
+	 *    class constructor
3039
+	 */
3040
+	public function __construct()
3041
+	{
3042
+		$this->show_ticket_sale_columns = true;
3043
+		$this->show_ticket_details = true;
3044
+		$this->show_expired_tickets = true;
3045
+		$this->show_datetime_selector = EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3046
+		$this->datetime_selector_threshold = 3;
3047
+		$this->datetime_selector_max_checked = 10;
3048
+	}
3049
+
3050
+
3051
+	/**
3052
+	 * returns true if a datetime selector should be displayed
3053
+	 *
3054
+	 * @param array $datetimes
3055
+	 * @return bool
3056
+	 */
3057
+	public function showDatetimeSelector(array $datetimes)
3058
+	{
3059
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
3060
+		return ! (
3061
+			$this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3062
+			|| (
3063
+				$this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3064
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
3065
+			)
3066
+		);
3067
+	}
3068
+
3069
+
3070
+	/**
3071
+	 * @return string
3072
+	 */
3073
+	public function getShowDatetimeSelector()
3074
+	{
3075
+		return $this->show_datetime_selector;
3076
+	}
3077
+
3078
+
3079
+	/**
3080
+	 * @param bool $keys_only
3081
+	 * @return array
3082
+	 */
3083
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3084
+	{
3085
+		return $keys_only
3086
+			? array(
3087
+				EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3088
+				EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3089
+			)
3090
+			: array(
3091
+				EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3092
+					'Do not show date & time filter',
3093
+					'event_espresso'
3094
+				),
3095
+				EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3096
+					'Maybe show date & time filter',
3097
+					'event_espresso'
3098
+				),
3099
+			);
3100
+	}
3101
+
3102
+
3103
+	/**
3104
+	 * @param string $show_datetime_selector
3105
+	 */
3106
+	public function setShowDatetimeSelector($show_datetime_selector)
3107
+	{
3108
+		$this->show_datetime_selector = in_array(
3109
+			$show_datetime_selector,
3110
+			$this->getShowDatetimeSelectorOptions(),
3111
+			true
3112
+		)
3113
+			? $show_datetime_selector
3114
+			: EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3115
+	}
3116
+
3117
+
3118
+	/**
3119
+	 * @return int
3120
+	 */
3121
+	public function getDatetimeSelectorThreshold()
3122
+	{
3123
+		return $this->datetime_selector_threshold;
3124
+	}
3125
+
3126
+
3127
+	/**
3128
+	 * @param int $datetime_selector_threshold
3129
+	 */
3130
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3131
+	{
3132
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3133
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3134
+	}
3135
+
3136
+
3137
+	/**
3138
+	 * @return int
3139
+	 */
3140
+	public function getDatetimeSelectorMaxChecked()
3141
+	{
3142
+		return $this->datetime_selector_max_checked;
3143
+	}
3144
+
3145
+
3146
+	/**
3147
+	 * @param int $datetime_selector_max_checked
3148
+	 */
3149
+	public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3150
+	{
3151
+		$this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3152
+	}
3153 3153
 }
3154 3154
 
3155 3155
 /**
@@ -3162,87 +3162,87 @@  discard block
 block discarded – undo
3162 3162
 class EE_Environment_Config extends EE_Config_Base
3163 3163
 {
3164 3164
 
3165
-    /**
3166
-     * Hold any php environment variables that we want to track.
3167
-     *
3168
-     * @var stdClass;
3169
-     */
3170
-    public $php;
3171
-
3172
-
3173
-    /**
3174
-     *    constructor
3175
-     */
3176
-    public function __construct()
3177
-    {
3178
-        $this->php = new stdClass();
3179
-        $this->_set_php_values();
3180
-    }
3181
-
3182
-
3183
-    /**
3184
-     * This sets the php environment variables.
3185
-     *
3186
-     * @since 4.4.0
3187
-     * @return void
3188
-     */
3189
-    protected function _set_php_values()
3190
-    {
3191
-        $this->php->max_input_vars = ini_get('max_input_vars');
3192
-        $this->php->version = phpversion();
3193
-    }
3194
-
3195
-
3196
-    /**
3197
-     * helper method for determining whether input_count is
3198
-     * reaching the potential maximum the server can handle
3199
-     * according to max_input_vars
3200
-     *
3201
-     * @param int   $input_count the count of input vars.
3202
-     * @return array {
3203
-     *                           An array that represents whether available space and if no available space the error
3204
-     *                           message.
3205
-     * @type bool   $has_space   whether more inputs can be added.
3206
-     * @type string $msg         Any message to be displayed.
3207
-     *                           }
3208
-     */
3209
-    public function max_input_vars_limit_check($input_count = 0)
3210
-    {
3211
-        if (
3212
-            ! empty($this->php->max_input_vars)
3213
-            && ($input_count >= $this->php->max_input_vars)
3214
-        ) {
3215
-            // check the server setting because the config value could be stale
3216
-            $max_input_vars = ini_get('max_input_vars');
3217
-            if ($input_count >= $max_input_vars) {
3218
-                return sprintf(
3219
-                    esc_html__(
3220
-                        'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3221
-                        'event_espresso'
3222
-                    ),
3223
-                    '<br>',
3224
-                    $input_count,
3225
-                    $max_input_vars
3226
-                );
3227
-            } else {
3228
-                return '';
3229
-            }
3230
-        } else {
3231
-            return '';
3232
-        }
3233
-    }
3234
-
3235
-
3236
-    /**
3237
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3238
-     *
3239
-     * @since 4.4.1
3240
-     * @return void
3241
-     */
3242
-    public function recheck_values()
3243
-    {
3244
-        $this->_set_php_values();
3245
-    }
3165
+	/**
3166
+	 * Hold any php environment variables that we want to track.
3167
+	 *
3168
+	 * @var stdClass;
3169
+	 */
3170
+	public $php;
3171
+
3172
+
3173
+	/**
3174
+	 *    constructor
3175
+	 */
3176
+	public function __construct()
3177
+	{
3178
+		$this->php = new stdClass();
3179
+		$this->_set_php_values();
3180
+	}
3181
+
3182
+
3183
+	/**
3184
+	 * This sets the php environment variables.
3185
+	 *
3186
+	 * @since 4.4.0
3187
+	 * @return void
3188
+	 */
3189
+	protected function _set_php_values()
3190
+	{
3191
+		$this->php->max_input_vars = ini_get('max_input_vars');
3192
+		$this->php->version = phpversion();
3193
+	}
3194
+
3195
+
3196
+	/**
3197
+	 * helper method for determining whether input_count is
3198
+	 * reaching the potential maximum the server can handle
3199
+	 * according to max_input_vars
3200
+	 *
3201
+	 * @param int   $input_count the count of input vars.
3202
+	 * @return array {
3203
+	 *                           An array that represents whether available space and if no available space the error
3204
+	 *                           message.
3205
+	 * @type bool   $has_space   whether more inputs can be added.
3206
+	 * @type string $msg         Any message to be displayed.
3207
+	 *                           }
3208
+	 */
3209
+	public function max_input_vars_limit_check($input_count = 0)
3210
+	{
3211
+		if (
3212
+			! empty($this->php->max_input_vars)
3213
+			&& ($input_count >= $this->php->max_input_vars)
3214
+		) {
3215
+			// check the server setting because the config value could be stale
3216
+			$max_input_vars = ini_get('max_input_vars');
3217
+			if ($input_count >= $max_input_vars) {
3218
+				return sprintf(
3219
+					esc_html__(
3220
+						'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3221
+						'event_espresso'
3222
+					),
3223
+					'<br>',
3224
+					$input_count,
3225
+					$max_input_vars
3226
+				);
3227
+			} else {
3228
+				return '';
3229
+			}
3230
+		} else {
3231
+			return '';
3232
+		}
3233
+	}
3234
+
3235
+
3236
+	/**
3237
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3238
+	 *
3239
+	 * @since 4.4.1
3240
+	 * @return void
3241
+	 */
3242
+	public function recheck_values()
3243
+	{
3244
+		$this->_set_php_values();
3245
+	}
3246 3246
 }
3247 3247
 
3248 3248
 /**
@@ -3255,21 +3255,21 @@  discard block
 block discarded – undo
3255 3255
 class EE_Tax_Config extends EE_Config_Base
3256 3256
 {
3257 3257
 
3258
-    /*
3258
+	/*
3259 3259
      * flag to indicate whether or not to display ticket prices with the taxes included
3260 3260
      *
3261 3261
      * @var boolean $prices_displayed_including_taxes
3262 3262
      */
3263
-    public $prices_displayed_including_taxes;
3263
+	public $prices_displayed_including_taxes;
3264 3264
 
3265 3265
 
3266
-    /**
3267
-     *    class constructor
3268
-     */
3269
-    public function __construct()
3270
-    {
3271
-        $this->prices_displayed_including_taxes = true;
3272
-    }
3266
+	/**
3267
+	 *    class constructor
3268
+	 */
3269
+	public function __construct()
3270
+	{
3271
+		$this->prices_displayed_including_taxes = true;
3272
+	}
3273 3273
 }
3274 3274
 
3275 3275
 /**
@@ -3283,19 +3283,19 @@  discard block
 block discarded – undo
3283 3283
 class EE_Messages_Config extends EE_Config_Base
3284 3284
 {
3285 3285
 
3286
-    /**
3287
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3288
-     * A value of 0 represents never deleting.  Default is 0.
3289
-     *
3290
-     * @var integer
3291
-     */
3292
-    public $delete_threshold;
3286
+	/**
3287
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3288
+	 * A value of 0 represents never deleting.  Default is 0.
3289
+	 *
3290
+	 * @var integer
3291
+	 */
3292
+	public $delete_threshold;
3293 3293
 
3294 3294
 
3295
-    public function __construct()
3296
-    {
3297
-        $this->delete_threshold = 0;
3298
-    }
3295
+	public function __construct()
3296
+	{
3297
+		$this->delete_threshold = 0;
3298
+	}
3299 3299
 }
3300 3300
 
3301 3301
 /**
@@ -3306,31 +3306,31 @@  discard block
 block discarded – undo
3306 3306
 class EE_Gateway_Config extends EE_Config_Base
3307 3307
 {
3308 3308
 
3309
-    /**
3310
-     * Array with keys that are payment gateways slugs, and values are arrays
3311
-     * with any config info the gateway wants to store
3312
-     *
3313
-     * @var array
3314
-     */
3315
-    public $payment_settings;
3316
-
3317
-    /**
3318
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3319
-     * the gateway is stored in the uploads directory
3320
-     *
3321
-     * @var array
3322
-     */
3323
-    public $active_gateways;
3324
-
3325
-
3326
-    /**
3327
-     *    class constructor
3328
-     *
3329
-     * @deprecated
3330
-     */
3331
-    public function __construct()
3332
-    {
3333
-        $this->payment_settings = array();
3334
-        $this->active_gateways = array('Invoice' => false);
3335
-    }
3309
+	/**
3310
+	 * Array with keys that are payment gateways slugs, and values are arrays
3311
+	 * with any config info the gateway wants to store
3312
+	 *
3313
+	 * @var array
3314
+	 */
3315
+	public $payment_settings;
3316
+
3317
+	/**
3318
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3319
+	 * the gateway is stored in the uploads directory
3320
+	 *
3321
+	 * @var array
3322
+	 */
3323
+	public $active_gateways;
3324
+
3325
+
3326
+	/**
3327
+	 *    class constructor
3328
+	 *
3329
+	 * @deprecated
3330
+	 */
3331
+	public function __construct()
3332
+	{
3333
+		$this->payment_settings = array();
3334
+		$this->active_gateways = array('Invoice' => false);
3335
+	}
3336 3336
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin.core.php 1 patch
Indentation   +994 added lines, -994 removed lines patch added patch discarded remove patch
@@ -21,998 +21,998 @@
 block discarded – undo
21 21
 final class EE_Admin implements InterminableInterface
22 22
 {
23 23
 
24
-    /**
25
-     * @var EE_Admin $_instance
26
-     */
27
-    private static $_instance;
28
-
29
-    /**
30
-     * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
31
-     */
32
-    private $persistent_admin_notice_manager;
33
-
34
-    /**
35
-     * @var LoaderInterface
36
-     */
37
-    protected $loader;
38
-
39
-    /**
40
-     * @var RequestInterface
41
-     */
42
-    protected $request;
43
-
44
-
45
-    /**
46
-     * @param RequestInterface $request
47
-     * @singleton method used to instantiate class object
48
-     * @return EE_Admin
49
-     * @throws EE_Error
50
-     */
51
-    public static function instance(RequestInterface $request = null)
52
-    {
53
-        // check if class object is instantiated
54
-        if (! self::$_instance instanceof EE_Admin) {
55
-            self::$_instance = new self($request);
56
-        }
57
-        return self::$_instance;
58
-    }
59
-
60
-
61
-    /**
62
-     * @return EE_Admin
63
-     * @throws EE_Error
64
-     */
65
-    public static function reset()
66
-    {
67
-        self::$_instance = null;
68
-        $request         = LoaderFactory::getLoader()->getShared(RequestInterface::class);
69
-        return self::instance($request);
70
-    }
71
-
72
-
73
-    /**
74
-     * @param RequestInterface $request
75
-     * @throws EE_Error
76
-     * @throws InvalidDataTypeException
77
-     * @throws InvalidInterfaceException
78
-     * @throws InvalidArgumentException
79
-     */
80
-    protected function __construct(RequestInterface $request)
81
-    {
82
-        $this->request = $request;
83
-        $this->loader = LoaderFactory::getLoader();
84
-        // define global EE_Admin constants
85
-        $this->_define_all_constants();
86
-        // set autoloaders for our admin page classes based on included path information
87
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
88
-        // admin hooks
89
-        add_filter('plugin_action_links', [$this, 'filter_plugin_actions'], 10, 2);
90
-        add_action('AHEE__EE_System__initialize_last', [$this, 'init']);
91
-        add_action('AHEE__EE_Admin_Page__route_admin_request', [$this, 'route_admin_request'], 100, 2);
92
-        add_action('wp_loaded', [$this, 'wp_loaded'], 100);
93
-        add_action('admin_init', [$this, 'admin_init'], 100);
94
-        add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts'], 20);
95
-        add_action('admin_notices', [$this, 'display_admin_notices'], 10);
96
-        add_action('network_admin_notices', [$this, 'display_admin_notices'], 10);
97
-        add_filter('pre_update_option', [$this, 'check_for_invalid_datetime_formats'], 100, 2);
98
-        add_filter('admin_footer_text', [$this, 'espresso_admin_footer']);
99
-        add_action('load-plugins.php', [$this, 'hookIntoWpPluginsPage']);
100
-        add_action('display_post_states', [$this, 'displayStateForCriticalPages'], 10, 2);
101
-        add_filter('plugin_row_meta', [$this, 'addLinksToPluginRowMeta'], 10, 2);
102
-        // reset Environment config (we only do this on admin page loads);
103
-        EE_Registry::instance()->CFG->environment->recheck_values();
104
-        do_action('AHEE__EE_Admin__loaded');
105
-    }
106
-
107
-
108
-    /**
109
-     * _define_all_constants
110
-     * define constants that are set globally for all admin pages
111
-     *
112
-     * @return void
113
-     */
114
-    private function _define_all_constants()
115
-    {
116
-        if (! defined('EE_ADMIN_URL')) {
117
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
118
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
119
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/');
120
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
121
-            define('WP_AJAX_URL', admin_url('admin-ajax.php'));
122
-        }
123
-    }
124
-
125
-
126
-    /**
127
-     * filter_plugin_actions - adds links to the Plugins page listing
128
-     *
129
-     * @param array  $links
130
-     * @param string $plugin
131
-     * @return    array
132
-     */
133
-    public function filter_plugin_actions($links, $plugin)
134
-    {
135
-        // set $main_file in stone
136
-        static $main_file;
137
-        // if $main_file is not set yet
138
-        if (! $main_file) {
139
-            $main_file = EE_PLUGIN_BASENAME;
140
-        }
141
-        if ($plugin === $main_file) {
142
-            // compare current plugin to this one
143
-            if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
144
-                $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
145
-                                    . ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
146
-                                    . esc_html__('Maintenance Mode Active', 'event_espresso')
147
-                                    . '</a>';
148
-                array_unshift($links, $maintenance_link);
149
-            } else {
150
-                $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
151
-                                     . esc_html__('Settings', 'event_espresso')
152
-                                     . '</a>';
153
-                $events_link       = '<a href="admin.php?page=espresso_events">'
154
-                                     . esc_html__('Events', 'event_espresso')
155
-                                     . '</a>';
156
-                // add before other links
157
-                array_unshift($links, $org_settings_link, $events_link);
158
-            }
159
-        }
160
-        return $links;
161
-    }
162
-
163
-
164
-    /**
165
-     * @deprecated 4.10.14.p
166
-     */
167
-    public function get_request()
168
-    {
169
-    }
170
-
171
-
172
-    /**
173
-     * hide_admin_pages_except_maintenance_mode
174
-     *
175
-     * @param array $admin_page_folder_names
176
-     * @return array
177
-     */
178
-    public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = [])
179
-    {
180
-        return [
181
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance/',
182
-            'about'       => EE_ADMIN_PAGES . 'about/',
183
-            'support'     => EE_ADMIN_PAGES . 'support/',
184
-        ];
185
-    }
186
-
187
-
188
-    /**
189
-     * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
190
-     * EE_Front_Controller's init phases have run
191
-     *
192
-     * @return void
193
-     * @throws EE_Error
194
-     * @throws InvalidArgumentException
195
-     * @throws InvalidDataTypeException
196
-     * @throws InvalidInterfaceException
197
-     * @throws ReflectionException
198
-     * @throws ServiceNotFoundException
199
-     */
200
-    public function init()
201
-    {
202
-        // only enable most of the EE_Admin IF we're not in full maintenance mode
203
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
204
-            $this->initModelsReady();
205
-        }
206
-        // run the admin page factory but ONLY if:
207
-        // - it is a regular non ajax admin request
208
-        // - we are doing an ee admin ajax request
209
-        if ($this->request->isAdmin() || $this->request->isAdminAjax()) {
210
-            // this loads the controller for the admin pages which will setup routing etc
211
-            $this->loader->getShared('EE_Admin_Page_Loader', [$this->loader]);
212
-        }
213
-        if ($this->request->isAdminAjax()) {
214
-            return;
215
-        }
216
-        add_filter('content_save_pre', [$this, 'its_eSpresso'], 10, 1);
217
-        // make sure our CPTs and custom taxonomy metaboxes get shown for first time users
218
-        add_action('admin_head', [$this, 'enable_hidden_ee_nav_menu_metaboxes'], 10);
219
-        add_action('admin_head', [$this, 'register_custom_nav_menu_boxes'], 10);
220
-        // exclude EE critical pages from all nav menus and wp_list_pages
221
-        add_filter('nav_menu_meta_box_object', [$this, 'remove_pages_from_nav_menu'], 10);
222
-    }
223
-
224
-
225
-    /**
226
-     * Gets the loader (and if it wasn't previously set, sets it)
227
-     *
228
-     * @return LoaderInterface
229
-     * @throws InvalidArgumentException
230
-     * @throws InvalidDataTypeException
231
-     * @throws InvalidInterfaceException
232
-     */
233
-    protected function getLoader()
234
-    {
235
-        return $this->loader;
236
-    }
237
-
238
-
239
-    /**
240
-     * Method that's fired on admin requests (including admin ajax) but only when the models are usable
241
-     * (ie, the site isn't in maintenance mode)
242
-     *
243
-     * @return void
244
-     * @throws EE_Error
245
-     * @since 4.9.63.p
246
-     */
247
-    protected function initModelsReady()
248
-    {
249
-        // ok so we want to enable the entire admin
250
-        $this->persistent_admin_notice_manager = $this->loader->getShared(
251
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
252
-        );
253
-        $this->persistent_admin_notice_manager->setReturnUrl(
254
-            EE_Admin_Page::add_query_args_and_nonce(
255
-                [
256
-                    'page'   => $this->request->getRequestParam('page'),
257
-                    'action' => $this->request->getRequestParam('action'),
258
-                ],
259
-                EE_ADMIN_URL
260
-            )
261
-        );
262
-        $this->maybeSetDatetimeWarningNotice();
263
-        // at a glance dashboard widget
264
-        add_filter('dashboard_glance_items', [$this, 'dashboard_glance_items'], 10);
265
-        // filter for get_edit_post_link used on comments for custom post types
266
-        add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 2);
267
-    }
268
-
269
-
270
-    /**
271
-     *    get_persistent_admin_notices
272
-     *
273
-     * @access    public
274
-     * @return void
275
-     * @throws EE_Error
276
-     * @throws InvalidArgumentException
277
-     * @throws InvalidDataTypeException
278
-     * @throws InvalidInterfaceException
279
-     */
280
-    public function maybeSetDatetimeWarningNotice()
281
-    {
282
-        // add dismissible notice for datetime changes.  Only valid if site does not have a timezone_string set.
283
-        // @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
284
-        // with this.  But after enough time (indeterminate at this point) we can just remove this notice.
285
-        // this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
286
-        if (
287
-            apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
288
-            && ! get_option('timezone_string')
289
-            && EEM_Event::instance()->count() > 0
290
-        ) {
291
-            new PersistentAdminNotice(
292
-                'datetime_fix_notice',
293
-                sprintf(
294
-                    esc_html__(
295
-                        '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
296
-                        'event_espresso'
297
-                    ),
298
-                    '<strong>',
299
-                    '</strong>',
300
-                    '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
301
-                    '</a>',
302
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
303
-                        [
304
-                            'page'   => 'espresso_maintenance_settings',
305
-                            'action' => 'datetime_tools',
306
-                        ],
307
-                        admin_url('admin.php')
308
-                    ) . '">'
309
-                ),
310
-                false,
311
-                'manage_options',
312
-                'datetime_fix_persistent_notice'
313
-            );
314
-        }
315
-    }
316
-
317
-
318
-    /**
319
-     * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
320
-     * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
321
-     * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
322
-     * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
323
-     * normal property on the post_type object.  It's found ONLY in this particular context.
324
-     *
325
-     * @param WP_Post $post_type WP post type object
326
-     * @return WP_Post
327
-     * @throws InvalidArgumentException
328
-     * @throws InvalidDataTypeException
329
-     * @throws InvalidInterfaceException
330
-     */
331
-    public function remove_pages_from_nav_menu($post_type)
332
-    {
333
-        // if this isn't the "pages" post type let's get out
334
-        if ($post_type->name !== 'page') {
335
-            return $post_type;
336
-        }
337
-        $critical_pages            = EE_Registry::instance()->CFG->core->get_critical_pages_array();
338
-        $post_type->_default_query = [
339
-            'post__not_in' => $critical_pages,
340
-        ];
341
-        return $post_type;
342
-    }
343
-
344
-
345
-    /**
346
-     * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
347
-     * metaboxes get shown as well
348
-     *
349
-     * @return void
350
-     */
351
-    public function enable_hidden_ee_nav_menu_metaboxes()
352
-    {
353
-        global $wp_meta_boxes, $pagenow;
354
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
355
-            return;
356
-        }
357
-        $user = wp_get_current_user();
358
-        // has this been done yet?
359
-        if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
360
-            return;
361
-        }
362
-
363
-        $hidden_meta_boxes  = get_user_option('metaboxhidden_nav-menus', $user->ID);
364
-        $initial_meta_boxes = apply_filters(
365
-            'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
366
-            [
367
-                'nav-menu-theme-locations',
368
-                'add-page',
369
-                'add-custom-links',
370
-                'add-category',
371
-                'add-espresso_events',
372
-                'add-espresso_venues',
373
-                'add-espresso_event_categories',
374
-                'add-espresso_venue_categories',
375
-                'add-post-type-post',
376
-                'add-post-type-page',
377
-            ]
378
-        );
379
-
380
-        if (is_array($hidden_meta_boxes)) {
381
-            foreach ($hidden_meta_boxes as $key => $meta_box_id) {
382
-                if (in_array($meta_box_id, $initial_meta_boxes, true)) {
383
-                    unset($hidden_meta_boxes[ $key ]);
384
-                }
385
-            }
386
-        }
387
-        update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
388
-        update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
389
-    }
390
-
391
-
392
-    /**
393
-     * This method simply registers custom nav menu boxes for "nav_menus.php route"
394
-     * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
395
-     *
396
-     * @return void
397
-     * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
398
-     *         addons etc.
399
-     */
400
-    public function register_custom_nav_menu_boxes()
401
-    {
402
-        add_meta_box(
403
-            'add-extra-nav-menu-pages',
404
-            esc_html__('Event Espresso Pages', 'event_espresso'),
405
-            [$this, 'ee_cpt_archive_pages'],
406
-            'nav-menus',
407
-            'side',
408
-            'core'
409
-        );
410
-    }
411
-
412
-
413
-    /**
414
-     * Use this to edit the post link for our cpts so that the edit link points to the correct page.
415
-     *
416
-     * @param string $link the original link generated by wp
417
-     * @param int    $id   post id
418
-     * @return string  the (maybe) modified link
419
-     * @since   4.3.0
420
-     */
421
-    public function modify_edit_post_link($link, $id)
422
-    {
423
-        if (! $post = get_post($id)) {
424
-            return $link;
425
-        }
426
-        if ($post->post_type === 'espresso_attendees') {
427
-            $query_args = [
428
-                'action' => 'edit_attendee',
429
-                'post'   => $id,
430
-            ];
431
-            return EEH_URL::add_query_args_and_nonce(
432
-                $query_args,
433
-                admin_url('admin.php?page=espresso_registrations')
434
-            );
435
-        }
436
-        return $link;
437
-    }
438
-
439
-
440
-    public function ee_cpt_archive_pages()
441
-    {
442
-        global $nav_menu_selected_id;
443
-        $removed_args = [
444
-            'action',
445
-            'customlink-tab',
446
-            'edit-menu-item',
447
-            'menu-item',
448
-            'page-tab',
449
-            '_wpnonce',
450
-        ];
451
-        $nav_tab_link = $nav_menu_selected_id
452
-            ? esc_url(
453
-                add_query_arg(
454
-                    'extra-nav-menu-pages-tab',
455
-                    'event-archives',
456
-                    remove_query_arg($removed_args)
457
-                )
458
-            )
459
-            : '';
460
-        $select_all_link = esc_url(
461
-            add_query_arg(
462
-                [
463
-                    'extra-nav-menu-pages-tab' => 'event-archives',
464
-                    'selectall'                => 1,
465
-                ],
466
-                remove_query_arg($removed_args)
467
-            )
468
-        );
469
-        $pages = $this->_get_extra_nav_menu_pages_items();
470
-        $args['walker'] = new Walker_Nav_Menu_Checklist(false);
471
-        ;
472
-        $nav_menu_pages_items = walk_nav_menu_tree(
473
-            array_map(
474
-                [$this, '_setup_extra_nav_menu_pages_items'],
475
-                $pages
476
-            ),
477
-            0,
478
-            (object) $args
479
-        );
480
-
481
-        EEH_Template::display_template(
482
-            EE_ADMIN_TEMPLATE . 'cpt_archive_page.template.php',
483
-            [
484
-                $nav_menu_pages_items,
485
-                $nav_tab_link,
486
-                $select_all_link,
487
-            ]
488
-        );
489
-    }
490
-
491
-
492
-    /**
493
-     * Returns an array of event archive nav items.
494
-     *
495
-     * @return array
496
-     * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
497
-     *        method we use for getting the extra nav menu items
498
-     */
499
-    private function _get_extra_nav_menu_pages_items()
500
-    {
501
-        $menuitems[] = [
502
-            'title'       => esc_html__('Event List', 'event_espresso'),
503
-            'url'         => get_post_type_archive_link('espresso_events'),
504
-            'description' => esc_html__('Archive page for all events.', 'event_espresso'),
505
-        ];
506
-        return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
507
-    }
508
-
509
-
510
-    /**
511
-     * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
512
-     * the properties and converts it to the menu item object.
513
-     *
514
-     * @param $menu_item_values
515
-     * @return stdClass
516
-     * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
517
-     */
518
-    private function _setup_extra_nav_menu_pages_items($menu_item_values)
519
-    {
520
-        $menu_item = new stdClass();
521
-        $keys      = [
522
-            'ID'               => 0,
523
-            'db_id'            => 0,
524
-            'menu_item_parent' => 0,
525
-            'object_id'        => -1,
526
-            'post_parent'      => 0,
527
-            'type'             => 'custom',
528
-            'object'           => '',
529
-            'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
530
-            'title'            => '',
531
-            'url'              => '',
532
-            'target'           => '',
533
-            'attr_title'       => '',
534
-            'description'      => '',
535
-            'classes'          => [],
536
-            'xfn'              => '',
537
-        ];
538
-
539
-        foreach ($keys as $key => $value) {
540
-            $menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
541
-        }
542
-        return $menu_item;
543
-    }
544
-
545
-
546
-    /**
547
-     * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
548
-     * EE_Admin_Page route is called.
549
-     *
550
-     * @return void
551
-     */
552
-    public function route_admin_request()
553
-    {
554
-    }
555
-
556
-
557
-    /**
558
-     * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
559
-     *
560
-     * @return void
561
-     */
562
-    public function wp_loaded()
563
-    {
564
-    }
565
-
566
-
567
-    /**
568
-     * admin_init
569
-     *
570
-     * @return void
571
-     * @throws InvalidArgumentException
572
-     * @throws InvalidDataTypeException
573
-     * @throws InvalidInterfaceException
574
-     */
575
-    public function admin_init()
576
-    {
577
-        /**
578
-         * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
579
-         * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
580
-         * - check if doing post processing.
581
-         * - check if doing post processing of one of EE CPTs
582
-         * - instantiate the corresponding EE CPT model for the post_type being processed.
583
-         */
584
-        $action    = $this->request->getRequestParam('action');
585
-        $post_type = $this->request->getRequestParam('post_type');
586
-        if ($post_type && $action === 'editpost') {
587
-            /** @var CustomPostTypeDefinitions $custom_post_types */
588
-            $custom_post_types = $this->loader->getShared(CustomPostTypeDefinitions::class);
589
-            $custom_post_types->getCustomPostTypeModels($post_type);
590
-        }
591
-
592
-
593
-        /**
594
-         * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
595
-         * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
596
-         * Pages" tab in the EE General Settings Admin page.
597
-         * This is for user-proofing.
598
-         */
599
-        add_filter('wp_dropdown_pages', [$this, 'modify_dropdown_pages']);
600
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
601
-            $this->adminInitModelsReady();
602
-        }
603
-    }
604
-
605
-
606
-    /**
607
-     * Runs on admin_init but only if models are usable (ie, we're not in maintenance mode)
608
-     */
609
-    protected function adminInitModelsReady()
610
-    {
611
-        if (function_exists('wp_add_privacy_policy_content')) {
612
-            $this->loader->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
613
-        }
614
-    }
615
-
616
-
617
-    /**
618
-     * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
619
-     *
620
-     * @param string $output Current output.
621
-     * @return string
622
-     * @throws InvalidArgumentException
623
-     * @throws InvalidDataTypeException
624
-     * @throws InvalidInterfaceException
625
-     */
626
-    public function modify_dropdown_pages($output)
627
-    {
628
-        // get critical pages
629
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
630
-
631
-        // split current output by line break for easier parsing.
632
-        $split_output = explode("\n", $output);
633
-
634
-        // loop through to remove any critical pages from the array.
635
-        foreach ($critical_pages as $page_id) {
636
-            $needle = 'value="' . $page_id . '"';
637
-            foreach ($split_output as $key => $haystack) {
638
-                if (strpos($haystack, $needle) !== false) {
639
-                    unset($split_output[ $key ]);
640
-                }
641
-            }
642
-        }
643
-        // replace output with the new contents
644
-        return implode("\n", $split_output);
645
-    }
646
-
647
-
648
-    /**
649
-     * enqueue all admin scripts that need loaded for admin pages
650
-     *
651
-     * @return void
652
-     */
653
-    public function enqueue_admin_scripts()
654
-    {
655
-        // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
656
-        // Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
657
-        // calls.
658
-        wp_enqueue_script(
659
-            'ee-inject-wp',
660
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
661
-            ['jquery'],
662
-            EVENT_ESPRESSO_VERSION,
663
-            true
664
-        );
665
-        // register cookie script for future dependencies
666
-        wp_register_script(
667
-            'jquery-cookie',
668
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
669
-            ['jquery'],
670
-            '2.1',
671
-            true
672
-        );
673
-    }
674
-
675
-
676
-    /**
677
-     * display_admin_notices
678
-     *
679
-     * @return void
680
-     */
681
-    public function display_admin_notices()
682
-    {
683
-        echo EE_Error::get_notices(); // already escaped
684
-    }
685
-
686
-
687
-    /**
688
-     * @param array $elements
689
-     * @return array
690
-     * @throws EE_Error
691
-     * @throws InvalidArgumentException
692
-     * @throws InvalidDataTypeException
693
-     * @throws InvalidInterfaceException
694
-     */
695
-    public function dashboard_glance_items($elements)
696
-    {
697
-        $elements                        = is_array($elements) ? $elements : [$elements];
698
-        $events                          = EEM_Event::instance()->count();
699
-        $items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
700
-            ['page' => 'espresso_events'],
701
-            admin_url('admin.php')
702
-        );
703
-        $items['events']['text']         = sprintf(
704
-            esc_html(
705
-                _n('%s Event', '%s Events', $events, 'event_espresso')
706
-            ),
707
-            number_format_i18n($events)
708
-        );
709
-        $items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
710
-        $registrations                   = EEM_Registration::instance()->count(
711
-            [
712
-                [
713
-                    'STS_ID' => ['!=', EEM_Registration::status_id_incomplete],
714
-                ],
715
-            ]
716
-        );
717
-        $items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
718
-            ['page' => 'espresso_registrations'],
719
-            admin_url('admin.php')
720
-        );
721
-        $items['registrations']['text']  = sprintf(
722
-            esc_html(
723
-                _n('%s Registration', '%s Registrations', $registrations, 'event_espresso')
724
-            ),
725
-            number_format_i18n($registrations)
726
-        );
727
-        $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
728
-
729
-        $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
730
-
731
-        foreach ($items as $type => $item_properties) {
732
-            $elements[] = sprintf(
733
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
734
-                $item_properties['url'],
735
-                $item_properties['title'],
736
-                $item_properties['text']
737
-            );
738
-        }
739
-        return $elements;
740
-    }
741
-
742
-
743
-    /**
744
-     * check_for_invalid_datetime_formats
745
-     * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
746
-     * their selected format can be parsed by PHP
747
-     *
748
-     * @param    $value
749
-     * @param    $option
750
-     * @return    string
751
-     */
752
-    public function check_for_invalid_datetime_formats($value, $option)
753
-    {
754
-        // check for date_format or time_format
755
-        switch ($option) {
756
-            case 'date_format':
757
-                $date_time_format = $value . ' ' . get_option('time_format');
758
-                break;
759
-            case 'time_format':
760
-                $date_time_format = get_option('date_format') . ' ' . $value;
761
-                break;
762
-            default:
763
-                $date_time_format = false;
764
-        }
765
-        // do we have a date_time format to check ?
766
-        if ($date_time_format) {
767
-            $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
768
-
769
-            if (is_array($error_msg)) {
770
-                $msg = '<p>'
771
-                       . sprintf(
772
-                           esc_html__(
773
-                               'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
774
-                               'event_espresso'
775
-                           ),
776
-                           date($date_time_format),
777
-                           $date_time_format
778
-                       )
779
-                       . '</p><p><ul>';
780
-
781
-
782
-                foreach ($error_msg as $error) {
783
-                    $msg .= '<li>' . $error . '</li>';
784
-                }
785
-
786
-                $msg .= '</ul></p><p>'
787
-                        . sprintf(
788
-                            esc_html__(
789
-                                '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
790
-                                'event_espresso'
791
-                            ),
792
-                            '<span style="color:#D54E21;">',
793
-                            '</span>'
794
-                        )
795
-                        . '</p>';
796
-
797
-                // trigger WP settings error
798
-                add_settings_error(
799
-                    'date_format',
800
-                    'date_format',
801
-                    $msg
802
-                );
803
-
804
-                // set format to something valid
805
-                switch ($option) {
806
-                    case 'date_format':
807
-                        $value = 'F j, Y';
808
-                        break;
809
-                    case 'time_format':
810
-                        $value = 'g:i a';
811
-                        break;
812
-                }
813
-            }
814
-        }
815
-        return $value;
816
-    }
817
-
818
-
819
-    /**
820
-     * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
821
-     *
822
-     * @param $content
823
-     * @return    string
824
-     */
825
-    public function its_eSpresso($content)
826
-    {
827
-        return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
828
-    }
829
-
830
-
831
-    /**
832
-     * espresso_admin_footer
833
-     *
834
-     * @return    string
835
-     */
836
-    public function espresso_admin_footer()
837
-    {
838
-        return EEH_Template::powered_by_event_espresso('aln-cntr', '', ['utm_content' => 'admin_footer']);
839
-    }
840
-
841
-
842
-    /**
843
-     * static method for registering ee admin page.
844
-     * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
845
-     *
846
-     * @param       $page_basename
847
-     * @param       $page_path
848
-     * @param array $config
849
-     * @return void
850
-     * @throws EE_Error
851
-     * @see        EE_Register_Admin_Page::register()
852
-     * @since      4.3.0
853
-     * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
854
-     */
855
-    public static function register_ee_admin_page($page_basename, $page_path, $config = [])
856
-    {
857
-        EE_Error::doing_it_wrong(
858
-            __METHOD__,
859
-            sprintf(
860
-                esc_html__(
861
-                    'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
862
-                    'event_espresso'
863
-                ),
864
-                $page_basename
865
-            ),
866
-            '4.3'
867
-        );
868
-        if (class_exists('EE_Register_Admin_Page')) {
869
-            $config['page_path'] = $page_path;
870
-        }
871
-        EE_Register_Admin_Page::register($page_basename, $config);
872
-    }
873
-
874
-
875
-    /**
876
-     * @param int     $post_ID
877
-     * @param WP_Post $post
878
-     * @return void
879
-     * @deprecated 4.8.41
880
-     */
881
-    public static function parse_post_content_on_save($post_ID, $post)
882
-    {
883
-        EE_Error::doing_it_wrong(
884
-            __METHOD__,
885
-            esc_html__('Usage is deprecated', 'event_espresso'),
886
-            '4.8.41'
887
-        );
888
-    }
889
-
890
-
891
-    /**
892
-     * @param  $option
893
-     * @param  $old_value
894
-     * @param  $value
895
-     * @return void
896
-     * @deprecated 4.8.41
897
-     */
898
-    public function reset_page_for_posts_on_change($option, $old_value, $value)
899
-    {
900
-        EE_Error::doing_it_wrong(
901
-            __METHOD__,
902
-            esc_html__('Usage is deprecated', 'event_espresso'),
903
-            '4.8.41'
904
-        );
905
-    }
906
-
907
-
908
-    /**
909
-     * @return void
910
-     * @deprecated 4.9.27
911
-     */
912
-    public function get_persistent_admin_notices()
913
-    {
914
-        EE_Error::doing_it_wrong(
915
-            __METHOD__,
916
-            sprintf(
917
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
918
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
919
-            ),
920
-            '4.9.27'
921
-        );
922
-    }
923
-
924
-
925
-    /**
926
-     * @throws InvalidInterfaceException
927
-     * @throws InvalidDataTypeException
928
-     * @throws DomainException
929
-     * @deprecated 4.9.27
930
-     */
931
-    public function dismiss_ee_nag_notice_callback()
932
-    {
933
-        EE_Error::doing_it_wrong(
934
-            __METHOD__,
935
-            sprintf(
936
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
937
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
938
-            ),
939
-            '4.9.27'
940
-        );
941
-        $this->persistent_admin_notice_manager->dismissNotice();
942
-    }
943
-
944
-
945
-    /**
946
-     * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page.
947
-     *
948
-     * @throws InvalidArgumentException
949
-     * @throws InvalidDataTypeException
950
-     * @throws InvalidInterfaceException
951
-     */
952
-    public function hookIntoWpPluginsPage()
953
-    {
954
-        $this->loader->getShared('EventEspresso\core\domain\services\admin\ExitModal');
955
-        $this->loader
956
-             ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells')
957
-             ->decafUpsells();
958
-    }
959
-
960
-
961
-    /**
962
-     * Hooks into the "post states" filter in a wp post type list table.
963
-     *
964
-     * @param array   $post_states
965
-     * @param WP_Post $post
966
-     * @return array
967
-     * @throws InvalidArgumentException
968
-     * @throws InvalidDataTypeException
969
-     * @throws InvalidInterfaceException
970
-     */
971
-    public function displayStateForCriticalPages($post_states, $post)
972
-    {
973
-        $post_states = (array) $post_states;
974
-        if (! $post instanceof WP_Post || $post->post_type !== 'page') {
975
-            return $post_states;
976
-        }
977
-        /** @var EE_Core_Config $config */
978
-        $config = $this->loader->getShared('EE_Config')->core;
979
-        if (in_array($post->ID, $config->get_critical_pages_array(), true)) {
980
-            $post_states[] = sprintf(
981
-            /* Translators: Using company name - Event Espresso Critical Page */
982
-                esc_html__('%s Critical Page', 'event_espresso'),
983
-                'Event Espresso'
984
-            );
985
-        }
986
-        return $post_states;
987
-    }
988
-
989
-
990
-    /**
991
-     * Show documentation links on the plugins page
992
-     *
993
-     * @param mixed $meta Plugin Row Meta
994
-     * @param mixed $file Plugin Base file
995
-     * @return array
996
-     */
997
-    public function addLinksToPluginRowMeta($meta, $file)
998
-    {
999
-        if (EE_PLUGIN_BASENAME === $file) {
1000
-            $row_meta = [
1001
-                'docs' => '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4"'
1002
-                          . ' aria-label="'
1003
-                          . esc_attr__('View Event Espresso documentation', 'event_espresso')
1004
-                          . '">'
1005
-                          . esc_html__('Docs', 'event_espresso')
1006
-                          . '</a>',
1007
-                'api'  => '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API"'
1008
-                          . ' aria-label="'
1009
-                          . esc_attr__('View Event Espresso API docs', 'event_espresso')
1010
-                          . '">'
1011
-                          . esc_html__('API docs', 'event_espresso')
1012
-                          . '</a>',
1013
-            ];
1014
-            return array_merge($meta, $row_meta);
1015
-        }
1016
-        return (array) $meta;
1017
-    }
24
+	/**
25
+	 * @var EE_Admin $_instance
26
+	 */
27
+	private static $_instance;
28
+
29
+	/**
30
+	 * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
31
+	 */
32
+	private $persistent_admin_notice_manager;
33
+
34
+	/**
35
+	 * @var LoaderInterface
36
+	 */
37
+	protected $loader;
38
+
39
+	/**
40
+	 * @var RequestInterface
41
+	 */
42
+	protected $request;
43
+
44
+
45
+	/**
46
+	 * @param RequestInterface $request
47
+	 * @singleton method used to instantiate class object
48
+	 * @return EE_Admin
49
+	 * @throws EE_Error
50
+	 */
51
+	public static function instance(RequestInterface $request = null)
52
+	{
53
+		// check if class object is instantiated
54
+		if (! self::$_instance instanceof EE_Admin) {
55
+			self::$_instance = new self($request);
56
+		}
57
+		return self::$_instance;
58
+	}
59
+
60
+
61
+	/**
62
+	 * @return EE_Admin
63
+	 * @throws EE_Error
64
+	 */
65
+	public static function reset()
66
+	{
67
+		self::$_instance = null;
68
+		$request         = LoaderFactory::getLoader()->getShared(RequestInterface::class);
69
+		return self::instance($request);
70
+	}
71
+
72
+
73
+	/**
74
+	 * @param RequestInterface $request
75
+	 * @throws EE_Error
76
+	 * @throws InvalidDataTypeException
77
+	 * @throws InvalidInterfaceException
78
+	 * @throws InvalidArgumentException
79
+	 */
80
+	protected function __construct(RequestInterface $request)
81
+	{
82
+		$this->request = $request;
83
+		$this->loader = LoaderFactory::getLoader();
84
+		// define global EE_Admin constants
85
+		$this->_define_all_constants();
86
+		// set autoloaders for our admin page classes based on included path information
87
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
88
+		// admin hooks
89
+		add_filter('plugin_action_links', [$this, 'filter_plugin_actions'], 10, 2);
90
+		add_action('AHEE__EE_System__initialize_last', [$this, 'init']);
91
+		add_action('AHEE__EE_Admin_Page__route_admin_request', [$this, 'route_admin_request'], 100, 2);
92
+		add_action('wp_loaded', [$this, 'wp_loaded'], 100);
93
+		add_action('admin_init', [$this, 'admin_init'], 100);
94
+		add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts'], 20);
95
+		add_action('admin_notices', [$this, 'display_admin_notices'], 10);
96
+		add_action('network_admin_notices', [$this, 'display_admin_notices'], 10);
97
+		add_filter('pre_update_option', [$this, 'check_for_invalid_datetime_formats'], 100, 2);
98
+		add_filter('admin_footer_text', [$this, 'espresso_admin_footer']);
99
+		add_action('load-plugins.php', [$this, 'hookIntoWpPluginsPage']);
100
+		add_action('display_post_states', [$this, 'displayStateForCriticalPages'], 10, 2);
101
+		add_filter('plugin_row_meta', [$this, 'addLinksToPluginRowMeta'], 10, 2);
102
+		// reset Environment config (we only do this on admin page loads);
103
+		EE_Registry::instance()->CFG->environment->recheck_values();
104
+		do_action('AHEE__EE_Admin__loaded');
105
+	}
106
+
107
+
108
+	/**
109
+	 * _define_all_constants
110
+	 * define constants that are set globally for all admin pages
111
+	 *
112
+	 * @return void
113
+	 */
114
+	private function _define_all_constants()
115
+	{
116
+		if (! defined('EE_ADMIN_URL')) {
117
+			define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
118
+			define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
119
+			define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/');
120
+			define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
121
+			define('WP_AJAX_URL', admin_url('admin-ajax.php'));
122
+		}
123
+	}
124
+
125
+
126
+	/**
127
+	 * filter_plugin_actions - adds links to the Plugins page listing
128
+	 *
129
+	 * @param array  $links
130
+	 * @param string $plugin
131
+	 * @return    array
132
+	 */
133
+	public function filter_plugin_actions($links, $plugin)
134
+	{
135
+		// set $main_file in stone
136
+		static $main_file;
137
+		// if $main_file is not set yet
138
+		if (! $main_file) {
139
+			$main_file = EE_PLUGIN_BASENAME;
140
+		}
141
+		if ($plugin === $main_file) {
142
+			// compare current plugin to this one
143
+			if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
144
+				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
145
+									. ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
146
+									. esc_html__('Maintenance Mode Active', 'event_espresso')
147
+									. '</a>';
148
+				array_unshift($links, $maintenance_link);
149
+			} else {
150
+				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
151
+									 . esc_html__('Settings', 'event_espresso')
152
+									 . '</a>';
153
+				$events_link       = '<a href="admin.php?page=espresso_events">'
154
+									 . esc_html__('Events', 'event_espresso')
155
+									 . '</a>';
156
+				// add before other links
157
+				array_unshift($links, $org_settings_link, $events_link);
158
+			}
159
+		}
160
+		return $links;
161
+	}
162
+
163
+
164
+	/**
165
+	 * @deprecated 4.10.14.p
166
+	 */
167
+	public function get_request()
168
+	{
169
+	}
170
+
171
+
172
+	/**
173
+	 * hide_admin_pages_except_maintenance_mode
174
+	 *
175
+	 * @param array $admin_page_folder_names
176
+	 * @return array
177
+	 */
178
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = [])
179
+	{
180
+		return [
181
+			'maintenance' => EE_ADMIN_PAGES . 'maintenance/',
182
+			'about'       => EE_ADMIN_PAGES . 'about/',
183
+			'support'     => EE_ADMIN_PAGES . 'support/',
184
+		];
185
+	}
186
+
187
+
188
+	/**
189
+	 * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
190
+	 * EE_Front_Controller's init phases have run
191
+	 *
192
+	 * @return void
193
+	 * @throws EE_Error
194
+	 * @throws InvalidArgumentException
195
+	 * @throws InvalidDataTypeException
196
+	 * @throws InvalidInterfaceException
197
+	 * @throws ReflectionException
198
+	 * @throws ServiceNotFoundException
199
+	 */
200
+	public function init()
201
+	{
202
+		// only enable most of the EE_Admin IF we're not in full maintenance mode
203
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
204
+			$this->initModelsReady();
205
+		}
206
+		// run the admin page factory but ONLY if:
207
+		// - it is a regular non ajax admin request
208
+		// - we are doing an ee admin ajax request
209
+		if ($this->request->isAdmin() || $this->request->isAdminAjax()) {
210
+			// this loads the controller for the admin pages which will setup routing etc
211
+			$this->loader->getShared('EE_Admin_Page_Loader', [$this->loader]);
212
+		}
213
+		if ($this->request->isAdminAjax()) {
214
+			return;
215
+		}
216
+		add_filter('content_save_pre', [$this, 'its_eSpresso'], 10, 1);
217
+		// make sure our CPTs and custom taxonomy metaboxes get shown for first time users
218
+		add_action('admin_head', [$this, 'enable_hidden_ee_nav_menu_metaboxes'], 10);
219
+		add_action('admin_head', [$this, 'register_custom_nav_menu_boxes'], 10);
220
+		// exclude EE critical pages from all nav menus and wp_list_pages
221
+		add_filter('nav_menu_meta_box_object', [$this, 'remove_pages_from_nav_menu'], 10);
222
+	}
223
+
224
+
225
+	/**
226
+	 * Gets the loader (and if it wasn't previously set, sets it)
227
+	 *
228
+	 * @return LoaderInterface
229
+	 * @throws InvalidArgumentException
230
+	 * @throws InvalidDataTypeException
231
+	 * @throws InvalidInterfaceException
232
+	 */
233
+	protected function getLoader()
234
+	{
235
+		return $this->loader;
236
+	}
237
+
238
+
239
+	/**
240
+	 * Method that's fired on admin requests (including admin ajax) but only when the models are usable
241
+	 * (ie, the site isn't in maintenance mode)
242
+	 *
243
+	 * @return void
244
+	 * @throws EE_Error
245
+	 * @since 4.9.63.p
246
+	 */
247
+	protected function initModelsReady()
248
+	{
249
+		// ok so we want to enable the entire admin
250
+		$this->persistent_admin_notice_manager = $this->loader->getShared(
251
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
252
+		);
253
+		$this->persistent_admin_notice_manager->setReturnUrl(
254
+			EE_Admin_Page::add_query_args_and_nonce(
255
+				[
256
+					'page'   => $this->request->getRequestParam('page'),
257
+					'action' => $this->request->getRequestParam('action'),
258
+				],
259
+				EE_ADMIN_URL
260
+			)
261
+		);
262
+		$this->maybeSetDatetimeWarningNotice();
263
+		// at a glance dashboard widget
264
+		add_filter('dashboard_glance_items', [$this, 'dashboard_glance_items'], 10);
265
+		// filter for get_edit_post_link used on comments for custom post types
266
+		add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 2);
267
+	}
268
+
269
+
270
+	/**
271
+	 *    get_persistent_admin_notices
272
+	 *
273
+	 * @access    public
274
+	 * @return void
275
+	 * @throws EE_Error
276
+	 * @throws InvalidArgumentException
277
+	 * @throws InvalidDataTypeException
278
+	 * @throws InvalidInterfaceException
279
+	 */
280
+	public function maybeSetDatetimeWarningNotice()
281
+	{
282
+		// add dismissible notice for datetime changes.  Only valid if site does not have a timezone_string set.
283
+		// @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
284
+		// with this.  But after enough time (indeterminate at this point) we can just remove this notice.
285
+		// this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
286
+		if (
287
+			apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
288
+			&& ! get_option('timezone_string')
289
+			&& EEM_Event::instance()->count() > 0
290
+		) {
291
+			new PersistentAdminNotice(
292
+				'datetime_fix_notice',
293
+				sprintf(
294
+					esc_html__(
295
+						'%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
296
+						'event_espresso'
297
+					),
298
+					'<strong>',
299
+					'</strong>',
300
+					'<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
301
+					'</a>',
302
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
303
+						[
304
+							'page'   => 'espresso_maintenance_settings',
305
+							'action' => 'datetime_tools',
306
+						],
307
+						admin_url('admin.php')
308
+					) . '">'
309
+				),
310
+				false,
311
+				'manage_options',
312
+				'datetime_fix_persistent_notice'
313
+			);
314
+		}
315
+	}
316
+
317
+
318
+	/**
319
+	 * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
320
+	 * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
321
+	 * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
322
+	 * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
323
+	 * normal property on the post_type object.  It's found ONLY in this particular context.
324
+	 *
325
+	 * @param WP_Post $post_type WP post type object
326
+	 * @return WP_Post
327
+	 * @throws InvalidArgumentException
328
+	 * @throws InvalidDataTypeException
329
+	 * @throws InvalidInterfaceException
330
+	 */
331
+	public function remove_pages_from_nav_menu($post_type)
332
+	{
333
+		// if this isn't the "pages" post type let's get out
334
+		if ($post_type->name !== 'page') {
335
+			return $post_type;
336
+		}
337
+		$critical_pages            = EE_Registry::instance()->CFG->core->get_critical_pages_array();
338
+		$post_type->_default_query = [
339
+			'post__not_in' => $critical_pages,
340
+		];
341
+		return $post_type;
342
+	}
343
+
344
+
345
+	/**
346
+	 * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
347
+	 * metaboxes get shown as well
348
+	 *
349
+	 * @return void
350
+	 */
351
+	public function enable_hidden_ee_nav_menu_metaboxes()
352
+	{
353
+		global $wp_meta_boxes, $pagenow;
354
+		if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
355
+			return;
356
+		}
357
+		$user = wp_get_current_user();
358
+		// has this been done yet?
359
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
360
+			return;
361
+		}
362
+
363
+		$hidden_meta_boxes  = get_user_option('metaboxhidden_nav-menus', $user->ID);
364
+		$initial_meta_boxes = apply_filters(
365
+			'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
366
+			[
367
+				'nav-menu-theme-locations',
368
+				'add-page',
369
+				'add-custom-links',
370
+				'add-category',
371
+				'add-espresso_events',
372
+				'add-espresso_venues',
373
+				'add-espresso_event_categories',
374
+				'add-espresso_venue_categories',
375
+				'add-post-type-post',
376
+				'add-post-type-page',
377
+			]
378
+		);
379
+
380
+		if (is_array($hidden_meta_boxes)) {
381
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
382
+				if (in_array($meta_box_id, $initial_meta_boxes, true)) {
383
+					unset($hidden_meta_boxes[ $key ]);
384
+				}
385
+			}
386
+		}
387
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
388
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
389
+	}
390
+
391
+
392
+	/**
393
+	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
394
+	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
395
+	 *
396
+	 * @return void
397
+	 * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
398
+	 *         addons etc.
399
+	 */
400
+	public function register_custom_nav_menu_boxes()
401
+	{
402
+		add_meta_box(
403
+			'add-extra-nav-menu-pages',
404
+			esc_html__('Event Espresso Pages', 'event_espresso'),
405
+			[$this, 'ee_cpt_archive_pages'],
406
+			'nav-menus',
407
+			'side',
408
+			'core'
409
+		);
410
+	}
411
+
412
+
413
+	/**
414
+	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
415
+	 *
416
+	 * @param string $link the original link generated by wp
417
+	 * @param int    $id   post id
418
+	 * @return string  the (maybe) modified link
419
+	 * @since   4.3.0
420
+	 */
421
+	public function modify_edit_post_link($link, $id)
422
+	{
423
+		if (! $post = get_post($id)) {
424
+			return $link;
425
+		}
426
+		if ($post->post_type === 'espresso_attendees') {
427
+			$query_args = [
428
+				'action' => 'edit_attendee',
429
+				'post'   => $id,
430
+			];
431
+			return EEH_URL::add_query_args_and_nonce(
432
+				$query_args,
433
+				admin_url('admin.php?page=espresso_registrations')
434
+			);
435
+		}
436
+		return $link;
437
+	}
438
+
439
+
440
+	public function ee_cpt_archive_pages()
441
+	{
442
+		global $nav_menu_selected_id;
443
+		$removed_args = [
444
+			'action',
445
+			'customlink-tab',
446
+			'edit-menu-item',
447
+			'menu-item',
448
+			'page-tab',
449
+			'_wpnonce',
450
+		];
451
+		$nav_tab_link = $nav_menu_selected_id
452
+			? esc_url(
453
+				add_query_arg(
454
+					'extra-nav-menu-pages-tab',
455
+					'event-archives',
456
+					remove_query_arg($removed_args)
457
+				)
458
+			)
459
+			: '';
460
+		$select_all_link = esc_url(
461
+			add_query_arg(
462
+				[
463
+					'extra-nav-menu-pages-tab' => 'event-archives',
464
+					'selectall'                => 1,
465
+				],
466
+				remove_query_arg($removed_args)
467
+			)
468
+		);
469
+		$pages = $this->_get_extra_nav_menu_pages_items();
470
+		$args['walker'] = new Walker_Nav_Menu_Checklist(false);
471
+		;
472
+		$nav_menu_pages_items = walk_nav_menu_tree(
473
+			array_map(
474
+				[$this, '_setup_extra_nav_menu_pages_items'],
475
+				$pages
476
+			),
477
+			0,
478
+			(object) $args
479
+		);
480
+
481
+		EEH_Template::display_template(
482
+			EE_ADMIN_TEMPLATE . 'cpt_archive_page.template.php',
483
+			[
484
+				$nav_menu_pages_items,
485
+				$nav_tab_link,
486
+				$select_all_link,
487
+			]
488
+		);
489
+	}
490
+
491
+
492
+	/**
493
+	 * Returns an array of event archive nav items.
494
+	 *
495
+	 * @return array
496
+	 * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
497
+	 *        method we use for getting the extra nav menu items
498
+	 */
499
+	private function _get_extra_nav_menu_pages_items()
500
+	{
501
+		$menuitems[] = [
502
+			'title'       => esc_html__('Event List', 'event_espresso'),
503
+			'url'         => get_post_type_archive_link('espresso_events'),
504
+			'description' => esc_html__('Archive page for all events.', 'event_espresso'),
505
+		];
506
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
507
+	}
508
+
509
+
510
+	/**
511
+	 * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
512
+	 * the properties and converts it to the menu item object.
513
+	 *
514
+	 * @param $menu_item_values
515
+	 * @return stdClass
516
+	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
517
+	 */
518
+	private function _setup_extra_nav_menu_pages_items($menu_item_values)
519
+	{
520
+		$menu_item = new stdClass();
521
+		$keys      = [
522
+			'ID'               => 0,
523
+			'db_id'            => 0,
524
+			'menu_item_parent' => 0,
525
+			'object_id'        => -1,
526
+			'post_parent'      => 0,
527
+			'type'             => 'custom',
528
+			'object'           => '',
529
+			'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
530
+			'title'            => '',
531
+			'url'              => '',
532
+			'target'           => '',
533
+			'attr_title'       => '',
534
+			'description'      => '',
535
+			'classes'          => [],
536
+			'xfn'              => '',
537
+		];
538
+
539
+		foreach ($keys as $key => $value) {
540
+			$menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
541
+		}
542
+		return $menu_item;
543
+	}
544
+
545
+
546
+	/**
547
+	 * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
548
+	 * EE_Admin_Page route is called.
549
+	 *
550
+	 * @return void
551
+	 */
552
+	public function route_admin_request()
553
+	{
554
+	}
555
+
556
+
557
+	/**
558
+	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
559
+	 *
560
+	 * @return void
561
+	 */
562
+	public function wp_loaded()
563
+	{
564
+	}
565
+
566
+
567
+	/**
568
+	 * admin_init
569
+	 *
570
+	 * @return void
571
+	 * @throws InvalidArgumentException
572
+	 * @throws InvalidDataTypeException
573
+	 * @throws InvalidInterfaceException
574
+	 */
575
+	public function admin_init()
576
+	{
577
+		/**
578
+		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
579
+		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
580
+		 * - check if doing post processing.
581
+		 * - check if doing post processing of one of EE CPTs
582
+		 * - instantiate the corresponding EE CPT model for the post_type being processed.
583
+		 */
584
+		$action    = $this->request->getRequestParam('action');
585
+		$post_type = $this->request->getRequestParam('post_type');
586
+		if ($post_type && $action === 'editpost') {
587
+			/** @var CustomPostTypeDefinitions $custom_post_types */
588
+			$custom_post_types = $this->loader->getShared(CustomPostTypeDefinitions::class);
589
+			$custom_post_types->getCustomPostTypeModels($post_type);
590
+		}
591
+
592
+
593
+		/**
594
+		 * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
595
+		 * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
596
+		 * Pages" tab in the EE General Settings Admin page.
597
+		 * This is for user-proofing.
598
+		 */
599
+		add_filter('wp_dropdown_pages', [$this, 'modify_dropdown_pages']);
600
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
601
+			$this->adminInitModelsReady();
602
+		}
603
+	}
604
+
605
+
606
+	/**
607
+	 * Runs on admin_init but only if models are usable (ie, we're not in maintenance mode)
608
+	 */
609
+	protected function adminInitModelsReady()
610
+	{
611
+		if (function_exists('wp_add_privacy_policy_content')) {
612
+			$this->loader->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
613
+		}
614
+	}
615
+
616
+
617
+	/**
618
+	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
619
+	 *
620
+	 * @param string $output Current output.
621
+	 * @return string
622
+	 * @throws InvalidArgumentException
623
+	 * @throws InvalidDataTypeException
624
+	 * @throws InvalidInterfaceException
625
+	 */
626
+	public function modify_dropdown_pages($output)
627
+	{
628
+		// get critical pages
629
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
630
+
631
+		// split current output by line break for easier parsing.
632
+		$split_output = explode("\n", $output);
633
+
634
+		// loop through to remove any critical pages from the array.
635
+		foreach ($critical_pages as $page_id) {
636
+			$needle = 'value="' . $page_id . '"';
637
+			foreach ($split_output as $key => $haystack) {
638
+				if (strpos($haystack, $needle) !== false) {
639
+					unset($split_output[ $key ]);
640
+				}
641
+			}
642
+		}
643
+		// replace output with the new contents
644
+		return implode("\n", $split_output);
645
+	}
646
+
647
+
648
+	/**
649
+	 * enqueue all admin scripts that need loaded for admin pages
650
+	 *
651
+	 * @return void
652
+	 */
653
+	public function enqueue_admin_scripts()
654
+	{
655
+		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
656
+		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
657
+		// calls.
658
+		wp_enqueue_script(
659
+			'ee-inject-wp',
660
+			EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
661
+			['jquery'],
662
+			EVENT_ESPRESSO_VERSION,
663
+			true
664
+		);
665
+		// register cookie script for future dependencies
666
+		wp_register_script(
667
+			'jquery-cookie',
668
+			EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
669
+			['jquery'],
670
+			'2.1',
671
+			true
672
+		);
673
+	}
674
+
675
+
676
+	/**
677
+	 * display_admin_notices
678
+	 *
679
+	 * @return void
680
+	 */
681
+	public function display_admin_notices()
682
+	{
683
+		echo EE_Error::get_notices(); // already escaped
684
+	}
685
+
686
+
687
+	/**
688
+	 * @param array $elements
689
+	 * @return array
690
+	 * @throws EE_Error
691
+	 * @throws InvalidArgumentException
692
+	 * @throws InvalidDataTypeException
693
+	 * @throws InvalidInterfaceException
694
+	 */
695
+	public function dashboard_glance_items($elements)
696
+	{
697
+		$elements                        = is_array($elements) ? $elements : [$elements];
698
+		$events                          = EEM_Event::instance()->count();
699
+		$items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
700
+			['page' => 'espresso_events'],
701
+			admin_url('admin.php')
702
+		);
703
+		$items['events']['text']         = sprintf(
704
+			esc_html(
705
+				_n('%s Event', '%s Events', $events, 'event_espresso')
706
+			),
707
+			number_format_i18n($events)
708
+		);
709
+		$items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
710
+		$registrations                   = EEM_Registration::instance()->count(
711
+			[
712
+				[
713
+					'STS_ID' => ['!=', EEM_Registration::status_id_incomplete],
714
+				],
715
+			]
716
+		);
717
+		$items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
718
+			['page' => 'espresso_registrations'],
719
+			admin_url('admin.php')
720
+		);
721
+		$items['registrations']['text']  = sprintf(
722
+			esc_html(
723
+				_n('%s Registration', '%s Registrations', $registrations, 'event_espresso')
724
+			),
725
+			number_format_i18n($registrations)
726
+		);
727
+		$items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
728
+
729
+		$items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
730
+
731
+		foreach ($items as $type => $item_properties) {
732
+			$elements[] = sprintf(
733
+				'<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
734
+				$item_properties['url'],
735
+				$item_properties['title'],
736
+				$item_properties['text']
737
+			);
738
+		}
739
+		return $elements;
740
+	}
741
+
742
+
743
+	/**
744
+	 * check_for_invalid_datetime_formats
745
+	 * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
746
+	 * their selected format can be parsed by PHP
747
+	 *
748
+	 * @param    $value
749
+	 * @param    $option
750
+	 * @return    string
751
+	 */
752
+	public function check_for_invalid_datetime_formats($value, $option)
753
+	{
754
+		// check for date_format or time_format
755
+		switch ($option) {
756
+			case 'date_format':
757
+				$date_time_format = $value . ' ' . get_option('time_format');
758
+				break;
759
+			case 'time_format':
760
+				$date_time_format = get_option('date_format') . ' ' . $value;
761
+				break;
762
+			default:
763
+				$date_time_format = false;
764
+		}
765
+		// do we have a date_time format to check ?
766
+		if ($date_time_format) {
767
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
768
+
769
+			if (is_array($error_msg)) {
770
+				$msg = '<p>'
771
+					   . sprintf(
772
+						   esc_html__(
773
+							   'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
774
+							   'event_espresso'
775
+						   ),
776
+						   date($date_time_format),
777
+						   $date_time_format
778
+					   )
779
+					   . '</p><p><ul>';
780
+
781
+
782
+				foreach ($error_msg as $error) {
783
+					$msg .= '<li>' . $error . '</li>';
784
+				}
785
+
786
+				$msg .= '</ul></p><p>'
787
+						. sprintf(
788
+							esc_html__(
789
+								'%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
790
+								'event_espresso'
791
+							),
792
+							'<span style="color:#D54E21;">',
793
+							'</span>'
794
+						)
795
+						. '</p>';
796
+
797
+				// trigger WP settings error
798
+				add_settings_error(
799
+					'date_format',
800
+					'date_format',
801
+					$msg
802
+				);
803
+
804
+				// set format to something valid
805
+				switch ($option) {
806
+					case 'date_format':
807
+						$value = 'F j, Y';
808
+						break;
809
+					case 'time_format':
810
+						$value = 'g:i a';
811
+						break;
812
+				}
813
+			}
814
+		}
815
+		return $value;
816
+	}
817
+
818
+
819
+	/**
820
+	 * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
821
+	 *
822
+	 * @param $content
823
+	 * @return    string
824
+	 */
825
+	public function its_eSpresso($content)
826
+	{
827
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
828
+	}
829
+
830
+
831
+	/**
832
+	 * espresso_admin_footer
833
+	 *
834
+	 * @return    string
835
+	 */
836
+	public function espresso_admin_footer()
837
+	{
838
+		return EEH_Template::powered_by_event_espresso('aln-cntr', '', ['utm_content' => 'admin_footer']);
839
+	}
840
+
841
+
842
+	/**
843
+	 * static method for registering ee admin page.
844
+	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
845
+	 *
846
+	 * @param       $page_basename
847
+	 * @param       $page_path
848
+	 * @param array $config
849
+	 * @return void
850
+	 * @throws EE_Error
851
+	 * @see        EE_Register_Admin_Page::register()
852
+	 * @since      4.3.0
853
+	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
854
+	 */
855
+	public static function register_ee_admin_page($page_basename, $page_path, $config = [])
856
+	{
857
+		EE_Error::doing_it_wrong(
858
+			__METHOD__,
859
+			sprintf(
860
+				esc_html__(
861
+					'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
862
+					'event_espresso'
863
+				),
864
+				$page_basename
865
+			),
866
+			'4.3'
867
+		);
868
+		if (class_exists('EE_Register_Admin_Page')) {
869
+			$config['page_path'] = $page_path;
870
+		}
871
+		EE_Register_Admin_Page::register($page_basename, $config);
872
+	}
873
+
874
+
875
+	/**
876
+	 * @param int     $post_ID
877
+	 * @param WP_Post $post
878
+	 * @return void
879
+	 * @deprecated 4.8.41
880
+	 */
881
+	public static function parse_post_content_on_save($post_ID, $post)
882
+	{
883
+		EE_Error::doing_it_wrong(
884
+			__METHOD__,
885
+			esc_html__('Usage is deprecated', 'event_espresso'),
886
+			'4.8.41'
887
+		);
888
+	}
889
+
890
+
891
+	/**
892
+	 * @param  $option
893
+	 * @param  $old_value
894
+	 * @param  $value
895
+	 * @return void
896
+	 * @deprecated 4.8.41
897
+	 */
898
+	public function reset_page_for_posts_on_change($option, $old_value, $value)
899
+	{
900
+		EE_Error::doing_it_wrong(
901
+			__METHOD__,
902
+			esc_html__('Usage is deprecated', 'event_espresso'),
903
+			'4.8.41'
904
+		);
905
+	}
906
+
907
+
908
+	/**
909
+	 * @return void
910
+	 * @deprecated 4.9.27
911
+	 */
912
+	public function get_persistent_admin_notices()
913
+	{
914
+		EE_Error::doing_it_wrong(
915
+			__METHOD__,
916
+			sprintf(
917
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
918
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
919
+			),
920
+			'4.9.27'
921
+		);
922
+	}
923
+
924
+
925
+	/**
926
+	 * @throws InvalidInterfaceException
927
+	 * @throws InvalidDataTypeException
928
+	 * @throws DomainException
929
+	 * @deprecated 4.9.27
930
+	 */
931
+	public function dismiss_ee_nag_notice_callback()
932
+	{
933
+		EE_Error::doing_it_wrong(
934
+			__METHOD__,
935
+			sprintf(
936
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
937
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
938
+			),
939
+			'4.9.27'
940
+		);
941
+		$this->persistent_admin_notice_manager->dismissNotice();
942
+	}
943
+
944
+
945
+	/**
946
+	 * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page.
947
+	 *
948
+	 * @throws InvalidArgumentException
949
+	 * @throws InvalidDataTypeException
950
+	 * @throws InvalidInterfaceException
951
+	 */
952
+	public function hookIntoWpPluginsPage()
953
+	{
954
+		$this->loader->getShared('EventEspresso\core\domain\services\admin\ExitModal');
955
+		$this->loader
956
+			 ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells')
957
+			 ->decafUpsells();
958
+	}
959
+
960
+
961
+	/**
962
+	 * Hooks into the "post states" filter in a wp post type list table.
963
+	 *
964
+	 * @param array   $post_states
965
+	 * @param WP_Post $post
966
+	 * @return array
967
+	 * @throws InvalidArgumentException
968
+	 * @throws InvalidDataTypeException
969
+	 * @throws InvalidInterfaceException
970
+	 */
971
+	public function displayStateForCriticalPages($post_states, $post)
972
+	{
973
+		$post_states = (array) $post_states;
974
+		if (! $post instanceof WP_Post || $post->post_type !== 'page') {
975
+			return $post_states;
976
+		}
977
+		/** @var EE_Core_Config $config */
978
+		$config = $this->loader->getShared('EE_Config')->core;
979
+		if (in_array($post->ID, $config->get_critical_pages_array(), true)) {
980
+			$post_states[] = sprintf(
981
+			/* Translators: Using company name - Event Espresso Critical Page */
982
+				esc_html__('%s Critical Page', 'event_espresso'),
983
+				'Event Espresso'
984
+			);
985
+		}
986
+		return $post_states;
987
+	}
988
+
989
+
990
+	/**
991
+	 * Show documentation links on the plugins page
992
+	 *
993
+	 * @param mixed $meta Plugin Row Meta
994
+	 * @param mixed $file Plugin Base file
995
+	 * @return array
996
+	 */
997
+	public function addLinksToPluginRowMeta($meta, $file)
998
+	{
999
+		if (EE_PLUGIN_BASENAME === $file) {
1000
+			$row_meta = [
1001
+				'docs' => '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4"'
1002
+						  . ' aria-label="'
1003
+						  . esc_attr__('View Event Espresso documentation', 'event_espresso')
1004
+						  . '">'
1005
+						  . esc_html__('Docs', 'event_espresso')
1006
+						  . '</a>',
1007
+				'api'  => '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API"'
1008
+						  . ' aria-label="'
1009
+						  . esc_attr__('View Event Espresso API docs', 'event_espresso')
1010
+						  . '">'
1011
+						  . esc_html__('API docs', 'event_espresso')
1012
+						  . '</a>',
1013
+			];
1014
+			return array_merge($meta, $row_meta);
1015
+		}
1016
+		return (array) $meta;
1017
+	}
1018 1018
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 2 patches
Indentation   +3905 added lines, -3905 removed lines patch added patch discarded remove patch
@@ -18,3979 +18,3979 @@
 block discarded – undo
18 18
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @var LoaderInterface
23
-     */
24
-    protected $loader;
21
+	/**
22
+	 * @var LoaderInterface
23
+	 */
24
+	protected $loader;
25 25
 
26
-    /**
27
-     * @var RequestInterface
28
-     */
29
-    protected $request;
26
+	/**
27
+	 * @var RequestInterface
28
+	 */
29
+	protected $request;
30 30
 
31
-    // set in _init_page_props()
32
-    public $page_slug;
31
+	// set in _init_page_props()
32
+	public $page_slug;
33 33
 
34
-    public $page_label;
34
+	public $page_label;
35 35
 
36
-    public $page_folder;
36
+	public $page_folder;
37 37
 
38
-    // set in define_page_props()
39
-    protected $_admin_base_url;
38
+	// set in define_page_props()
39
+	protected $_admin_base_url;
40 40
 
41
-    protected $_admin_base_path;
41
+	protected $_admin_base_path;
42 42
 
43
-    protected $_admin_page_title;
43
+	protected $_admin_page_title;
44 44
 
45
-    protected $_labels;
45
+	protected $_labels;
46 46
 
47 47
 
48
-    // set early within EE_Admin_Init
49
-    protected $_wp_page_slug;
48
+	// set early within EE_Admin_Init
49
+	protected $_wp_page_slug;
50 50
 
51
-    // navtabs
52
-    protected $_nav_tabs;
51
+	// navtabs
52
+	protected $_nav_tabs;
53 53
 
54
-    protected $_default_nav_tab_name;
54
+	protected $_default_nav_tab_name;
55 55
 
56 56
 
57
-    // template variables (used by templates)
58
-    protected $_template_path;
57
+	// template variables (used by templates)
58
+	protected $_template_path;
59 59
 
60
-    protected $_column_template_path;
60
+	protected $_column_template_path;
61 61
 
62
-    /**
63
-     * @var array $_template_args
64
-     */
65
-    protected $_template_args = [];
62
+	/**
63
+	 * @var array $_template_args
64
+	 */
65
+	protected $_template_args = [];
66 66
 
67
-    /**
68
-     * this will hold the list table object for a given view.
69
-     *
70
-     * @var EE_Admin_List_Table $_list_table_object
71
-     */
72
-    protected $_list_table_object;
67
+	/**
68
+	 * this will hold the list table object for a given view.
69
+	 *
70
+	 * @var EE_Admin_List_Table $_list_table_object
71
+	 */
72
+	protected $_list_table_object;
73 73
 
74
-    // bools
75
-    protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
74
+	// bools
75
+	protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
76 76
 
77
-    protected $_routing;
77
+	protected $_routing;
78 78
 
79
-    // list table args
80
-    protected $_view;
79
+	// list table args
80
+	protected $_view;
81 81
 
82
-    protected $_views;
82
+	protected $_views;
83 83
 
84 84
 
85
-    // action => method pairs used for routing incoming requests
86
-    protected $_page_routes;
85
+	// action => method pairs used for routing incoming requests
86
+	protected $_page_routes;
87 87
 
88
-    /**
89
-     * @var array $_page_config
90
-     */
91
-    protected $_page_config;
88
+	/**
89
+	 * @var array $_page_config
90
+	 */
91
+	protected $_page_config;
92 92
 
93
-    /**
94
-     * the current page route and route config
95
-     *
96
-     * @var string $_route
97
-     */
98
-    protected $_route;
93
+	/**
94
+	 * the current page route and route config
95
+	 *
96
+	 * @var string $_route
97
+	 */
98
+	protected $_route;
99 99
 
100
-    /**
101
-     * @var string $_cpt_route
102
-     */
103
-    protected $_cpt_route;
100
+	/**
101
+	 * @var string $_cpt_route
102
+	 */
103
+	protected $_cpt_route;
104 104
 
105
-    /**
106
-     * @var array $_route_config
107
-     */
108
-    protected $_route_config;
105
+	/**
106
+	 * @var array $_route_config
107
+	 */
108
+	protected $_route_config;
109 109
 
110
-    /**
111
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
112
-     * actions.
113
-     *
114
-     * @since 4.6.x
115
-     * @var array.
116
-     */
117
-    protected $_default_route_query_args;
118
-
119
-    // set via request page and action args.
120
-    protected $_current_page;
121
-
122
-    protected $_current_view;
123
-
124
-    protected $_current_page_view_url;
125
-
126
-    /**
127
-     * unprocessed value for the 'action' request param (default '')
128
-     *
129
-     * @var string
130
-     */
131
-    protected $raw_req_action = '';
132
-
133
-    /**
134
-     * unprocessed value for the 'page' request param (default '')
135
-     *
136
-     * @var string
137
-     */
138
-    protected $raw_req_page = '';
139
-
140
-    /**
141
-     * sanitized request action (and nonce)
142
-     *
143
-     * @var string
144
-     */
145
-    protected $_req_action = '';
146
-
147
-    /**
148
-     * sanitized request action nonce
149
-     *
150
-     * @var string
151
-     */
152
-    protected $_req_nonce = '';
153
-
154
-    /**
155
-     * @var string
156
-     */
157
-    protected $_search_btn_label = '';
158
-
159
-    /**
160
-     * @var string
161
-     */
162
-    protected $_search_box_callback = '';
163
-
164
-    /**
165
-     * @var WP_Screen
166
-     */
167
-    protected $_current_screen;
168
-
169
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
170
-    protected $_hook_obj;
171
-
172
-    // for holding incoming request data
173
-    protected $_req_data = [];
174
-
175
-    // yes / no array for admin form fields
176
-    protected $_yes_no_values = [];
177
-
178
-    // some default things shared by all child classes
179
-    protected $_default_espresso_metaboxes;
180
-
181
-    /**
182
-     * @var EE_Registry
183
-     */
184
-    protected $EE = null;
185
-
186
-
187
-    /**
188
-     * This is just a property that flags whether the given route is a caffeinated route or not.
189
-     *
190
-     * @var boolean
191
-     */
192
-    protected $_is_caf = false;
193
-
194
-
195
-    /**
196
-     * @Constructor
197
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
198
-     * @throws EE_Error
199
-     * @throws InvalidArgumentException
200
-     * @throws ReflectionException
201
-     * @throws InvalidDataTypeException
202
-     * @throws InvalidInterfaceException
203
-     */
204
-    public function __construct($routing = true)
205
-    {
206
-        $this->loader  = LoaderFactory::getLoader();
207
-        $this->request = $this->loader->getShared(RequestInterface::class);
208
-        $this->_routing = $routing;
209
-
210
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
211
-            $this->_is_caf = true;
212
-        }
213
-        $this->_yes_no_values = [
214
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
215
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
216
-        ];
217
-        // set the _req_data property.
218
-        $this->_req_data = $this->request->requestParams();
219
-        // set initial page props (child method)
220
-        $this->_init_page_props();
221
-        // set global defaults
222
-        $this->_set_defaults();
223
-        // set early because incoming requests could be ajax related and we need to register those hooks.
224
-        $this->_global_ajax_hooks();
225
-        $this->_ajax_hooks();
226
-        // other_page_hooks have to be early too.
227
-        $this->_do_other_page_hooks();
228
-        // set up page dependencies
229
-        $this->_before_page_setup();
230
-        $this->_page_setup();
231
-        // die();
232
-    }
233
-
234
-
235
-    /**
236
-     * _init_page_props
237
-     * Child classes use to set at least the following properties:
238
-     * $page_slug.
239
-     * $page_label.
240
-     *
241
-     * @abstract
242
-     * @return void
243
-     */
244
-    abstract protected function _init_page_props();
245
-
246
-
247
-    /**
248
-     * _ajax_hooks
249
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
250
-     * Note: within the ajax callback methods.
251
-     *
252
-     * @abstract
253
-     * @return void
254
-     */
255
-    abstract protected function _ajax_hooks();
256
-
257
-
258
-    /**
259
-     * _define_page_props
260
-     * child classes define page properties in here.  Must include at least:
261
-     * $_admin_base_url = base_url for all admin pages
262
-     * $_admin_page_title = default admin_page_title for admin pages
263
-     * $_labels = array of default labels for various automatically generated elements:
264
-     *    array(
265
-     *        'buttons' => array(
266
-     *            'add' => esc_html__('label for add new button'),
267
-     *            'edit' => esc_html__('label for edit button'),
268
-     *            'delete' => esc_html__('label for delete button')
269
-     *            )
270
-     *        )
271
-     *
272
-     * @abstract
273
-     * @return void
274
-     */
275
-    abstract protected function _define_page_props();
276
-
277
-
278
-    /**
279
-     * _set_page_routes
280
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
281
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
282
-     * have a 'default' route. Here's the format
283
-     * $this->_page_routes = array(
284
-     *        'default' => array(
285
-     *            'func' => '_default_method_handling_route',
286
-     *            'args' => array('array','of','args'),
287
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
288
-     *            ajax request, backend processing)
289
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
290
-     *            headers route after.  The string you enter here should match the defined route reference for a
291
-     *            headers sent route.
292
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
293
-     *            this route.
294
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
295
-     *            checks).
296
-     *        ),
297
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
298
-     *        handling method.
299
-     *        )
300
-     * )
301
-     *
302
-     * @abstract
303
-     * @return void
304
-     */
305
-    abstract protected function _set_page_routes();
306
-
307
-
308
-    /**
309
-     * _set_page_config
310
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
311
-     * array corresponds to the page_route for the loaded page. Format:
312
-     * $this->_page_config = array(
313
-     *        'default' => array(
314
-     *            'labels' => array(
315
-     *                'buttons' => array(
316
-     *                    'add' => esc_html__('label for adding item'),
317
-     *                    'edit' => esc_html__('label for editing item'),
318
-     *                    'delete' => esc_html__('label for deleting item')
319
-     *                ),
320
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
321
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
322
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
323
-     *            _define_page_props() method
324
-     *            'nav' => array(
325
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
326
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
327
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
328
-     *                'order' => 10, //required to indicate tab position.
329
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
330
-     *                displayed then add this parameter.
331
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
332
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
333
-     *            metaboxes set for eventespresso admin pages.
334
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
335
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
336
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
337
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
338
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
339
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
340
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
341
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
342
-     *            want to display.
343
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
344
-     *                'tab_id' => array(
345
-     *                    'title' => 'tab_title',
346
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
347
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
348
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
349
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
350
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
351
-     *                    attempt to use the callback which should match the name of a method in the class
352
-     *                    ),
353
-     *                'tab2_id' => array(
354
-     *                    'title' => 'tab2 title',
355
-     *                    'filename' => 'file_name_2'
356
-     *                    'callback' => 'callback_method_for_content',
357
-     *                 ),
358
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
359
-     *            help tab area on an admin page. @return void
360
-     *
361
-     * @abstract
362
-     */
363
-    abstract protected function _set_page_config();
364
-
365
-
366
-    /**
367
-     * _add_screen_options
368
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
369
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
370
-     * to a particular view.
371
-     *
372
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
373
-     *         see also WP_Screen object documents...
374
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
375
-     * @abstract
376
-     * @return void
377
-     */
378
-    abstract protected function _add_screen_options();
379
-
380
-
381
-    /**
382
-     * _add_feature_pointers
383
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
384
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
385
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
386
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
387
-     * extended) also see:
388
-     *
389
-     * @link   http://eamann.com/tech/wordpress-portland/
390
-     * @abstract
391
-     * @return void
392
-     */
393
-    abstract protected function _add_feature_pointers();
394
-
395
-
396
-    /**
397
-     * load_scripts_styles
398
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
399
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
400
-     * scripts/styles per view by putting them in a dynamic function in this format
401
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
402
-     *
403
-     * @abstract
404
-     * @return void
405
-     */
406
-    abstract public function load_scripts_styles();
407
-
408
-
409
-    /**
410
-     * admin_init
411
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
412
-     * all pages/views loaded by child class.
413
-     *
414
-     * @abstract
415
-     * @return void
416
-     */
417
-    abstract public function admin_init();
418
-
419
-
420
-    /**
421
-     * admin_notices
422
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
423
-     * all pages/views loaded by child class.
424
-     *
425
-     * @abstract
426
-     * @return void
427
-     */
428
-    abstract public function admin_notices();
429
-
430
-
431
-    /**
432
-     * admin_footer_scripts
433
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
434
-     * will apply to all pages/views loaded by child class.
435
-     *
436
-     * @return void
437
-     */
438
-    abstract public function admin_footer_scripts();
439
-
440
-
441
-    /**
442
-     * admin_footer
443
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
444
-     * apply to all pages/views loaded by child class.
445
-     *
446
-     * @return void
447
-     */
448
-    public function admin_footer()
449
-    {
450
-    }
451
-
452
-
453
-    /**
454
-     * _global_ajax_hooks
455
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
456
-     * Note: within the ajax callback methods.
457
-     *
458
-     * @abstract
459
-     * @return void
460
-     */
461
-    protected function _global_ajax_hooks()
462
-    {
463
-        // for lazy loading of metabox content
464
-        add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
465
-    }
466
-
467
-
468
-    public function ajax_metabox_content()
469
-    {
470
-        $content_id  = $this->request->getRequestParam('contentid', '');
471
-        $content_url = $this->request->getRequestParam('contenturl', '', 'url');
472
-        self::cached_rss_display($content_id, $content_url);
473
-        wp_die();
474
-    }
475
-
476
-
477
-    /**
478
-     * allows extending classes do something specific before the parent constructor runs _page_setup().
479
-     *
480
-     * @return void
481
-     */
482
-    protected function _before_page_setup()
483
-    {
484
-        // default is to do nothing
485
-    }
486
-
487
-
488
-    /**
489
-     * Makes sure any things that need to be loaded early get handled.
490
-     * We also escape early here if the page requested doesn't match the object.
491
-     *
492
-     * @final
493
-     * @return void
494
-     * @throws EE_Error
495
-     * @throws InvalidArgumentException
496
-     * @throws ReflectionException
497
-     * @throws InvalidDataTypeException
498
-     * @throws InvalidInterfaceException
499
-     */
500
-    final protected function _page_setup()
501
-    {
502
-        // requires?
503
-        // admin_init stuff - global - we're setting this REALLY early
504
-        // so if EE_Admin pages have to hook into other WP pages they can.
505
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
506
-        add_action('admin_init', [$this, 'admin_init_global'], 5);
507
-        // next verify if we need to load anything...
508
-        $this->_current_page = $this->request->getRequestParam('page', '', 'key');
509
-        $this->page_folder   = strtolower(
510
-            str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
511
-        );
512
-        global $ee_menu_slugs;
513
-        $ee_menu_slugs = (array) $ee_menu_slugs;
514
-        if (
515
-            ! $this->request->isAjax()
516
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
517
-        ) {
518
-            return;
519
-        }
520
-        // because WP List tables have two duplicate select inputs for choosing bulk actions,
521
-        // we need to copy the action from the second to the first
522
-        $action     = $this->request->getRequestParam('action', '-1', 'key');
523
-        $action2    = $this->request->getRequestParam('action2', '-1', 'key');
524
-        $action     = $action !== '-1' ? $action : $action2;
525
-        $req_action = $action !== '-1' ? $action : 'default';
526
-
527
-        // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
528
-        // then let's use the route as the action.
529
-        // This covers cases where we're coming in from a list table that isn't on the default route.
530
-        $route = $this->request->getRequestParam('route');
531
-        $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
532
-            ? $route
533
-            : $req_action;
534
-
535
-        $this->_current_view = $this->_req_action;
536
-        $this->_req_nonce    = $this->_req_action . '_nonce';
537
-        $this->_define_page_props();
538
-        $this->_current_page_view_url = add_query_arg(
539
-            ['page' => $this->_current_page, 'action' => $this->_current_view],
540
-            $this->_admin_base_url
541
-        );
542
-        // default things
543
-        $this->_default_espresso_metaboxes = [
544
-            '_espresso_news_post_box',
545
-            '_espresso_links_post_box',
546
-            '_espresso_ratings_request',
547
-            '_espresso_sponsors_post_box',
548
-        ];
549
-        // set page configs
550
-        $this->_set_page_routes();
551
-        $this->_set_page_config();
552
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
553
-        if ($this->request->requestParamIsSet('wp_referer')) {
554
-            $wp_referer = $this->request->getRequestParam('wp_referer');
555
-            if ($wp_referer) {
556
-                $this->_default_route_query_args['wp_referer'] = $wp_referer;
557
-            }
558
-        }
559
-        // for caffeinated and other extended functionality.
560
-        //  If there is a _extend_page_config method
561
-        // then let's run that to modify the all the various page configuration arrays
562
-        if (method_exists($this, '_extend_page_config')) {
563
-            $this->_extend_page_config();
564
-        }
565
-        // for CPT and other extended functionality.
566
-        // If there is an _extend_page_config_for_cpt
567
-        // then let's run that to modify all the various page configuration arrays.
568
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
569
-            $this->_extend_page_config_for_cpt();
570
-        }
571
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
572
-        $this->_page_routes = apply_filters(
573
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
574
-            $this->_page_routes,
575
-            $this
576
-        );
577
-        $this->_page_config = apply_filters(
578
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
579
-            $this->_page_config,
580
-            $this
581
-        );
582
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
583
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
584
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
585
-            add_action(
586
-                'AHEE__EE_Admin_Page__route_admin_request',
587
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
588
-                10,
589
-                2
590
-            );
591
-        }
592
-        // next route only if routing enabled
593
-        if ($this->_routing && ! $this->request->isAjax()) {
594
-            $this->_verify_routes();
595
-            // next let's just check user_access and kill if no access
596
-            $this->check_user_access();
597
-            if ($this->_is_UI_request) {
598
-                // admin_init stuff - global, all views for this page class, specific view
599
-                add_action('admin_init', [$this, 'admin_init'], 10);
600
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
601
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
602
-                }
603
-            } else {
604
-                // hijack regular WP loading and route admin request immediately
605
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
606
-                $this->route_admin_request();
607
-            }
608
-        }
609
-    }
610
-
611
-
612
-    /**
613
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
614
-     *
615
-     * @return void
616
-     * @throws EE_Error
617
-     */
618
-    private function _do_other_page_hooks()
619
-    {
620
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
621
-        foreach ($registered_pages as $page) {
622
-            // now let's setup the file name and class that should be present
623
-            $classname = str_replace('.class.php', '', $page);
624
-            // autoloaders should take care of loading file
625
-            if (! class_exists($classname)) {
626
-                $error_msg[] = sprintf(
627
-                    esc_html__(
628
-                        'Something went wrong with loading the %s admin hooks page.',
629
-                        'event_espresso'
630
-                    ),
631
-                    $page
632
-                );
633
-                $error_msg[] = $error_msg[0]
634
-                               . "\r\n"
635
-                               . sprintf(
636
-                                   esc_html__(
637
-                                       'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
638
-                                       'event_espresso'
639
-                                   ),
640
-                                   $page,
641
-                                   '<br />',
642
-                                   '<strong>' . $classname . '</strong>'
643
-                               );
644
-                throw new EE_Error(implode('||', $error_msg));
645
-            }
646
-            // notice we are passing the instance of this class to the hook object.
647
-            $this->loader->getShared($classname, [$this]);
648
-        }
649
-    }
650
-
651
-
652
-    /**
653
-     * @throws ReflectionException
654
-     * @throws EE_Error
655
-     */
656
-    public function load_page_dependencies()
657
-    {
658
-        try {
659
-            $this->_load_page_dependencies();
660
-        } catch (EE_Error $e) {
661
-            $e->get_error();
662
-        }
663
-    }
664
-
665
-
666
-    /**
667
-     * load_page_dependencies
668
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
669
-     *
670
-     * @return void
671
-     * @throws DomainException
672
-     * @throws EE_Error
673
-     * @throws InvalidArgumentException
674
-     * @throws InvalidDataTypeException
675
-     * @throws InvalidInterfaceException
676
-     */
677
-    protected function _load_page_dependencies()
678
-    {
679
-        // let's set the current_screen and screen options to override what WP set
680
-        $this->_current_screen = get_current_screen();
681
-        // load admin_notices - global, page class, and view specific
682
-        add_action('admin_notices', [$this, 'admin_notices_global'], 5);
683
-        add_action('admin_notices', [$this, 'admin_notices'], 10);
684
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
685
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
686
-        }
687
-        // load network admin_notices - global, page class, and view specific
688
-        add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
689
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
690
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
691
-        }
692
-        // this will save any per_page screen options if they are present
693
-        $this->_set_per_page_screen_options();
694
-        // setup list table properties
695
-        $this->_set_list_table();
696
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
697
-        // However in some cases the metaboxes will need to be added within a route handling callback.
698
-        $this->_add_registered_meta_boxes();
699
-        $this->_add_screen_columns();
700
-        // add screen options - global, page child class, and view specific
701
-        $this->_add_global_screen_options();
702
-        $this->_add_screen_options();
703
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
704
-        if (method_exists($this, $add_screen_options)) {
705
-            $this->{$add_screen_options}();
706
-        }
707
-        // add help tab(s) - set via page_config and qtips.
708
-        $this->_add_help_tabs();
709
-        $this->_add_qtips();
710
-        // add feature_pointers - global, page child class, and view specific
711
-        $this->_add_feature_pointers();
712
-        $this->_add_global_feature_pointers();
713
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
714
-        if (method_exists($this, $add_feature_pointer)) {
715
-            $this->{$add_feature_pointer}();
716
-        }
717
-        // enqueue scripts/styles - global, page class, and view specific
718
-        add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
719
-        add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
720
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
721
-            add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
722
-        }
723
-        add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
724
-        // admin_print_footer_scripts - global, page child class, and view specific.
725
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
726
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
727
-        // is a good use case. Notice the late priority we're giving these
728
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
729
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
730
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
731
-            add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
732
-        }
733
-        // admin footer scripts
734
-        add_action('admin_footer', [$this, 'admin_footer_global'], 99);
735
-        add_action('admin_footer', [$this, 'admin_footer'], 100);
736
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
737
-            add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
738
-        }
739
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
740
-        // targeted hook
741
-        do_action(
742
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
743
-        );
744
-    }
745
-
746
-
747
-    /**
748
-     * _set_defaults
749
-     * This sets some global defaults for class properties.
750
-     */
751
-    private function _set_defaults()
752
-    {
753
-        $this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
754
-        $this->_event                = $this->_template_path = $this->_column_template_path = null;
755
-        $this->_nav_tabs             = $this->_views = $this->_page_routes = [];
756
-        $this->_page_config          = $this->_default_route_query_args = [];
757
-        $this->_default_nav_tab_name = 'overview';
758
-        // init template args
759
-        $this->_template_args = [
760
-            'admin_page_header'  => '',
761
-            'admin_page_content' => '',
762
-            'post_body_content'  => '',
763
-            'before_list_table'  => '',
764
-            'after_list_table'   => '',
765
-        ];
766
-    }
767
-
768
-
769
-    /**
770
-     * route_admin_request
771
-     *
772
-     * @return void
773
-     * @throws InvalidArgumentException
774
-     * @throws InvalidInterfaceException
775
-     * @throws InvalidDataTypeException
776
-     * @throws EE_Error
777
-     * @throws ReflectionException
778
-     * @see    _route_admin_request()
779
-     */
780
-    public function route_admin_request()
781
-    {
782
-        try {
783
-            $this->_route_admin_request();
784
-        } catch (EE_Error $e) {
785
-            $e->get_error();
786
-        }
787
-    }
788
-
789
-
790
-    public function set_wp_page_slug($wp_page_slug)
791
-    {
792
-        $this->_wp_page_slug = $wp_page_slug;
793
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
794
-        if (is_network_admin()) {
795
-            $this->_wp_page_slug .= '-network';
796
-        }
797
-    }
798
-
799
-
800
-    /**
801
-     * _verify_routes
802
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
803
-     * we know if we need to drop out.
804
-     *
805
-     * @return bool
806
-     * @throws EE_Error
807
-     */
808
-    protected function _verify_routes()
809
-    {
810
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
811
-        if (! $this->_current_page && ! $this->request->isAjax()) {
812
-            return false;
813
-        }
814
-        $this->_route = false;
815
-        // check that the page_routes array is not empty
816
-        if (empty($this->_page_routes)) {
817
-            // user error msg
818
-            $error_msg = sprintf(
819
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
820
-                $this->_admin_page_title
821
-            );
822
-            // developer error msg
823
-            $error_msg .= '||' . $error_msg
824
-                          . esc_html__(
825
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
826
-                              'event_espresso'
827
-                          );
828
-            throw new EE_Error($error_msg);
829
-        }
830
-        // and that the requested page route exists
831
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
832
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
833
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
834
-                ? $this->_page_config[ $this->_req_action ]
835
-                : [];
836
-        } else {
837
-            // user error msg
838
-            $error_msg = sprintf(
839
-                esc_html__(
840
-                    'The requested page route does not exist for the %s admin page.',
841
-                    'event_espresso'
842
-                ),
843
-                $this->_admin_page_title
844
-            );
845
-            // developer error msg
846
-            $error_msg .= '||' . $error_msg
847
-                          . sprintf(
848
-                              esc_html__(
849
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
850
-                                  'event_espresso'
851
-                              ),
852
-                              $this->_req_action
853
-                          );
854
-            throw new EE_Error($error_msg);
855
-        }
856
-        // and that a default route exists
857
-        if (! array_key_exists('default', $this->_page_routes)) {
858
-            // user error msg
859
-            $error_msg = sprintf(
860
-                esc_html__(
861
-                    'A default page route has not been set for the % admin page.',
862
-                    'event_espresso'
863
-                ),
864
-                $this->_admin_page_title
865
-            );
866
-            // developer error msg
867
-            $error_msg .= '||' . $error_msg
868
-                          . esc_html__(
869
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
870
-                              'event_espresso'
871
-                          );
872
-            throw new EE_Error($error_msg);
873
-        }
874
-        // first lets' catch if the UI request has EVER been set.
875
-        if ($this->_is_UI_request === null) {
876
-            // lets set if this is a UI request or not.
877
-            $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
878
-            // wait a minute... we might have a noheader in the route array
879
-            $this->_is_UI_request = ! (
880
-                is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
881
-            )
882
-                ? $this->_is_UI_request
883
-                : false;
884
-        }
885
-        $this->_set_current_labels();
886
-        return true;
887
-    }
888
-
889
-
890
-    /**
891
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
892
-     *
893
-     * @param string $route the route name we're verifying
894
-     * @return bool we'll throw an exception if this isn't a valid route.
895
-     * @throws EE_Error
896
-     */
897
-    protected function _verify_route($route)
898
-    {
899
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
900
-            return true;
901
-        }
902
-        // user error msg
903
-        $error_msg = sprintf(
904
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
905
-            $this->_admin_page_title
906
-        );
907
-        // developer error msg
908
-        $error_msg .= '||' . $error_msg
909
-                      . sprintf(
910
-                          esc_html__(
911
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
912
-                              'event_espresso'
913
-                          ),
914
-                          $route
915
-                      );
916
-        throw new EE_Error($error_msg);
917
-    }
918
-
919
-
920
-    /**
921
-     * perform nonce verification
922
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
923
-     * using this method (and save retyping!)
924
-     *
925
-     * @param string $nonce     The nonce sent
926
-     * @param string $nonce_ref The nonce reference string (name0)
927
-     * @return void
928
-     * @throws EE_Error
929
-     */
930
-    protected function _verify_nonce($nonce, $nonce_ref)
931
-    {
932
-        // verify nonce against expected value
933
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
934
-            // these are not the droids you are looking for !!!
935
-            $msg = sprintf(
936
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
937
-                '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
938
-                '</a>'
939
-            );
940
-            if (WP_DEBUG) {
941
-                $msg .= "\n  ";
942
-                $msg .= sprintf(
943
-                    esc_html__(
944
-                        'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
945
-                        'event_espresso'
946
-                    ),
947
-                    __CLASS__
948
-                );
949
-            }
950
-            if (! $this->request->isAjax()) {
951
-                wp_die($msg);
952
-            }
953
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
954
-            $this->_return_json();
955
-        }
956
-    }
957
-
958
-
959
-    /**
960
-     * _route_admin_request()
961
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
962
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
963
-     * in the page routes and then will try to load the corresponding method.
964
-     *
965
-     * @return void
966
-     * @throws EE_Error
967
-     * @throws InvalidArgumentException
968
-     * @throws InvalidDataTypeException
969
-     * @throws InvalidInterfaceException
970
-     * @throws ReflectionException
971
-     */
972
-    protected function _route_admin_request()
973
-    {
974
-        if (! $this->_is_UI_request) {
975
-            $this->_verify_routes();
976
-        }
977
-        $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
978
-        if ($this->_req_action !== 'default' && $nonce_check) {
979
-            // set nonce from post data
980
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
981
-            $this->_verify_nonce($nonce, $this->_req_nonce);
982
-        }
983
-        // set the nav_tabs array but ONLY if this is  UI_request
984
-        if ($this->_is_UI_request) {
985
-            $this->_set_nav_tabs();
986
-        }
987
-        // grab callback function
988
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
989
-        // check if callback has args
990
-        $args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
991
-        $error_msg = '';
992
-        // action right before calling route
993
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
994
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
995
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
996
-        }
997
-        // right before calling the route, let's clean the _wp_http_referer
998
-        $this->request->setServerParam(
999
-            'REQUEST_URI',
1000
-            remove_query_arg(
1001
-                '_wp_http_referer',
1002
-                wp_unslash($this->request->getServerParam('REQUEST_URI'))
1003
-            )
1004
-        );
1005
-        if (! empty($func)) {
1006
-            if (is_array($func)) {
1007
-                list($class, $method) = $func;
1008
-            } elseif (strpos($func, '::') !== false) {
1009
-                list($class, $method) = explode('::', $func);
1010
-            } else {
1011
-                $class  = $this;
1012
-                $method = $func;
1013
-            }
1014
-            if (! (is_object($class) && $class === $this)) {
1015
-                // send along this admin page object for access by addons.
1016
-                $args['admin_page_object'] = $this;
1017
-            }
1018
-            if (
1019
-                // is it a method on a class that doesn't work?
1020
-                (
1021
-                    (
1022
-                        method_exists($class, $method)
1023
-                        && call_user_func_array([$class, $method], $args) === false
1024
-                    )
1025
-                    && (
1026
-                        // is it a standalone function that doesn't work?
1027
-                        function_exists($method)
1028
-                        && call_user_func_array(
1029
-                            $func,
1030
-                            array_merge(['admin_page_object' => $this], $args)
1031
-                        ) === false
1032
-                    )
1033
-                )
1034
-                || (
1035
-                    // is it neither a class method NOR a standalone function?
1036
-                    ! method_exists($class, $method)
1037
-                    && ! function_exists($method)
1038
-                )
1039
-            ) {
1040
-                // user error msg
1041
-                $error_msg = esc_html__(
1042
-                    'An error occurred. The  requested page route could not be found.',
1043
-                    'event_espresso'
1044
-                );
1045
-                // developer error msg
1046
-                $error_msg .= '||';
1047
-                $error_msg .= sprintf(
1048
-                    esc_html__(
1049
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1050
-                        'event_espresso'
1051
-                    ),
1052
-                    $method
1053
-                );
1054
-            }
1055
-            if (! empty($error_msg)) {
1056
-                throw new EE_Error($error_msg);
1057
-            }
1058
-        }
1059
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1060
-        // then we need to reset the routing properties to the new route.
1061
-        // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1062
-        if (
1063
-            $this->_is_UI_request === false
1064
-            && is_array($this->_route)
1065
-            && ! empty($this->_route['headers_sent_route'])
1066
-        ) {
1067
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1068
-        }
1069
-    }
1070
-
1071
-
1072
-    /**
1073
-     * This method just allows the resetting of page properties in the case where a no headers
1074
-     * route redirects to a headers route in its route config.
1075
-     *
1076
-     * @param string $new_route New (non header) route to redirect to.
1077
-     * @return   void
1078
-     * @throws ReflectionException
1079
-     * @throws InvalidArgumentException
1080
-     * @throws InvalidInterfaceException
1081
-     * @throws InvalidDataTypeException
1082
-     * @throws EE_Error
1083
-     * @since   4.3.0
1084
-     */
1085
-    protected function _reset_routing_properties($new_route)
1086
-    {
1087
-        $this->_is_UI_request = true;
1088
-        // now we set the current route to whatever the headers_sent_route is set at
1089
-        $this->request->setRequestParam('action', $new_route);
1090
-        // rerun page setup
1091
-        $this->_page_setup();
1092
-    }
1093
-
1094
-
1095
-    /**
1096
-     * _add_query_arg
1097
-     * adds nonce to array of arguments then calls WP add_query_arg function
1098
-     *(internally just uses EEH_URL's function with the same name)
1099
-     *
1100
-     * @param array  $args
1101
-     * @param string $url
1102
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1103
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1104
-     *                                        Example usage: If the current page is:
1105
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1106
-     *                                        &action=default&event_id=20&month_range=March%202015
1107
-     *                                        &_wpnonce=5467821
1108
-     *                                        and you call:
1109
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1110
-     *                                        array(
1111
-     *                                        'action' => 'resend_something',
1112
-     *                                        'page=>espresso_registrations'
1113
-     *                                        ),
1114
-     *                                        $some_url,
1115
-     *                                        true
1116
-     *                                        );
1117
-     *                                        It will produce a url in this structure:
1118
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1119
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1120
-     *                                        month_range]=March%202015
1121
-     * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1122
-     * @return string
1123
-     */
1124
-    public static function add_query_args_and_nonce(
1125
-        $args = [],
1126
-        $url = false,
1127
-        $sticky = false,
1128
-        $exclude_nonce = false
1129
-    ) {
1130
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1131
-        if ($sticky) {
1132
-            /** @var RequestInterface $request */
1133
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1134
-            $request->unSetRequestParams(['_wp_http_referer', 'wp_referer']);
1135
-            foreach ($request->requestParams() as $key => $value) {
1136
-                // do not add nonces
1137
-                if (strpos($key, 'nonce') !== false) {
1138
-                    continue;
1139
-                }
1140
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1141
-            }
1142
-        }
1143
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1144
-    }
1145
-
1146
-
1147
-    /**
1148
-     * This returns a generated link that will load the related help tab.
1149
-     *
1150
-     * @param string $help_tab_id the id for the connected help tab
1151
-     * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1152
-     * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1153
-     * @return string              generated link
1154
-     * @uses EEH_Template::get_help_tab_link()
1155
-     */
1156
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1157
-    {
1158
-        return EEH_Template::get_help_tab_link(
1159
-            $help_tab_id,
1160
-            $this->page_slug,
1161
-            $this->_req_action,
1162
-            $icon_style,
1163
-            $help_text
1164
-        );
1165
-    }
1166
-
1167
-
1168
-    /**
1169
-     * _add_help_tabs
1170
-     * Note child classes define their help tabs within the page_config array.
1171
-     *
1172
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1173
-     * @return void
1174
-     * @throws DomainException
1175
-     * @throws EE_Error
1176
-     */
1177
-    protected function _add_help_tabs()
1178
-    {
1179
-        if (isset($this->_page_config[ $this->_req_action ])) {
1180
-            $config = $this->_page_config[ $this->_req_action ];
1181
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1182
-            if (is_array($config) && isset($config['help_sidebar'])) {
1183
-                // check that the callback given is valid
1184
-                if (! method_exists($this, $config['help_sidebar'])) {
1185
-                    throw new EE_Error(
1186
-                        sprintf(
1187
-                            esc_html__(
1188
-                                'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1189
-                                'event_espresso'
1190
-                            ),
1191
-                            $config['help_sidebar'],
1192
-                            get_class($this)
1193
-                        )
1194
-                    );
1195
-                }
1196
-                $content = apply_filters(
1197
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1198
-                    $this->{$config['help_sidebar']}()
1199
-                );
1200
-                $this->_current_screen->set_help_sidebar($content);
1201
-            }
1202
-            if (! isset($config['help_tabs'])) {
1203
-                return;
1204
-            } //no help tabs for this route
1205
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1206
-                // we're here so there ARE help tabs!
1207
-                // make sure we've got what we need
1208
-                if (! isset($cfg['title'])) {
1209
-                    throw new EE_Error(
1210
-                        esc_html__(
1211
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1212
-                            'event_espresso'
1213
-                        )
1214
-                    );
1215
-                }
1216
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1217
-                    throw new EE_Error(
1218
-                        esc_html__(
1219
-                            'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1220
-                            'event_espresso'
1221
-                        )
1222
-                    );
1223
-                }
1224
-                // first priority goes to content.
1225
-                if (! empty($cfg['content'])) {
1226
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1227
-                    // second priority goes to filename
1228
-                } elseif (! empty($cfg['filename'])) {
1229
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1230
-                    // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1231
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1232
-                                                             . basename($this->_get_dir())
1233
-                                                             . '/help_tabs/'
1234
-                                                             . $cfg['filename']
1235
-                                                             . '.help_tab.php' : $file_path;
1236
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1237
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1238
-                        EE_Error::add_error(
1239
-                            sprintf(
1240
-                                esc_html__(
1241
-                                    'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1242
-                                    'event_espresso'
1243
-                                ),
1244
-                                $tab_id,
1245
-                                key($config),
1246
-                                $file_path
1247
-                            ),
1248
-                            __FILE__,
1249
-                            __FUNCTION__,
1250
-                            __LINE__
1251
-                        );
1252
-                        return;
1253
-                    }
1254
-                    $template_args['admin_page_obj'] = $this;
1255
-                    $content                         = EEH_Template::display_template(
1256
-                        $file_path,
1257
-                        $template_args,
1258
-                        true
1259
-                    );
1260
-                } else {
1261
-                    $content = '';
1262
-                }
1263
-                // check if callback is valid
1264
-                if (
1265
-                    empty($content)
1266
-                    && (
1267
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1268
-                    )
1269
-                ) {
1270
-                    EE_Error::add_error(
1271
-                        sprintf(
1272
-                            esc_html__(
1273
-                                'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1274
-                                'event_espresso'
1275
-                            ),
1276
-                            $cfg['title']
1277
-                        ),
1278
-                        __FILE__,
1279
-                        __FUNCTION__,
1280
-                        __LINE__
1281
-                    );
1282
-                    return;
1283
-                }
1284
-                // setup config array for help tab method
1285
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1286
-                $_ht = [
1287
-                    'id'       => $id,
1288
-                    'title'    => $cfg['title'],
1289
-                    'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1290
-                    'content'  => $content,
1291
-                ];
1292
-                $this->_current_screen->add_help_tab($_ht);
1293
-            }
1294
-        }
1295
-    }
1296
-
1297
-
1298
-    /**
1299
-     * This simply sets up any qtips that have been defined in the page config
1300
-     *
1301
-     * @return void
1302
-     */
1303
-    protected function _add_qtips()
1304
-    {
1305
-        if (isset($this->_route_config['qtips'])) {
1306
-            $qtips = (array) $this->_route_config['qtips'];
1307
-            // load qtip loader
1308
-            $path = [
1309
-                $this->_get_dir() . '/qtips/',
1310
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1311
-            ];
1312
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1313
-        }
1314
-    }
1315
-
1316
-
1317
-    /**
1318
-     * _set_nav_tabs
1319
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1320
-     * wish to add additional tabs or modify accordingly.
1321
-     *
1322
-     * @return void
1323
-     * @throws InvalidArgumentException
1324
-     * @throws InvalidInterfaceException
1325
-     * @throws InvalidDataTypeException
1326
-     */
1327
-    protected function _set_nav_tabs()
1328
-    {
1329
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1330
-        $i = 0;
1331
-        foreach ($this->_page_config as $slug => $config) {
1332
-            if (! is_array($config) || empty($config['nav'])) {
1333
-                continue;
1334
-            }
1335
-            // no nav tab for this config
1336
-            // check for persistent flag
1337
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1338
-                // nav tab is only to appear when route requested.
1339
-                continue;
1340
-            }
1341
-            if (! $this->check_user_access($slug, true)) {
1342
-                // no nav tab because current user does not have access.
1343
-                continue;
1344
-            }
1345
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1346
-            $this->_nav_tabs[ $slug ] = [
1347
-                'url'       => isset($config['nav']['url'])
1348
-                    ? $config['nav']['url']
1349
-                    : self::add_query_args_and_nonce(
1350
-                        ['action' => $slug],
1351
-                        $this->_admin_base_url
1352
-                    ),
1353
-                'link_text' => isset($config['nav']['label'])
1354
-                    ? $config['nav']['label']
1355
-                    : ucwords(
1356
-                        str_replace('_', ' ', $slug)
1357
-                    ),
1358
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1359
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1360
-            ];
1361
-            $i++;
1362
-        }
1363
-        // if $this->_nav_tabs is empty then lets set the default
1364
-        if (empty($this->_nav_tabs)) {
1365
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1366
-                'url'       => $this->_admin_base_url,
1367
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1368
-                'css_class' => 'nav-tab-active',
1369
-                'order'     => 10,
1370
-            ];
1371
-        }
1372
-        // now let's sort the tabs according to order
1373
-        usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1374
-    }
1375
-
1376
-
1377
-    /**
1378
-     * _set_current_labels
1379
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1380
-     * property array
1381
-     *
1382
-     * @return void
1383
-     */
1384
-    private function _set_current_labels()
1385
-    {
1386
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1387
-            foreach ($this->_route_config['labels'] as $label => $text) {
1388
-                if (is_array($text)) {
1389
-                    foreach ($text as $sublabel => $subtext) {
1390
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1391
-                    }
1392
-                } else {
1393
-                    $this->_labels[ $label ] = $text;
1394
-                }
1395
-            }
1396
-        }
1397
-    }
1398
-
1399
-
1400
-    /**
1401
-     *        verifies user access for this admin page
1402
-     *
1403
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1404
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1405
-     *                               return false if verify fail.
1406
-     * @return bool
1407
-     * @throws InvalidArgumentException
1408
-     * @throws InvalidDataTypeException
1409
-     * @throws InvalidInterfaceException
1410
-     */
1411
-    public function check_user_access($route_to_check = '', $verify_only = false)
1412
-    {
1413
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1414
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1415
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1416
-                          && is_array(
1417
-                              $this->_page_routes[ $route_to_check ]
1418
-                          )
1419
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1420
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1421
-        if (empty($capability) && empty($route_to_check)) {
1422
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1423
-                : $this->_route['capability'];
1424
-        } else {
1425
-            $capability = empty($capability) ? 'manage_options' : $capability;
1426
-        }
1427
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1428
-        if (
1429
-            ! $this->request->isAjax()
1430
-            && (
1431
-                ! function_exists('is_admin')
1432
-                || ! EE_Registry::instance()->CAP->current_user_can(
1433
-                    $capability,
1434
-                    $this->page_slug
1435
-                    . '_'
1436
-                    . $route_to_check,
1437
-                    $id
1438
-                )
1439
-            )
1440
-        ) {
1441
-            if ($verify_only) {
1442
-                return false;
1443
-            }
1444
-            if (is_user_logged_in()) {
1445
-                wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1446
-            } else {
1447
-                return false;
1448
-            }
1449
-        }
1450
-        return true;
1451
-    }
1452
-
1453
-
1454
-    /**
1455
-     * admin_init_global
1456
-     * This runs all the code that we want executed within the WP admin_init hook.
1457
-     * This method executes for ALL EE Admin pages.
1458
-     *
1459
-     * @return void
1460
-     */
1461
-    public function admin_init_global()
1462
-    {
1463
-    }
1464
-
1465
-
1466
-    /**
1467
-     * wp_loaded_global
1468
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1469
-     * EE_Admin page and will execute on every EE Admin Page load
1470
-     *
1471
-     * @return void
1472
-     */
1473
-    public function wp_loaded()
1474
-    {
1475
-    }
1476
-
1477
-
1478
-    /**
1479
-     * admin_notices
1480
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1481
-     * ALL EE_Admin pages.
1482
-     *
1483
-     * @return void
1484
-     */
1485
-    public function admin_notices_global()
1486
-    {
1487
-        $this->_display_no_javascript_warning();
1488
-        $this->_display_espresso_notices();
1489
-    }
1490
-
1491
-
1492
-    public function network_admin_notices_global()
1493
-    {
1494
-        $this->_display_no_javascript_warning();
1495
-        $this->_display_espresso_notices();
1496
-    }
1497
-
1498
-
1499
-    /**
1500
-     * admin_footer_scripts_global
1501
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1502
-     * will apply on ALL EE_Admin pages.
1503
-     *
1504
-     * @return void
1505
-     */
1506
-    public function admin_footer_scripts_global()
1507
-    {
1508
-        $this->_add_admin_page_ajax_loading_img();
1509
-        $this->_add_admin_page_overlay();
1510
-        // if metaboxes are present we need to add the nonce field
1511
-        if (
1512
-            isset($this->_route_config['metaboxes'])
1513
-            || isset($this->_route_config['list_table'])
1514
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1515
-        ) {
1516
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1517
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1518
-        }
1519
-    }
1520
-
1521
-
1522
-    /**
1523
-     * admin_footer_global
1524
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1525
-     * ALL EE_Admin Pages.
1526
-     *
1527
-     * @return void
1528
-     */
1529
-    public function admin_footer_global()
1530
-    {
1531
-        // dialog container for dialog helper
1532
-        echo '
110
+	/**
111
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
112
+	 * actions.
113
+	 *
114
+	 * @since 4.6.x
115
+	 * @var array.
116
+	 */
117
+	protected $_default_route_query_args;
118
+
119
+	// set via request page and action args.
120
+	protected $_current_page;
121
+
122
+	protected $_current_view;
123
+
124
+	protected $_current_page_view_url;
125
+
126
+	/**
127
+	 * unprocessed value for the 'action' request param (default '')
128
+	 *
129
+	 * @var string
130
+	 */
131
+	protected $raw_req_action = '';
132
+
133
+	/**
134
+	 * unprocessed value for the 'page' request param (default '')
135
+	 *
136
+	 * @var string
137
+	 */
138
+	protected $raw_req_page = '';
139
+
140
+	/**
141
+	 * sanitized request action (and nonce)
142
+	 *
143
+	 * @var string
144
+	 */
145
+	protected $_req_action = '';
146
+
147
+	/**
148
+	 * sanitized request action nonce
149
+	 *
150
+	 * @var string
151
+	 */
152
+	protected $_req_nonce = '';
153
+
154
+	/**
155
+	 * @var string
156
+	 */
157
+	protected $_search_btn_label = '';
158
+
159
+	/**
160
+	 * @var string
161
+	 */
162
+	protected $_search_box_callback = '';
163
+
164
+	/**
165
+	 * @var WP_Screen
166
+	 */
167
+	protected $_current_screen;
168
+
169
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
170
+	protected $_hook_obj;
171
+
172
+	// for holding incoming request data
173
+	protected $_req_data = [];
174
+
175
+	// yes / no array for admin form fields
176
+	protected $_yes_no_values = [];
177
+
178
+	// some default things shared by all child classes
179
+	protected $_default_espresso_metaboxes;
180
+
181
+	/**
182
+	 * @var EE_Registry
183
+	 */
184
+	protected $EE = null;
185
+
186
+
187
+	/**
188
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
189
+	 *
190
+	 * @var boolean
191
+	 */
192
+	protected $_is_caf = false;
193
+
194
+
195
+	/**
196
+	 * @Constructor
197
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
198
+	 * @throws EE_Error
199
+	 * @throws InvalidArgumentException
200
+	 * @throws ReflectionException
201
+	 * @throws InvalidDataTypeException
202
+	 * @throws InvalidInterfaceException
203
+	 */
204
+	public function __construct($routing = true)
205
+	{
206
+		$this->loader  = LoaderFactory::getLoader();
207
+		$this->request = $this->loader->getShared(RequestInterface::class);
208
+		$this->_routing = $routing;
209
+
210
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
211
+			$this->_is_caf = true;
212
+		}
213
+		$this->_yes_no_values = [
214
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
215
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
216
+		];
217
+		// set the _req_data property.
218
+		$this->_req_data = $this->request->requestParams();
219
+		// set initial page props (child method)
220
+		$this->_init_page_props();
221
+		// set global defaults
222
+		$this->_set_defaults();
223
+		// set early because incoming requests could be ajax related and we need to register those hooks.
224
+		$this->_global_ajax_hooks();
225
+		$this->_ajax_hooks();
226
+		// other_page_hooks have to be early too.
227
+		$this->_do_other_page_hooks();
228
+		// set up page dependencies
229
+		$this->_before_page_setup();
230
+		$this->_page_setup();
231
+		// die();
232
+	}
233
+
234
+
235
+	/**
236
+	 * _init_page_props
237
+	 * Child classes use to set at least the following properties:
238
+	 * $page_slug.
239
+	 * $page_label.
240
+	 *
241
+	 * @abstract
242
+	 * @return void
243
+	 */
244
+	abstract protected function _init_page_props();
245
+
246
+
247
+	/**
248
+	 * _ajax_hooks
249
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
250
+	 * Note: within the ajax callback methods.
251
+	 *
252
+	 * @abstract
253
+	 * @return void
254
+	 */
255
+	abstract protected function _ajax_hooks();
256
+
257
+
258
+	/**
259
+	 * _define_page_props
260
+	 * child classes define page properties in here.  Must include at least:
261
+	 * $_admin_base_url = base_url for all admin pages
262
+	 * $_admin_page_title = default admin_page_title for admin pages
263
+	 * $_labels = array of default labels for various automatically generated elements:
264
+	 *    array(
265
+	 *        'buttons' => array(
266
+	 *            'add' => esc_html__('label for add new button'),
267
+	 *            'edit' => esc_html__('label for edit button'),
268
+	 *            'delete' => esc_html__('label for delete button')
269
+	 *            )
270
+	 *        )
271
+	 *
272
+	 * @abstract
273
+	 * @return void
274
+	 */
275
+	abstract protected function _define_page_props();
276
+
277
+
278
+	/**
279
+	 * _set_page_routes
280
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
281
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
282
+	 * have a 'default' route. Here's the format
283
+	 * $this->_page_routes = array(
284
+	 *        'default' => array(
285
+	 *            'func' => '_default_method_handling_route',
286
+	 *            'args' => array('array','of','args'),
287
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
288
+	 *            ajax request, backend processing)
289
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
290
+	 *            headers route after.  The string you enter here should match the defined route reference for a
291
+	 *            headers sent route.
292
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
293
+	 *            this route.
294
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
295
+	 *            checks).
296
+	 *        ),
297
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
298
+	 *        handling method.
299
+	 *        )
300
+	 * )
301
+	 *
302
+	 * @abstract
303
+	 * @return void
304
+	 */
305
+	abstract protected function _set_page_routes();
306
+
307
+
308
+	/**
309
+	 * _set_page_config
310
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
311
+	 * array corresponds to the page_route for the loaded page. Format:
312
+	 * $this->_page_config = array(
313
+	 *        'default' => array(
314
+	 *            'labels' => array(
315
+	 *                'buttons' => array(
316
+	 *                    'add' => esc_html__('label for adding item'),
317
+	 *                    'edit' => esc_html__('label for editing item'),
318
+	 *                    'delete' => esc_html__('label for deleting item')
319
+	 *                ),
320
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
321
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
322
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
323
+	 *            _define_page_props() method
324
+	 *            'nav' => array(
325
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
326
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
327
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
328
+	 *                'order' => 10, //required to indicate tab position.
329
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
330
+	 *                displayed then add this parameter.
331
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
332
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
333
+	 *            metaboxes set for eventespresso admin pages.
334
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
335
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
336
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
337
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
338
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
339
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
340
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
341
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
342
+	 *            want to display.
343
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
344
+	 *                'tab_id' => array(
345
+	 *                    'title' => 'tab_title',
346
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
347
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
348
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
349
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
350
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
351
+	 *                    attempt to use the callback which should match the name of a method in the class
352
+	 *                    ),
353
+	 *                'tab2_id' => array(
354
+	 *                    'title' => 'tab2 title',
355
+	 *                    'filename' => 'file_name_2'
356
+	 *                    'callback' => 'callback_method_for_content',
357
+	 *                 ),
358
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
359
+	 *            help tab area on an admin page. @return void
360
+	 *
361
+	 * @abstract
362
+	 */
363
+	abstract protected function _set_page_config();
364
+
365
+
366
+	/**
367
+	 * _add_screen_options
368
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
369
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
370
+	 * to a particular view.
371
+	 *
372
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
373
+	 *         see also WP_Screen object documents...
374
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
375
+	 * @abstract
376
+	 * @return void
377
+	 */
378
+	abstract protected function _add_screen_options();
379
+
380
+
381
+	/**
382
+	 * _add_feature_pointers
383
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
384
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
385
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
386
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
387
+	 * extended) also see:
388
+	 *
389
+	 * @link   http://eamann.com/tech/wordpress-portland/
390
+	 * @abstract
391
+	 * @return void
392
+	 */
393
+	abstract protected function _add_feature_pointers();
394
+
395
+
396
+	/**
397
+	 * load_scripts_styles
398
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
399
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
400
+	 * scripts/styles per view by putting them in a dynamic function in this format
401
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
402
+	 *
403
+	 * @abstract
404
+	 * @return void
405
+	 */
406
+	abstract public function load_scripts_styles();
407
+
408
+
409
+	/**
410
+	 * admin_init
411
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
412
+	 * all pages/views loaded by child class.
413
+	 *
414
+	 * @abstract
415
+	 * @return void
416
+	 */
417
+	abstract public function admin_init();
418
+
419
+
420
+	/**
421
+	 * admin_notices
422
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
423
+	 * all pages/views loaded by child class.
424
+	 *
425
+	 * @abstract
426
+	 * @return void
427
+	 */
428
+	abstract public function admin_notices();
429
+
430
+
431
+	/**
432
+	 * admin_footer_scripts
433
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
434
+	 * will apply to all pages/views loaded by child class.
435
+	 *
436
+	 * @return void
437
+	 */
438
+	abstract public function admin_footer_scripts();
439
+
440
+
441
+	/**
442
+	 * admin_footer
443
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
444
+	 * apply to all pages/views loaded by child class.
445
+	 *
446
+	 * @return void
447
+	 */
448
+	public function admin_footer()
449
+	{
450
+	}
451
+
452
+
453
+	/**
454
+	 * _global_ajax_hooks
455
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
456
+	 * Note: within the ajax callback methods.
457
+	 *
458
+	 * @abstract
459
+	 * @return void
460
+	 */
461
+	protected function _global_ajax_hooks()
462
+	{
463
+		// for lazy loading of metabox content
464
+		add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
465
+	}
466
+
467
+
468
+	public function ajax_metabox_content()
469
+	{
470
+		$content_id  = $this->request->getRequestParam('contentid', '');
471
+		$content_url = $this->request->getRequestParam('contenturl', '', 'url');
472
+		self::cached_rss_display($content_id, $content_url);
473
+		wp_die();
474
+	}
475
+
476
+
477
+	/**
478
+	 * allows extending classes do something specific before the parent constructor runs _page_setup().
479
+	 *
480
+	 * @return void
481
+	 */
482
+	protected function _before_page_setup()
483
+	{
484
+		// default is to do nothing
485
+	}
486
+
487
+
488
+	/**
489
+	 * Makes sure any things that need to be loaded early get handled.
490
+	 * We also escape early here if the page requested doesn't match the object.
491
+	 *
492
+	 * @final
493
+	 * @return void
494
+	 * @throws EE_Error
495
+	 * @throws InvalidArgumentException
496
+	 * @throws ReflectionException
497
+	 * @throws InvalidDataTypeException
498
+	 * @throws InvalidInterfaceException
499
+	 */
500
+	final protected function _page_setup()
501
+	{
502
+		// requires?
503
+		// admin_init stuff - global - we're setting this REALLY early
504
+		// so if EE_Admin pages have to hook into other WP pages they can.
505
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
506
+		add_action('admin_init', [$this, 'admin_init_global'], 5);
507
+		// next verify if we need to load anything...
508
+		$this->_current_page = $this->request->getRequestParam('page', '', 'key');
509
+		$this->page_folder   = strtolower(
510
+			str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
511
+		);
512
+		global $ee_menu_slugs;
513
+		$ee_menu_slugs = (array) $ee_menu_slugs;
514
+		if (
515
+			! $this->request->isAjax()
516
+			&& (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
517
+		) {
518
+			return;
519
+		}
520
+		// because WP List tables have two duplicate select inputs for choosing bulk actions,
521
+		// we need to copy the action from the second to the first
522
+		$action     = $this->request->getRequestParam('action', '-1', 'key');
523
+		$action2    = $this->request->getRequestParam('action2', '-1', 'key');
524
+		$action     = $action !== '-1' ? $action : $action2;
525
+		$req_action = $action !== '-1' ? $action : 'default';
526
+
527
+		// if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
528
+		// then let's use the route as the action.
529
+		// This covers cases where we're coming in from a list table that isn't on the default route.
530
+		$route = $this->request->getRequestParam('route');
531
+		$this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
532
+			? $route
533
+			: $req_action;
534
+
535
+		$this->_current_view = $this->_req_action;
536
+		$this->_req_nonce    = $this->_req_action . '_nonce';
537
+		$this->_define_page_props();
538
+		$this->_current_page_view_url = add_query_arg(
539
+			['page' => $this->_current_page, 'action' => $this->_current_view],
540
+			$this->_admin_base_url
541
+		);
542
+		// default things
543
+		$this->_default_espresso_metaboxes = [
544
+			'_espresso_news_post_box',
545
+			'_espresso_links_post_box',
546
+			'_espresso_ratings_request',
547
+			'_espresso_sponsors_post_box',
548
+		];
549
+		// set page configs
550
+		$this->_set_page_routes();
551
+		$this->_set_page_config();
552
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
553
+		if ($this->request->requestParamIsSet('wp_referer')) {
554
+			$wp_referer = $this->request->getRequestParam('wp_referer');
555
+			if ($wp_referer) {
556
+				$this->_default_route_query_args['wp_referer'] = $wp_referer;
557
+			}
558
+		}
559
+		// for caffeinated and other extended functionality.
560
+		//  If there is a _extend_page_config method
561
+		// then let's run that to modify the all the various page configuration arrays
562
+		if (method_exists($this, '_extend_page_config')) {
563
+			$this->_extend_page_config();
564
+		}
565
+		// for CPT and other extended functionality.
566
+		// If there is an _extend_page_config_for_cpt
567
+		// then let's run that to modify all the various page configuration arrays.
568
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
569
+			$this->_extend_page_config_for_cpt();
570
+		}
571
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
572
+		$this->_page_routes = apply_filters(
573
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
574
+			$this->_page_routes,
575
+			$this
576
+		);
577
+		$this->_page_config = apply_filters(
578
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
579
+			$this->_page_config,
580
+			$this
581
+		);
582
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
583
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
584
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
585
+			add_action(
586
+				'AHEE__EE_Admin_Page__route_admin_request',
587
+				[$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
588
+				10,
589
+				2
590
+			);
591
+		}
592
+		// next route only if routing enabled
593
+		if ($this->_routing && ! $this->request->isAjax()) {
594
+			$this->_verify_routes();
595
+			// next let's just check user_access and kill if no access
596
+			$this->check_user_access();
597
+			if ($this->_is_UI_request) {
598
+				// admin_init stuff - global, all views for this page class, specific view
599
+				add_action('admin_init', [$this, 'admin_init'], 10);
600
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
601
+					add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
602
+				}
603
+			} else {
604
+				// hijack regular WP loading and route admin request immediately
605
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
606
+				$this->route_admin_request();
607
+			}
608
+		}
609
+	}
610
+
611
+
612
+	/**
613
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
614
+	 *
615
+	 * @return void
616
+	 * @throws EE_Error
617
+	 */
618
+	private function _do_other_page_hooks()
619
+	{
620
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
621
+		foreach ($registered_pages as $page) {
622
+			// now let's setup the file name and class that should be present
623
+			$classname = str_replace('.class.php', '', $page);
624
+			// autoloaders should take care of loading file
625
+			if (! class_exists($classname)) {
626
+				$error_msg[] = sprintf(
627
+					esc_html__(
628
+						'Something went wrong with loading the %s admin hooks page.',
629
+						'event_espresso'
630
+					),
631
+					$page
632
+				);
633
+				$error_msg[] = $error_msg[0]
634
+							   . "\r\n"
635
+							   . sprintf(
636
+								   esc_html__(
637
+									   'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
638
+									   'event_espresso'
639
+								   ),
640
+								   $page,
641
+								   '<br />',
642
+								   '<strong>' . $classname . '</strong>'
643
+							   );
644
+				throw new EE_Error(implode('||', $error_msg));
645
+			}
646
+			// notice we are passing the instance of this class to the hook object.
647
+			$this->loader->getShared($classname, [$this]);
648
+		}
649
+	}
650
+
651
+
652
+	/**
653
+	 * @throws ReflectionException
654
+	 * @throws EE_Error
655
+	 */
656
+	public function load_page_dependencies()
657
+	{
658
+		try {
659
+			$this->_load_page_dependencies();
660
+		} catch (EE_Error $e) {
661
+			$e->get_error();
662
+		}
663
+	}
664
+
665
+
666
+	/**
667
+	 * load_page_dependencies
668
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
669
+	 *
670
+	 * @return void
671
+	 * @throws DomainException
672
+	 * @throws EE_Error
673
+	 * @throws InvalidArgumentException
674
+	 * @throws InvalidDataTypeException
675
+	 * @throws InvalidInterfaceException
676
+	 */
677
+	protected function _load_page_dependencies()
678
+	{
679
+		// let's set the current_screen and screen options to override what WP set
680
+		$this->_current_screen = get_current_screen();
681
+		// load admin_notices - global, page class, and view specific
682
+		add_action('admin_notices', [$this, 'admin_notices_global'], 5);
683
+		add_action('admin_notices', [$this, 'admin_notices'], 10);
684
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
685
+			add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
686
+		}
687
+		// load network admin_notices - global, page class, and view specific
688
+		add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
689
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
690
+			add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
691
+		}
692
+		// this will save any per_page screen options if they are present
693
+		$this->_set_per_page_screen_options();
694
+		// setup list table properties
695
+		$this->_set_list_table();
696
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
697
+		// However in some cases the metaboxes will need to be added within a route handling callback.
698
+		$this->_add_registered_meta_boxes();
699
+		$this->_add_screen_columns();
700
+		// add screen options - global, page child class, and view specific
701
+		$this->_add_global_screen_options();
702
+		$this->_add_screen_options();
703
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
704
+		if (method_exists($this, $add_screen_options)) {
705
+			$this->{$add_screen_options}();
706
+		}
707
+		// add help tab(s) - set via page_config and qtips.
708
+		$this->_add_help_tabs();
709
+		$this->_add_qtips();
710
+		// add feature_pointers - global, page child class, and view specific
711
+		$this->_add_feature_pointers();
712
+		$this->_add_global_feature_pointers();
713
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
714
+		if (method_exists($this, $add_feature_pointer)) {
715
+			$this->{$add_feature_pointer}();
716
+		}
717
+		// enqueue scripts/styles - global, page class, and view specific
718
+		add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
719
+		add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
720
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
721
+			add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
722
+		}
723
+		add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
724
+		// admin_print_footer_scripts - global, page child class, and view specific.
725
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
726
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
727
+		// is a good use case. Notice the late priority we're giving these
728
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
729
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
730
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
731
+			add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
732
+		}
733
+		// admin footer scripts
734
+		add_action('admin_footer', [$this, 'admin_footer_global'], 99);
735
+		add_action('admin_footer', [$this, 'admin_footer'], 100);
736
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
737
+			add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
738
+		}
739
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
740
+		// targeted hook
741
+		do_action(
742
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
743
+		);
744
+	}
745
+
746
+
747
+	/**
748
+	 * _set_defaults
749
+	 * This sets some global defaults for class properties.
750
+	 */
751
+	private function _set_defaults()
752
+	{
753
+		$this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
754
+		$this->_event                = $this->_template_path = $this->_column_template_path = null;
755
+		$this->_nav_tabs             = $this->_views = $this->_page_routes = [];
756
+		$this->_page_config          = $this->_default_route_query_args = [];
757
+		$this->_default_nav_tab_name = 'overview';
758
+		// init template args
759
+		$this->_template_args = [
760
+			'admin_page_header'  => '',
761
+			'admin_page_content' => '',
762
+			'post_body_content'  => '',
763
+			'before_list_table'  => '',
764
+			'after_list_table'   => '',
765
+		];
766
+	}
767
+
768
+
769
+	/**
770
+	 * route_admin_request
771
+	 *
772
+	 * @return void
773
+	 * @throws InvalidArgumentException
774
+	 * @throws InvalidInterfaceException
775
+	 * @throws InvalidDataTypeException
776
+	 * @throws EE_Error
777
+	 * @throws ReflectionException
778
+	 * @see    _route_admin_request()
779
+	 */
780
+	public function route_admin_request()
781
+	{
782
+		try {
783
+			$this->_route_admin_request();
784
+		} catch (EE_Error $e) {
785
+			$e->get_error();
786
+		}
787
+	}
788
+
789
+
790
+	public function set_wp_page_slug($wp_page_slug)
791
+	{
792
+		$this->_wp_page_slug = $wp_page_slug;
793
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
794
+		if (is_network_admin()) {
795
+			$this->_wp_page_slug .= '-network';
796
+		}
797
+	}
798
+
799
+
800
+	/**
801
+	 * _verify_routes
802
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
803
+	 * we know if we need to drop out.
804
+	 *
805
+	 * @return bool
806
+	 * @throws EE_Error
807
+	 */
808
+	protected function _verify_routes()
809
+	{
810
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
811
+		if (! $this->_current_page && ! $this->request->isAjax()) {
812
+			return false;
813
+		}
814
+		$this->_route = false;
815
+		// check that the page_routes array is not empty
816
+		if (empty($this->_page_routes)) {
817
+			// user error msg
818
+			$error_msg = sprintf(
819
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
820
+				$this->_admin_page_title
821
+			);
822
+			// developer error msg
823
+			$error_msg .= '||' . $error_msg
824
+						  . esc_html__(
825
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
826
+							  'event_espresso'
827
+						  );
828
+			throw new EE_Error($error_msg);
829
+		}
830
+		// and that the requested page route exists
831
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
832
+			$this->_route        = $this->_page_routes[ $this->_req_action ];
833
+			$this->_route_config = isset($this->_page_config[ $this->_req_action ])
834
+				? $this->_page_config[ $this->_req_action ]
835
+				: [];
836
+		} else {
837
+			// user error msg
838
+			$error_msg = sprintf(
839
+				esc_html__(
840
+					'The requested page route does not exist for the %s admin page.',
841
+					'event_espresso'
842
+				),
843
+				$this->_admin_page_title
844
+			);
845
+			// developer error msg
846
+			$error_msg .= '||' . $error_msg
847
+						  . sprintf(
848
+							  esc_html__(
849
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
850
+								  'event_espresso'
851
+							  ),
852
+							  $this->_req_action
853
+						  );
854
+			throw new EE_Error($error_msg);
855
+		}
856
+		// and that a default route exists
857
+		if (! array_key_exists('default', $this->_page_routes)) {
858
+			// user error msg
859
+			$error_msg = sprintf(
860
+				esc_html__(
861
+					'A default page route has not been set for the % admin page.',
862
+					'event_espresso'
863
+				),
864
+				$this->_admin_page_title
865
+			);
866
+			// developer error msg
867
+			$error_msg .= '||' . $error_msg
868
+						  . esc_html__(
869
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
870
+							  'event_espresso'
871
+						  );
872
+			throw new EE_Error($error_msg);
873
+		}
874
+		// first lets' catch if the UI request has EVER been set.
875
+		if ($this->_is_UI_request === null) {
876
+			// lets set if this is a UI request or not.
877
+			$this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
878
+			// wait a minute... we might have a noheader in the route array
879
+			$this->_is_UI_request = ! (
880
+				is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
881
+			)
882
+				? $this->_is_UI_request
883
+				: false;
884
+		}
885
+		$this->_set_current_labels();
886
+		return true;
887
+	}
888
+
889
+
890
+	/**
891
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
892
+	 *
893
+	 * @param string $route the route name we're verifying
894
+	 * @return bool we'll throw an exception if this isn't a valid route.
895
+	 * @throws EE_Error
896
+	 */
897
+	protected function _verify_route($route)
898
+	{
899
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
900
+			return true;
901
+		}
902
+		// user error msg
903
+		$error_msg = sprintf(
904
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
905
+			$this->_admin_page_title
906
+		);
907
+		// developer error msg
908
+		$error_msg .= '||' . $error_msg
909
+					  . sprintf(
910
+						  esc_html__(
911
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
912
+							  'event_espresso'
913
+						  ),
914
+						  $route
915
+					  );
916
+		throw new EE_Error($error_msg);
917
+	}
918
+
919
+
920
+	/**
921
+	 * perform nonce verification
922
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
923
+	 * using this method (and save retyping!)
924
+	 *
925
+	 * @param string $nonce     The nonce sent
926
+	 * @param string $nonce_ref The nonce reference string (name0)
927
+	 * @return void
928
+	 * @throws EE_Error
929
+	 */
930
+	protected function _verify_nonce($nonce, $nonce_ref)
931
+	{
932
+		// verify nonce against expected value
933
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
934
+			// these are not the droids you are looking for !!!
935
+			$msg = sprintf(
936
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
937
+				'<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
938
+				'</a>'
939
+			);
940
+			if (WP_DEBUG) {
941
+				$msg .= "\n  ";
942
+				$msg .= sprintf(
943
+					esc_html__(
944
+						'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
945
+						'event_espresso'
946
+					),
947
+					__CLASS__
948
+				);
949
+			}
950
+			if (! $this->request->isAjax()) {
951
+				wp_die($msg);
952
+			}
953
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
954
+			$this->_return_json();
955
+		}
956
+	}
957
+
958
+
959
+	/**
960
+	 * _route_admin_request()
961
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
962
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
963
+	 * in the page routes and then will try to load the corresponding method.
964
+	 *
965
+	 * @return void
966
+	 * @throws EE_Error
967
+	 * @throws InvalidArgumentException
968
+	 * @throws InvalidDataTypeException
969
+	 * @throws InvalidInterfaceException
970
+	 * @throws ReflectionException
971
+	 */
972
+	protected function _route_admin_request()
973
+	{
974
+		if (! $this->_is_UI_request) {
975
+			$this->_verify_routes();
976
+		}
977
+		$nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
978
+		if ($this->_req_action !== 'default' && $nonce_check) {
979
+			// set nonce from post data
980
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
981
+			$this->_verify_nonce($nonce, $this->_req_nonce);
982
+		}
983
+		// set the nav_tabs array but ONLY if this is  UI_request
984
+		if ($this->_is_UI_request) {
985
+			$this->_set_nav_tabs();
986
+		}
987
+		// grab callback function
988
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
989
+		// check if callback has args
990
+		$args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
991
+		$error_msg = '';
992
+		// action right before calling route
993
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
994
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
995
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
996
+		}
997
+		// right before calling the route, let's clean the _wp_http_referer
998
+		$this->request->setServerParam(
999
+			'REQUEST_URI',
1000
+			remove_query_arg(
1001
+				'_wp_http_referer',
1002
+				wp_unslash($this->request->getServerParam('REQUEST_URI'))
1003
+			)
1004
+		);
1005
+		if (! empty($func)) {
1006
+			if (is_array($func)) {
1007
+				list($class, $method) = $func;
1008
+			} elseif (strpos($func, '::') !== false) {
1009
+				list($class, $method) = explode('::', $func);
1010
+			} else {
1011
+				$class  = $this;
1012
+				$method = $func;
1013
+			}
1014
+			if (! (is_object($class) && $class === $this)) {
1015
+				// send along this admin page object for access by addons.
1016
+				$args['admin_page_object'] = $this;
1017
+			}
1018
+			if (
1019
+				// is it a method on a class that doesn't work?
1020
+				(
1021
+					(
1022
+						method_exists($class, $method)
1023
+						&& call_user_func_array([$class, $method], $args) === false
1024
+					)
1025
+					&& (
1026
+						// is it a standalone function that doesn't work?
1027
+						function_exists($method)
1028
+						&& call_user_func_array(
1029
+							$func,
1030
+							array_merge(['admin_page_object' => $this], $args)
1031
+						) === false
1032
+					)
1033
+				)
1034
+				|| (
1035
+					// is it neither a class method NOR a standalone function?
1036
+					! method_exists($class, $method)
1037
+					&& ! function_exists($method)
1038
+				)
1039
+			) {
1040
+				// user error msg
1041
+				$error_msg = esc_html__(
1042
+					'An error occurred. The  requested page route could not be found.',
1043
+					'event_espresso'
1044
+				);
1045
+				// developer error msg
1046
+				$error_msg .= '||';
1047
+				$error_msg .= sprintf(
1048
+					esc_html__(
1049
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1050
+						'event_espresso'
1051
+					),
1052
+					$method
1053
+				);
1054
+			}
1055
+			if (! empty($error_msg)) {
1056
+				throw new EE_Error($error_msg);
1057
+			}
1058
+		}
1059
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1060
+		// then we need to reset the routing properties to the new route.
1061
+		// now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1062
+		if (
1063
+			$this->_is_UI_request === false
1064
+			&& is_array($this->_route)
1065
+			&& ! empty($this->_route['headers_sent_route'])
1066
+		) {
1067
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1068
+		}
1069
+	}
1070
+
1071
+
1072
+	/**
1073
+	 * This method just allows the resetting of page properties in the case where a no headers
1074
+	 * route redirects to a headers route in its route config.
1075
+	 *
1076
+	 * @param string $new_route New (non header) route to redirect to.
1077
+	 * @return   void
1078
+	 * @throws ReflectionException
1079
+	 * @throws InvalidArgumentException
1080
+	 * @throws InvalidInterfaceException
1081
+	 * @throws InvalidDataTypeException
1082
+	 * @throws EE_Error
1083
+	 * @since   4.3.0
1084
+	 */
1085
+	protected function _reset_routing_properties($new_route)
1086
+	{
1087
+		$this->_is_UI_request = true;
1088
+		// now we set the current route to whatever the headers_sent_route is set at
1089
+		$this->request->setRequestParam('action', $new_route);
1090
+		// rerun page setup
1091
+		$this->_page_setup();
1092
+	}
1093
+
1094
+
1095
+	/**
1096
+	 * _add_query_arg
1097
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1098
+	 *(internally just uses EEH_URL's function with the same name)
1099
+	 *
1100
+	 * @param array  $args
1101
+	 * @param string $url
1102
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1103
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1104
+	 *                                        Example usage: If the current page is:
1105
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1106
+	 *                                        &action=default&event_id=20&month_range=March%202015
1107
+	 *                                        &_wpnonce=5467821
1108
+	 *                                        and you call:
1109
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1110
+	 *                                        array(
1111
+	 *                                        'action' => 'resend_something',
1112
+	 *                                        'page=>espresso_registrations'
1113
+	 *                                        ),
1114
+	 *                                        $some_url,
1115
+	 *                                        true
1116
+	 *                                        );
1117
+	 *                                        It will produce a url in this structure:
1118
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1119
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1120
+	 *                                        month_range]=March%202015
1121
+	 * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1122
+	 * @return string
1123
+	 */
1124
+	public static function add_query_args_and_nonce(
1125
+		$args = [],
1126
+		$url = false,
1127
+		$sticky = false,
1128
+		$exclude_nonce = false
1129
+	) {
1130
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1131
+		if ($sticky) {
1132
+			/** @var RequestInterface $request */
1133
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1134
+			$request->unSetRequestParams(['_wp_http_referer', 'wp_referer']);
1135
+			foreach ($request->requestParams() as $key => $value) {
1136
+				// do not add nonces
1137
+				if (strpos($key, 'nonce') !== false) {
1138
+					continue;
1139
+				}
1140
+				$args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1141
+			}
1142
+		}
1143
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1144
+	}
1145
+
1146
+
1147
+	/**
1148
+	 * This returns a generated link that will load the related help tab.
1149
+	 *
1150
+	 * @param string $help_tab_id the id for the connected help tab
1151
+	 * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1152
+	 * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1153
+	 * @return string              generated link
1154
+	 * @uses EEH_Template::get_help_tab_link()
1155
+	 */
1156
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1157
+	{
1158
+		return EEH_Template::get_help_tab_link(
1159
+			$help_tab_id,
1160
+			$this->page_slug,
1161
+			$this->_req_action,
1162
+			$icon_style,
1163
+			$help_text
1164
+		);
1165
+	}
1166
+
1167
+
1168
+	/**
1169
+	 * _add_help_tabs
1170
+	 * Note child classes define their help tabs within the page_config array.
1171
+	 *
1172
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1173
+	 * @return void
1174
+	 * @throws DomainException
1175
+	 * @throws EE_Error
1176
+	 */
1177
+	protected function _add_help_tabs()
1178
+	{
1179
+		if (isset($this->_page_config[ $this->_req_action ])) {
1180
+			$config = $this->_page_config[ $this->_req_action ];
1181
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1182
+			if (is_array($config) && isset($config['help_sidebar'])) {
1183
+				// check that the callback given is valid
1184
+				if (! method_exists($this, $config['help_sidebar'])) {
1185
+					throw new EE_Error(
1186
+						sprintf(
1187
+							esc_html__(
1188
+								'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1189
+								'event_espresso'
1190
+							),
1191
+							$config['help_sidebar'],
1192
+							get_class($this)
1193
+						)
1194
+					);
1195
+				}
1196
+				$content = apply_filters(
1197
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1198
+					$this->{$config['help_sidebar']}()
1199
+				);
1200
+				$this->_current_screen->set_help_sidebar($content);
1201
+			}
1202
+			if (! isset($config['help_tabs'])) {
1203
+				return;
1204
+			} //no help tabs for this route
1205
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1206
+				// we're here so there ARE help tabs!
1207
+				// make sure we've got what we need
1208
+				if (! isset($cfg['title'])) {
1209
+					throw new EE_Error(
1210
+						esc_html__(
1211
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1212
+							'event_espresso'
1213
+						)
1214
+					);
1215
+				}
1216
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1217
+					throw new EE_Error(
1218
+						esc_html__(
1219
+							'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1220
+							'event_espresso'
1221
+						)
1222
+					);
1223
+				}
1224
+				// first priority goes to content.
1225
+				if (! empty($cfg['content'])) {
1226
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1227
+					// second priority goes to filename
1228
+				} elseif (! empty($cfg['filename'])) {
1229
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1230
+					// it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1231
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1232
+															 . basename($this->_get_dir())
1233
+															 . '/help_tabs/'
1234
+															 . $cfg['filename']
1235
+															 . '.help_tab.php' : $file_path;
1236
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1237
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1238
+						EE_Error::add_error(
1239
+							sprintf(
1240
+								esc_html__(
1241
+									'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1242
+									'event_espresso'
1243
+								),
1244
+								$tab_id,
1245
+								key($config),
1246
+								$file_path
1247
+							),
1248
+							__FILE__,
1249
+							__FUNCTION__,
1250
+							__LINE__
1251
+						);
1252
+						return;
1253
+					}
1254
+					$template_args['admin_page_obj'] = $this;
1255
+					$content                         = EEH_Template::display_template(
1256
+						$file_path,
1257
+						$template_args,
1258
+						true
1259
+					);
1260
+				} else {
1261
+					$content = '';
1262
+				}
1263
+				// check if callback is valid
1264
+				if (
1265
+					empty($content)
1266
+					&& (
1267
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1268
+					)
1269
+				) {
1270
+					EE_Error::add_error(
1271
+						sprintf(
1272
+							esc_html__(
1273
+								'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1274
+								'event_espresso'
1275
+							),
1276
+							$cfg['title']
1277
+						),
1278
+						__FILE__,
1279
+						__FUNCTION__,
1280
+						__LINE__
1281
+					);
1282
+					return;
1283
+				}
1284
+				// setup config array for help tab method
1285
+				$id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1286
+				$_ht = [
1287
+					'id'       => $id,
1288
+					'title'    => $cfg['title'],
1289
+					'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1290
+					'content'  => $content,
1291
+				];
1292
+				$this->_current_screen->add_help_tab($_ht);
1293
+			}
1294
+		}
1295
+	}
1296
+
1297
+
1298
+	/**
1299
+	 * This simply sets up any qtips that have been defined in the page config
1300
+	 *
1301
+	 * @return void
1302
+	 */
1303
+	protected function _add_qtips()
1304
+	{
1305
+		if (isset($this->_route_config['qtips'])) {
1306
+			$qtips = (array) $this->_route_config['qtips'];
1307
+			// load qtip loader
1308
+			$path = [
1309
+				$this->_get_dir() . '/qtips/',
1310
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1311
+			];
1312
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1313
+		}
1314
+	}
1315
+
1316
+
1317
+	/**
1318
+	 * _set_nav_tabs
1319
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1320
+	 * wish to add additional tabs or modify accordingly.
1321
+	 *
1322
+	 * @return void
1323
+	 * @throws InvalidArgumentException
1324
+	 * @throws InvalidInterfaceException
1325
+	 * @throws InvalidDataTypeException
1326
+	 */
1327
+	protected function _set_nav_tabs()
1328
+	{
1329
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1330
+		$i = 0;
1331
+		foreach ($this->_page_config as $slug => $config) {
1332
+			if (! is_array($config) || empty($config['nav'])) {
1333
+				continue;
1334
+			}
1335
+			// no nav tab for this config
1336
+			// check for persistent flag
1337
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1338
+				// nav tab is only to appear when route requested.
1339
+				continue;
1340
+			}
1341
+			if (! $this->check_user_access($slug, true)) {
1342
+				// no nav tab because current user does not have access.
1343
+				continue;
1344
+			}
1345
+			$css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1346
+			$this->_nav_tabs[ $slug ] = [
1347
+				'url'       => isset($config['nav']['url'])
1348
+					? $config['nav']['url']
1349
+					: self::add_query_args_and_nonce(
1350
+						['action' => $slug],
1351
+						$this->_admin_base_url
1352
+					),
1353
+				'link_text' => isset($config['nav']['label'])
1354
+					? $config['nav']['label']
1355
+					: ucwords(
1356
+						str_replace('_', ' ', $slug)
1357
+					),
1358
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1359
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1360
+			];
1361
+			$i++;
1362
+		}
1363
+		// if $this->_nav_tabs is empty then lets set the default
1364
+		if (empty($this->_nav_tabs)) {
1365
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1366
+				'url'       => $this->_admin_base_url,
1367
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1368
+				'css_class' => 'nav-tab-active',
1369
+				'order'     => 10,
1370
+			];
1371
+		}
1372
+		// now let's sort the tabs according to order
1373
+		usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1374
+	}
1375
+
1376
+
1377
+	/**
1378
+	 * _set_current_labels
1379
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1380
+	 * property array
1381
+	 *
1382
+	 * @return void
1383
+	 */
1384
+	private function _set_current_labels()
1385
+	{
1386
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1387
+			foreach ($this->_route_config['labels'] as $label => $text) {
1388
+				if (is_array($text)) {
1389
+					foreach ($text as $sublabel => $subtext) {
1390
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1391
+					}
1392
+				} else {
1393
+					$this->_labels[ $label ] = $text;
1394
+				}
1395
+			}
1396
+		}
1397
+	}
1398
+
1399
+
1400
+	/**
1401
+	 *        verifies user access for this admin page
1402
+	 *
1403
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1404
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1405
+	 *                               return false if verify fail.
1406
+	 * @return bool
1407
+	 * @throws InvalidArgumentException
1408
+	 * @throws InvalidDataTypeException
1409
+	 * @throws InvalidInterfaceException
1410
+	 */
1411
+	public function check_user_access($route_to_check = '', $verify_only = false)
1412
+	{
1413
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1414
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1415
+		$capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1416
+						  && is_array(
1417
+							  $this->_page_routes[ $route_to_check ]
1418
+						  )
1419
+						  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1420
+			? $this->_page_routes[ $route_to_check ]['capability'] : null;
1421
+		if (empty($capability) && empty($route_to_check)) {
1422
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1423
+				: $this->_route['capability'];
1424
+		} else {
1425
+			$capability = empty($capability) ? 'manage_options' : $capability;
1426
+		}
1427
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1428
+		if (
1429
+			! $this->request->isAjax()
1430
+			&& (
1431
+				! function_exists('is_admin')
1432
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1433
+					$capability,
1434
+					$this->page_slug
1435
+					. '_'
1436
+					. $route_to_check,
1437
+					$id
1438
+				)
1439
+			)
1440
+		) {
1441
+			if ($verify_only) {
1442
+				return false;
1443
+			}
1444
+			if (is_user_logged_in()) {
1445
+				wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1446
+			} else {
1447
+				return false;
1448
+			}
1449
+		}
1450
+		return true;
1451
+	}
1452
+
1453
+
1454
+	/**
1455
+	 * admin_init_global
1456
+	 * This runs all the code that we want executed within the WP admin_init hook.
1457
+	 * This method executes for ALL EE Admin pages.
1458
+	 *
1459
+	 * @return void
1460
+	 */
1461
+	public function admin_init_global()
1462
+	{
1463
+	}
1464
+
1465
+
1466
+	/**
1467
+	 * wp_loaded_global
1468
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1469
+	 * EE_Admin page and will execute on every EE Admin Page load
1470
+	 *
1471
+	 * @return void
1472
+	 */
1473
+	public function wp_loaded()
1474
+	{
1475
+	}
1476
+
1477
+
1478
+	/**
1479
+	 * admin_notices
1480
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1481
+	 * ALL EE_Admin pages.
1482
+	 *
1483
+	 * @return void
1484
+	 */
1485
+	public function admin_notices_global()
1486
+	{
1487
+		$this->_display_no_javascript_warning();
1488
+		$this->_display_espresso_notices();
1489
+	}
1490
+
1491
+
1492
+	public function network_admin_notices_global()
1493
+	{
1494
+		$this->_display_no_javascript_warning();
1495
+		$this->_display_espresso_notices();
1496
+	}
1497
+
1498
+
1499
+	/**
1500
+	 * admin_footer_scripts_global
1501
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1502
+	 * will apply on ALL EE_Admin pages.
1503
+	 *
1504
+	 * @return void
1505
+	 */
1506
+	public function admin_footer_scripts_global()
1507
+	{
1508
+		$this->_add_admin_page_ajax_loading_img();
1509
+		$this->_add_admin_page_overlay();
1510
+		// if metaboxes are present we need to add the nonce field
1511
+		if (
1512
+			isset($this->_route_config['metaboxes'])
1513
+			|| isset($this->_route_config['list_table'])
1514
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1515
+		) {
1516
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1517
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1518
+		}
1519
+	}
1520
+
1521
+
1522
+	/**
1523
+	 * admin_footer_global
1524
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1525
+	 * ALL EE_Admin Pages.
1526
+	 *
1527
+	 * @return void
1528
+	 */
1529
+	public function admin_footer_global()
1530
+	{
1531
+		// dialog container for dialog helper
1532
+		echo '
1533 1533
         <div class="ee-admin-dialog-container auto-hide hidden">
1534 1534
             <div class="ee-notices"></div>
1535 1535
             <div class="ee-admin-dialog-container-inner-content"></div>
1536 1536
         </div>
1537 1537
         ';
1538 1538
 
1539
-        // current set timezone for timezone js
1540
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1541
-    }
1542
-
1543
-
1544
-    /**
1545
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1546
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1547
-     * help popups then in your templates or your content you set "triggers" for the content using the
1548
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1549
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1550
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1551
-     * for the
1552
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1553
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1554
-     *    'help_trigger_id' => array(
1555
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1556
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1557
-     *    )
1558
-     * );
1559
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1560
-     *
1561
-     * @param array $help_array
1562
-     * @param bool  $display
1563
-     * @return string content
1564
-     * @throws DomainException
1565
-     * @throws EE_Error
1566
-     */
1567
-    protected function _set_help_popup_content($help_array = [], $display = false)
1568
-    {
1569
-        $content    = '';
1570
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1571
-        // loop through the array and setup content
1572
-        foreach ($help_array as $trigger => $help) {
1573
-            // make sure the array is setup properly
1574
-            if (! isset($help['title']) || ! isset($help['content'])) {
1575
-                throw new EE_Error(
1576
-                    esc_html__(
1577
-                        'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1578
-                        'event_espresso'
1579
-                    )
1580
-                );
1581
-            }
1582
-            // we're good so let's setup the template vars and then assign parsed template content to our content.
1583
-            $template_args = [
1584
-                'help_popup_id'      => $trigger,
1585
-                'help_popup_title'   => $help['title'],
1586
-                'help_popup_content' => $help['content'],
1587
-            ];
1588
-            $content       .= EEH_Template::display_template(
1589
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1590
-                $template_args,
1591
-                true
1592
-            );
1593
-        }
1594
-        if ($display) {
1595
-            echo $content; // already escaped
1596
-            return '';
1597
-        }
1598
-        return $content;
1599
-    }
1600
-
1601
-
1602
-    /**
1603
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1604
-     *
1605
-     * @return array properly formatted array for help popup content
1606
-     * @throws EE_Error
1607
-     */
1608
-    private function _get_help_content()
1609
-    {
1610
-        // what is the method we're looking for?
1611
-        $method_name = '_help_popup_content_' . $this->_req_action;
1612
-        // if method doesn't exist let's get out.
1613
-        if (! method_exists($this, $method_name)) {
1614
-            return [];
1615
-        }
1616
-        // k we're good to go let's retrieve the help array
1617
-        $help_array = call_user_func([$this, $method_name]);
1618
-        // make sure we've got an array!
1619
-        if (! is_array($help_array)) {
1620
-            throw new EE_Error(
1621
-                esc_html__(
1622
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1623
-                    'event_espresso'
1624
-                )
1625
-            );
1626
-        }
1627
-        return $help_array;
1628
-    }
1629
-
1630
-
1631
-    /**
1632
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1633
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1634
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1635
-     *
1636
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1637
-     * @param boolean $display    if false then we return the trigger string
1638
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1639
-     * @return string
1640
-     * @throws DomainException
1641
-     * @throws EE_Error
1642
-     */
1643
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1644
-    {
1645
-        if ($this->request->isAjax()) {
1646
-            return '';
1647
-        }
1648
-        // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1649
-        $help_array   = $this->_get_help_content();
1650
-        $help_content = '';
1651
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1652
-            $help_array[ $trigger_id ] = [
1653
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1654
-                'content' => esc_html__(
1655
-                    'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1656
-                    'event_espresso'
1657
-                ),
1658
-            ];
1659
-            $help_content              = $this->_set_help_popup_content($help_array);
1660
-        }
1661
-        // let's setup the trigger
1662
-        $content = '<a class="ee-dialog" href="?height='
1663
-                   . esc_attr($dimensions[0])
1664
-                   . '&width='
1665
-                   . esc_attr($dimensions[1])
1666
-                   . '&inlineId='
1667
-                   . esc_attr($trigger_id)
1668
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1669
-        $content .= $help_content;
1670
-        if ($display) {
1671
-            echo $content; // already escaped
1672
-            return '';
1673
-        }
1674
-        return $content;
1675
-    }
1676
-
1677
-
1678
-    /**
1679
-     * _add_global_screen_options
1680
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1681
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1682
-     *
1683
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1684
-     *         see also WP_Screen object documents...
1685
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1686
-     * @abstract
1687
-     * @return void
1688
-     */
1689
-    private function _add_global_screen_options()
1690
-    {
1691
-    }
1692
-
1693
-
1694
-    /**
1695
-     * _add_global_feature_pointers
1696
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1697
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1698
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1699
-     *
1700
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1701
-     *         extended) also see:
1702
-     * @link   http://eamann.com/tech/wordpress-portland/
1703
-     * @abstract
1704
-     * @return void
1705
-     */
1706
-    private function _add_global_feature_pointers()
1707
-    {
1708
-    }
1709
-
1710
-
1711
-    /**
1712
-     * load_global_scripts_styles
1713
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1714
-     *
1715
-     * @return void
1716
-     */
1717
-    public function load_global_scripts_styles()
1718
-    {
1719
-        /** STYLES **/
1720
-        // add debugging styles
1721
-        if (WP_DEBUG) {
1722
-            add_action('admin_head', [$this, 'add_xdebug_style']);
1723
-        }
1724
-        // register all styles
1725
-        wp_register_style(
1726
-            'espresso-ui-theme',
1727
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1728
-            [],
1729
-            EVENT_ESPRESSO_VERSION
1730
-        );
1731
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1732
-        // helpers styles
1733
-        wp_register_style(
1734
-            'ee-text-links',
1735
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1736
-            [],
1737
-            EVENT_ESPRESSO_VERSION
1738
-        );
1739
-        /** SCRIPTS **/
1740
-        // register all scripts
1741
-        wp_register_script(
1742
-            'ee-dialog',
1743
-            EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1744
-            ['jquery', 'jquery-ui-draggable'],
1745
-            EVENT_ESPRESSO_VERSION,
1746
-            true
1747
-        );
1748
-        wp_register_script(
1749
-            'ee_admin_js',
1750
-            EE_ADMIN_URL . 'assets/ee-admin-page.js',
1751
-            ['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1752
-            EVENT_ESPRESSO_VERSION,
1753
-            true
1754
-        );
1755
-        wp_register_script(
1756
-            'jquery-ui-timepicker-addon',
1757
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1758
-            ['jquery-ui-datepicker', 'jquery-ui-slider'],
1759
-            EVENT_ESPRESSO_VERSION,
1760
-            true
1761
-        );
1762
-        // script for sorting tables
1763
-        wp_register_script(
1764
-            'espresso_ajax_table_sorting',
1765
-            EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1766
-            ['ee_admin_js', 'jquery-ui-sortable'],
1767
-            EVENT_ESPRESSO_VERSION,
1768
-            true
1769
-        );
1770
-        // script for parsing uri's
1771
-        wp_register_script(
1772
-            'ee-parse-uri',
1773
-            EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1774
-            [],
1775
-            EVENT_ESPRESSO_VERSION,
1776
-            true
1777
-        );
1778
-        // and parsing associative serialized form elements
1779
-        wp_register_script(
1780
-            'ee-serialize-full-array',
1781
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1782
-            ['jquery'],
1783
-            EVENT_ESPRESSO_VERSION,
1784
-            true
1785
-        );
1786
-        // helpers scripts
1787
-        wp_register_script(
1788
-            'ee-text-links',
1789
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1790
-            ['jquery'],
1791
-            EVENT_ESPRESSO_VERSION,
1792
-            true
1793
-        );
1794
-        wp_register_script(
1795
-            'ee-moment-core',
1796
-            EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1797
-            [],
1798
-            EVENT_ESPRESSO_VERSION,
1799
-            true
1800
-        );
1801
-        wp_register_script(
1802
-            'ee-moment',
1803
-            EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1804
-            ['ee-moment-core'],
1805
-            EVENT_ESPRESSO_VERSION,
1806
-            true
1807
-        );
1808
-        wp_register_script(
1809
-            'ee-datepicker',
1810
-            EE_ADMIN_URL . 'assets/ee-datepicker.js',
1811
-            ['jquery-ui-timepicker-addon', 'ee-moment'],
1812
-            EVENT_ESPRESSO_VERSION,
1813
-            true
1814
-        );
1815
-        // google charts
1816
-        wp_register_script(
1817
-            'google-charts',
1818
-            'https://www.gstatic.com/charts/loader.js',
1819
-            [],
1820
-            EVENT_ESPRESSO_VERSION
1821
-        );
1822
-        // ENQUEUE ALL BASICS BY DEFAULT
1823
-        wp_enqueue_style('ee-admin-css');
1824
-        wp_enqueue_script('ee_admin_js');
1825
-        wp_enqueue_script('ee-accounting');
1826
-        wp_enqueue_script('jquery-validate');
1827
-        // taking care of metaboxes
1828
-        if (
1829
-            empty($this->_cpt_route)
1830
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1831
-        ) {
1832
-            wp_enqueue_script('dashboard');
1833
-        }
1834
-        // LOCALIZED DATA
1835
-        // localize script for ajax lazy loading
1836
-        $lazy_loader_container_ids = apply_filters(
1837
-            'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1838
-            ['espresso_news_post_box_content']
1839
-        );
1840
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1841
-        add_filter(
1842
-            'admin_body_class',
1843
-            function ($classes) {
1844
-                if (strpos($classes, 'espresso-admin') === false) {
1845
-                    $classes .= ' espresso-admin';
1846
-                }
1847
-                return $classes;
1848
-            }
1849
-        );
1850
-    }
1851
-
1852
-
1853
-    /**
1854
-     *        admin_footer_scripts_eei18n_js_strings
1855
-     *
1856
-     * @return        void
1857
-     */
1858
-    public function admin_footer_scripts_eei18n_js_strings()
1859
-    {
1860
-        EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1861
-        EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1862
-            __(
1863
-                'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1864
-                'event_espresso'
1865
-            )
1866
-        );
1867
-        EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1868
-        EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1869
-        EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1870
-        EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1871
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1872
-        EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1873
-        EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1874
-        EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1875
-        EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1876
-        EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1877
-        EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1878
-        EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1879
-        EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1880
-        EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1881
-        EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1882
-        EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1883
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1884
-        EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1885
-        EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1886
-        EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1887
-        EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1888
-        EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1889
-        EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1890
-        EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1891
-        EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1892
-        EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1893
-        EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1894
-        EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1895
-        EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1896
-        EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1897
-        EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1898
-        EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1899
-        EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1900
-        EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1901
-        EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1902
-        EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1903
-        EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1904
-        EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1905
-    }
1906
-
1907
-
1908
-    /**
1909
-     *        load enhanced xdebug styles for ppl with failing eyesight
1910
-     *
1911
-     * @return        void
1912
-     */
1913
-    public function add_xdebug_style()
1914
-    {
1915
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1916
-    }
1917
-
1918
-
1919
-    /************************/
1920
-    /** LIST TABLE METHODS **/
1921
-    /************************/
1922
-    /**
1923
-     * this sets up the list table if the current view requires it.
1924
-     *
1925
-     * @return void
1926
-     * @throws EE_Error
1927
-     */
1928
-    protected function _set_list_table()
1929
-    {
1930
-        // first is this a list_table view?
1931
-        if (! isset($this->_route_config['list_table'])) {
1932
-            return;
1933
-        } //not a list_table view so get out.
1934
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
1935
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
1936
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1937
-            // user error msg
1938
-            $error_msg = esc_html__(
1939
-                'An error occurred. The requested list table views could not be found.',
1940
-                'event_espresso'
1941
-            );
1942
-            // developer error msg
1943
-            $error_msg .= '||'
1944
-                          . sprintf(
1945
-                              esc_html__(
1946
-                                  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
1947
-                                  'event_espresso'
1948
-                              ),
1949
-                              $this->_req_action,
1950
-                              $list_table_view
1951
-                          );
1952
-            throw new EE_Error($error_msg);
1953
-        }
1954
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1955
-        $this->_views = apply_filters(
1956
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
1957
-            $this->_views
1958
-        );
1959
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1960
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1961
-        $this->_set_list_table_view();
1962
-        $this->_set_list_table_object();
1963
-    }
1964
-
1965
-
1966
-    /**
1967
-     * set current view for List Table
1968
-     *
1969
-     * @return void
1970
-     */
1971
-    protected function _set_list_table_view()
1972
-    {
1973
-        $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1974
-        $status = $this->request->getRequestParam('status', null, 'key');
1975
-        $this->_view = $status && array_key_exists($status, $this->_views)
1976
-            ? $status
1977
-            : $this->_view;
1978
-    }
1979
-
1980
-
1981
-    /**
1982
-     * _set_list_table_object
1983
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1984
-     *
1985
-     * @throws InvalidInterfaceException
1986
-     * @throws InvalidArgumentException
1987
-     * @throws InvalidDataTypeException
1988
-     * @throws EE_Error
1989
-     * @throws InvalidInterfaceException
1990
-     */
1991
-    protected function _set_list_table_object()
1992
-    {
1993
-        if (isset($this->_route_config['list_table'])) {
1994
-            if (! class_exists($this->_route_config['list_table'])) {
1995
-                throw new EE_Error(
1996
-                    sprintf(
1997
-                        esc_html__(
1998
-                            'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1999
-                            'event_espresso'
2000
-                        ),
2001
-                        $this->_route_config['list_table'],
2002
-                        get_class($this)
2003
-                    )
2004
-                );
2005
-            }
2006
-            $this->_list_table_object = $this->loader->getShared(
2007
-                $this->_route_config['list_table'],
2008
-                [$this]
2009
-            );
2010
-        }
2011
-    }
2012
-
2013
-
2014
-    /**
2015
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2016
-     *
2017
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2018
-     *                                                    urls.  The array should be indexed by the view it is being
2019
-     *                                                    added to.
2020
-     * @return array
2021
-     */
2022
-    public function get_list_table_view_RLs($extra_query_args = [])
2023
-    {
2024
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2025
-        if (empty($this->_views)) {
2026
-            $this->_views = [];
2027
-        }
2028
-        // cycle thru views
2029
-        foreach ($this->_views as $key => $view) {
2030
-            $query_args = [];
2031
-            // check for current view
2032
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2033
-            $query_args['action']                        = $this->_req_action;
2034
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2035
-            $query_args['status']                        = $view['slug'];
2036
-            // merge any other arguments sent in.
2037
-            if (isset($extra_query_args[ $view['slug'] ])) {
2038
-                $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2039
-            }
2040
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2041
-        }
2042
-        return $this->_views;
2043
-    }
2044
-
2045
-
2046
-    /**
2047
-     * _entries_per_page_dropdown
2048
-     * generates a dropdown box for selecting the number of visible rows in an admin page list table
2049
-     *
2050
-     * @param int $max_entries total number of rows in the table
2051
-     * @return string
2052
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2053
-     *         WP does it.
2054
-     */
2055
-    protected function _entries_per_page_dropdown($max_entries = 0)
2056
-    {
2057
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2058
-        $values   = [10, 25, 50, 100];
2059
-        $per_page = $this->request->getRequestParam('per_page', 10, 'int');
2060
-        if ($max_entries) {
2061
-            $values[] = $max_entries;
2062
-            sort($values);
2063
-        }
2064
-        $entries_per_page_dropdown = '
1539
+		// current set timezone for timezone js
1540
+		echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1541
+	}
1542
+
1543
+
1544
+	/**
1545
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1546
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1547
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1548
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1549
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1550
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1551
+	 * for the
1552
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1553
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1554
+	 *    'help_trigger_id' => array(
1555
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1556
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1557
+	 *    )
1558
+	 * );
1559
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1560
+	 *
1561
+	 * @param array $help_array
1562
+	 * @param bool  $display
1563
+	 * @return string content
1564
+	 * @throws DomainException
1565
+	 * @throws EE_Error
1566
+	 */
1567
+	protected function _set_help_popup_content($help_array = [], $display = false)
1568
+	{
1569
+		$content    = '';
1570
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1571
+		// loop through the array and setup content
1572
+		foreach ($help_array as $trigger => $help) {
1573
+			// make sure the array is setup properly
1574
+			if (! isset($help['title']) || ! isset($help['content'])) {
1575
+				throw new EE_Error(
1576
+					esc_html__(
1577
+						'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1578
+						'event_espresso'
1579
+					)
1580
+				);
1581
+			}
1582
+			// we're good so let's setup the template vars and then assign parsed template content to our content.
1583
+			$template_args = [
1584
+				'help_popup_id'      => $trigger,
1585
+				'help_popup_title'   => $help['title'],
1586
+				'help_popup_content' => $help['content'],
1587
+			];
1588
+			$content       .= EEH_Template::display_template(
1589
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1590
+				$template_args,
1591
+				true
1592
+			);
1593
+		}
1594
+		if ($display) {
1595
+			echo $content; // already escaped
1596
+			return '';
1597
+		}
1598
+		return $content;
1599
+	}
1600
+
1601
+
1602
+	/**
1603
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1604
+	 *
1605
+	 * @return array properly formatted array for help popup content
1606
+	 * @throws EE_Error
1607
+	 */
1608
+	private function _get_help_content()
1609
+	{
1610
+		// what is the method we're looking for?
1611
+		$method_name = '_help_popup_content_' . $this->_req_action;
1612
+		// if method doesn't exist let's get out.
1613
+		if (! method_exists($this, $method_name)) {
1614
+			return [];
1615
+		}
1616
+		// k we're good to go let's retrieve the help array
1617
+		$help_array = call_user_func([$this, $method_name]);
1618
+		// make sure we've got an array!
1619
+		if (! is_array($help_array)) {
1620
+			throw new EE_Error(
1621
+				esc_html__(
1622
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1623
+					'event_espresso'
1624
+				)
1625
+			);
1626
+		}
1627
+		return $help_array;
1628
+	}
1629
+
1630
+
1631
+	/**
1632
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1633
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1634
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1635
+	 *
1636
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1637
+	 * @param boolean $display    if false then we return the trigger string
1638
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1639
+	 * @return string
1640
+	 * @throws DomainException
1641
+	 * @throws EE_Error
1642
+	 */
1643
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1644
+	{
1645
+		if ($this->request->isAjax()) {
1646
+			return '';
1647
+		}
1648
+		// let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1649
+		$help_array   = $this->_get_help_content();
1650
+		$help_content = '';
1651
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1652
+			$help_array[ $trigger_id ] = [
1653
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1654
+				'content' => esc_html__(
1655
+					'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1656
+					'event_espresso'
1657
+				),
1658
+			];
1659
+			$help_content              = $this->_set_help_popup_content($help_array);
1660
+		}
1661
+		// let's setup the trigger
1662
+		$content = '<a class="ee-dialog" href="?height='
1663
+				   . esc_attr($dimensions[0])
1664
+				   . '&width='
1665
+				   . esc_attr($dimensions[1])
1666
+				   . '&inlineId='
1667
+				   . esc_attr($trigger_id)
1668
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1669
+		$content .= $help_content;
1670
+		if ($display) {
1671
+			echo $content; // already escaped
1672
+			return '';
1673
+		}
1674
+		return $content;
1675
+	}
1676
+
1677
+
1678
+	/**
1679
+	 * _add_global_screen_options
1680
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1681
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1682
+	 *
1683
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1684
+	 *         see also WP_Screen object documents...
1685
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1686
+	 * @abstract
1687
+	 * @return void
1688
+	 */
1689
+	private function _add_global_screen_options()
1690
+	{
1691
+	}
1692
+
1693
+
1694
+	/**
1695
+	 * _add_global_feature_pointers
1696
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1697
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1698
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1699
+	 *
1700
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1701
+	 *         extended) also see:
1702
+	 * @link   http://eamann.com/tech/wordpress-portland/
1703
+	 * @abstract
1704
+	 * @return void
1705
+	 */
1706
+	private function _add_global_feature_pointers()
1707
+	{
1708
+	}
1709
+
1710
+
1711
+	/**
1712
+	 * load_global_scripts_styles
1713
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1714
+	 *
1715
+	 * @return void
1716
+	 */
1717
+	public function load_global_scripts_styles()
1718
+	{
1719
+		/** STYLES **/
1720
+		// add debugging styles
1721
+		if (WP_DEBUG) {
1722
+			add_action('admin_head', [$this, 'add_xdebug_style']);
1723
+		}
1724
+		// register all styles
1725
+		wp_register_style(
1726
+			'espresso-ui-theme',
1727
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1728
+			[],
1729
+			EVENT_ESPRESSO_VERSION
1730
+		);
1731
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1732
+		// helpers styles
1733
+		wp_register_style(
1734
+			'ee-text-links',
1735
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1736
+			[],
1737
+			EVENT_ESPRESSO_VERSION
1738
+		);
1739
+		/** SCRIPTS **/
1740
+		// register all scripts
1741
+		wp_register_script(
1742
+			'ee-dialog',
1743
+			EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1744
+			['jquery', 'jquery-ui-draggable'],
1745
+			EVENT_ESPRESSO_VERSION,
1746
+			true
1747
+		);
1748
+		wp_register_script(
1749
+			'ee_admin_js',
1750
+			EE_ADMIN_URL . 'assets/ee-admin-page.js',
1751
+			['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1752
+			EVENT_ESPRESSO_VERSION,
1753
+			true
1754
+		);
1755
+		wp_register_script(
1756
+			'jquery-ui-timepicker-addon',
1757
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1758
+			['jquery-ui-datepicker', 'jquery-ui-slider'],
1759
+			EVENT_ESPRESSO_VERSION,
1760
+			true
1761
+		);
1762
+		// script for sorting tables
1763
+		wp_register_script(
1764
+			'espresso_ajax_table_sorting',
1765
+			EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1766
+			['ee_admin_js', 'jquery-ui-sortable'],
1767
+			EVENT_ESPRESSO_VERSION,
1768
+			true
1769
+		);
1770
+		// script for parsing uri's
1771
+		wp_register_script(
1772
+			'ee-parse-uri',
1773
+			EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1774
+			[],
1775
+			EVENT_ESPRESSO_VERSION,
1776
+			true
1777
+		);
1778
+		// and parsing associative serialized form elements
1779
+		wp_register_script(
1780
+			'ee-serialize-full-array',
1781
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1782
+			['jquery'],
1783
+			EVENT_ESPRESSO_VERSION,
1784
+			true
1785
+		);
1786
+		// helpers scripts
1787
+		wp_register_script(
1788
+			'ee-text-links',
1789
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1790
+			['jquery'],
1791
+			EVENT_ESPRESSO_VERSION,
1792
+			true
1793
+		);
1794
+		wp_register_script(
1795
+			'ee-moment-core',
1796
+			EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1797
+			[],
1798
+			EVENT_ESPRESSO_VERSION,
1799
+			true
1800
+		);
1801
+		wp_register_script(
1802
+			'ee-moment',
1803
+			EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1804
+			['ee-moment-core'],
1805
+			EVENT_ESPRESSO_VERSION,
1806
+			true
1807
+		);
1808
+		wp_register_script(
1809
+			'ee-datepicker',
1810
+			EE_ADMIN_URL . 'assets/ee-datepicker.js',
1811
+			['jquery-ui-timepicker-addon', 'ee-moment'],
1812
+			EVENT_ESPRESSO_VERSION,
1813
+			true
1814
+		);
1815
+		// google charts
1816
+		wp_register_script(
1817
+			'google-charts',
1818
+			'https://www.gstatic.com/charts/loader.js',
1819
+			[],
1820
+			EVENT_ESPRESSO_VERSION
1821
+		);
1822
+		// ENQUEUE ALL BASICS BY DEFAULT
1823
+		wp_enqueue_style('ee-admin-css');
1824
+		wp_enqueue_script('ee_admin_js');
1825
+		wp_enqueue_script('ee-accounting');
1826
+		wp_enqueue_script('jquery-validate');
1827
+		// taking care of metaboxes
1828
+		if (
1829
+			empty($this->_cpt_route)
1830
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1831
+		) {
1832
+			wp_enqueue_script('dashboard');
1833
+		}
1834
+		// LOCALIZED DATA
1835
+		// localize script for ajax lazy loading
1836
+		$lazy_loader_container_ids = apply_filters(
1837
+			'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1838
+			['espresso_news_post_box_content']
1839
+		);
1840
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1841
+		add_filter(
1842
+			'admin_body_class',
1843
+			function ($classes) {
1844
+				if (strpos($classes, 'espresso-admin') === false) {
1845
+					$classes .= ' espresso-admin';
1846
+				}
1847
+				return $classes;
1848
+			}
1849
+		);
1850
+	}
1851
+
1852
+
1853
+	/**
1854
+	 *        admin_footer_scripts_eei18n_js_strings
1855
+	 *
1856
+	 * @return        void
1857
+	 */
1858
+	public function admin_footer_scripts_eei18n_js_strings()
1859
+	{
1860
+		EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1861
+		EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1862
+			__(
1863
+				'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1864
+				'event_espresso'
1865
+			)
1866
+		);
1867
+		EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1868
+		EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1869
+		EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1870
+		EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1871
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1872
+		EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1873
+		EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1874
+		EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1875
+		EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1876
+		EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1877
+		EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1878
+		EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1879
+		EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1880
+		EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1881
+		EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1882
+		EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1883
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1884
+		EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1885
+		EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1886
+		EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1887
+		EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1888
+		EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1889
+		EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1890
+		EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1891
+		EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1892
+		EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1893
+		EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1894
+		EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1895
+		EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1896
+		EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1897
+		EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1898
+		EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1899
+		EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1900
+		EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1901
+		EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1902
+		EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1903
+		EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1904
+		EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1905
+	}
1906
+
1907
+
1908
+	/**
1909
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1910
+	 *
1911
+	 * @return        void
1912
+	 */
1913
+	public function add_xdebug_style()
1914
+	{
1915
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1916
+	}
1917
+
1918
+
1919
+	/************************/
1920
+	/** LIST TABLE METHODS **/
1921
+	/************************/
1922
+	/**
1923
+	 * this sets up the list table if the current view requires it.
1924
+	 *
1925
+	 * @return void
1926
+	 * @throws EE_Error
1927
+	 */
1928
+	protected function _set_list_table()
1929
+	{
1930
+		// first is this a list_table view?
1931
+		if (! isset($this->_route_config['list_table'])) {
1932
+			return;
1933
+		} //not a list_table view so get out.
1934
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
1935
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
1936
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1937
+			// user error msg
1938
+			$error_msg = esc_html__(
1939
+				'An error occurred. The requested list table views could not be found.',
1940
+				'event_espresso'
1941
+			);
1942
+			// developer error msg
1943
+			$error_msg .= '||'
1944
+						  . sprintf(
1945
+							  esc_html__(
1946
+								  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
1947
+								  'event_espresso'
1948
+							  ),
1949
+							  $this->_req_action,
1950
+							  $list_table_view
1951
+						  );
1952
+			throw new EE_Error($error_msg);
1953
+		}
1954
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1955
+		$this->_views = apply_filters(
1956
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
1957
+			$this->_views
1958
+		);
1959
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1960
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1961
+		$this->_set_list_table_view();
1962
+		$this->_set_list_table_object();
1963
+	}
1964
+
1965
+
1966
+	/**
1967
+	 * set current view for List Table
1968
+	 *
1969
+	 * @return void
1970
+	 */
1971
+	protected function _set_list_table_view()
1972
+	{
1973
+		$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1974
+		$status = $this->request->getRequestParam('status', null, 'key');
1975
+		$this->_view = $status && array_key_exists($status, $this->_views)
1976
+			? $status
1977
+			: $this->_view;
1978
+	}
1979
+
1980
+
1981
+	/**
1982
+	 * _set_list_table_object
1983
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1984
+	 *
1985
+	 * @throws InvalidInterfaceException
1986
+	 * @throws InvalidArgumentException
1987
+	 * @throws InvalidDataTypeException
1988
+	 * @throws EE_Error
1989
+	 * @throws InvalidInterfaceException
1990
+	 */
1991
+	protected function _set_list_table_object()
1992
+	{
1993
+		if (isset($this->_route_config['list_table'])) {
1994
+			if (! class_exists($this->_route_config['list_table'])) {
1995
+				throw new EE_Error(
1996
+					sprintf(
1997
+						esc_html__(
1998
+							'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1999
+							'event_espresso'
2000
+						),
2001
+						$this->_route_config['list_table'],
2002
+						get_class($this)
2003
+					)
2004
+				);
2005
+			}
2006
+			$this->_list_table_object = $this->loader->getShared(
2007
+				$this->_route_config['list_table'],
2008
+				[$this]
2009
+			);
2010
+		}
2011
+	}
2012
+
2013
+
2014
+	/**
2015
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2016
+	 *
2017
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2018
+	 *                                                    urls.  The array should be indexed by the view it is being
2019
+	 *                                                    added to.
2020
+	 * @return array
2021
+	 */
2022
+	public function get_list_table_view_RLs($extra_query_args = [])
2023
+	{
2024
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2025
+		if (empty($this->_views)) {
2026
+			$this->_views = [];
2027
+		}
2028
+		// cycle thru views
2029
+		foreach ($this->_views as $key => $view) {
2030
+			$query_args = [];
2031
+			// check for current view
2032
+			$this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2033
+			$query_args['action']                        = $this->_req_action;
2034
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2035
+			$query_args['status']                        = $view['slug'];
2036
+			// merge any other arguments sent in.
2037
+			if (isset($extra_query_args[ $view['slug'] ])) {
2038
+				$query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2039
+			}
2040
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2041
+		}
2042
+		return $this->_views;
2043
+	}
2044
+
2045
+
2046
+	/**
2047
+	 * _entries_per_page_dropdown
2048
+	 * generates a dropdown box for selecting the number of visible rows in an admin page list table
2049
+	 *
2050
+	 * @param int $max_entries total number of rows in the table
2051
+	 * @return string
2052
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2053
+	 *         WP does it.
2054
+	 */
2055
+	protected function _entries_per_page_dropdown($max_entries = 0)
2056
+	{
2057
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2058
+		$values   = [10, 25, 50, 100];
2059
+		$per_page = $this->request->getRequestParam('per_page', 10, 'int');
2060
+		if ($max_entries) {
2061
+			$values[] = $max_entries;
2062
+			sort($values);
2063
+		}
2064
+		$entries_per_page_dropdown = '
2065 2065
 			<div id="entries-per-page-dv" class="alignleft actions">
2066 2066
 				<label class="hide-if-no-js">
2067 2067
 					Show
2068 2068
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2069
-        foreach ($values as $value) {
2070
-            if ($value < $max_entries) {
2071
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2072
-                $entries_per_page_dropdown .= '
2069
+		foreach ($values as $value) {
2070
+			if ($value < $max_entries) {
2071
+				$selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2072
+				$entries_per_page_dropdown .= '
2073 2073
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2074
-            }
2075
-        }
2076
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2077
-        $entries_per_page_dropdown .= '
2074
+			}
2075
+		}
2076
+		$selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2077
+		$entries_per_page_dropdown .= '
2078 2078
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2079
-        $entries_per_page_dropdown .= '
2079
+		$entries_per_page_dropdown .= '
2080 2080
 					</select>
2081 2081
 					entries
2082 2082
 				</label>
2083 2083
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2084 2084
 			</div>
2085 2085
 		';
2086
-        return $entries_per_page_dropdown;
2087
-    }
2088
-
2089
-
2090
-    /**
2091
-     *        _set_search_attributes
2092
-     *
2093
-     * @return        void
2094
-     */
2095
-    public function _set_search_attributes()
2096
-    {
2097
-        $this->_template_args['search']['btn_label'] = sprintf(
2098
-            esc_html__('Search %s', 'event_espresso'),
2099
-            empty($this->_search_btn_label) ? $this->page_label
2100
-                : $this->_search_btn_label
2101
-        );
2102
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2103
-    }
2104
-
2105
-
2106
-
2107
-    /*** END LIST TABLE METHODS **/
2108
-
2109
-
2110
-    /**
2111
-     * _add_registered_metaboxes
2112
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2113
-     *
2114
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2115
-     * @return void
2116
-     * @throws EE_Error
2117
-     */
2118
-    private function _add_registered_meta_boxes()
2119
-    {
2120
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2121
-        // we only add meta boxes if the page_route calls for it
2122
-        if (
2123
-            is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2124
-            && is_array(
2125
-                $this->_route_config['metaboxes']
2126
-            )
2127
-        ) {
2128
-            // this simply loops through the callbacks provided
2129
-            // and checks if there is a corresponding callback registered by the child
2130
-            // if there is then we go ahead and process the metabox loader.
2131
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2132
-                // first check for Closures
2133
-                if ($metabox_callback instanceof Closure) {
2134
-                    $result = $metabox_callback();
2135
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2136
-                    $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2137
-                } else {
2138
-                    $result = call_user_func([$this, &$metabox_callback]);
2139
-                }
2140
-                if ($result === false) {
2141
-                    // user error msg
2142
-                    $error_msg = esc_html__(
2143
-                        'An error occurred. The  requested metabox could not be found.',
2144
-                        'event_espresso'
2145
-                    );
2146
-                    // developer error msg
2147
-                    $error_msg .= '||'
2148
-                                  . sprintf(
2149
-                                      esc_html__(
2150
-                                          'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2151
-                                          'event_espresso'
2152
-                                      ),
2153
-                                      $metabox_callback
2154
-                                  );
2155
-                    throw new EE_Error($error_msg);
2156
-                }
2157
-            }
2158
-        }
2159
-    }
2160
-
2161
-
2162
-    /**
2163
-     * _add_screen_columns
2164
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2165
-     * the dynamic column template and we'll setup the column options for the page.
2166
-     *
2167
-     * @return void
2168
-     */
2169
-    private function _add_screen_columns()
2170
-    {
2171
-        if (
2172
-            is_array($this->_route_config)
2173
-            && isset($this->_route_config['columns'])
2174
-            && is_array($this->_route_config['columns'])
2175
-            && count($this->_route_config['columns']) === 2
2176
-        ) {
2177
-            add_screen_option(
2178
-                'layout_columns',
2179
-                [
2180
-                    'max'     => (int) $this->_route_config['columns'][0],
2181
-                    'default' => (int) $this->_route_config['columns'][1],
2182
-                ]
2183
-            );
2184
-            $this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2185
-            $screen_id                                           = $this->_current_screen->id;
2186
-            $screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2187
-            $total_columns                                       = ! empty($screen_columns)
2188
-                ? $screen_columns
2189
-                : $this->_route_config['columns'][1];
2190
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2191
-            $this->_template_args['current_page']                = $this->_wp_page_slug;
2192
-            $this->_template_args['screen']                      = $this->_current_screen;
2193
-            $this->_column_template_path                         = EE_ADMIN_TEMPLATE
2194
-                                                                   . 'admin_details_metabox_column_wrapper.template.php';
2195
-            // finally if we don't have has_metaboxes set in the route config
2196
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2197
-            $this->_route_config['has_metaboxes'] = true;
2198
-        }
2199
-    }
2200
-
2201
-
2202
-
2203
-    /** GLOBALLY AVAILABLE METABOXES **/
2204
-
2205
-
2206
-    /**
2207
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2208
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2209
-     * these get loaded on.
2210
-     */
2211
-    private function _espresso_news_post_box()
2212
-    {
2213
-        $news_box_title = apply_filters(
2214
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2215
-            esc_html__('New @ Event Espresso', 'event_espresso')
2216
-        );
2217
-        add_meta_box(
2218
-            'espresso_news_post_box',
2219
-            $news_box_title,
2220
-            [
2221
-                $this,
2222
-                'espresso_news_post_box',
2223
-            ],
2224
-            $this->_wp_page_slug,
2225
-            'side'
2226
-        );
2227
-    }
2228
-
2229
-
2230
-    /**
2231
-     * Code for setting up espresso ratings request metabox.
2232
-     */
2233
-    protected function _espresso_ratings_request()
2234
-    {
2235
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2236
-            return;
2237
-        }
2238
-        $ratings_box_title = apply_filters(
2239
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2240
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2241
-        );
2242
-        add_meta_box(
2243
-            'espresso_ratings_request',
2244
-            $ratings_box_title,
2245
-            [
2246
-                $this,
2247
-                'espresso_ratings_request',
2248
-            ],
2249
-            $this->_wp_page_slug,
2250
-            'side'
2251
-        );
2252
-    }
2253
-
2254
-
2255
-    /**
2256
-     * Code for setting up espresso ratings request metabox content.
2257
-     *
2258
-     * @throws DomainException
2259
-     */
2260
-    public function espresso_ratings_request()
2261
-    {
2262
-        EEH_Template::display_template(
2263
-            EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2264
-            []
2265
-        );
2266
-    }
2267
-
2268
-
2269
-    public static function cached_rss_display($rss_id, $url)
2270
-    {
2271
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2272
-                     . esc_html__('Loading&#8230;', 'event_espresso')
2273
-                     . '</p><p class="hide-if-js">'
2274
-                     . esc_html__('This widget requires JavaScript.', 'event_espresso')
2275
-                     . '</p>';
2276
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2277
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2278
-        $post      = '</div>' . "\n";
2279
-        $cache_key = 'ee_rss_' . md5($rss_id);
2280
-        $output    = get_transient($cache_key);
2281
-        if ($output !== false) {
2282
-            echo $pre . $output . $post; // already escaped
2283
-            return true;
2284
-        }
2285
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2286
-            echo $pre . $loading . $post; // already escaped
2287
-            return false;
2288
-        }
2289
-        ob_start();
2290
-        wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2291
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2292
-        return true;
2293
-    }
2294
-
2295
-
2296
-    public function espresso_news_post_box()
2297
-    {
2298
-        ?>
2086
+		return $entries_per_page_dropdown;
2087
+	}
2088
+
2089
+
2090
+	/**
2091
+	 *        _set_search_attributes
2092
+	 *
2093
+	 * @return        void
2094
+	 */
2095
+	public function _set_search_attributes()
2096
+	{
2097
+		$this->_template_args['search']['btn_label'] = sprintf(
2098
+			esc_html__('Search %s', 'event_espresso'),
2099
+			empty($this->_search_btn_label) ? $this->page_label
2100
+				: $this->_search_btn_label
2101
+		);
2102
+		$this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2103
+	}
2104
+
2105
+
2106
+
2107
+	/*** END LIST TABLE METHODS **/
2108
+
2109
+
2110
+	/**
2111
+	 * _add_registered_metaboxes
2112
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2113
+	 *
2114
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2115
+	 * @return void
2116
+	 * @throws EE_Error
2117
+	 */
2118
+	private function _add_registered_meta_boxes()
2119
+	{
2120
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2121
+		// we only add meta boxes if the page_route calls for it
2122
+		if (
2123
+			is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2124
+			&& is_array(
2125
+				$this->_route_config['metaboxes']
2126
+			)
2127
+		) {
2128
+			// this simply loops through the callbacks provided
2129
+			// and checks if there is a corresponding callback registered by the child
2130
+			// if there is then we go ahead and process the metabox loader.
2131
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2132
+				// first check for Closures
2133
+				if ($metabox_callback instanceof Closure) {
2134
+					$result = $metabox_callback();
2135
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2136
+					$result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2137
+				} else {
2138
+					$result = call_user_func([$this, &$metabox_callback]);
2139
+				}
2140
+				if ($result === false) {
2141
+					// user error msg
2142
+					$error_msg = esc_html__(
2143
+						'An error occurred. The  requested metabox could not be found.',
2144
+						'event_espresso'
2145
+					);
2146
+					// developer error msg
2147
+					$error_msg .= '||'
2148
+								  . sprintf(
2149
+									  esc_html__(
2150
+										  'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2151
+										  'event_espresso'
2152
+									  ),
2153
+									  $metabox_callback
2154
+								  );
2155
+					throw new EE_Error($error_msg);
2156
+				}
2157
+			}
2158
+		}
2159
+	}
2160
+
2161
+
2162
+	/**
2163
+	 * _add_screen_columns
2164
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2165
+	 * the dynamic column template and we'll setup the column options for the page.
2166
+	 *
2167
+	 * @return void
2168
+	 */
2169
+	private function _add_screen_columns()
2170
+	{
2171
+		if (
2172
+			is_array($this->_route_config)
2173
+			&& isset($this->_route_config['columns'])
2174
+			&& is_array($this->_route_config['columns'])
2175
+			&& count($this->_route_config['columns']) === 2
2176
+		) {
2177
+			add_screen_option(
2178
+				'layout_columns',
2179
+				[
2180
+					'max'     => (int) $this->_route_config['columns'][0],
2181
+					'default' => (int) $this->_route_config['columns'][1],
2182
+				]
2183
+			);
2184
+			$this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2185
+			$screen_id                                           = $this->_current_screen->id;
2186
+			$screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2187
+			$total_columns                                       = ! empty($screen_columns)
2188
+				? $screen_columns
2189
+				: $this->_route_config['columns'][1];
2190
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2191
+			$this->_template_args['current_page']                = $this->_wp_page_slug;
2192
+			$this->_template_args['screen']                      = $this->_current_screen;
2193
+			$this->_column_template_path                         = EE_ADMIN_TEMPLATE
2194
+																   . 'admin_details_metabox_column_wrapper.template.php';
2195
+			// finally if we don't have has_metaboxes set in the route config
2196
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2197
+			$this->_route_config['has_metaboxes'] = true;
2198
+		}
2199
+	}
2200
+
2201
+
2202
+
2203
+	/** GLOBALLY AVAILABLE METABOXES **/
2204
+
2205
+
2206
+	/**
2207
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2208
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2209
+	 * these get loaded on.
2210
+	 */
2211
+	private function _espresso_news_post_box()
2212
+	{
2213
+		$news_box_title = apply_filters(
2214
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2215
+			esc_html__('New @ Event Espresso', 'event_espresso')
2216
+		);
2217
+		add_meta_box(
2218
+			'espresso_news_post_box',
2219
+			$news_box_title,
2220
+			[
2221
+				$this,
2222
+				'espresso_news_post_box',
2223
+			],
2224
+			$this->_wp_page_slug,
2225
+			'side'
2226
+		);
2227
+	}
2228
+
2229
+
2230
+	/**
2231
+	 * Code for setting up espresso ratings request metabox.
2232
+	 */
2233
+	protected function _espresso_ratings_request()
2234
+	{
2235
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2236
+			return;
2237
+		}
2238
+		$ratings_box_title = apply_filters(
2239
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2240
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2241
+		);
2242
+		add_meta_box(
2243
+			'espresso_ratings_request',
2244
+			$ratings_box_title,
2245
+			[
2246
+				$this,
2247
+				'espresso_ratings_request',
2248
+			],
2249
+			$this->_wp_page_slug,
2250
+			'side'
2251
+		);
2252
+	}
2253
+
2254
+
2255
+	/**
2256
+	 * Code for setting up espresso ratings request metabox content.
2257
+	 *
2258
+	 * @throws DomainException
2259
+	 */
2260
+	public function espresso_ratings_request()
2261
+	{
2262
+		EEH_Template::display_template(
2263
+			EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2264
+			[]
2265
+		);
2266
+	}
2267
+
2268
+
2269
+	public static function cached_rss_display($rss_id, $url)
2270
+	{
2271
+		$loading   = '<p class="widget-loading hide-if-no-js">'
2272
+					 . esc_html__('Loading&#8230;', 'event_espresso')
2273
+					 . '</p><p class="hide-if-js">'
2274
+					 . esc_html__('This widget requires JavaScript.', 'event_espresso')
2275
+					 . '</p>';
2276
+		$pre       = '<div class="espresso-rss-display">' . "\n\t";
2277
+		$pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2278
+		$post      = '</div>' . "\n";
2279
+		$cache_key = 'ee_rss_' . md5($rss_id);
2280
+		$output    = get_transient($cache_key);
2281
+		if ($output !== false) {
2282
+			echo $pre . $output . $post; // already escaped
2283
+			return true;
2284
+		}
2285
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2286
+			echo $pre . $loading . $post; // already escaped
2287
+			return false;
2288
+		}
2289
+		ob_start();
2290
+		wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2291
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2292
+		return true;
2293
+	}
2294
+
2295
+
2296
+	public function espresso_news_post_box()
2297
+	{
2298
+		?>
2299 2299
         <div class="padding">
2300 2300
             <div id="espresso_news_post_box_content" class="infolinks">
2301 2301
                 <?php
2302
-                // Get RSS Feed(s)
2303
-                self::cached_rss_display(
2304
-                    'espresso_news_post_box_content',
2305
-                    esc_url_raw(
2306
-                        apply_filters(
2307
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2308
-                            'https://eventespresso.com/feed/'
2309
-                        )
2310
-                    )
2311
-                );
2312
-                ?>
2302
+				// Get RSS Feed(s)
2303
+				self::cached_rss_display(
2304
+					'espresso_news_post_box_content',
2305
+					esc_url_raw(
2306
+						apply_filters(
2307
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2308
+							'https://eventespresso.com/feed/'
2309
+						)
2310
+					)
2311
+				);
2312
+				?>
2313 2313
             </div>
2314 2314
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2315 2315
         </div>
2316 2316
         <?php
2317
-    }
2318
-
2319
-
2320
-    private function _espresso_links_post_box()
2321
-    {
2322
-        // Hiding until we actually have content to put in here...
2323
-        // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2324
-    }
2325
-
2326
-
2327
-    public function espresso_links_post_box()
2328
-    {
2329
-        // Hiding until we actually have content to put in here...
2330
-        // EEH_Template::display_template(
2331
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2332
-        // );
2333
-    }
2334
-
2335
-
2336
-    protected function _espresso_sponsors_post_box()
2337
-    {
2338
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2339
-            add_meta_box(
2340
-                'espresso_sponsors_post_box',
2341
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2342
-                [$this, 'espresso_sponsors_post_box'],
2343
-                $this->_wp_page_slug,
2344
-                'side'
2345
-            );
2346
-        }
2347
-    }
2348
-
2349
-
2350
-    public function espresso_sponsors_post_box()
2351
-    {
2352
-        EEH_Template::display_template(
2353
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2354
-        );
2355
-    }
2356
-
2357
-
2358
-    private function _publish_post_box()
2359
-    {
2360
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2361
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2362
-        // then we'll use that for the metabox label.
2363
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2364
-        if (! empty($this->_labels['publishbox'])) {
2365
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2366
-                : $this->_labels['publishbox'];
2367
-        } else {
2368
-            $box_label = esc_html__('Publish', 'event_espresso');
2369
-        }
2370
-        $box_label = apply_filters(
2371
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2372
-            $box_label,
2373
-            $this->_req_action,
2374
-            $this
2375
-        );
2376
-        add_meta_box(
2377
-            $meta_box_ref,
2378
-            $box_label,
2379
-            [$this, 'editor_overview'],
2380
-            $this->_current_screen->id,
2381
-            'side',
2382
-            'high'
2383
-        );
2384
-    }
2385
-
2386
-
2387
-    public function editor_overview()
2388
-    {
2389
-        // if we have extra content set let's add it in if not make sure its empty
2390
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2391
-            ? $this->_template_args['publish_box_extra_content']
2392
-            : '';
2393
-        echo EEH_Template::display_template(
2394
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2395
-            $this->_template_args,
2396
-            true
2397
-        );
2398
-    }
2399
-
2400
-
2401
-    /** end of globally available metaboxes section **/
2402
-
2403
-
2404
-    /**
2405
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2406
-     * protected method.
2407
-     *
2408
-     * @param string $name
2409
-     * @param int    $id
2410
-     * @param bool   $delete
2411
-     * @param string $save_close_redirect_URL
2412
-     * @param bool   $both_btns
2413
-     * @throws EE_Error
2414
-     * @throws InvalidArgumentException
2415
-     * @throws InvalidDataTypeException
2416
-     * @throws InvalidInterfaceException
2417
-     * @see   $this->_set_publish_post_box_vars for param details
2418
-     * @since 4.6.0
2419
-     */
2420
-    public function set_publish_post_box_vars(
2421
-        $name = '',
2422
-        $id = 0,
2423
-        $delete = false,
2424
-        $save_close_redirect_URL = '',
2425
-        $both_btns = true
2426
-    ) {
2427
-        $this->_set_publish_post_box_vars(
2428
-            $name,
2429
-            $id,
2430
-            $delete,
2431
-            $save_close_redirect_URL,
2432
-            $both_btns
2433
-        );
2434
-    }
2435
-
2436
-
2437
-    /**
2438
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2439
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2440
-     * save, and save and close buttons to work properly, then you will want to include a
2441
-     * values for the name and id arguments.
2442
-     *
2443
-     * @param string  $name                       key used for the action ID (i.e. event_id)
2444
-     * @param int     $id                         id attached to the item published
2445
-     * @param string  $delete                     page route callback for the delete action
2446
-     * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2447
-     * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2448
-     *                                            the Save button
2449
-     * @throws EE_Error
2450
-     * @throws InvalidArgumentException
2451
-     * @throws InvalidDataTypeException
2452
-     * @throws InvalidInterfaceException
2453
-     * @todo  Add in validation for name/id arguments.
2454
-     */
2455
-    protected function _set_publish_post_box_vars(
2456
-        $name = '',
2457
-        $id = 0,
2458
-        $delete = '',
2459
-        $save_close_redirect_URL = '',
2460
-        $both_btns = true
2461
-    ) {
2462
-        // if Save & Close, use a custom redirect URL or default to the main page?
2463
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2464
-            ? $save_close_redirect_URL
2465
-            : $this->_admin_base_url;
2466
-        // create the Save & Close and Save buttons
2467
-        $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2468
-        // if we have extra content set let's add it in if not make sure its empty
2469
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2470
-            ? $this->_template_args['publish_box_extra_content']
2471
-            : '';
2472
-        if ($delete && ! empty($id)) {
2473
-            // make sure we have a default if just true is sent.
2474
-            $delete           = ! empty($delete) ? $delete : 'delete';
2475
-            $delete_link_args = [$name => $id];
2476
-            $delete           = $this->get_action_link_or_button(
2477
-                $delete,
2478
-                $delete,
2479
-                $delete_link_args,
2480
-                'submitdelete deletion',
2481
-                '',
2482
-                false
2483
-            );
2484
-        }
2485
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2486
-        if (! empty($name) && ! empty($id)) {
2487
-            $hidden_field_arr[ $name ] = [
2488
-                'type'  => 'hidden',
2489
-                'value' => $id,
2490
-            ];
2491
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2492
-        } else {
2493
-            $hf = '';
2494
-        }
2495
-        // add hidden field
2496
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2497
-            ? $hf[ $name ]['field']
2498
-            : $hf;
2499
-    }
2500
-
2501
-
2502
-    /**
2503
-     * displays an error message to ppl who have javascript disabled
2504
-     *
2505
-     * @return void
2506
-     */
2507
-    private function _display_no_javascript_warning()
2508
-    {
2509
-        ?>
2317
+	}
2318
+
2319
+
2320
+	private function _espresso_links_post_box()
2321
+	{
2322
+		// Hiding until we actually have content to put in here...
2323
+		// add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2324
+	}
2325
+
2326
+
2327
+	public function espresso_links_post_box()
2328
+	{
2329
+		// Hiding until we actually have content to put in here...
2330
+		// EEH_Template::display_template(
2331
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2332
+		// );
2333
+	}
2334
+
2335
+
2336
+	protected function _espresso_sponsors_post_box()
2337
+	{
2338
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2339
+			add_meta_box(
2340
+				'espresso_sponsors_post_box',
2341
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2342
+				[$this, 'espresso_sponsors_post_box'],
2343
+				$this->_wp_page_slug,
2344
+				'side'
2345
+			);
2346
+		}
2347
+	}
2348
+
2349
+
2350
+	public function espresso_sponsors_post_box()
2351
+	{
2352
+		EEH_Template::display_template(
2353
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2354
+		);
2355
+	}
2356
+
2357
+
2358
+	private function _publish_post_box()
2359
+	{
2360
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2361
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2362
+		// then we'll use that for the metabox label.
2363
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2364
+		if (! empty($this->_labels['publishbox'])) {
2365
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2366
+				: $this->_labels['publishbox'];
2367
+		} else {
2368
+			$box_label = esc_html__('Publish', 'event_espresso');
2369
+		}
2370
+		$box_label = apply_filters(
2371
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2372
+			$box_label,
2373
+			$this->_req_action,
2374
+			$this
2375
+		);
2376
+		add_meta_box(
2377
+			$meta_box_ref,
2378
+			$box_label,
2379
+			[$this, 'editor_overview'],
2380
+			$this->_current_screen->id,
2381
+			'side',
2382
+			'high'
2383
+		);
2384
+	}
2385
+
2386
+
2387
+	public function editor_overview()
2388
+	{
2389
+		// if we have extra content set let's add it in if not make sure its empty
2390
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2391
+			? $this->_template_args['publish_box_extra_content']
2392
+			: '';
2393
+		echo EEH_Template::display_template(
2394
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2395
+			$this->_template_args,
2396
+			true
2397
+		);
2398
+	}
2399
+
2400
+
2401
+	/** end of globally available metaboxes section **/
2402
+
2403
+
2404
+	/**
2405
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2406
+	 * protected method.
2407
+	 *
2408
+	 * @param string $name
2409
+	 * @param int    $id
2410
+	 * @param bool   $delete
2411
+	 * @param string $save_close_redirect_URL
2412
+	 * @param bool   $both_btns
2413
+	 * @throws EE_Error
2414
+	 * @throws InvalidArgumentException
2415
+	 * @throws InvalidDataTypeException
2416
+	 * @throws InvalidInterfaceException
2417
+	 * @see   $this->_set_publish_post_box_vars for param details
2418
+	 * @since 4.6.0
2419
+	 */
2420
+	public function set_publish_post_box_vars(
2421
+		$name = '',
2422
+		$id = 0,
2423
+		$delete = false,
2424
+		$save_close_redirect_URL = '',
2425
+		$both_btns = true
2426
+	) {
2427
+		$this->_set_publish_post_box_vars(
2428
+			$name,
2429
+			$id,
2430
+			$delete,
2431
+			$save_close_redirect_URL,
2432
+			$both_btns
2433
+		);
2434
+	}
2435
+
2436
+
2437
+	/**
2438
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2439
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2440
+	 * save, and save and close buttons to work properly, then you will want to include a
2441
+	 * values for the name and id arguments.
2442
+	 *
2443
+	 * @param string  $name                       key used for the action ID (i.e. event_id)
2444
+	 * @param int     $id                         id attached to the item published
2445
+	 * @param string  $delete                     page route callback for the delete action
2446
+	 * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2447
+	 * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2448
+	 *                                            the Save button
2449
+	 * @throws EE_Error
2450
+	 * @throws InvalidArgumentException
2451
+	 * @throws InvalidDataTypeException
2452
+	 * @throws InvalidInterfaceException
2453
+	 * @todo  Add in validation for name/id arguments.
2454
+	 */
2455
+	protected function _set_publish_post_box_vars(
2456
+		$name = '',
2457
+		$id = 0,
2458
+		$delete = '',
2459
+		$save_close_redirect_URL = '',
2460
+		$both_btns = true
2461
+	) {
2462
+		// if Save & Close, use a custom redirect URL or default to the main page?
2463
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2464
+			? $save_close_redirect_URL
2465
+			: $this->_admin_base_url;
2466
+		// create the Save & Close and Save buttons
2467
+		$this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2468
+		// if we have extra content set let's add it in if not make sure its empty
2469
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2470
+			? $this->_template_args['publish_box_extra_content']
2471
+			: '';
2472
+		if ($delete && ! empty($id)) {
2473
+			// make sure we have a default if just true is sent.
2474
+			$delete           = ! empty($delete) ? $delete : 'delete';
2475
+			$delete_link_args = [$name => $id];
2476
+			$delete           = $this->get_action_link_or_button(
2477
+				$delete,
2478
+				$delete,
2479
+				$delete_link_args,
2480
+				'submitdelete deletion',
2481
+				'',
2482
+				false
2483
+			);
2484
+		}
2485
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2486
+		if (! empty($name) && ! empty($id)) {
2487
+			$hidden_field_arr[ $name ] = [
2488
+				'type'  => 'hidden',
2489
+				'value' => $id,
2490
+			];
2491
+			$hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2492
+		} else {
2493
+			$hf = '';
2494
+		}
2495
+		// add hidden field
2496
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2497
+			? $hf[ $name ]['field']
2498
+			: $hf;
2499
+	}
2500
+
2501
+
2502
+	/**
2503
+	 * displays an error message to ppl who have javascript disabled
2504
+	 *
2505
+	 * @return void
2506
+	 */
2507
+	private function _display_no_javascript_warning()
2508
+	{
2509
+		?>
2510 2510
         <noscript>
2511 2511
             <div id="no-js-message" class="error">
2512 2512
                 <p style="font-size:1.3em;">
2513 2513
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2514 2514
                     <?php esc_html_e(
2515
-                        'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2516
-                        'event_espresso'
2517
-                    ); ?>
2515
+						'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2516
+						'event_espresso'
2517
+					); ?>
2518 2518
                 </p>
2519 2519
             </div>
2520 2520
         </noscript>
2521 2521
         <?php
2522
-    }
2523
-
2524
-
2525
-    /**
2526
-     * displays espresso success and/or error notices
2527
-     *
2528
-     * @return void
2529
-     */
2530
-    protected function _display_espresso_notices()
2531
-    {
2532
-        $notices = $this->_get_transient(true);
2533
-        echo stripslashes($notices);
2534
-    }
2535
-
2536
-
2537
-    /**
2538
-     * spinny things pacify the masses
2539
-     *
2540
-     * @return void
2541
-     */
2542
-    protected function _add_admin_page_ajax_loading_img()
2543
-    {
2544
-        ?>
2522
+	}
2523
+
2524
+
2525
+	/**
2526
+	 * displays espresso success and/or error notices
2527
+	 *
2528
+	 * @return void
2529
+	 */
2530
+	protected function _display_espresso_notices()
2531
+	{
2532
+		$notices = $this->_get_transient(true);
2533
+		echo stripslashes($notices);
2534
+	}
2535
+
2536
+
2537
+	/**
2538
+	 * spinny things pacify the masses
2539
+	 *
2540
+	 * @return void
2541
+	 */
2542
+	protected function _add_admin_page_ajax_loading_img()
2543
+	{
2544
+		?>
2545 2545
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2546 2546
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2547
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2547
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2548 2548
         </div>
2549 2549
         <?php
2550
-    }
2550
+	}
2551 2551
 
2552 2552
 
2553
-    /**
2554
-     * add admin page overlay for modal boxes
2555
-     *
2556
-     * @return void
2557
-     */
2558
-    protected function _add_admin_page_overlay()
2559
-    {
2560
-        ?>
2553
+	/**
2554
+	 * add admin page overlay for modal boxes
2555
+	 *
2556
+	 * @return void
2557
+	 */
2558
+	protected function _add_admin_page_overlay()
2559
+	{
2560
+		?>
2561 2561
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2562 2562
         <?php
2563
-    }
2564
-
2565
-
2566
-    /**
2567
-     * facade for add_meta_box
2568
-     *
2569
-     * @param string  $action        where the metabox gets displayed
2570
-     * @param string  $title         Title of Metabox (output in metabox header)
2571
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2572
-     *                               instead of the one created in here.
2573
-     * @param array   $callback_args an array of args supplied for the metabox
2574
-     * @param string  $column        what metabox column
2575
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2576
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2577
-     *                               created but just set our own callback for wp's add_meta_box.
2578
-     * @throws DomainException
2579
-     */
2580
-    public function _add_admin_page_meta_box(
2581
-        $action,
2582
-        $title,
2583
-        $callback,
2584
-        $callback_args,
2585
-        $column = 'normal',
2586
-        $priority = 'high',
2587
-        $create_func = true
2588
-    ) {
2589
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2590
-        // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2591
-        if (empty($callback_args) && $create_func) {
2592
-            $callback_args = [
2593
-                'template_path' => $this->_template_path,
2594
-                'template_args' => $this->_template_args,
2595
-            ];
2596
-        }
2597
-        // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2598
-        $call_back_func = $create_func
2599
-            ? function ($post, $metabox) {
2600
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2601
-                echo EEH_Template::display_template(
2602
-                    $metabox['args']['template_path'],
2603
-                    $metabox['args']['template_args'],
2604
-                    true
2605
-                );
2606
-            }
2607
-            : $callback;
2608
-        add_meta_box(
2609
-            str_replace('_', '-', $action) . '-mbox',
2610
-            $title,
2611
-            $call_back_func,
2612
-            $this->_wp_page_slug,
2613
-            $column,
2614
-            $priority,
2615
-            $callback_args
2616
-        );
2617
-    }
2618
-
2619
-
2620
-    /**
2621
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2622
-     *
2623
-     * @throws DomainException
2624
-     * @throws EE_Error
2625
-     */
2626
-    public function display_admin_page_with_metabox_columns()
2627
-    {
2628
-        $this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2629
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2630
-            $this->_column_template_path,
2631
-            $this->_template_args,
2632
-            true
2633
-        );
2634
-        // the final wrapper
2635
-        $this->admin_page_wrapper();
2636
-    }
2637
-
2638
-
2639
-    /**
2640
-     * generates  HTML wrapper for an admin details page
2641
-     *
2642
-     * @return void
2643
-     * @throws EE_Error
2644
-     * @throws DomainException
2645
-     */
2646
-    public function display_admin_page_with_sidebar()
2647
-    {
2648
-        $this->_display_admin_page(true);
2649
-    }
2650
-
2651
-
2652
-    /**
2653
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2654
-     *
2655
-     * @return void
2656
-     * @throws EE_Error
2657
-     * @throws DomainException
2658
-     */
2659
-    public function display_admin_page_with_no_sidebar()
2660
-    {
2661
-        $this->_display_admin_page();
2662
-    }
2663
-
2664
-
2665
-    /**
2666
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2667
-     *
2668
-     * @return void
2669
-     * @throws EE_Error
2670
-     * @throws DomainException
2671
-     */
2672
-    public function display_about_admin_page()
2673
-    {
2674
-        $this->_display_admin_page(false, true);
2675
-    }
2676
-
2677
-
2678
-    /**
2679
-     * display_admin_page
2680
-     * contains the code for actually displaying an admin page
2681
-     *
2682
-     * @param boolean $sidebar true with sidebar, false without
2683
-     * @param boolean $about   use the about_admin_wrapper instead of the default.
2684
-     * @return void
2685
-     * @throws DomainException
2686
-     * @throws EE_Error
2687
-     */
2688
-    private function _display_admin_page($sidebar = false, $about = false)
2689
-    {
2690
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2691
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2692
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2693
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2694
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2695
-        $this->_template_args['current_page']              = $this->_wp_page_slug;
2696
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2697
-            ? 'poststuff'
2698
-            : 'espresso-default-admin';
2699
-        $template_path                                     = $sidebar
2700
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2701
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2702
-        if ($this->request->isAjax()) {
2703
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2704
-        }
2705
-        $template_path                                     = ! empty($this->_column_template_path)
2706
-            ? $this->_column_template_path : $template_path;
2707
-        $this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2708
-            ? $this->_template_args['admin_page_content']
2709
-            : '';
2710
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2711
-            ? $this->_template_args['before_admin_page_content']
2712
-            : '';
2713
-        $this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2714
-            ? $this->_template_args['after_admin_page_content']
2715
-            : '';
2716
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
2717
-            $template_path,
2718
-            $this->_template_args,
2719
-            true
2720
-        );
2721
-        // the final template wrapper
2722
-        $this->admin_page_wrapper($about);
2723
-    }
2724
-
2725
-
2726
-    /**
2727
-     * This is used to display caf preview pages.
2728
-     *
2729
-     * @param string $utm_campaign_source what is the key used for google analytics link
2730
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2731
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2732
-     * @return void
2733
-     * @throws DomainException
2734
-     * @throws EE_Error
2735
-     * @throws InvalidArgumentException
2736
-     * @throws InvalidDataTypeException
2737
-     * @throws InvalidInterfaceException
2738
-     * @since 4.3.2
2739
-     */
2740
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2741
-    {
2742
-        // let's generate a default preview action button if there isn't one already present.
2743
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2744
-            'Upgrade to Event Espresso 4 Right Now',
2745
-            'event_espresso'
2746
-        );
2747
-        $buy_now_url                                   = add_query_arg(
2748
-            [
2749
-                'ee_ver'       => 'ee4',
2750
-                'utm_source'   => 'ee4_plugin_admin',
2751
-                'utm_medium'   => 'link',
2752
-                'utm_campaign' => $utm_campaign_source,
2753
-                'utm_content'  => 'buy_now_button',
2754
-            ],
2755
-            'https://eventespresso.com/pricing/'
2756
-        );
2757
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2758
-            ? $this->get_action_link_or_button(
2759
-                '',
2760
-                'buy_now',
2761
-                [],
2762
-                'button-primary button-large',
2763
-                esc_url_raw($buy_now_url),
2764
-                true
2765
-            )
2766
-            : $this->_template_args['preview_action_button'];
2767
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2768
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2769
-            $this->_template_args,
2770
-            true
2771
-        );
2772
-        $this->_display_admin_page($display_sidebar);
2773
-    }
2774
-
2775
-
2776
-    /**
2777
-     * display_admin_list_table_page_with_sidebar
2778
-     * generates HTML wrapper for an admin_page with list_table
2779
-     *
2780
-     * @return void
2781
-     * @throws EE_Error
2782
-     * @throws DomainException
2783
-     */
2784
-    public function display_admin_list_table_page_with_sidebar()
2785
-    {
2786
-        $this->_display_admin_list_table_page(true);
2787
-    }
2788
-
2789
-
2790
-    /**
2791
-     * display_admin_list_table_page_with_no_sidebar
2792
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2793
-     *
2794
-     * @return void
2795
-     * @throws EE_Error
2796
-     * @throws DomainException
2797
-     */
2798
-    public function display_admin_list_table_page_with_no_sidebar()
2799
-    {
2800
-        $this->_display_admin_list_table_page();
2801
-    }
2802
-
2803
-
2804
-    /**
2805
-     * generates html wrapper for an admin_list_table page
2806
-     *
2807
-     * @param boolean $sidebar whether to display with sidebar or not.
2808
-     * @return void
2809
-     * @throws DomainException
2810
-     * @throws EE_Error
2811
-     */
2812
-    private function _display_admin_list_table_page($sidebar = false)
2813
-    {
2814
-        // setup search attributes
2815
-        $this->_set_search_attributes();
2816
-        $this->_template_args['current_page']     = $this->_wp_page_slug;
2817
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2818
-        $this->_template_args['table_url']        = $this->request->isAjax()
2819
-            ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2820
-            : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2821
-        $this->_template_args['list_table']       = $this->_list_table_object;
2822
-        $this->_template_args['current_route']    = $this->_req_action;
2823
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2824
-        $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2825
-        if (! empty($ajax_sorting_callback)) {
2826
-            $sortable_list_table_form_fields = wp_nonce_field(
2827
-                $ajax_sorting_callback . '_nonce',
2828
-                $ajax_sorting_callback . '_nonce',
2829
-                false,
2830
-                false
2831
-            );
2832
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2833
-                                                . $this->page_slug
2834
-                                                . '" />';
2835
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2836
-                                                . $ajax_sorting_callback
2837
-                                                . '" />';
2838
-        } else {
2839
-            $sortable_list_table_form_fields = '';
2840
-        }
2841
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2842
-        $hidden_form_fields                                      =
2843
-            isset($this->_template_args['list_table_hidden_fields'])
2844
-                ? $this->_template_args['list_table_hidden_fields']
2845
-                : '';
2846
-        $nonce_ref                                               = $this->_req_action . '_nonce';
2847
-        $hidden_form_fields                                      .= '<input type="hidden" name="'
2848
-                                                                    . $nonce_ref
2849
-                                                                    . '" value="'
2850
-                                                                    . wp_create_nonce($nonce_ref)
2851
-                                                                    . '">';
2852
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2853
-        // display message about search results?
2854
-        $search = $this->request->getRequestParam('s');
2855
-        $this->_template_args['before_list_table'] .= ! empty($search)
2856
-            ? '<p class="ee-search-results">' . sprintf(
2857
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2858
-                trim($search, '%')
2859
-            ) . '</p>'
2860
-            : '';
2861
-        // filter before_list_table template arg
2862
-        $this->_template_args['before_list_table'] = apply_filters(
2863
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2864
-            $this->_template_args['before_list_table'],
2865
-            $this->page_slug,
2866
-            $this->request->requestParams(),
2867
-            $this->_req_action
2868
-        );
2869
-        // convert to array and filter again
2870
-        // arrays are easier to inject new items in a specific location,
2871
-        // but would not be backwards compatible, so we have to add a new filter
2872
-        $this->_template_args['before_list_table'] = implode(
2873
-            " \n",
2874
-            (array) apply_filters(
2875
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2876
-                (array) $this->_template_args['before_list_table'],
2877
-                $this->page_slug,
2878
-                $this->request->requestParams(),
2879
-                $this->_req_action
2880
-            )
2881
-        );
2882
-        // filter after_list_table template arg
2883
-        $this->_template_args['after_list_table'] = apply_filters(
2884
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2885
-            $this->_template_args['after_list_table'],
2886
-            $this->page_slug,
2887
-            $this->request->requestParams(),
2888
-            $this->_req_action
2889
-        );
2890
-        // convert to array and filter again
2891
-        // arrays are easier to inject new items in a specific location,
2892
-        // but would not be backwards compatible, so we have to add a new filter
2893
-        $this->_template_args['after_list_table']   = implode(
2894
-            " \n",
2895
-            (array) apply_filters(
2896
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2897
-                (array) $this->_template_args['after_list_table'],
2898
-                $this->page_slug,
2899
-                $this->request->requestParams(),
2900
-                $this->_req_action
2901
-            )
2902
-        );
2903
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2904
-            $template_path,
2905
-            $this->_template_args,
2906
-            true
2907
-        );
2908
-        // the final template wrapper
2909
-        if ($sidebar) {
2910
-            $this->display_admin_page_with_sidebar();
2911
-        } else {
2912
-            $this->display_admin_page_with_no_sidebar();
2913
-        }
2914
-    }
2915
-
2916
-
2917
-    /**
2918
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
2919
-     * html string for the legend.
2920
-     * $items are expected in an array in the following format:
2921
-     * $legend_items = array(
2922
-     *        'item_id' => array(
2923
-     *            'icon' => 'http://url_to_icon_being_described.png',
2924
-     *            'desc' => esc_html__('localized description of item');
2925
-     *        )
2926
-     * );
2927
-     *
2928
-     * @param array $items see above for format of array
2929
-     * @return string html string of legend
2930
-     * @throws DomainException
2931
-     */
2932
-    protected function _display_legend($items)
2933
-    {
2934
-        $this->_template_args['items'] = apply_filters(
2935
-            'FHEE__EE_Admin_Page___display_legend__items',
2936
-            (array) $items,
2937
-            $this
2938
-        );
2939
-        return EEH_Template::display_template(
2940
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
2941
-            $this->_template_args,
2942
-            true
2943
-        );
2944
-    }
2945
-
2946
-
2947
-    /**
2948
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2949
-     * The returned json object is created from an array in the following format:
2950
-     * array(
2951
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2952
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
2953
-     *  'notices' => '', // - contains any EE_Error formatted notices
2954
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2955
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
2956
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
2957
-     *  that might be included in here)
2958
-     * )
2959
-     * The json object is populated by whatever is set in the $_template_args property.
2960
-     *
2961
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
2962
-     *                                 instead of displayed.
2963
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
2964
-     * @return void
2965
-     * @throws EE_Error
2966
-     */
2967
-    protected function _return_json($sticky_notices = false, $notices_arguments = [])
2968
-    {
2969
-        // make sure any EE_Error notices have been handled.
2970
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
2971
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
2972
-        unset($this->_template_args['data']);
2973
-        $json = [
2974
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2975
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2976
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2977
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2978
-            'notices'   => EE_Error::get_notices(),
2979
-            'content'   => isset($this->_template_args['admin_page_content'])
2980
-                ? $this->_template_args['admin_page_content'] : '',
2981
-            'data'      => array_merge($data, ['template_args' => $this->_template_args]),
2982
-            'isEEajax'  => true
2983
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2984
-        ];
2985
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
2986
-        if (null === error_get_last() || ! headers_sent()) {
2987
-            header('Content-Type: application/json; charset=UTF-8');
2988
-        }
2989
-        echo wp_json_encode($json);
2990
-        exit();
2991
-    }
2992
-
2993
-
2994
-    /**
2995
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2996
-     *
2997
-     * @return void
2998
-     * @throws EE_Error
2999
-     */
3000
-    public function return_json()
3001
-    {
3002
-        if ($this->request->isAjax()) {
3003
-            $this->_return_json();
3004
-        } else {
3005
-            throw new EE_Error(
3006
-                sprintf(
3007
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3008
-                    __FUNCTION__
3009
-                )
3010
-            );
3011
-        }
3012
-    }
3013
-
3014
-
3015
-    /**
3016
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3017
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3018
-     *
3019
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3020
-     */
3021
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3022
-    {
3023
-        $this->_hook_obj = $hook_obj;
3024
-    }
3025
-
3026
-
3027
-    /**
3028
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3029
-     *
3030
-     * @param boolean $about whether to use the special about page wrapper or default.
3031
-     * @return void
3032
-     * @throws DomainException
3033
-     * @throws EE_Error
3034
-     */
3035
-    public function admin_page_wrapper($about = false)
3036
-    {
3037
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3038
-        $this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3039
-        $this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3040
-        $this->_template_args['admin_page_title']          = $this->_admin_page_title;
3041
-
3042
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3043
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3044
-            isset($this->_template_args['before_admin_page_content'])
3045
-                ? $this->_template_args['before_admin_page_content']
3046
-                : ''
3047
-        );
3048
-
3049
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3050
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3051
-            isset($this->_template_args['after_admin_page_content'])
3052
-                ? $this->_template_args['after_admin_page_content']
3053
-                : ''
3054
-        );
3055
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3056
-
3057
-        if ($this->request->isAjax()) {
3058
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3059
-                // $template_path,
3060
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3061
-                $this->_template_args,
3062
-                true
3063
-            );
3064
-            $this->_return_json();
3065
-        }
3066
-        // load settings page wrapper template
3067
-        $template_path = $about
3068
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3069
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3070
-
3071
-        EEH_Template::display_template($template_path, $this->_template_args);
3072
-    }
3073
-
3074
-
3075
-    /**
3076
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3077
-     *
3078
-     * @return string html
3079
-     * @throws EE_Error
3080
-     */
3081
-    protected function _get_main_nav_tabs()
3082
-    {
3083
-        // let's generate the html using the EEH_Tabbed_Content helper.
3084
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3085
-        // (rather than setting in the page_routes array)
3086
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3087
-    }
3088
-
3089
-
3090
-    /**
3091
-     *        sort nav tabs
3092
-     *
3093
-     * @param $a
3094
-     * @param $b
3095
-     * @return int
3096
-     */
3097
-    private function _sort_nav_tabs($a, $b)
3098
-    {
3099
-        if ($a['order'] === $b['order']) {
3100
-            return 0;
3101
-        }
3102
-        return ($a['order'] < $b['order']) ? -1 : 1;
3103
-    }
3104
-
3105
-
3106
-    /**
3107
-     *    generates HTML for the forms used on admin pages
3108
-     *
3109
-     * @param array  $input_vars   - array of input field details
3110
-     * @param string $generator    (options are 'string' or 'array', basically use this to indicate which generator to
3111
-     *                             use)
3112
-     * @param bool   $id
3113
-     * @return array|string
3114
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3115
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3116
-     */
3117
-    protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3118
-    {
3119
-        return $generator === 'string'
3120
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3121
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3122
-    }
3123
-
3124
-
3125
-    /**
3126
-     * generates the "Save" and "Save & Close" buttons for edit forms
3127
-     *
3128
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3129
-     *                                   Close" button.
3130
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3131
-     *                                   'Save', [1] => 'save & close')
3132
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3133
-     *                                   via the "name" value in the button).  We can also use this to just dump
3134
-     *                                   default actions by submitting some other value.
3135
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3136
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3137
-     *                                   close (normal form handling).
3138
-     */
3139
-    protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3140
-    {
3141
-        // make sure $text and $actions are in an array
3142
-        $text          = (array) $text;
3143
-        $actions       = (array) $actions;
3144
-        $referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3145
-        $button_text   = ! empty($text)
3146
-            ? $text
3147
-            : [
3148
-                esc_html__('Save', 'event_espresso'),
3149
-                esc_html__('Save and Close', 'event_espresso'),
3150
-            ];
3151
-        $default_names = ['save', 'save_and_close'];
3152
-        $buttons = '';
3153
-        foreach ($button_text as $key => $button) {
3154
-            $ref     = $default_names[ $key ];
3155
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3156
-            $buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3157
-                        . 'value="' . $button . '" name="' . $name . '" '
3158
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3159
-            if (! $both) {
3160
-                break;
3161
-            }
3162
-        }
3163
-        // add in a hidden index for the current page (so save and close redirects properly)
3164
-        $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3165
-                   . $referrer_url
3166
-                   . '" />';
3167
-        $this->_template_args['save_buttons'] = $buttons;
3168
-    }
3169
-
3170
-
3171
-    /**
3172
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3173
-     *
3174
-     * @param string $route
3175
-     * @param array  $additional_hidden_fields
3176
-     * @see   $this->_set_add_edit_form_tags() for details on params
3177
-     * @since 4.6.0
3178
-     */
3179
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3180
-    {
3181
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3182
-    }
3183
-
3184
-
3185
-    /**
3186
-     * set form open and close tags on add/edit pages.
3187
-     *
3188
-     * @param string $route                    the route you want the form to direct to
3189
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3190
-     * @return void
3191
-     */
3192
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3193
-    {
3194
-        if (empty($route)) {
3195
-            $user_msg = esc_html__(
3196
-                'An error occurred. No action was set for this page\'s form.',
3197
-                'event_espresso'
3198
-            );
3199
-            $dev_msg  = $user_msg . "\n"
3200
-                        . sprintf(
3201
-                            esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3202
-                            __FUNCTION__,
3203
-                            __CLASS__
3204
-                        );
3205
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3206
-        }
3207
-        // open form
3208
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3209
-                                                             . $this->_admin_base_url
3210
-                                                             . '" id="'
3211
-                                                             . $route
3212
-                                                             . '_event_form" >';
3213
-        // add nonce
3214
-        $nonce                                             =
3215
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3216
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3217
-        // add REQUIRED form action
3218
-        $hidden_fields = [
3219
-            'action' => ['type' => 'hidden', 'value' => $route],
3220
-        ];
3221
-        // merge arrays
3222
-        $hidden_fields = is_array($additional_hidden_fields)
3223
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3224
-            : $hidden_fields;
3225
-        // generate form fields
3226
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3227
-        // add fields to form
3228
-        foreach ((array) $form_fields as $form_field) {
3229
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3230
-        }
3231
-        // close form
3232
-        $this->_template_args['after_admin_page_content'] = '</form>';
3233
-    }
3234
-
3235
-
3236
-    /**
3237
-     * Public Wrapper for _redirect_after_action() method since its
3238
-     * discovered it would be useful for external code to have access.
3239
-     *
3240
-     * @param bool   $success
3241
-     * @param string $what
3242
-     * @param string $action_desc
3243
-     * @param array  $query_args
3244
-     * @param bool   $override_overwrite
3245
-     * @throws EE_Error
3246
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3247
-     * @since 4.5.0
3248
-     */
3249
-    public function redirect_after_action(
3250
-        $success = false,
3251
-        $what = 'item',
3252
-        $action_desc = 'processed',
3253
-        $query_args = [],
3254
-        $override_overwrite = false
3255
-    ) {
3256
-        $this->_redirect_after_action(
3257
-            $success,
3258
-            $what,
3259
-            $action_desc,
3260
-            $query_args,
3261
-            $override_overwrite
3262
-        );
3263
-    }
3264
-
3265
-
3266
-    /**
3267
-     * Helper method for merging existing request data with the returned redirect url.
3268
-     *
3269
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3270
-     * filters are still applied.
3271
-     *
3272
-     * @param array $new_route_data
3273
-     * @return array
3274
-     */
3275
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3276
-    {
3277
-        foreach ($this->request->requestParams() as $ref => $value) {
3278
-            // unset nonces
3279
-            if (strpos($ref, 'nonce') !== false) {
3280
-                $this->request->unSetRequestParam($ref);
3281
-                continue;
3282
-            }
3283
-            // urlencode values.
3284
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3285
-            $this->request->setRequestParam($ref, $value);
3286
-        }
3287
-        return array_merge($this->request->requestParams(), $new_route_data);
3288
-    }
3289
-
3290
-
3291
-    /**
3292
-     *    _redirect_after_action
3293
-     *
3294
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3295
-     * @param string $what               - what the action was performed on
3296
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3297
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3298
-     *                                   action is completed
3299
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3300
-     *                                   override this so that they show.
3301
-     * @return void
3302
-     * @throws EE_Error
3303
-     */
3304
-    protected function _redirect_after_action(
3305
-        $success = 0,
3306
-        $what = 'item',
3307
-        $action_desc = 'processed',
3308
-        $query_args = [],
3309
-        $override_overwrite = false
3310
-    ) {
3311
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3312
-        // class name for actions/filters.
3313
-        $classname = get_class($this);
3314
-        // set redirect url.
3315
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3316
-        // otherwise we go with whatever is set as the _admin_base_url
3317
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3318
-        $notices      = EE_Error::get_notices(false);
3319
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3320
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3321
-            EE_Error::overwrite_success();
3322
-        }
3323
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3324
-            // how many records affected ? more than one record ? or just one ?
3325
-            if ($success > 1) {
3326
-                // set plural msg
3327
-                EE_Error::add_success(
3328
-                    sprintf(
3329
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3330
-                        $what,
3331
-                        $action_desc
3332
-                    ),
3333
-                    __FILE__,
3334
-                    __FUNCTION__,
3335
-                    __LINE__
3336
-                );
3337
-            } elseif ($success === 1) {
3338
-                // set singular msg
3339
-                EE_Error::add_success(
3340
-                    sprintf(
3341
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3342
-                        $what,
3343
-                        $action_desc
3344
-                    ),
3345
-                    __FILE__,
3346
-                    __FUNCTION__,
3347
-                    __LINE__
3348
-                );
3349
-            }
3350
-        }
3351
-        // check that $query_args isn't something crazy
3352
-        if (! is_array($query_args)) {
3353
-            $query_args = [];
3354
-        }
3355
-        /**
3356
-         * Allow injecting actions before the query_args are modified for possible different
3357
-         * redirections on save and close actions
3358
-         *
3359
-         * @param array $query_args       The original query_args array coming into the
3360
-         *                                method.
3361
-         * @since 4.2.0
3362
-         */
3363
-        do_action(
3364
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3365
-            $query_args
3366
-        );
3367
-        // calculate where we're going (if we have a "save and close" button pushed)
3368
-
3369
-        if (
3370
-            $this->request->requestParamIsSet('save_and_close')
3371
-            && $this->request->requestParamIsSet('save_and_close_referrer')
3372
-        ) {
3373
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3374
-            $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3375
-            // regenerate query args array from referrer URL
3376
-            parse_str($parsed_url['query'], $query_args);
3377
-            // correct page and action will be in the query args now
3378
-            $redirect_url = admin_url('admin.php');
3379
-        }
3380
-        // merge any default query_args set in _default_route_query_args property
3381
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3382
-            $args_to_merge = [];
3383
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3384
-                // is there a wp_referer array in our _default_route_query_args property?
3385
-                if ($query_param === 'wp_referer') {
3386
-                    $query_value = (array) $query_value;
3387
-                    foreach ($query_value as $reference => $value) {
3388
-                        if (strpos($reference, 'nonce') !== false) {
3389
-                            continue;
3390
-                        }
3391
-                        // finally we will override any arguments in the referer with
3392
-                        // what might be set on the _default_route_query_args array.
3393
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3394
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3395
-                        } else {
3396
-                            $args_to_merge[ $reference ] = urlencode($value);
3397
-                        }
3398
-                    }
3399
-                    continue;
3400
-                }
3401
-                $args_to_merge[ $query_param ] = $query_value;
3402
-            }
3403
-            // now let's merge these arguments but override with what was specifically sent in to the
3404
-            // redirect.
3405
-            $query_args = array_merge($args_to_merge, $query_args);
3406
-        }
3407
-        $this->_process_notices($query_args);
3408
-        // generate redirect url
3409
-        // if redirecting to anything other than the main page, add a nonce
3410
-        if (isset($query_args['action'])) {
3411
-            // manually generate wp_nonce and merge that with the query vars
3412
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3413
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3414
-        }
3415
-        // we're adding some hooks and filters in here for processing any things just before redirects
3416
-        // (example: an admin page has done an insert or update and we want to run something after that).
3417
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3418
-        $redirect_url = apply_filters(
3419
-            'FHEE_redirect_' . $classname . $this->_req_action,
3420
-            self::add_query_args_and_nonce($query_args, $redirect_url),
3421
-            $query_args
3422
-        );
3423
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3424
-        if ($this->request->isAjax()) {
3425
-            $default_data                    = [
3426
-                'close'        => true,
3427
-                'redirect_url' => $redirect_url,
3428
-                'where'        => 'main',
3429
-                'what'         => 'append',
3430
-            ];
3431
-            $this->_template_args['success'] = $success;
3432
-            $this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3433
-                $default_data,
3434
-                $this->_template_args['data']
3435
-            ) : $default_data;
3436
-            $this->_return_json();
3437
-        }
3438
-        wp_safe_redirect($redirect_url);
3439
-        exit();
3440
-    }
3441
-
3442
-
3443
-    /**
3444
-     * process any notices before redirecting (or returning ajax request)
3445
-     * This method sets the $this->_template_args['notices'] attribute;
3446
-     *
3447
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3448
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3449
-     *                                  page_routes haven't been defined yet.
3450
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3451
-     *                                  still save a transient for the notice.
3452
-     * @return void
3453
-     * @throws EE_Error
3454
-     */
3455
-    protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3456
-    {
3457
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3458
-        if ($this->request->isAjax()) {
3459
-            $notices = EE_Error::get_notices(false);
3460
-            if (empty($this->_template_args['success'])) {
3461
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3462
-            }
3463
-            if (empty($this->_template_args['errors'])) {
3464
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3465
-            }
3466
-            if (empty($this->_template_args['attention'])) {
3467
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3468
-            }
3469
-        }
3470
-        $this->_template_args['notices'] = EE_Error::get_notices();
3471
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3472
-        if (! $this->request->isAjax() || $sticky_notices) {
3473
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3474
-            $this->_add_transient(
3475
-                $route,
3476
-                $this->_template_args['notices'],
3477
-                true,
3478
-                $skip_route_verify
3479
-            );
3480
-        }
3481
-    }
3482
-
3483
-
3484
-    /**
3485
-     * get_action_link_or_button
3486
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3487
-     *
3488
-     * @param string $action        use this to indicate which action the url is generated with.
3489
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3490
-     *                              property.
3491
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3492
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3493
-     * @param string $base_url      If this is not provided
3494
-     *                              the _admin_base_url will be used as the default for the button base_url.
3495
-     *                              Otherwise this value will be used.
3496
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3497
-     * @return string
3498
-     * @throws InvalidArgumentException
3499
-     * @throws InvalidInterfaceException
3500
-     * @throws InvalidDataTypeException
3501
-     * @throws EE_Error
3502
-     */
3503
-    public function get_action_link_or_button(
3504
-        $action,
3505
-        $type = 'add',
3506
-        $extra_request = [],
3507
-        $class = 'button-primary',
3508
-        $base_url = '',
3509
-        $exclude_nonce = false
3510
-    ) {
3511
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3512
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3513
-            throw new EE_Error(
3514
-                sprintf(
3515
-                    esc_html__(
3516
-                        'There is no page route for given action for the button.  This action was given: %s',
3517
-                        'event_espresso'
3518
-                    ),
3519
-                    $action
3520
-                )
3521
-            );
3522
-        }
3523
-        if (! isset($this->_labels['buttons'][ $type ])) {
3524
-            throw new EE_Error(
3525
-                sprintf(
3526
-                    esc_html__(
3527
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3528
-                        'event_espresso'
3529
-                    ),
3530
-                    $type
3531
-                )
3532
-            );
3533
-        }
3534
-        // finally check user access for this button.
3535
-        $has_access = $this->check_user_access($action, true);
3536
-        if (! $has_access) {
3537
-            return '';
3538
-        }
3539
-        $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3540
-        $query_args = [
3541
-            'action' => $action,
3542
-        ];
3543
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3544
-        if (! empty($extra_request)) {
3545
-            $query_args = array_merge($extra_request, $query_args);
3546
-        }
3547
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3548
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3549
-    }
3550
-
3551
-
3552
-    /**
3553
-     * _per_page_screen_option
3554
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3555
-     *
3556
-     * @return void
3557
-     * @throws InvalidArgumentException
3558
-     * @throws InvalidInterfaceException
3559
-     * @throws InvalidDataTypeException
3560
-     */
3561
-    protected function _per_page_screen_option()
3562
-    {
3563
-        $option = 'per_page';
3564
-        $args   = [
3565
-            'label'   => apply_filters(
3566
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3567
-                $this->_admin_page_title,
3568
-                $this
3569
-            ),
3570
-            'default' => (int) apply_filters(
3571
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3572
-                20
3573
-            ),
3574
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3575
-        ];
3576
-        // ONLY add the screen option if the user has access to it.
3577
-        if ($this->check_user_access($this->_current_view, true)) {
3578
-            add_screen_option($option, $args);
3579
-        }
3580
-    }
3581
-
3582
-
3583
-    /**
3584
-     * set_per_page_screen_option
3585
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3586
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3587
-     * admin_menu.
3588
-     *
3589
-     * @return void
3590
-     */
3591
-    private function _set_per_page_screen_options()
3592
-    {
3593
-        if ($this->request->requestParamIsSet('wp_screen_options')) {
3594
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3595
-            if (! $user = wp_get_current_user()) {
3596
-                return;
3597
-            }
3598
-            $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3599
-            if (! $option) {
3600
-                return;
3601
-            }
3602
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3603
-            $map_option = $option;
3604
-            $option     = str_replace('-', '_', $option);
3605
-            switch ($map_option) {
3606
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3607
-                    $max_value = apply_filters(
3608
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3609
-                        999,
3610
-                        $this->_current_page,
3611
-                        $this->_current_view
3612
-                    );
3613
-                    if ($value < 1) {
3614
-                        return;
3615
-                    }
3616
-                    $value = min($value, $max_value);
3617
-                    break;
3618
-                default:
3619
-                    $value = apply_filters(
3620
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3621
-                        false,
3622
-                        $option,
3623
-                        $value
3624
-                    );
3625
-                    if (false === $value) {
3626
-                        return;
3627
-                    }
3628
-                    break;
3629
-            }
3630
-            update_user_meta($user->ID, $option, $value);
3631
-            wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3632
-            exit;
3633
-        }
3634
-    }
3635
-
3636
-
3637
-    /**
3638
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3639
-     *
3640
-     * @param array $data array that will be assigned to template args.
3641
-     */
3642
-    public function set_template_args($data)
3643
-    {
3644
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3645
-    }
3646
-
3647
-
3648
-    /**
3649
-     * This makes available the WP transient system for temporarily moving data between routes
3650
-     *
3651
-     * @param string $route             the route that should receive the transient
3652
-     * @param array  $data              the data that gets sent
3653
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3654
-     *                                  normal route transient.
3655
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3656
-     *                                  when we are adding a transient before page_routes have been defined.
3657
-     * @return void
3658
-     * @throws EE_Error
3659
-     */
3660
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3661
-    {
3662
-        $user_id = get_current_user_id();
3663
-        if (! $skip_route_verify) {
3664
-            $this->_verify_route($route);
3665
-        }
3666
-        // now let's set the string for what kind of transient we're setting
3667
-        $transient = $notices
3668
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3669
-            : 'rte_tx_' . $route . '_' . $user_id;
3670
-        $data      = $notices ? ['notices' => $data] : $data;
3671
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3672
-        $existing = is_multisite() && is_network_admin()
3673
-            ? get_site_transient($transient)
3674
-            : get_transient($transient);
3675
-        if ($existing) {
3676
-            $data = array_merge((array) $data, (array) $existing);
3677
-        }
3678
-        if (is_multisite() && is_network_admin()) {
3679
-            set_site_transient($transient, $data, 8);
3680
-        } else {
3681
-            set_transient($transient, $data, 8);
3682
-        }
3683
-    }
3684
-
3685
-
3686
-    /**
3687
-     * this retrieves the temporary transient that has been set for moving data between routes.
3688
-     *
3689
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3690
-     * @param string $route
3691
-     * @return mixed data
3692
-     */
3693
-    protected function _get_transient($notices = false, $route = '')
3694
-    {
3695
-        $user_id   = get_current_user_id();
3696
-        $route     = ! $route ? $this->_req_action : $route;
3697
-        $transient = $notices
3698
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3699
-            : 'rte_tx_' . $route . '_' . $user_id;
3700
-        $data      = is_multisite() && is_network_admin()
3701
-            ? get_site_transient($transient)
3702
-            : get_transient($transient);
3703
-        // delete transient after retrieval (just in case it hasn't expired);
3704
-        if (is_multisite() && is_network_admin()) {
3705
-            delete_site_transient($transient);
3706
-        } else {
3707
-            delete_transient($transient);
3708
-        }
3709
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3710
-    }
3711
-
3712
-
3713
-    /**
3714
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3715
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3716
-     * default route callback on the EE_Admin page you want it run.)
3717
-     *
3718
-     * @return void
3719
-     */
3720
-    protected function _transient_garbage_collection()
3721
-    {
3722
-        global $wpdb;
3723
-        // retrieve all existing transients
3724
-        $query =
3725
-            "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3726
-        if ($results = $wpdb->get_results($query)) {
3727
-            foreach ($results as $result) {
3728
-                $transient = str_replace('_transient_', '', $result->option_name);
3729
-                get_transient($transient);
3730
-                if (is_multisite() && is_network_admin()) {
3731
-                    get_site_transient($transient);
3732
-                }
3733
-            }
3734
-        }
3735
-    }
3736
-
3737
-
3738
-    /**
3739
-     * get_view
3740
-     *
3741
-     * @return string content of _view property
3742
-     */
3743
-    public function get_view()
3744
-    {
3745
-        return $this->_view;
3746
-    }
3747
-
3748
-
3749
-    /**
3750
-     * getter for the protected $_views property
3751
-     *
3752
-     * @return array
3753
-     */
3754
-    public function get_views()
3755
-    {
3756
-        return $this->_views;
3757
-    }
3758
-
3759
-
3760
-    /**
3761
-     * get_current_page
3762
-     *
3763
-     * @return string _current_page property value
3764
-     */
3765
-    public function get_current_page()
3766
-    {
3767
-        return $this->_current_page;
3768
-    }
3769
-
3770
-
3771
-    /**
3772
-     * get_current_view
3773
-     *
3774
-     * @return string _current_view property value
3775
-     */
3776
-    public function get_current_view()
3777
-    {
3778
-        return $this->_current_view;
3779
-    }
3780
-
3781
-
3782
-    /**
3783
-     * get_current_screen
3784
-     *
3785
-     * @return object The current WP_Screen object
3786
-     */
3787
-    public function get_current_screen()
3788
-    {
3789
-        return $this->_current_screen;
3790
-    }
3791
-
3792
-
3793
-    /**
3794
-     * get_current_page_view_url
3795
-     *
3796
-     * @return string This returns the url for the current_page_view.
3797
-     */
3798
-    public function get_current_page_view_url()
3799
-    {
3800
-        return $this->_current_page_view_url;
3801
-    }
3802
-
3803
-
3804
-    /**
3805
-     * just returns the Request
3806
-     *
3807
-     * @return RequestInterface
3808
-     */
3809
-    public function get_request()
3810
-    {
3811
-        return $this->request;
3812
-    }
3813
-
3814
-
3815
-    /**
3816
-     * just returns the _req_data property
3817
-     *
3818
-     * @return array
3819
-     */
3820
-    public function get_request_data()
3821
-    {
3822
-        return $this->request->requestParams();
3823
-    }
3824
-
3825
-
3826
-    /**
3827
-     * returns the _req_data protected property
3828
-     *
3829
-     * @return string
3830
-     */
3831
-    public function get_req_action()
3832
-    {
3833
-        return $this->_req_action;
3834
-    }
3835
-
3836
-
3837
-    /**
3838
-     * @return bool  value of $_is_caf property
3839
-     */
3840
-    public function is_caf()
3841
-    {
3842
-        return $this->_is_caf;
3843
-    }
3844
-
3845
-
3846
-    /**
3847
-     * @return mixed
3848
-     */
3849
-    public function default_espresso_metaboxes()
3850
-    {
3851
-        return $this->_default_espresso_metaboxes;
3852
-    }
3853
-
3854
-
3855
-    /**
3856
-     * @return mixed
3857
-     */
3858
-    public function admin_base_url()
3859
-    {
3860
-        return $this->_admin_base_url;
3861
-    }
3862
-
3863
-
3864
-    /**
3865
-     * @return mixed
3866
-     */
3867
-    public function wp_page_slug()
3868
-    {
3869
-        return $this->_wp_page_slug;
3870
-    }
3871
-
3872
-
3873
-    /**
3874
-     * updates  espresso configuration settings
3875
-     *
3876
-     * @param string                   $tab
3877
-     * @param EE_Config_Base|EE_Config $config
3878
-     * @param string                   $file file where error occurred
3879
-     * @param string                   $func function  where error occurred
3880
-     * @param string                   $line line no where error occurred
3881
-     * @return boolean
3882
-     */
3883
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3884
-    {
3885
-        // remove any options that are NOT going to be saved with the config settings.
3886
-        if (isset($config->core->ee_ueip_optin)) {
3887
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3888
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3889
-            update_option('ee_ueip_has_notified', true);
3890
-        }
3891
-        // and save it (note we're also doing the network save here)
3892
-        $net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3893
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3894
-        if ($config_saved && $net_saved) {
3895
-            EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3896
-            return true;
3897
-        }
3898
-        EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3899
-        return false;
3900
-    }
3901
-
3902
-
3903
-    /**
3904
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3905
-     *
3906
-     * @return array
3907
-     */
3908
-    public function get_yes_no_values()
3909
-    {
3910
-        return $this->_yes_no_values;
3911
-    }
3912
-
3913
-
3914
-    protected function _get_dir()
3915
-    {
3916
-        $reflector = new ReflectionClass(get_class($this));
3917
-        return dirname($reflector->getFileName());
3918
-    }
3919
-
3920
-
3921
-    /**
3922
-     * A helper for getting a "next link".
3923
-     *
3924
-     * @param string $url   The url to link to
3925
-     * @param string $class The class to use.
3926
-     * @return string
3927
-     */
3928
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3929
-    {
3930
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3931
-    }
3932
-
3933
-
3934
-    /**
3935
-     * A helper for getting a "previous link".
3936
-     *
3937
-     * @param string $url   The url to link to
3938
-     * @param string $class The class to use.
3939
-     * @return string
3940
-     */
3941
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3942
-    {
3943
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3944
-    }
3945
-
3946
-
3947
-
3948
-
3949
-
3950
-
3951
-
3952
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3953
-
3954
-
3955
-    /**
3956
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
3957
-     * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
3958
-     * _req_data array.
3959
-     *
3960
-     * @return bool success/fail
3961
-     * @throws EE_Error
3962
-     * @throws InvalidArgumentException
3963
-     * @throws ReflectionException
3964
-     * @throws InvalidDataTypeException
3965
-     * @throws InvalidInterfaceException
3966
-     */
3967
-    protected function _process_resend_registration()
3968
-    {
3969
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3970
-        do_action(
3971
-            'AHEE__EE_Admin_Page___process_resend_registration',
3972
-            $this->_template_args['success'],
3973
-            $this->request->requestParams()
3974
-        );
3975
-        return $this->_template_args['success'];
3976
-    }
3977
-
3978
-
3979
-    /**
3980
-     * This automatically processes any payment message notifications when manual payment has been applied.
3981
-     *
3982
-     * @param EE_Payment $payment
3983
-     * @return bool success/fail
3984
-     */
3985
-    protected function _process_payment_notification(EE_Payment $payment)
3986
-    {
3987
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3988
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3989
-        $this->_template_args['success'] = apply_filters(
3990
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
3991
-            false,
3992
-            $payment
3993
-        );
3994
-        return $this->_template_args['success'];
3995
-    }
2563
+	}
2564
+
2565
+
2566
+	/**
2567
+	 * facade for add_meta_box
2568
+	 *
2569
+	 * @param string  $action        where the metabox gets displayed
2570
+	 * @param string  $title         Title of Metabox (output in metabox header)
2571
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2572
+	 *                               instead of the one created in here.
2573
+	 * @param array   $callback_args an array of args supplied for the metabox
2574
+	 * @param string  $column        what metabox column
2575
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2576
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2577
+	 *                               created but just set our own callback for wp's add_meta_box.
2578
+	 * @throws DomainException
2579
+	 */
2580
+	public function _add_admin_page_meta_box(
2581
+		$action,
2582
+		$title,
2583
+		$callback,
2584
+		$callback_args,
2585
+		$column = 'normal',
2586
+		$priority = 'high',
2587
+		$create_func = true
2588
+	) {
2589
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2590
+		// if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2591
+		if (empty($callback_args) && $create_func) {
2592
+			$callback_args = [
2593
+				'template_path' => $this->_template_path,
2594
+				'template_args' => $this->_template_args,
2595
+			];
2596
+		}
2597
+		// if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2598
+		$call_back_func = $create_func
2599
+			? function ($post, $metabox) {
2600
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2601
+				echo EEH_Template::display_template(
2602
+					$metabox['args']['template_path'],
2603
+					$metabox['args']['template_args'],
2604
+					true
2605
+				);
2606
+			}
2607
+			: $callback;
2608
+		add_meta_box(
2609
+			str_replace('_', '-', $action) . '-mbox',
2610
+			$title,
2611
+			$call_back_func,
2612
+			$this->_wp_page_slug,
2613
+			$column,
2614
+			$priority,
2615
+			$callback_args
2616
+		);
2617
+	}
2618
+
2619
+
2620
+	/**
2621
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2622
+	 *
2623
+	 * @throws DomainException
2624
+	 * @throws EE_Error
2625
+	 */
2626
+	public function display_admin_page_with_metabox_columns()
2627
+	{
2628
+		$this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2629
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2630
+			$this->_column_template_path,
2631
+			$this->_template_args,
2632
+			true
2633
+		);
2634
+		// the final wrapper
2635
+		$this->admin_page_wrapper();
2636
+	}
2637
+
2638
+
2639
+	/**
2640
+	 * generates  HTML wrapper for an admin details page
2641
+	 *
2642
+	 * @return void
2643
+	 * @throws EE_Error
2644
+	 * @throws DomainException
2645
+	 */
2646
+	public function display_admin_page_with_sidebar()
2647
+	{
2648
+		$this->_display_admin_page(true);
2649
+	}
2650
+
2651
+
2652
+	/**
2653
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2654
+	 *
2655
+	 * @return void
2656
+	 * @throws EE_Error
2657
+	 * @throws DomainException
2658
+	 */
2659
+	public function display_admin_page_with_no_sidebar()
2660
+	{
2661
+		$this->_display_admin_page();
2662
+	}
2663
+
2664
+
2665
+	/**
2666
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2667
+	 *
2668
+	 * @return void
2669
+	 * @throws EE_Error
2670
+	 * @throws DomainException
2671
+	 */
2672
+	public function display_about_admin_page()
2673
+	{
2674
+		$this->_display_admin_page(false, true);
2675
+	}
2676
+
2677
+
2678
+	/**
2679
+	 * display_admin_page
2680
+	 * contains the code for actually displaying an admin page
2681
+	 *
2682
+	 * @param boolean $sidebar true with sidebar, false without
2683
+	 * @param boolean $about   use the about_admin_wrapper instead of the default.
2684
+	 * @return void
2685
+	 * @throws DomainException
2686
+	 * @throws EE_Error
2687
+	 */
2688
+	private function _display_admin_page($sidebar = false, $about = false)
2689
+	{
2690
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2691
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2692
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2693
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2694
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2695
+		$this->_template_args['current_page']              = $this->_wp_page_slug;
2696
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2697
+			? 'poststuff'
2698
+			: 'espresso-default-admin';
2699
+		$template_path                                     = $sidebar
2700
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2701
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2702
+		if ($this->request->isAjax()) {
2703
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2704
+		}
2705
+		$template_path                                     = ! empty($this->_column_template_path)
2706
+			? $this->_column_template_path : $template_path;
2707
+		$this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2708
+			? $this->_template_args['admin_page_content']
2709
+			: '';
2710
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2711
+			? $this->_template_args['before_admin_page_content']
2712
+			: '';
2713
+		$this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2714
+			? $this->_template_args['after_admin_page_content']
2715
+			: '';
2716
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
2717
+			$template_path,
2718
+			$this->_template_args,
2719
+			true
2720
+		);
2721
+		// the final template wrapper
2722
+		$this->admin_page_wrapper($about);
2723
+	}
2724
+
2725
+
2726
+	/**
2727
+	 * This is used to display caf preview pages.
2728
+	 *
2729
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2730
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2731
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2732
+	 * @return void
2733
+	 * @throws DomainException
2734
+	 * @throws EE_Error
2735
+	 * @throws InvalidArgumentException
2736
+	 * @throws InvalidDataTypeException
2737
+	 * @throws InvalidInterfaceException
2738
+	 * @since 4.3.2
2739
+	 */
2740
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2741
+	{
2742
+		// let's generate a default preview action button if there isn't one already present.
2743
+		$this->_labels['buttons']['buy_now']           = esc_html__(
2744
+			'Upgrade to Event Espresso 4 Right Now',
2745
+			'event_espresso'
2746
+		);
2747
+		$buy_now_url                                   = add_query_arg(
2748
+			[
2749
+				'ee_ver'       => 'ee4',
2750
+				'utm_source'   => 'ee4_plugin_admin',
2751
+				'utm_medium'   => 'link',
2752
+				'utm_campaign' => $utm_campaign_source,
2753
+				'utm_content'  => 'buy_now_button',
2754
+			],
2755
+			'https://eventespresso.com/pricing/'
2756
+		);
2757
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2758
+			? $this->get_action_link_or_button(
2759
+				'',
2760
+				'buy_now',
2761
+				[],
2762
+				'button-primary button-large',
2763
+				esc_url_raw($buy_now_url),
2764
+				true
2765
+			)
2766
+			: $this->_template_args['preview_action_button'];
2767
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
2768
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2769
+			$this->_template_args,
2770
+			true
2771
+		);
2772
+		$this->_display_admin_page($display_sidebar);
2773
+	}
2774
+
2775
+
2776
+	/**
2777
+	 * display_admin_list_table_page_with_sidebar
2778
+	 * generates HTML wrapper for an admin_page with list_table
2779
+	 *
2780
+	 * @return void
2781
+	 * @throws EE_Error
2782
+	 * @throws DomainException
2783
+	 */
2784
+	public function display_admin_list_table_page_with_sidebar()
2785
+	{
2786
+		$this->_display_admin_list_table_page(true);
2787
+	}
2788
+
2789
+
2790
+	/**
2791
+	 * display_admin_list_table_page_with_no_sidebar
2792
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2793
+	 *
2794
+	 * @return void
2795
+	 * @throws EE_Error
2796
+	 * @throws DomainException
2797
+	 */
2798
+	public function display_admin_list_table_page_with_no_sidebar()
2799
+	{
2800
+		$this->_display_admin_list_table_page();
2801
+	}
2802
+
2803
+
2804
+	/**
2805
+	 * generates html wrapper for an admin_list_table page
2806
+	 *
2807
+	 * @param boolean $sidebar whether to display with sidebar or not.
2808
+	 * @return void
2809
+	 * @throws DomainException
2810
+	 * @throws EE_Error
2811
+	 */
2812
+	private function _display_admin_list_table_page($sidebar = false)
2813
+	{
2814
+		// setup search attributes
2815
+		$this->_set_search_attributes();
2816
+		$this->_template_args['current_page']     = $this->_wp_page_slug;
2817
+		$template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2818
+		$this->_template_args['table_url']        = $this->request->isAjax()
2819
+			? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2820
+			: add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2821
+		$this->_template_args['list_table']       = $this->_list_table_object;
2822
+		$this->_template_args['current_route']    = $this->_req_action;
2823
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2824
+		$ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2825
+		if (! empty($ajax_sorting_callback)) {
2826
+			$sortable_list_table_form_fields = wp_nonce_field(
2827
+				$ajax_sorting_callback . '_nonce',
2828
+				$ajax_sorting_callback . '_nonce',
2829
+				false,
2830
+				false
2831
+			);
2832
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2833
+												. $this->page_slug
2834
+												. '" />';
2835
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2836
+												. $ajax_sorting_callback
2837
+												. '" />';
2838
+		} else {
2839
+			$sortable_list_table_form_fields = '';
2840
+		}
2841
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2842
+		$hidden_form_fields                                      =
2843
+			isset($this->_template_args['list_table_hidden_fields'])
2844
+				? $this->_template_args['list_table_hidden_fields']
2845
+				: '';
2846
+		$nonce_ref                                               = $this->_req_action . '_nonce';
2847
+		$hidden_form_fields                                      .= '<input type="hidden" name="'
2848
+																	. $nonce_ref
2849
+																	. '" value="'
2850
+																	. wp_create_nonce($nonce_ref)
2851
+																	. '">';
2852
+		$this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2853
+		// display message about search results?
2854
+		$search = $this->request->getRequestParam('s');
2855
+		$this->_template_args['before_list_table'] .= ! empty($search)
2856
+			? '<p class="ee-search-results">' . sprintf(
2857
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2858
+				trim($search, '%')
2859
+			) . '</p>'
2860
+			: '';
2861
+		// filter before_list_table template arg
2862
+		$this->_template_args['before_list_table'] = apply_filters(
2863
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2864
+			$this->_template_args['before_list_table'],
2865
+			$this->page_slug,
2866
+			$this->request->requestParams(),
2867
+			$this->_req_action
2868
+		);
2869
+		// convert to array and filter again
2870
+		// arrays are easier to inject new items in a specific location,
2871
+		// but would not be backwards compatible, so we have to add a new filter
2872
+		$this->_template_args['before_list_table'] = implode(
2873
+			" \n",
2874
+			(array) apply_filters(
2875
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2876
+				(array) $this->_template_args['before_list_table'],
2877
+				$this->page_slug,
2878
+				$this->request->requestParams(),
2879
+				$this->_req_action
2880
+			)
2881
+		);
2882
+		// filter after_list_table template arg
2883
+		$this->_template_args['after_list_table'] = apply_filters(
2884
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2885
+			$this->_template_args['after_list_table'],
2886
+			$this->page_slug,
2887
+			$this->request->requestParams(),
2888
+			$this->_req_action
2889
+		);
2890
+		// convert to array and filter again
2891
+		// arrays are easier to inject new items in a specific location,
2892
+		// but would not be backwards compatible, so we have to add a new filter
2893
+		$this->_template_args['after_list_table']   = implode(
2894
+			" \n",
2895
+			(array) apply_filters(
2896
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2897
+				(array) $this->_template_args['after_list_table'],
2898
+				$this->page_slug,
2899
+				$this->request->requestParams(),
2900
+				$this->_req_action
2901
+			)
2902
+		);
2903
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2904
+			$template_path,
2905
+			$this->_template_args,
2906
+			true
2907
+		);
2908
+		// the final template wrapper
2909
+		if ($sidebar) {
2910
+			$this->display_admin_page_with_sidebar();
2911
+		} else {
2912
+			$this->display_admin_page_with_no_sidebar();
2913
+		}
2914
+	}
2915
+
2916
+
2917
+	/**
2918
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
2919
+	 * html string for the legend.
2920
+	 * $items are expected in an array in the following format:
2921
+	 * $legend_items = array(
2922
+	 *        'item_id' => array(
2923
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2924
+	 *            'desc' => esc_html__('localized description of item');
2925
+	 *        )
2926
+	 * );
2927
+	 *
2928
+	 * @param array $items see above for format of array
2929
+	 * @return string html string of legend
2930
+	 * @throws DomainException
2931
+	 */
2932
+	protected function _display_legend($items)
2933
+	{
2934
+		$this->_template_args['items'] = apply_filters(
2935
+			'FHEE__EE_Admin_Page___display_legend__items',
2936
+			(array) $items,
2937
+			$this
2938
+		);
2939
+		return EEH_Template::display_template(
2940
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
2941
+			$this->_template_args,
2942
+			true
2943
+		);
2944
+	}
2945
+
2946
+
2947
+	/**
2948
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2949
+	 * The returned json object is created from an array in the following format:
2950
+	 * array(
2951
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2952
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
2953
+	 *  'notices' => '', // - contains any EE_Error formatted notices
2954
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2955
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
2956
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
2957
+	 *  that might be included in here)
2958
+	 * )
2959
+	 * The json object is populated by whatever is set in the $_template_args property.
2960
+	 *
2961
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
2962
+	 *                                 instead of displayed.
2963
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
2964
+	 * @return void
2965
+	 * @throws EE_Error
2966
+	 */
2967
+	protected function _return_json($sticky_notices = false, $notices_arguments = [])
2968
+	{
2969
+		// make sure any EE_Error notices have been handled.
2970
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
2971
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
2972
+		unset($this->_template_args['data']);
2973
+		$json = [
2974
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2975
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2976
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2977
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2978
+			'notices'   => EE_Error::get_notices(),
2979
+			'content'   => isset($this->_template_args['admin_page_content'])
2980
+				? $this->_template_args['admin_page_content'] : '',
2981
+			'data'      => array_merge($data, ['template_args' => $this->_template_args]),
2982
+			'isEEajax'  => true
2983
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2984
+		];
2985
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2986
+		if (null === error_get_last() || ! headers_sent()) {
2987
+			header('Content-Type: application/json; charset=UTF-8');
2988
+		}
2989
+		echo wp_json_encode($json);
2990
+		exit();
2991
+	}
2992
+
2993
+
2994
+	/**
2995
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2996
+	 *
2997
+	 * @return void
2998
+	 * @throws EE_Error
2999
+	 */
3000
+	public function return_json()
3001
+	{
3002
+		if ($this->request->isAjax()) {
3003
+			$this->_return_json();
3004
+		} else {
3005
+			throw new EE_Error(
3006
+				sprintf(
3007
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3008
+					__FUNCTION__
3009
+				)
3010
+			);
3011
+		}
3012
+	}
3013
+
3014
+
3015
+	/**
3016
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3017
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3018
+	 *
3019
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3020
+	 */
3021
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3022
+	{
3023
+		$this->_hook_obj = $hook_obj;
3024
+	}
3025
+
3026
+
3027
+	/**
3028
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3029
+	 *
3030
+	 * @param boolean $about whether to use the special about page wrapper or default.
3031
+	 * @return void
3032
+	 * @throws DomainException
3033
+	 * @throws EE_Error
3034
+	 */
3035
+	public function admin_page_wrapper($about = false)
3036
+	{
3037
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3038
+		$this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3039
+		$this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3040
+		$this->_template_args['admin_page_title']          = $this->_admin_page_title;
3041
+
3042
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3043
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3044
+			isset($this->_template_args['before_admin_page_content'])
3045
+				? $this->_template_args['before_admin_page_content']
3046
+				: ''
3047
+		);
3048
+
3049
+		$this->_template_args['after_admin_page_content']  = apply_filters(
3050
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3051
+			isset($this->_template_args['after_admin_page_content'])
3052
+				? $this->_template_args['after_admin_page_content']
3053
+				: ''
3054
+		);
3055
+		$this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3056
+
3057
+		if ($this->request->isAjax()) {
3058
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3059
+				// $template_path,
3060
+				EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3061
+				$this->_template_args,
3062
+				true
3063
+			);
3064
+			$this->_return_json();
3065
+		}
3066
+		// load settings page wrapper template
3067
+		$template_path = $about
3068
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3069
+			: EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3070
+
3071
+		EEH_Template::display_template($template_path, $this->_template_args);
3072
+	}
3073
+
3074
+
3075
+	/**
3076
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3077
+	 *
3078
+	 * @return string html
3079
+	 * @throws EE_Error
3080
+	 */
3081
+	protected function _get_main_nav_tabs()
3082
+	{
3083
+		// let's generate the html using the EEH_Tabbed_Content helper.
3084
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3085
+		// (rather than setting in the page_routes array)
3086
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3087
+	}
3088
+
3089
+
3090
+	/**
3091
+	 *        sort nav tabs
3092
+	 *
3093
+	 * @param $a
3094
+	 * @param $b
3095
+	 * @return int
3096
+	 */
3097
+	private function _sort_nav_tabs($a, $b)
3098
+	{
3099
+		if ($a['order'] === $b['order']) {
3100
+			return 0;
3101
+		}
3102
+		return ($a['order'] < $b['order']) ? -1 : 1;
3103
+	}
3104
+
3105
+
3106
+	/**
3107
+	 *    generates HTML for the forms used on admin pages
3108
+	 *
3109
+	 * @param array  $input_vars   - array of input field details
3110
+	 * @param string $generator    (options are 'string' or 'array', basically use this to indicate which generator to
3111
+	 *                             use)
3112
+	 * @param bool   $id
3113
+	 * @return array|string
3114
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3115
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3116
+	 */
3117
+	protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3118
+	{
3119
+		return $generator === 'string'
3120
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3121
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3122
+	}
3123
+
3124
+
3125
+	/**
3126
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3127
+	 *
3128
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3129
+	 *                                   Close" button.
3130
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3131
+	 *                                   'Save', [1] => 'save & close')
3132
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3133
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3134
+	 *                                   default actions by submitting some other value.
3135
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3136
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3137
+	 *                                   close (normal form handling).
3138
+	 */
3139
+	protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3140
+	{
3141
+		// make sure $text and $actions are in an array
3142
+		$text          = (array) $text;
3143
+		$actions       = (array) $actions;
3144
+		$referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3145
+		$button_text   = ! empty($text)
3146
+			? $text
3147
+			: [
3148
+				esc_html__('Save', 'event_espresso'),
3149
+				esc_html__('Save and Close', 'event_espresso'),
3150
+			];
3151
+		$default_names = ['save', 'save_and_close'];
3152
+		$buttons = '';
3153
+		foreach ($button_text as $key => $button) {
3154
+			$ref     = $default_names[ $key ];
3155
+			$name    = ! empty($actions) ? $actions[ $key ] : $ref;
3156
+			$buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3157
+						. 'value="' . $button . '" name="' . $name . '" '
3158
+						. 'id="' . $this->_current_view . '_' . $ref . '" />';
3159
+			if (! $both) {
3160
+				break;
3161
+			}
3162
+		}
3163
+		// add in a hidden index for the current page (so save and close redirects properly)
3164
+		$buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3165
+				   . $referrer_url
3166
+				   . '" />';
3167
+		$this->_template_args['save_buttons'] = $buttons;
3168
+	}
3169
+
3170
+
3171
+	/**
3172
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3173
+	 *
3174
+	 * @param string $route
3175
+	 * @param array  $additional_hidden_fields
3176
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3177
+	 * @since 4.6.0
3178
+	 */
3179
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3180
+	{
3181
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3182
+	}
3183
+
3184
+
3185
+	/**
3186
+	 * set form open and close tags on add/edit pages.
3187
+	 *
3188
+	 * @param string $route                    the route you want the form to direct to
3189
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3190
+	 * @return void
3191
+	 */
3192
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3193
+	{
3194
+		if (empty($route)) {
3195
+			$user_msg = esc_html__(
3196
+				'An error occurred. No action was set for this page\'s form.',
3197
+				'event_espresso'
3198
+			);
3199
+			$dev_msg  = $user_msg . "\n"
3200
+						. sprintf(
3201
+							esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3202
+							__FUNCTION__,
3203
+							__CLASS__
3204
+						);
3205
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3206
+		}
3207
+		// open form
3208
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3209
+															 . $this->_admin_base_url
3210
+															 . '" id="'
3211
+															 . $route
3212
+															 . '_event_form" >';
3213
+		// add nonce
3214
+		$nonce                                             =
3215
+			wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3216
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3217
+		// add REQUIRED form action
3218
+		$hidden_fields = [
3219
+			'action' => ['type' => 'hidden', 'value' => $route],
3220
+		];
3221
+		// merge arrays
3222
+		$hidden_fields = is_array($additional_hidden_fields)
3223
+			? array_merge($hidden_fields, $additional_hidden_fields)
3224
+			: $hidden_fields;
3225
+		// generate form fields
3226
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3227
+		// add fields to form
3228
+		foreach ((array) $form_fields as $form_field) {
3229
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3230
+		}
3231
+		// close form
3232
+		$this->_template_args['after_admin_page_content'] = '</form>';
3233
+	}
3234
+
3235
+
3236
+	/**
3237
+	 * Public Wrapper for _redirect_after_action() method since its
3238
+	 * discovered it would be useful for external code to have access.
3239
+	 *
3240
+	 * @param bool   $success
3241
+	 * @param string $what
3242
+	 * @param string $action_desc
3243
+	 * @param array  $query_args
3244
+	 * @param bool   $override_overwrite
3245
+	 * @throws EE_Error
3246
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3247
+	 * @since 4.5.0
3248
+	 */
3249
+	public function redirect_after_action(
3250
+		$success = false,
3251
+		$what = 'item',
3252
+		$action_desc = 'processed',
3253
+		$query_args = [],
3254
+		$override_overwrite = false
3255
+	) {
3256
+		$this->_redirect_after_action(
3257
+			$success,
3258
+			$what,
3259
+			$action_desc,
3260
+			$query_args,
3261
+			$override_overwrite
3262
+		);
3263
+	}
3264
+
3265
+
3266
+	/**
3267
+	 * Helper method for merging existing request data with the returned redirect url.
3268
+	 *
3269
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3270
+	 * filters are still applied.
3271
+	 *
3272
+	 * @param array $new_route_data
3273
+	 * @return array
3274
+	 */
3275
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3276
+	{
3277
+		foreach ($this->request->requestParams() as $ref => $value) {
3278
+			// unset nonces
3279
+			if (strpos($ref, 'nonce') !== false) {
3280
+				$this->request->unSetRequestParam($ref);
3281
+				continue;
3282
+			}
3283
+			// urlencode values.
3284
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3285
+			$this->request->setRequestParam($ref, $value);
3286
+		}
3287
+		return array_merge($this->request->requestParams(), $new_route_data);
3288
+	}
3289
+
3290
+
3291
+	/**
3292
+	 *    _redirect_after_action
3293
+	 *
3294
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3295
+	 * @param string $what               - what the action was performed on
3296
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3297
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3298
+	 *                                   action is completed
3299
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3300
+	 *                                   override this so that they show.
3301
+	 * @return void
3302
+	 * @throws EE_Error
3303
+	 */
3304
+	protected function _redirect_after_action(
3305
+		$success = 0,
3306
+		$what = 'item',
3307
+		$action_desc = 'processed',
3308
+		$query_args = [],
3309
+		$override_overwrite = false
3310
+	) {
3311
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3312
+		// class name for actions/filters.
3313
+		$classname = get_class($this);
3314
+		// set redirect url.
3315
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3316
+		// otherwise we go with whatever is set as the _admin_base_url
3317
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3318
+		$notices      = EE_Error::get_notices(false);
3319
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3320
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3321
+			EE_Error::overwrite_success();
3322
+		}
3323
+		if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3324
+			// how many records affected ? more than one record ? or just one ?
3325
+			if ($success > 1) {
3326
+				// set plural msg
3327
+				EE_Error::add_success(
3328
+					sprintf(
3329
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3330
+						$what,
3331
+						$action_desc
3332
+					),
3333
+					__FILE__,
3334
+					__FUNCTION__,
3335
+					__LINE__
3336
+				);
3337
+			} elseif ($success === 1) {
3338
+				// set singular msg
3339
+				EE_Error::add_success(
3340
+					sprintf(
3341
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3342
+						$what,
3343
+						$action_desc
3344
+					),
3345
+					__FILE__,
3346
+					__FUNCTION__,
3347
+					__LINE__
3348
+				);
3349
+			}
3350
+		}
3351
+		// check that $query_args isn't something crazy
3352
+		if (! is_array($query_args)) {
3353
+			$query_args = [];
3354
+		}
3355
+		/**
3356
+		 * Allow injecting actions before the query_args are modified for possible different
3357
+		 * redirections on save and close actions
3358
+		 *
3359
+		 * @param array $query_args       The original query_args array coming into the
3360
+		 *                                method.
3361
+		 * @since 4.2.0
3362
+		 */
3363
+		do_action(
3364
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3365
+			$query_args
3366
+		);
3367
+		// calculate where we're going (if we have a "save and close" button pushed)
3368
+
3369
+		if (
3370
+			$this->request->requestParamIsSet('save_and_close')
3371
+			&& $this->request->requestParamIsSet('save_and_close_referrer')
3372
+		) {
3373
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3374
+			$parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3375
+			// regenerate query args array from referrer URL
3376
+			parse_str($parsed_url['query'], $query_args);
3377
+			// correct page and action will be in the query args now
3378
+			$redirect_url = admin_url('admin.php');
3379
+		}
3380
+		// merge any default query_args set in _default_route_query_args property
3381
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3382
+			$args_to_merge = [];
3383
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3384
+				// is there a wp_referer array in our _default_route_query_args property?
3385
+				if ($query_param === 'wp_referer') {
3386
+					$query_value = (array) $query_value;
3387
+					foreach ($query_value as $reference => $value) {
3388
+						if (strpos($reference, 'nonce') !== false) {
3389
+							continue;
3390
+						}
3391
+						// finally we will override any arguments in the referer with
3392
+						// what might be set on the _default_route_query_args array.
3393
+						if (isset($this->_default_route_query_args[ $reference ])) {
3394
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3395
+						} else {
3396
+							$args_to_merge[ $reference ] = urlencode($value);
3397
+						}
3398
+					}
3399
+					continue;
3400
+				}
3401
+				$args_to_merge[ $query_param ] = $query_value;
3402
+			}
3403
+			// now let's merge these arguments but override with what was specifically sent in to the
3404
+			// redirect.
3405
+			$query_args = array_merge($args_to_merge, $query_args);
3406
+		}
3407
+		$this->_process_notices($query_args);
3408
+		// generate redirect url
3409
+		// if redirecting to anything other than the main page, add a nonce
3410
+		if (isset($query_args['action'])) {
3411
+			// manually generate wp_nonce and merge that with the query vars
3412
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3413
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3414
+		}
3415
+		// we're adding some hooks and filters in here for processing any things just before redirects
3416
+		// (example: an admin page has done an insert or update and we want to run something after that).
3417
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3418
+		$redirect_url = apply_filters(
3419
+			'FHEE_redirect_' . $classname . $this->_req_action,
3420
+			self::add_query_args_and_nonce($query_args, $redirect_url),
3421
+			$query_args
3422
+		);
3423
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3424
+		if ($this->request->isAjax()) {
3425
+			$default_data                    = [
3426
+				'close'        => true,
3427
+				'redirect_url' => $redirect_url,
3428
+				'where'        => 'main',
3429
+				'what'         => 'append',
3430
+			];
3431
+			$this->_template_args['success'] = $success;
3432
+			$this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3433
+				$default_data,
3434
+				$this->_template_args['data']
3435
+			) : $default_data;
3436
+			$this->_return_json();
3437
+		}
3438
+		wp_safe_redirect($redirect_url);
3439
+		exit();
3440
+	}
3441
+
3442
+
3443
+	/**
3444
+	 * process any notices before redirecting (or returning ajax request)
3445
+	 * This method sets the $this->_template_args['notices'] attribute;
3446
+	 *
3447
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3448
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3449
+	 *                                  page_routes haven't been defined yet.
3450
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3451
+	 *                                  still save a transient for the notice.
3452
+	 * @return void
3453
+	 * @throws EE_Error
3454
+	 */
3455
+	protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3456
+	{
3457
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3458
+		if ($this->request->isAjax()) {
3459
+			$notices = EE_Error::get_notices(false);
3460
+			if (empty($this->_template_args['success'])) {
3461
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3462
+			}
3463
+			if (empty($this->_template_args['errors'])) {
3464
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3465
+			}
3466
+			if (empty($this->_template_args['attention'])) {
3467
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3468
+			}
3469
+		}
3470
+		$this->_template_args['notices'] = EE_Error::get_notices();
3471
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3472
+		if (! $this->request->isAjax() || $sticky_notices) {
3473
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3474
+			$this->_add_transient(
3475
+				$route,
3476
+				$this->_template_args['notices'],
3477
+				true,
3478
+				$skip_route_verify
3479
+			);
3480
+		}
3481
+	}
3482
+
3483
+
3484
+	/**
3485
+	 * get_action_link_or_button
3486
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3487
+	 *
3488
+	 * @param string $action        use this to indicate which action the url is generated with.
3489
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3490
+	 *                              property.
3491
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3492
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3493
+	 * @param string $base_url      If this is not provided
3494
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3495
+	 *                              Otherwise this value will be used.
3496
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3497
+	 * @return string
3498
+	 * @throws InvalidArgumentException
3499
+	 * @throws InvalidInterfaceException
3500
+	 * @throws InvalidDataTypeException
3501
+	 * @throws EE_Error
3502
+	 */
3503
+	public function get_action_link_or_button(
3504
+		$action,
3505
+		$type = 'add',
3506
+		$extra_request = [],
3507
+		$class = 'button-primary',
3508
+		$base_url = '',
3509
+		$exclude_nonce = false
3510
+	) {
3511
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3512
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3513
+			throw new EE_Error(
3514
+				sprintf(
3515
+					esc_html__(
3516
+						'There is no page route for given action for the button.  This action was given: %s',
3517
+						'event_espresso'
3518
+					),
3519
+					$action
3520
+				)
3521
+			);
3522
+		}
3523
+		if (! isset($this->_labels['buttons'][ $type ])) {
3524
+			throw new EE_Error(
3525
+				sprintf(
3526
+					esc_html__(
3527
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3528
+						'event_espresso'
3529
+					),
3530
+					$type
3531
+				)
3532
+			);
3533
+		}
3534
+		// finally check user access for this button.
3535
+		$has_access = $this->check_user_access($action, true);
3536
+		if (! $has_access) {
3537
+			return '';
3538
+		}
3539
+		$_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3540
+		$query_args = [
3541
+			'action' => $action,
3542
+		];
3543
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3544
+		if (! empty($extra_request)) {
3545
+			$query_args = array_merge($extra_request, $query_args);
3546
+		}
3547
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3548
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3549
+	}
3550
+
3551
+
3552
+	/**
3553
+	 * _per_page_screen_option
3554
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3555
+	 *
3556
+	 * @return void
3557
+	 * @throws InvalidArgumentException
3558
+	 * @throws InvalidInterfaceException
3559
+	 * @throws InvalidDataTypeException
3560
+	 */
3561
+	protected function _per_page_screen_option()
3562
+	{
3563
+		$option = 'per_page';
3564
+		$args   = [
3565
+			'label'   => apply_filters(
3566
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3567
+				$this->_admin_page_title,
3568
+				$this
3569
+			),
3570
+			'default' => (int) apply_filters(
3571
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3572
+				20
3573
+			),
3574
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3575
+		];
3576
+		// ONLY add the screen option if the user has access to it.
3577
+		if ($this->check_user_access($this->_current_view, true)) {
3578
+			add_screen_option($option, $args);
3579
+		}
3580
+	}
3581
+
3582
+
3583
+	/**
3584
+	 * set_per_page_screen_option
3585
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3586
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3587
+	 * admin_menu.
3588
+	 *
3589
+	 * @return void
3590
+	 */
3591
+	private function _set_per_page_screen_options()
3592
+	{
3593
+		if ($this->request->requestParamIsSet('wp_screen_options')) {
3594
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3595
+			if (! $user = wp_get_current_user()) {
3596
+				return;
3597
+			}
3598
+			$option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3599
+			if (! $option) {
3600
+				return;
3601
+			}
3602
+			$value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3603
+			$map_option = $option;
3604
+			$option     = str_replace('-', '_', $option);
3605
+			switch ($map_option) {
3606
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3607
+					$max_value = apply_filters(
3608
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3609
+						999,
3610
+						$this->_current_page,
3611
+						$this->_current_view
3612
+					);
3613
+					if ($value < 1) {
3614
+						return;
3615
+					}
3616
+					$value = min($value, $max_value);
3617
+					break;
3618
+				default:
3619
+					$value = apply_filters(
3620
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3621
+						false,
3622
+						$option,
3623
+						$value
3624
+					);
3625
+					if (false === $value) {
3626
+						return;
3627
+					}
3628
+					break;
3629
+			}
3630
+			update_user_meta($user->ID, $option, $value);
3631
+			wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3632
+			exit;
3633
+		}
3634
+	}
3635
+
3636
+
3637
+	/**
3638
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3639
+	 *
3640
+	 * @param array $data array that will be assigned to template args.
3641
+	 */
3642
+	public function set_template_args($data)
3643
+	{
3644
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3645
+	}
3646
+
3647
+
3648
+	/**
3649
+	 * This makes available the WP transient system for temporarily moving data between routes
3650
+	 *
3651
+	 * @param string $route             the route that should receive the transient
3652
+	 * @param array  $data              the data that gets sent
3653
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3654
+	 *                                  normal route transient.
3655
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3656
+	 *                                  when we are adding a transient before page_routes have been defined.
3657
+	 * @return void
3658
+	 * @throws EE_Error
3659
+	 */
3660
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3661
+	{
3662
+		$user_id = get_current_user_id();
3663
+		if (! $skip_route_verify) {
3664
+			$this->_verify_route($route);
3665
+		}
3666
+		// now let's set the string for what kind of transient we're setting
3667
+		$transient = $notices
3668
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3669
+			: 'rte_tx_' . $route . '_' . $user_id;
3670
+		$data      = $notices ? ['notices' => $data] : $data;
3671
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3672
+		$existing = is_multisite() && is_network_admin()
3673
+			? get_site_transient($transient)
3674
+			: get_transient($transient);
3675
+		if ($existing) {
3676
+			$data = array_merge((array) $data, (array) $existing);
3677
+		}
3678
+		if (is_multisite() && is_network_admin()) {
3679
+			set_site_transient($transient, $data, 8);
3680
+		} else {
3681
+			set_transient($transient, $data, 8);
3682
+		}
3683
+	}
3684
+
3685
+
3686
+	/**
3687
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3688
+	 *
3689
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3690
+	 * @param string $route
3691
+	 * @return mixed data
3692
+	 */
3693
+	protected function _get_transient($notices = false, $route = '')
3694
+	{
3695
+		$user_id   = get_current_user_id();
3696
+		$route     = ! $route ? $this->_req_action : $route;
3697
+		$transient = $notices
3698
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3699
+			: 'rte_tx_' . $route . '_' . $user_id;
3700
+		$data      = is_multisite() && is_network_admin()
3701
+			? get_site_transient($transient)
3702
+			: get_transient($transient);
3703
+		// delete transient after retrieval (just in case it hasn't expired);
3704
+		if (is_multisite() && is_network_admin()) {
3705
+			delete_site_transient($transient);
3706
+		} else {
3707
+			delete_transient($transient);
3708
+		}
3709
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3710
+	}
3711
+
3712
+
3713
+	/**
3714
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3715
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3716
+	 * default route callback on the EE_Admin page you want it run.)
3717
+	 *
3718
+	 * @return void
3719
+	 */
3720
+	protected function _transient_garbage_collection()
3721
+	{
3722
+		global $wpdb;
3723
+		// retrieve all existing transients
3724
+		$query =
3725
+			"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3726
+		if ($results = $wpdb->get_results($query)) {
3727
+			foreach ($results as $result) {
3728
+				$transient = str_replace('_transient_', '', $result->option_name);
3729
+				get_transient($transient);
3730
+				if (is_multisite() && is_network_admin()) {
3731
+					get_site_transient($transient);
3732
+				}
3733
+			}
3734
+		}
3735
+	}
3736
+
3737
+
3738
+	/**
3739
+	 * get_view
3740
+	 *
3741
+	 * @return string content of _view property
3742
+	 */
3743
+	public function get_view()
3744
+	{
3745
+		return $this->_view;
3746
+	}
3747
+
3748
+
3749
+	/**
3750
+	 * getter for the protected $_views property
3751
+	 *
3752
+	 * @return array
3753
+	 */
3754
+	public function get_views()
3755
+	{
3756
+		return $this->_views;
3757
+	}
3758
+
3759
+
3760
+	/**
3761
+	 * get_current_page
3762
+	 *
3763
+	 * @return string _current_page property value
3764
+	 */
3765
+	public function get_current_page()
3766
+	{
3767
+		return $this->_current_page;
3768
+	}
3769
+
3770
+
3771
+	/**
3772
+	 * get_current_view
3773
+	 *
3774
+	 * @return string _current_view property value
3775
+	 */
3776
+	public function get_current_view()
3777
+	{
3778
+		return $this->_current_view;
3779
+	}
3780
+
3781
+
3782
+	/**
3783
+	 * get_current_screen
3784
+	 *
3785
+	 * @return object The current WP_Screen object
3786
+	 */
3787
+	public function get_current_screen()
3788
+	{
3789
+		return $this->_current_screen;
3790
+	}
3791
+
3792
+
3793
+	/**
3794
+	 * get_current_page_view_url
3795
+	 *
3796
+	 * @return string This returns the url for the current_page_view.
3797
+	 */
3798
+	public function get_current_page_view_url()
3799
+	{
3800
+		return $this->_current_page_view_url;
3801
+	}
3802
+
3803
+
3804
+	/**
3805
+	 * just returns the Request
3806
+	 *
3807
+	 * @return RequestInterface
3808
+	 */
3809
+	public function get_request()
3810
+	{
3811
+		return $this->request;
3812
+	}
3813
+
3814
+
3815
+	/**
3816
+	 * just returns the _req_data property
3817
+	 *
3818
+	 * @return array
3819
+	 */
3820
+	public function get_request_data()
3821
+	{
3822
+		return $this->request->requestParams();
3823
+	}
3824
+
3825
+
3826
+	/**
3827
+	 * returns the _req_data protected property
3828
+	 *
3829
+	 * @return string
3830
+	 */
3831
+	public function get_req_action()
3832
+	{
3833
+		return $this->_req_action;
3834
+	}
3835
+
3836
+
3837
+	/**
3838
+	 * @return bool  value of $_is_caf property
3839
+	 */
3840
+	public function is_caf()
3841
+	{
3842
+		return $this->_is_caf;
3843
+	}
3844
+
3845
+
3846
+	/**
3847
+	 * @return mixed
3848
+	 */
3849
+	public function default_espresso_metaboxes()
3850
+	{
3851
+		return $this->_default_espresso_metaboxes;
3852
+	}
3853
+
3854
+
3855
+	/**
3856
+	 * @return mixed
3857
+	 */
3858
+	public function admin_base_url()
3859
+	{
3860
+		return $this->_admin_base_url;
3861
+	}
3862
+
3863
+
3864
+	/**
3865
+	 * @return mixed
3866
+	 */
3867
+	public function wp_page_slug()
3868
+	{
3869
+		return $this->_wp_page_slug;
3870
+	}
3871
+
3872
+
3873
+	/**
3874
+	 * updates  espresso configuration settings
3875
+	 *
3876
+	 * @param string                   $tab
3877
+	 * @param EE_Config_Base|EE_Config $config
3878
+	 * @param string                   $file file where error occurred
3879
+	 * @param string                   $func function  where error occurred
3880
+	 * @param string                   $line line no where error occurred
3881
+	 * @return boolean
3882
+	 */
3883
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3884
+	{
3885
+		// remove any options that are NOT going to be saved with the config settings.
3886
+		if (isset($config->core->ee_ueip_optin)) {
3887
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3888
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3889
+			update_option('ee_ueip_has_notified', true);
3890
+		}
3891
+		// and save it (note we're also doing the network save here)
3892
+		$net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3893
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3894
+		if ($config_saved && $net_saved) {
3895
+			EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3896
+			return true;
3897
+		}
3898
+		EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3899
+		return false;
3900
+	}
3901
+
3902
+
3903
+	/**
3904
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3905
+	 *
3906
+	 * @return array
3907
+	 */
3908
+	public function get_yes_no_values()
3909
+	{
3910
+		return $this->_yes_no_values;
3911
+	}
3912
+
3913
+
3914
+	protected function _get_dir()
3915
+	{
3916
+		$reflector = new ReflectionClass(get_class($this));
3917
+		return dirname($reflector->getFileName());
3918
+	}
3919
+
3920
+
3921
+	/**
3922
+	 * A helper for getting a "next link".
3923
+	 *
3924
+	 * @param string $url   The url to link to
3925
+	 * @param string $class The class to use.
3926
+	 * @return string
3927
+	 */
3928
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3929
+	{
3930
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3931
+	}
3932
+
3933
+
3934
+	/**
3935
+	 * A helper for getting a "previous link".
3936
+	 *
3937
+	 * @param string $url   The url to link to
3938
+	 * @param string $class The class to use.
3939
+	 * @return string
3940
+	 */
3941
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3942
+	{
3943
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3944
+	}
3945
+
3946
+
3947
+
3948
+
3949
+
3950
+
3951
+
3952
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3953
+
3954
+
3955
+	/**
3956
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
3957
+	 * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
3958
+	 * _req_data array.
3959
+	 *
3960
+	 * @return bool success/fail
3961
+	 * @throws EE_Error
3962
+	 * @throws InvalidArgumentException
3963
+	 * @throws ReflectionException
3964
+	 * @throws InvalidDataTypeException
3965
+	 * @throws InvalidInterfaceException
3966
+	 */
3967
+	protected function _process_resend_registration()
3968
+	{
3969
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3970
+		do_action(
3971
+			'AHEE__EE_Admin_Page___process_resend_registration',
3972
+			$this->_template_args['success'],
3973
+			$this->request->requestParams()
3974
+		);
3975
+		return $this->_template_args['success'];
3976
+	}
3977
+
3978
+
3979
+	/**
3980
+	 * This automatically processes any payment message notifications when manual payment has been applied.
3981
+	 *
3982
+	 * @param EE_Payment $payment
3983
+	 * @return bool success/fail
3984
+	 */
3985
+	protected function _process_payment_notification(EE_Payment $payment)
3986
+	{
3987
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3988
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3989
+		$this->_template_args['success'] = apply_filters(
3990
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
3991
+			false,
3992
+			$payment
3993
+		);
3994
+		return $this->_template_args['success'];
3995
+	}
3996 3996
 }
Please login to merge, or discard this patch.
Spacing   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
         $ee_menu_slugs = (array) $ee_menu_slugs;
514 514
         if (
515 515
             ! $this->request->isAjax()
516
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
516
+            && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))
517 517
         ) {
518 518
             return;
519 519
         }
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
             : $req_action;
534 534
 
535 535
         $this->_current_view = $this->_req_action;
536
-        $this->_req_nonce    = $this->_req_action . '_nonce';
536
+        $this->_req_nonce    = $this->_req_action.'_nonce';
537 537
         $this->_define_page_props();
538 538
         $this->_current_page_view_url = add_query_arg(
539 539
             ['page' => $this->_current_page, 'action' => $this->_current_view],
@@ -570,21 +570,21 @@  discard block
 block discarded – undo
570 570
         }
571 571
         // filter routes and page_config so addons can add their stuff. Filtering done per class
572 572
         $this->_page_routes = apply_filters(
573
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
573
+            'FHEE__'.get_class($this).'__page_setup__page_routes',
574 574
             $this->_page_routes,
575 575
             $this
576 576
         );
577 577
         $this->_page_config = apply_filters(
578
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
578
+            'FHEE__'.get_class($this).'__page_setup__page_config',
579 579
             $this->_page_config,
580 580
             $this
581 581
         );
582 582
         // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
583 583
         // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
584
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
584
+        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) {
585 585
             add_action(
586 586
                 'AHEE__EE_Admin_Page__route_admin_request',
587
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
587
+                [$this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view],
588 588
                 10,
589 589
                 2
590 590
             );
@@ -597,8 +597,8 @@  discard block
 block discarded – undo
597 597
             if ($this->_is_UI_request) {
598 598
                 // admin_init stuff - global, all views for this page class, specific view
599 599
                 add_action('admin_init', [$this, 'admin_init'], 10);
600
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
601
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
600
+                if (method_exists($this, 'admin_init_'.$this->_current_view)) {
601
+                    add_action('admin_init', [$this, 'admin_init_'.$this->_current_view], 15);
602 602
                 }
603 603
             } else {
604 604
                 // hijack regular WP loading and route admin request immediately
@@ -617,12 +617,12 @@  discard block
 block discarded – undo
617 617
      */
618 618
     private function _do_other_page_hooks()
619 619
     {
620
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
620
+        $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, []);
621 621
         foreach ($registered_pages as $page) {
622 622
             // now let's setup the file name and class that should be present
623 623
             $classname = str_replace('.class.php', '', $page);
624 624
             // autoloaders should take care of loading file
625
-            if (! class_exists($classname)) {
625
+            if ( ! class_exists($classname)) {
626 626
                 $error_msg[] = sprintf(
627 627
                     esc_html__(
628 628
                         'Something went wrong with loading the %s admin hooks page.',
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
                                    ),
640 640
                                    $page,
641 641
                                    '<br />',
642
-                                   '<strong>' . $classname . '</strong>'
642
+                                   '<strong>'.$classname.'</strong>'
643 643
                                );
644 644
                 throw new EE_Error(implode('||', $error_msg));
645 645
             }
@@ -681,13 +681,13 @@  discard block
 block discarded – undo
681 681
         // load admin_notices - global, page class, and view specific
682 682
         add_action('admin_notices', [$this, 'admin_notices_global'], 5);
683 683
         add_action('admin_notices', [$this, 'admin_notices'], 10);
684
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
685
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
684
+        if (method_exists($this, 'admin_notices_'.$this->_current_view)) {
685
+            add_action('admin_notices', [$this, 'admin_notices_'.$this->_current_view], 15);
686 686
         }
687 687
         // load network admin_notices - global, page class, and view specific
688 688
         add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
689
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
690
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
689
+        if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) {
690
+            add_action('network_admin_notices', [$this, 'network_admin_notices_'.$this->_current_view]);
691 691
         }
692 692
         // this will save any per_page screen options if they are present
693 693
         $this->_set_per_page_screen_options();
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
     protected function _verify_routes()
809 809
     {
810 810
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
811
-        if (! $this->_current_page && ! $this->request->isAjax()) {
811
+        if ( ! $this->_current_page && ! $this->request->isAjax()) {
812 812
             return false;
813 813
         }
814 814
         $this->_route = false;
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
                 $this->_admin_page_title
821 821
             );
822 822
             // developer error msg
823
-            $error_msg .= '||' . $error_msg
823
+            $error_msg .= '||'.$error_msg
824 824
                           . esc_html__(
825 825
                               ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
826 826
                               'event_espresso'
@@ -829,9 +829,9 @@  discard block
 block discarded – undo
829 829
         }
830 830
         // and that the requested page route exists
831 831
         if (array_key_exists($this->_req_action, $this->_page_routes)) {
832
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
833
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
834
-                ? $this->_page_config[ $this->_req_action ]
832
+            $this->_route        = $this->_page_routes[$this->_req_action];
833
+            $this->_route_config = isset($this->_page_config[$this->_req_action])
834
+                ? $this->_page_config[$this->_req_action]
835 835
                 : [];
836 836
         } else {
837 837
             // user error msg
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
                 $this->_admin_page_title
844 844
             );
845 845
             // developer error msg
846
-            $error_msg .= '||' . $error_msg
846
+            $error_msg .= '||'.$error_msg
847 847
                           . sprintf(
848 848
                               esc_html__(
849 849
                                   ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
@@ -854,7 +854,7 @@  discard block
 block discarded – undo
854 854
             throw new EE_Error($error_msg);
855 855
         }
856 856
         // and that a default route exists
857
-        if (! array_key_exists('default', $this->_page_routes)) {
857
+        if ( ! array_key_exists('default', $this->_page_routes)) {
858 858
             // user error msg
859 859
             $error_msg = sprintf(
860 860
                 esc_html__(
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
                 $this->_admin_page_title
865 865
             );
866 866
             // developer error msg
867
-            $error_msg .= '||' . $error_msg
867
+            $error_msg .= '||'.$error_msg
868 868
                           . esc_html__(
869 869
                               ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
870 870
                               'event_espresso'
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
             $this->_admin_page_title
906 906
         );
907 907
         // developer error msg
908
-        $error_msg .= '||' . $error_msg
908
+        $error_msg .= '||'.$error_msg
909 909
                       . sprintf(
910 910
                           esc_html__(
911 911
                               ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
     protected function _verify_nonce($nonce, $nonce_ref)
931 931
     {
932 932
         // verify nonce against expected value
933
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
933
+        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
934 934
             // these are not the droids you are looking for !!!
935 935
             $msg = sprintf(
936 936
                 esc_html__('%sNonce Fail.%s', 'event_espresso'),
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
                     __CLASS__
948 948
                 );
949 949
             }
950
-            if (! $this->request->isAjax()) {
950
+            if ( ! $this->request->isAjax()) {
951 951
                 wp_die($msg);
952 952
             }
953 953
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
      */
972 972
     protected function _route_admin_request()
973 973
     {
974
-        if (! $this->_is_UI_request) {
974
+        if ( ! $this->_is_UI_request) {
975 975
             $this->_verify_routes();
976 976
         }
977 977
         $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
@@ -991,7 +991,7 @@  discard block
 block discarded – undo
991 991
         $error_msg = '';
992 992
         // action right before calling route
993 993
         // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
994
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
994
+        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
995 995
             do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
996 996
         }
997 997
         // right before calling the route, let's clean the _wp_http_referer
@@ -1002,7 +1002,7 @@  discard block
 block discarded – undo
1002 1002
                 wp_unslash($this->request->getServerParam('REQUEST_URI'))
1003 1003
             )
1004 1004
         );
1005
-        if (! empty($func)) {
1005
+        if ( ! empty($func)) {
1006 1006
             if (is_array($func)) {
1007 1007
                 list($class, $method) = $func;
1008 1008
             } elseif (strpos($func, '::') !== false) {
@@ -1011,7 +1011,7 @@  discard block
 block discarded – undo
1011 1011
                 $class  = $this;
1012 1012
                 $method = $func;
1013 1013
             }
1014
-            if (! (is_object($class) && $class === $this)) {
1014
+            if ( ! (is_object($class) && $class === $this)) {
1015 1015
                 // send along this admin page object for access by addons.
1016 1016
                 $args['admin_page_object'] = $this;
1017 1017
             }
@@ -1052,7 +1052,7 @@  discard block
 block discarded – undo
1052 1052
                     $method
1053 1053
                 );
1054 1054
             }
1055
-            if (! empty($error_msg)) {
1055
+            if ( ! empty($error_msg)) {
1056 1056
                 throw new EE_Error($error_msg);
1057 1057
             }
1058 1058
         }
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
                 if (strpos($key, 'nonce') !== false) {
1138 1138
                     continue;
1139 1139
                 }
1140
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1140
+                $args['wp_referer['.$key.']'] = is_string($value) ? htmlspecialchars($value) : $value;
1141 1141
             }
1142 1142
         }
1143 1143
         return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
@@ -1176,12 +1176,12 @@  discard block
 block discarded – undo
1176 1176
      */
1177 1177
     protected function _add_help_tabs()
1178 1178
     {
1179
-        if (isset($this->_page_config[ $this->_req_action ])) {
1180
-            $config = $this->_page_config[ $this->_req_action ];
1179
+        if (isset($this->_page_config[$this->_req_action])) {
1180
+            $config = $this->_page_config[$this->_req_action];
1181 1181
             // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1182 1182
             if (is_array($config) && isset($config['help_sidebar'])) {
1183 1183
                 // check that the callback given is valid
1184
-                if (! method_exists($this, $config['help_sidebar'])) {
1184
+                if ( ! method_exists($this, $config['help_sidebar'])) {
1185 1185
                     throw new EE_Error(
1186 1186
                         sprintf(
1187 1187
                             esc_html__(
@@ -1194,18 +1194,18 @@  discard block
 block discarded – undo
1194 1194
                     );
1195 1195
                 }
1196 1196
                 $content = apply_filters(
1197
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1197
+                    'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar',
1198 1198
                     $this->{$config['help_sidebar']}()
1199 1199
                 );
1200 1200
                 $this->_current_screen->set_help_sidebar($content);
1201 1201
             }
1202
-            if (! isset($config['help_tabs'])) {
1202
+            if ( ! isset($config['help_tabs'])) {
1203 1203
                 return;
1204 1204
             } //no help tabs for this route
1205 1205
             foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1206 1206
                 // we're here so there ARE help tabs!
1207 1207
                 // make sure we've got what we need
1208
-                if (! isset($cfg['title'])) {
1208
+                if ( ! isset($cfg['title'])) {
1209 1209
                     throw new EE_Error(
1210 1210
                         esc_html__(
1211 1211
                             'The _page_config array is not set up properly for help tabs.  It is missing a title',
@@ -1213,7 +1213,7 @@  discard block
 block discarded – undo
1213 1213
                         )
1214 1214
                     );
1215 1215
                 }
1216
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1216
+                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1217 1217
                     throw new EE_Error(
1218 1218
                         esc_html__(
1219 1219
                             'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
@@ -1222,11 +1222,11 @@  discard block
 block discarded – undo
1222 1222
                     );
1223 1223
                 }
1224 1224
                 // first priority goes to content.
1225
-                if (! empty($cfg['content'])) {
1225
+                if ( ! empty($cfg['content'])) {
1226 1226
                     $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1227 1227
                     // second priority goes to filename
1228
-                } elseif (! empty($cfg['filename'])) {
1229
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1228
+                } elseif ( ! empty($cfg['filename'])) {
1229
+                    $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php';
1230 1230
                     // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1231 1231
                     $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1232 1232
                                                              . basename($this->_get_dir())
@@ -1234,7 +1234,7 @@  discard block
 block discarded – undo
1234 1234
                                                              . $cfg['filename']
1235 1235
                                                              . '.help_tab.php' : $file_path;
1236 1236
                     // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1237
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1237
+                    if ( ! isset($cfg['callback']) && ! is_readable($file_path)) {
1238 1238
                         EE_Error::add_error(
1239 1239
                             sprintf(
1240 1240
                                 esc_html__(
@@ -1282,7 +1282,7 @@  discard block
 block discarded – undo
1282 1282
                     return;
1283 1283
                 }
1284 1284
                 // setup config array for help tab method
1285
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1285
+                $id  = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id;
1286 1286
                 $_ht = [
1287 1287
                     'id'       => $id,
1288 1288
                     'title'    => $cfg['title'],
@@ -1306,8 +1306,8 @@  discard block
 block discarded – undo
1306 1306
             $qtips = (array) $this->_route_config['qtips'];
1307 1307
             // load qtip loader
1308 1308
             $path = [
1309
-                $this->_get_dir() . '/qtips/',
1310
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1309
+                $this->_get_dir().'/qtips/',
1310
+                EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/',
1311 1311
             ];
1312 1312
             EEH_Qtip_Loader::instance()->register($qtips, $path);
1313 1313
         }
@@ -1329,7 +1329,7 @@  discard block
 block discarded – undo
1329 1329
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1330 1330
         $i = 0;
1331 1331
         foreach ($this->_page_config as $slug => $config) {
1332
-            if (! is_array($config) || empty($config['nav'])) {
1332
+            if ( ! is_array($config) || empty($config['nav'])) {
1333 1333
                 continue;
1334 1334
             }
1335 1335
             // no nav tab for this config
@@ -1338,12 +1338,12 @@  discard block
 block discarded – undo
1338 1338
                 // nav tab is only to appear when route requested.
1339 1339
                 continue;
1340 1340
             }
1341
-            if (! $this->check_user_access($slug, true)) {
1341
+            if ( ! $this->check_user_access($slug, true)) {
1342 1342
                 // no nav tab because current user does not have access.
1343 1343
                 continue;
1344 1344
             }
1345
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1346
-            $this->_nav_tabs[ $slug ] = [
1345
+            $css_class                = isset($config['css_class']) ? $config['css_class'].' ' : '';
1346
+            $this->_nav_tabs[$slug] = [
1347 1347
                 'url'       => isset($config['nav']['url'])
1348 1348
                     ? $config['nav']['url']
1349 1349
                     : self::add_query_args_and_nonce(
@@ -1355,14 +1355,14 @@  discard block
 block discarded – undo
1355 1355
                     : ucwords(
1356 1356
                         str_replace('_', ' ', $slug)
1357 1357
                     ),
1358
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1358
+                'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class,
1359 1359
                 'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1360 1360
             ];
1361 1361
             $i++;
1362 1362
         }
1363 1363
         // if $this->_nav_tabs is empty then lets set the default
1364 1364
         if (empty($this->_nav_tabs)) {
1365
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1365
+            $this->_nav_tabs[$this->_default_nav_tab_name] = [
1366 1366
                 'url'       => $this->_admin_base_url,
1367 1367
                 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1368 1368
                 'css_class' => 'nav-tab-active',
@@ -1387,10 +1387,10 @@  discard block
 block discarded – undo
1387 1387
             foreach ($this->_route_config['labels'] as $label => $text) {
1388 1388
                 if (is_array($text)) {
1389 1389
                     foreach ($text as $sublabel => $subtext) {
1390
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1390
+                        $this->_labels[$label][$sublabel] = $subtext;
1391 1391
                     }
1392 1392
                 } else {
1393
-                    $this->_labels[ $label ] = $text;
1393
+                    $this->_labels[$label] = $text;
1394 1394
                 }
1395 1395
             }
1396 1396
         }
@@ -1412,12 +1412,12 @@  discard block
 block discarded – undo
1412 1412
     {
1413 1413
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1414 1414
         $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1415
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1415
+        $capability     = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check])
1416 1416
                           && is_array(
1417
-                              $this->_page_routes[ $route_to_check ]
1417
+                              $this->_page_routes[$route_to_check]
1418 1418
                           )
1419
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1420
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1419
+                          && ! empty($this->_page_routes[$route_to_check]['capability'])
1420
+            ? $this->_page_routes[$route_to_check]['capability'] : null;
1421 1421
         if (empty($capability) && empty($route_to_check)) {
1422 1422
             $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1423 1423
                 : $this->_route['capability'];
@@ -1537,7 +1537,7 @@  discard block
 block discarded – undo
1537 1537
         ';
1538 1538
 
1539 1539
         // current set timezone for timezone js
1540
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1540
+        echo '<span id="current_timezone" class="hidden">'.esc_html(EEH_DTT_Helper::get_timezone()).'</span>';
1541 1541
     }
1542 1542
 
1543 1543
 
@@ -1571,7 +1571,7 @@  discard block
 block discarded – undo
1571 1571
         // loop through the array and setup content
1572 1572
         foreach ($help_array as $trigger => $help) {
1573 1573
             // make sure the array is setup properly
1574
-            if (! isset($help['title']) || ! isset($help['content'])) {
1574
+            if ( ! isset($help['title']) || ! isset($help['content'])) {
1575 1575
                 throw new EE_Error(
1576 1576
                     esc_html__(
1577 1577
                         'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
@@ -1585,8 +1585,8 @@  discard block
 block discarded – undo
1585 1585
                 'help_popup_title'   => $help['title'],
1586 1586
                 'help_popup_content' => $help['content'],
1587 1587
             ];
1588
-            $content       .= EEH_Template::display_template(
1589
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1588
+            $content .= EEH_Template::display_template(
1589
+                EE_ADMIN_TEMPLATE.'admin_help_popup.template.php',
1590 1590
                 $template_args,
1591 1591
                 true
1592 1592
             );
@@ -1608,15 +1608,15 @@  discard block
 block discarded – undo
1608 1608
     private function _get_help_content()
1609 1609
     {
1610 1610
         // what is the method we're looking for?
1611
-        $method_name = '_help_popup_content_' . $this->_req_action;
1611
+        $method_name = '_help_popup_content_'.$this->_req_action;
1612 1612
         // if method doesn't exist let's get out.
1613
-        if (! method_exists($this, $method_name)) {
1613
+        if ( ! method_exists($this, $method_name)) {
1614 1614
             return [];
1615 1615
         }
1616 1616
         // k we're good to go let's retrieve the help array
1617 1617
         $help_array = call_user_func([$this, $method_name]);
1618 1618
         // make sure we've got an array!
1619
-        if (! is_array($help_array)) {
1619
+        if ( ! is_array($help_array)) {
1620 1620
             throw new EE_Error(
1621 1621
                 esc_html__(
1622 1622
                     'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
@@ -1648,15 +1648,15 @@  discard block
 block discarded – undo
1648 1648
         // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1649 1649
         $help_array   = $this->_get_help_content();
1650 1650
         $help_content = '';
1651
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1652
-            $help_array[ $trigger_id ] = [
1651
+        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1652
+            $help_array[$trigger_id] = [
1653 1653
                 'title'   => esc_html__('Missing Content', 'event_espresso'),
1654 1654
                 'content' => esc_html__(
1655 1655
                     'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1656 1656
                     'event_espresso'
1657 1657
                 ),
1658 1658
             ];
1659
-            $help_content              = $this->_set_help_popup_content($help_array);
1659
+            $help_content = $this->_set_help_popup_content($help_array);
1660 1660
         }
1661 1661
         // let's setup the trigger
1662 1662
         $content = '<a class="ee-dialog" href="?height='
@@ -1724,15 +1724,15 @@  discard block
 block discarded – undo
1724 1724
         // register all styles
1725 1725
         wp_register_style(
1726 1726
             'espresso-ui-theme',
1727
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1727
+            EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1728 1728
             [],
1729 1729
             EVENT_ESPRESSO_VERSION
1730 1730
         );
1731
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1731
+        wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1732 1732
         // helpers styles
1733 1733
         wp_register_style(
1734 1734
             'ee-text-links',
1735
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1735
+            EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css',
1736 1736
             [],
1737 1737
             EVENT_ESPRESSO_VERSION
1738 1738
         );
@@ -1740,21 +1740,21 @@  discard block
 block discarded – undo
1740 1740
         // register all scripts
1741 1741
         wp_register_script(
1742 1742
             'ee-dialog',
1743
-            EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1743
+            EE_ADMIN_URL.'assets/ee-dialog-helper.js',
1744 1744
             ['jquery', 'jquery-ui-draggable'],
1745 1745
             EVENT_ESPRESSO_VERSION,
1746 1746
             true
1747 1747
         );
1748 1748
         wp_register_script(
1749 1749
             'ee_admin_js',
1750
-            EE_ADMIN_URL . 'assets/ee-admin-page.js',
1750
+            EE_ADMIN_URL.'assets/ee-admin-page.js',
1751 1751
             ['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1752 1752
             EVENT_ESPRESSO_VERSION,
1753 1753
             true
1754 1754
         );
1755 1755
         wp_register_script(
1756 1756
             'jquery-ui-timepicker-addon',
1757
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1757
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js',
1758 1758
             ['jquery-ui-datepicker', 'jquery-ui-slider'],
1759 1759
             EVENT_ESPRESSO_VERSION,
1760 1760
             true
@@ -1762,7 +1762,7 @@  discard block
 block discarded – undo
1762 1762
         // script for sorting tables
1763 1763
         wp_register_script(
1764 1764
             'espresso_ajax_table_sorting',
1765
-            EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1765
+            EE_ADMIN_URL.'assets/espresso_ajax_table_sorting.js',
1766 1766
             ['ee_admin_js', 'jquery-ui-sortable'],
1767 1767
             EVENT_ESPRESSO_VERSION,
1768 1768
             true
@@ -1770,7 +1770,7 @@  discard block
 block discarded – undo
1770 1770
         // script for parsing uri's
1771 1771
         wp_register_script(
1772 1772
             'ee-parse-uri',
1773
-            EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1773
+            EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js',
1774 1774
             [],
1775 1775
             EVENT_ESPRESSO_VERSION,
1776 1776
             true
@@ -1778,7 +1778,7 @@  discard block
 block discarded – undo
1778 1778
         // and parsing associative serialized form elements
1779 1779
         wp_register_script(
1780 1780
             'ee-serialize-full-array',
1781
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1781
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js',
1782 1782
             ['jquery'],
1783 1783
             EVENT_ESPRESSO_VERSION,
1784 1784
             true
@@ -1786,28 +1786,28 @@  discard block
 block discarded – undo
1786 1786
         // helpers scripts
1787 1787
         wp_register_script(
1788 1788
             'ee-text-links',
1789
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1789
+            EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js',
1790 1790
             ['jquery'],
1791 1791
             EVENT_ESPRESSO_VERSION,
1792 1792
             true
1793 1793
         );
1794 1794
         wp_register_script(
1795 1795
             'ee-moment-core',
1796
-            EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1796
+            EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js',
1797 1797
             [],
1798 1798
             EVENT_ESPRESSO_VERSION,
1799 1799
             true
1800 1800
         );
1801 1801
         wp_register_script(
1802 1802
             'ee-moment',
1803
-            EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1803
+            EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js',
1804 1804
             ['ee-moment-core'],
1805 1805
             EVENT_ESPRESSO_VERSION,
1806 1806
             true
1807 1807
         );
1808 1808
         wp_register_script(
1809 1809
             'ee-datepicker',
1810
-            EE_ADMIN_URL . 'assets/ee-datepicker.js',
1810
+            EE_ADMIN_URL.'assets/ee-datepicker.js',
1811 1811
             ['jquery-ui-timepicker-addon', 'ee-moment'],
1812 1812
             EVENT_ESPRESSO_VERSION,
1813 1813
             true
@@ -1840,7 +1840,7 @@  discard block
 block discarded – undo
1840 1840
         wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1841 1841
         add_filter(
1842 1842
             'admin_body_class',
1843
-            function ($classes) {
1843
+            function($classes) {
1844 1844
                 if (strpos($classes, 'espresso-admin') === false) {
1845 1845
                     $classes .= ' espresso-admin';
1846 1846
                 }
@@ -1928,12 +1928,12 @@  discard block
 block discarded – undo
1928 1928
     protected function _set_list_table()
1929 1929
     {
1930 1930
         // first is this a list_table view?
1931
-        if (! isset($this->_route_config['list_table'])) {
1931
+        if ( ! isset($this->_route_config['list_table'])) {
1932 1932
             return;
1933 1933
         } //not a list_table view so get out.
1934 1934
         // list table functions are per view specific (because some admin pages might have more than one list table!)
1935
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
1936
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1935
+        $list_table_view = '_set_list_table_views_'.$this->_req_action;
1936
+        if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
1937 1937
             // user error msg
1938 1938
             $error_msg = esc_html__(
1939 1939
                 'An error occurred. The requested list table views could not be found.',
@@ -1953,10 +1953,10 @@  discard block
 block discarded – undo
1953 1953
         }
1954 1954
         // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1955 1955
         $this->_views = apply_filters(
1956
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
1956
+            'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action,
1957 1957
             $this->_views
1958 1958
         );
1959
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1959
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views);
1960 1960
         $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1961 1961
         $this->_set_list_table_view();
1962 1962
         $this->_set_list_table_object();
@@ -1991,7 +1991,7 @@  discard block
 block discarded – undo
1991 1991
     protected function _set_list_table_object()
1992 1992
     {
1993 1993
         if (isset($this->_route_config['list_table'])) {
1994
-            if (! class_exists($this->_route_config['list_table'])) {
1994
+            if ( ! class_exists($this->_route_config['list_table'])) {
1995 1995
                 throw new EE_Error(
1996 1996
                     sprintf(
1997 1997
                         esc_html__(
@@ -2029,15 +2029,15 @@  discard block
 block discarded – undo
2029 2029
         foreach ($this->_views as $key => $view) {
2030 2030
             $query_args = [];
2031 2031
             // check for current view
2032
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2032
+            $this->_views[$key]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2033 2033
             $query_args['action']                        = $this->_req_action;
2034
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2034
+            $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce');
2035 2035
             $query_args['status']                        = $view['slug'];
2036 2036
             // merge any other arguments sent in.
2037
-            if (isset($extra_query_args[ $view['slug'] ])) {
2038
-                $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2037
+            if (isset($extra_query_args[$view['slug']])) {
2038
+                $query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
2039 2039
             }
2040
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2040
+            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2041 2041
         }
2042 2042
         return $this->_views;
2043 2043
     }
@@ -2068,14 +2068,14 @@  discard block
 block discarded – undo
2068 2068
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2069 2069
         foreach ($values as $value) {
2070 2070
             if ($value < $max_entries) {
2071
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2071
+                $selected = $value === $per_page ? ' selected="'.$per_page.'"' : '';
2072 2072
                 $entries_per_page_dropdown .= '
2073
-						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2073
+						<option value="' . $value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
2074 2074
             }
2075 2075
         }
2076
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2076
+        $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : '';
2077 2077
         $entries_per_page_dropdown .= '
2078
-						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2078
+						<option value="' . $max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
2079 2079
         $entries_per_page_dropdown .= '
2080 2080
 					</select>
2081 2081
 					entries
@@ -2099,7 +2099,7 @@  discard block
 block discarded – undo
2099 2099
             empty($this->_search_btn_label) ? $this->page_label
2100 2100
                 : $this->_search_btn_label
2101 2101
         );
2102
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2102
+        $this->_template_args['search']['callback'] = 'search_'.$this->page_slug;
2103 2103
     }
2104 2104
 
2105 2105
 
@@ -2187,7 +2187,7 @@  discard block
 block discarded – undo
2187 2187
             $total_columns                                       = ! empty($screen_columns)
2188 2188
                 ? $screen_columns
2189 2189
                 : $this->_route_config['columns'][1];
2190
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2190
+            $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns;
2191 2191
             $this->_template_args['current_page']                = $this->_wp_page_slug;
2192 2192
             $this->_template_args['screen']                      = $this->_current_screen;
2193 2193
             $this->_column_template_path                         = EE_ADMIN_TEMPLATE
@@ -2232,7 +2232,7 @@  discard block
 block discarded – undo
2232 2232
      */
2233 2233
     protected function _espresso_ratings_request()
2234 2234
     {
2235
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2235
+        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2236 2236
             return;
2237 2237
         }
2238 2238
         $ratings_box_title = apply_filters(
@@ -2260,7 +2260,7 @@  discard block
 block discarded – undo
2260 2260
     public function espresso_ratings_request()
2261 2261
     {
2262 2262
         EEH_Template::display_template(
2263
-            EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2263
+            EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php',
2264 2264
             []
2265 2265
         );
2266 2266
     }
@@ -2268,22 +2268,22 @@  discard block
 block discarded – undo
2268 2268
 
2269 2269
     public static function cached_rss_display($rss_id, $url)
2270 2270
     {
2271
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2271
+        $loading = '<p class="widget-loading hide-if-no-js">'
2272 2272
                      . esc_html__('Loading&#8230;', 'event_espresso')
2273 2273
                      . '</p><p class="hide-if-js">'
2274 2274
                      . esc_html__('This widget requires JavaScript.', 'event_espresso')
2275 2275
                      . '</p>';
2276
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2277
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2278
-        $post      = '</div>' . "\n";
2279
-        $cache_key = 'ee_rss_' . md5($rss_id);
2276
+        $pre       = '<div class="espresso-rss-display">'."\n\t";
2277
+        $pre .= '<span id="'.esc_attr($rss_id).'_url" class="hidden">'.esc_url_raw($url).'</span>';
2278
+        $post      = '</div>'."\n";
2279
+        $cache_key = 'ee_rss_'.md5($rss_id);
2280 2280
         $output    = get_transient($cache_key);
2281 2281
         if ($output !== false) {
2282
-            echo $pre . $output . $post; // already escaped
2282
+            echo $pre.$output.$post; // already escaped
2283 2283
             return true;
2284 2284
         }
2285
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2286
-            echo $pre . $loading . $post; // already escaped
2285
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
2286
+            echo $pre.$loading.$post; // already escaped
2287 2287
             return false;
2288 2288
         }
2289 2289
         ob_start();
@@ -2350,19 +2350,19 @@  discard block
 block discarded – undo
2350 2350
     public function espresso_sponsors_post_box()
2351 2351
     {
2352 2352
         EEH_Template::display_template(
2353
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2353
+            EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php'
2354 2354
         );
2355 2355
     }
2356 2356
 
2357 2357
 
2358 2358
     private function _publish_post_box()
2359 2359
     {
2360
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2360
+        $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview';
2361 2361
         // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2362 2362
         // then we'll use that for the metabox label.
2363 2363
         // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2364
-        if (! empty($this->_labels['publishbox'])) {
2365
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2364
+        if ( ! empty($this->_labels['publishbox'])) {
2365
+            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action]
2366 2366
                 : $this->_labels['publishbox'];
2367 2367
         } else {
2368 2368
             $box_label = esc_html__('Publish', 'event_espresso');
@@ -2391,7 +2391,7 @@  discard block
 block discarded – undo
2391 2391
             ? $this->_template_args['publish_box_extra_content']
2392 2392
             : '';
2393 2393
         echo EEH_Template::display_template(
2394
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2394
+            EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php',
2395 2395
             $this->_template_args,
2396 2396
             true
2397 2397
         );
@@ -2483,18 +2483,18 @@  discard block
 block discarded – undo
2483 2483
             );
2484 2484
         }
2485 2485
         $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2486
-        if (! empty($name) && ! empty($id)) {
2487
-            $hidden_field_arr[ $name ] = [
2486
+        if ( ! empty($name) && ! empty($id)) {
2487
+            $hidden_field_arr[$name] = [
2488 2488
                 'type'  => 'hidden',
2489 2489
                 'value' => $id,
2490 2490
             ];
2491
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2491
+            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2492 2492
         } else {
2493 2493
             $hf = '';
2494 2494
         }
2495 2495
         // add hidden field
2496 2496
         $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2497
-            ? $hf[ $name ]['field']
2497
+            ? $hf[$name]['field']
2498 2498
             : $hf;
2499 2499
     }
2500 2500
 
@@ -2596,7 +2596,7 @@  discard block
 block discarded – undo
2596 2596
         }
2597 2597
         // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2598 2598
         $call_back_func = $create_func
2599
-            ? function ($post, $metabox) {
2599
+            ? function($post, $metabox) {
2600 2600
                 do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2601 2601
                 echo EEH_Template::display_template(
2602 2602
                     $metabox['args']['template_path'],
@@ -2606,7 +2606,7 @@  discard block
 block discarded – undo
2606 2606
             }
2607 2607
             : $callback;
2608 2608
         add_meta_box(
2609
-            str_replace('_', '-', $action) . '-mbox',
2609
+            str_replace('_', '-', $action).'-mbox',
2610 2610
             $title,
2611 2611
             $call_back_func,
2612 2612
             $this->_wp_page_slug,
@@ -2698,9 +2698,9 @@  discard block
 block discarded – undo
2698 2698
             : 'espresso-default-admin';
2699 2699
         $template_path                                     = $sidebar
2700 2700
             ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2701
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2701
+            : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php';
2702 2702
         if ($this->request->isAjax()) {
2703
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2703
+            $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php';
2704 2704
         }
2705 2705
         $template_path                                     = ! empty($this->_column_template_path)
2706 2706
             ? $this->_column_template_path : $template_path;
@@ -2740,11 +2740,11 @@  discard block
 block discarded – undo
2740 2740
     public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2741 2741
     {
2742 2742
         // let's generate a default preview action button if there isn't one already present.
2743
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2743
+        $this->_labels['buttons']['buy_now'] = esc_html__(
2744 2744
             'Upgrade to Event Espresso 4 Right Now',
2745 2745
             'event_espresso'
2746 2746
         );
2747
-        $buy_now_url                                   = add_query_arg(
2747
+        $buy_now_url = add_query_arg(
2748 2748
             [
2749 2749
                 'ee_ver'       => 'ee4',
2750 2750
                 'utm_source'   => 'ee4_plugin_admin',
@@ -2764,8 +2764,8 @@  discard block
 block discarded – undo
2764 2764
                 true
2765 2765
             )
2766 2766
             : $this->_template_args['preview_action_button'];
2767
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2768
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2767
+        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2768
+            EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php',
2769 2769
             $this->_template_args,
2770 2770
             true
2771 2771
         );
@@ -2814,7 +2814,7 @@  discard block
 block discarded – undo
2814 2814
         // setup search attributes
2815 2815
         $this->_set_search_attributes();
2816 2816
         $this->_template_args['current_page']     = $this->_wp_page_slug;
2817
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2817
+        $template_path                            = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php';
2818 2818
         $this->_template_args['table_url']        = $this->request->isAjax()
2819 2819
             ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2820 2820
             : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
@@ -2822,10 +2822,10 @@  discard block
 block discarded – undo
2822 2822
         $this->_template_args['current_route']    = $this->_req_action;
2823 2823
         $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2824 2824
         $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2825
-        if (! empty($ajax_sorting_callback)) {
2825
+        if ( ! empty($ajax_sorting_callback)) {
2826 2826
             $sortable_list_table_form_fields = wp_nonce_field(
2827
-                $ajax_sorting_callback . '_nonce',
2828
-                $ajax_sorting_callback . '_nonce',
2827
+                $ajax_sorting_callback.'_nonce',
2828
+                $ajax_sorting_callback.'_nonce',
2829 2829
                 false,
2830 2830
                 false
2831 2831
             );
@@ -2843,20 +2843,20 @@  discard block
 block discarded – undo
2843 2843
             isset($this->_template_args['list_table_hidden_fields'])
2844 2844
                 ? $this->_template_args['list_table_hidden_fields']
2845 2845
                 : '';
2846
-        $nonce_ref                                               = $this->_req_action . '_nonce';
2847
-        $hidden_form_fields                                      .= '<input type="hidden" name="'
2846
+        $nonce_ref = $this->_req_action.'_nonce';
2847
+        $hidden_form_fields .= '<input type="hidden" name="'
2848 2848
                                                                     . $nonce_ref
2849 2849
                                                                     . '" value="'
2850 2850
                                                                     . wp_create_nonce($nonce_ref)
2851 2851
                                                                     . '">';
2852
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2852
+        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2853 2853
         // display message about search results?
2854 2854
         $search = $this->request->getRequestParam('s');
2855 2855
         $this->_template_args['before_list_table'] .= ! empty($search)
2856
-            ? '<p class="ee-search-results">' . sprintf(
2856
+            ? '<p class="ee-search-results">'.sprintf(
2857 2857
                 esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2858 2858
                 trim($search, '%')
2859
-            ) . '</p>'
2859
+            ).'</p>'
2860 2860
             : '';
2861 2861
         // filter before_list_table template arg
2862 2862
         $this->_template_args['before_list_table'] = apply_filters(
@@ -2890,7 +2890,7 @@  discard block
 block discarded – undo
2890 2890
         // convert to array and filter again
2891 2891
         // arrays are easier to inject new items in a specific location,
2892 2892
         // but would not be backwards compatible, so we have to add a new filter
2893
-        $this->_template_args['after_list_table']   = implode(
2893
+        $this->_template_args['after_list_table'] = implode(
2894 2894
             " \n",
2895 2895
             (array) apply_filters(
2896 2896
                 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
@@ -2937,7 +2937,7 @@  discard block
 block discarded – undo
2937 2937
             $this
2938 2938
         );
2939 2939
         return EEH_Template::display_template(
2940
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
2940
+            EE_ADMIN_TEMPLATE.'admin_details_legend.template.php',
2941 2941
             $this->_template_args,
2942 2942
             true
2943 2943
         );
@@ -3046,18 +3046,18 @@  discard block
 block discarded – undo
3046 3046
                 : ''
3047 3047
         );
3048 3048
 
3049
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3049
+        $this->_template_args['after_admin_page_content'] = apply_filters(
3050 3050
             "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3051 3051
             isset($this->_template_args['after_admin_page_content'])
3052 3052
                 ? $this->_template_args['after_admin_page_content']
3053 3053
                 : ''
3054 3054
         );
3055
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3055
+        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3056 3056
 
3057 3057
         if ($this->request->isAjax()) {
3058 3058
             $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3059 3059
                 // $template_path,
3060
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3060
+                EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php',
3061 3061
                 $this->_template_args,
3062 3062
                 true
3063 3063
             );
@@ -3066,7 +3066,7 @@  discard block
 block discarded – undo
3066 3066
         // load settings page wrapper template
3067 3067
         $template_path = $about
3068 3068
             ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3069
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3069
+            : EE_ADMIN_TEMPLATE.'admin_wrapper.template.php';
3070 3070
 
3071 3071
         EEH_Template::display_template($template_path, $this->_template_args);
3072 3072
     }
@@ -3151,12 +3151,12 @@  discard block
 block discarded – undo
3151 3151
         $default_names = ['save', 'save_and_close'];
3152 3152
         $buttons = '';
3153 3153
         foreach ($button_text as $key => $button) {
3154
-            $ref     = $default_names[ $key ];
3155
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3156
-            $buttons .= '<input type="submit" class="button-primary ' . $ref . '" '
3157
-                        . 'value="' . $button . '" name="' . $name . '" '
3158
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3159
-            if (! $both) {
3154
+            $ref     = $default_names[$key];
3155
+            $name    = ! empty($actions) ? $actions[$key] : $ref;
3156
+            $buttons .= '<input type="submit" class="button-primary '.$ref.'" '
3157
+                        . 'value="'.$button.'" name="'.$name.'" '
3158
+                        . 'id="'.$this->_current_view.'_'.$ref.'" />';
3159
+            if ( ! $both) {
3160 3160
                 break;
3161 3161
             }
3162 3162
         }
@@ -3196,13 +3196,13 @@  discard block
 block discarded – undo
3196 3196
                 'An error occurred. No action was set for this page\'s form.',
3197 3197
                 'event_espresso'
3198 3198
             );
3199
-            $dev_msg  = $user_msg . "\n"
3199
+            $dev_msg = $user_msg."\n"
3200 3200
                         . sprintf(
3201 3201
                             esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3202 3202
                             __FUNCTION__,
3203 3203
                             __CLASS__
3204 3204
                         );
3205
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3205
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
3206 3206
         }
3207 3207
         // open form
3208 3208
         $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
@@ -3211,9 +3211,9 @@  discard block
 block discarded – undo
3211 3211
                                                              . $route
3212 3212
                                                              . '_event_form" >';
3213 3213
         // add nonce
3214
-        $nonce                                             =
3215
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3216
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3214
+        $nonce =
3215
+            wp_nonce_field($route.'_nonce', $route.'_nonce', false, false);
3216
+        $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce;
3217 3217
         // add REQUIRED form action
3218 3218
         $hidden_fields = [
3219 3219
             'action' => ['type' => 'hidden', 'value' => $route],
@@ -3226,7 +3226,7 @@  discard block
 block discarded – undo
3226 3226
         $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3227 3227
         // add fields to form
3228 3228
         foreach ((array) $form_fields as $form_field) {
3229
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3229
+            $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field'];
3230 3230
         }
3231 3231
         // close form
3232 3232
         $this->_template_args['after_admin_page_content'] = '</form>';
@@ -3317,10 +3317,10 @@  discard block
 block discarded – undo
3317 3317
         $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3318 3318
         $notices      = EE_Error::get_notices(false);
3319 3319
         // overwrite default success messages //BUT ONLY if overwrite not overridden
3320
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3320
+        if ( ! $override_overwrite || ! empty($notices['errors'])) {
3321 3321
             EE_Error::overwrite_success();
3322 3322
         }
3323
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3323
+        if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3324 3324
             // how many records affected ? more than one record ? or just one ?
3325 3325
             if ($success > 1) {
3326 3326
                 // set plural msg
@@ -3349,7 +3349,7 @@  discard block
 block discarded – undo
3349 3349
             }
3350 3350
         }
3351 3351
         // check that $query_args isn't something crazy
3352
-        if (! is_array($query_args)) {
3352
+        if ( ! is_array($query_args)) {
3353 3353
             $query_args = [];
3354 3354
         }
3355 3355
         /**
@@ -3378,7 +3378,7 @@  discard block
 block discarded – undo
3378 3378
             $redirect_url = admin_url('admin.php');
3379 3379
         }
3380 3380
         // merge any default query_args set in _default_route_query_args property
3381
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3381
+        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3382 3382
             $args_to_merge = [];
3383 3383
             foreach ($this->_default_route_query_args as $query_param => $query_value) {
3384 3384
                 // is there a wp_referer array in our _default_route_query_args property?
@@ -3390,15 +3390,15 @@  discard block
 block discarded – undo
3390 3390
                         }
3391 3391
                         // finally we will override any arguments in the referer with
3392 3392
                         // what might be set on the _default_route_query_args array.
3393
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3394
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3393
+                        if (isset($this->_default_route_query_args[$reference])) {
3394
+                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
3395 3395
                         } else {
3396
-                            $args_to_merge[ $reference ] = urlencode($value);
3396
+                            $args_to_merge[$reference] = urlencode($value);
3397 3397
                         }
3398 3398
                     }
3399 3399
                     continue;
3400 3400
                 }
3401
-                $args_to_merge[ $query_param ] = $query_value;
3401
+                $args_to_merge[$query_param] = $query_value;
3402 3402
             }
3403 3403
             // now let's merge these arguments but override with what was specifically sent in to the
3404 3404
             // redirect.
@@ -3410,19 +3410,19 @@  discard block
 block discarded – undo
3410 3410
         if (isset($query_args['action'])) {
3411 3411
             // manually generate wp_nonce and merge that with the query vars
3412 3412
             // becuz the wp_nonce_url function wrecks havoc on some vars
3413
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3413
+            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce');
3414 3414
         }
3415 3415
         // we're adding some hooks and filters in here for processing any things just before redirects
3416 3416
         // (example: an admin page has done an insert or update and we want to run something after that).
3417
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3417
+        do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args);
3418 3418
         $redirect_url = apply_filters(
3419
-            'FHEE_redirect_' . $classname . $this->_req_action,
3419
+            'FHEE_redirect_'.$classname.$this->_req_action,
3420 3420
             self::add_query_args_and_nonce($query_args, $redirect_url),
3421 3421
             $query_args
3422 3422
         );
3423 3423
         // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3424 3424
         if ($this->request->isAjax()) {
3425
-            $default_data                    = [
3425
+            $default_data = [
3426 3426
                 'close'        => true,
3427 3427
                 'redirect_url' => $redirect_url,
3428 3428
                 'where'        => 'main',
@@ -3469,7 +3469,7 @@  discard block
 block discarded – undo
3469 3469
         }
3470 3470
         $this->_template_args['notices'] = EE_Error::get_notices();
3471 3471
         // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3472
-        if (! $this->request->isAjax() || $sticky_notices) {
3472
+        if ( ! $this->request->isAjax() || $sticky_notices) {
3473 3473
             $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3474 3474
             $this->_add_transient(
3475 3475
                 $route,
@@ -3509,7 +3509,7 @@  discard block
 block discarded – undo
3509 3509
         $exclude_nonce = false
3510 3510
     ) {
3511 3511
         // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3512
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3512
+        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
3513 3513
             throw new EE_Error(
3514 3514
                 sprintf(
3515 3515
                     esc_html__(
@@ -3520,7 +3520,7 @@  discard block
 block discarded – undo
3520 3520
                 )
3521 3521
             );
3522 3522
         }
3523
-        if (! isset($this->_labels['buttons'][ $type ])) {
3523
+        if ( ! isset($this->_labels['buttons'][$type])) {
3524 3524
             throw new EE_Error(
3525 3525
                 sprintf(
3526 3526
                     esc_html__(
@@ -3533,7 +3533,7 @@  discard block
 block discarded – undo
3533 3533
         }
3534 3534
         // finally check user access for this button.
3535 3535
         $has_access = $this->check_user_access($action, true);
3536
-        if (! $has_access) {
3536
+        if ( ! $has_access) {
3537 3537
             return '';
3538 3538
         }
3539 3539
         $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
@@ -3541,11 +3541,11 @@  discard block
 block discarded – undo
3541 3541
             'action' => $action,
3542 3542
         ];
3543 3543
         // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3544
-        if (! empty($extra_request)) {
3544
+        if ( ! empty($extra_request)) {
3545 3545
             $query_args = array_merge($extra_request, $query_args);
3546 3546
         }
3547 3547
         $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3548
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3548
+        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
3549 3549
     }
3550 3550
 
3551 3551
 
@@ -3571,7 +3571,7 @@  discard block
 block discarded – undo
3571 3571
                 'FHEE__EE_Admin_Page___per_page_screen_options__default',
3572 3572
                 20
3573 3573
             ),
3574
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3574
+            'option'  => $this->_current_page.'_'.$this->_current_view.'_per_page',
3575 3575
         ];
3576 3576
         // ONLY add the screen option if the user has access to it.
3577 3577
         if ($this->check_user_access($this->_current_view, true)) {
@@ -3592,18 +3592,18 @@  discard block
 block discarded – undo
3592 3592
     {
3593 3593
         if ($this->request->requestParamIsSet('wp_screen_options')) {
3594 3594
             check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3595
-            if (! $user = wp_get_current_user()) {
3595
+            if ( ! $user = wp_get_current_user()) {
3596 3596
                 return;
3597 3597
             }
3598 3598
             $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3599
-            if (! $option) {
3599
+            if ( ! $option) {
3600 3600
                 return;
3601 3601
             }
3602
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3602
+            $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3603 3603
             $map_option = $option;
3604 3604
             $option     = str_replace('-', '_', $option);
3605 3605
             switch ($map_option) {
3606
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3606
+                case $this->_current_page.'_'.$this->_current_view.'_per_page':
3607 3607
                     $max_value = apply_filters(
3608 3608
                         'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3609 3609
                         999,
@@ -3660,13 +3660,13 @@  discard block
 block discarded – undo
3660 3660
     protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3661 3661
     {
3662 3662
         $user_id = get_current_user_id();
3663
-        if (! $skip_route_verify) {
3663
+        if ( ! $skip_route_verify) {
3664 3664
             $this->_verify_route($route);
3665 3665
         }
3666 3666
         // now let's set the string for what kind of transient we're setting
3667 3667
         $transient = $notices
3668
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3669
-            : 'rte_tx_' . $route . '_' . $user_id;
3668
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3669
+            : 'rte_tx_'.$route.'_'.$user_id;
3670 3670
         $data      = $notices ? ['notices' => $data] : $data;
3671 3671
         // is there already a transient for this route?  If there is then let's ADD to that transient
3672 3672
         $existing = is_multisite() && is_network_admin()
@@ -3695,8 +3695,8 @@  discard block
 block discarded – undo
3695 3695
         $user_id   = get_current_user_id();
3696 3696
         $route     = ! $route ? $this->_req_action : $route;
3697 3697
         $transient = $notices
3698
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3699
-            : 'rte_tx_' . $route . '_' . $user_id;
3698
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3699
+            : 'rte_tx_'.$route.'_'.$user_id;
3700 3700
         $data      = is_multisite() && is_network_admin()
3701 3701
             ? get_site_transient($transient)
3702 3702
             : get_transient($transient);
@@ -3927,7 +3927,7 @@  discard block
 block discarded – undo
3927 3927
      */
3928 3928
     protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3929 3929
     {
3930
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3930
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3931 3931
     }
3932 3932
 
3933 3933
 
@@ -3940,7 +3940,7 @@  discard block
 block discarded – undo
3940 3940
      */
3941 3941
     protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3942 3942
     {
3943
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3943
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3944 3944
     }
3945 3945
 
3946 3946
 
Please login to merge, or discard this patch.
templates/txn_admin_details_main_meta_box_txn_details.template.php 1 patch
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -80,25 +80,25 @@  discard block
 block discarded – undo
80 80
     </div>
81 81
     <br class="clear" />
82 82
     <?php
83
-    $no_payments = $grand_raw_total > 0
84
-                   || $TXN_status !== EEM_Transaction::complete_status_code
85
-                   || ! empty($payments);
86
-    ?>
83
+	$no_payments = $grand_raw_total > 0
84
+				   || $TXN_status !== EEM_Transaction::complete_status_code
85
+				   || ! empty($payments);
86
+	?>
87 87
     <?php if ($attendee instanceof EE_Attendee && $no_payments) : ?>
88 88
         <?php $no_payment_text = $can_edit_payments
89
-            ? esc_html__(
90
-                'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.',
91
-                'event_espresso'
92
-            )
93
-            : esc_html__(
94
-                'No payments have been applied to this transaction yet.',
95
-                'event_espresso'
96
-            );
97
-        ?>
89
+			? esc_html__(
90
+				'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.',
91
+				'event_espresso'
92
+			)
93
+			: esc_html__(
94
+				'No payments have been applied to this transaction yet.',
95
+				'event_espresso'
96
+			);
97
+		?>
98 98
 
99 99
         <h3 class="admin-primary-mbox-h4 hdr-has-icon">
100 100
             <span class="ee-icon ee-icon-cash"></span><?php
101
-            esc_html_e('Payment Details', 'event_espresso'); ?>
101
+			esc_html_e('Payment Details', 'event_espresso'); ?>
102 102
         </h3>
103 103
 
104 104
         <div class="admin-primary-mbox-tbl-wrap">
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
                         <th class="jst-left"><?php esc_html_e('TXN&nbsp;ID / CHQ&nbsp;#', 'event_espresso'); ?></th>
115 115
                         <th class="jst-left"><?php esc_html_e('P.O. / S.O.&nbsp;#', 'event_espresso'); ?></th>
116 116
                         <th class="jst-left"><?php esc_html_e(
117
-                            'Notes / Extra&nbsp;Accounting',
118
-                            'event_espresso'
119
-                        ); ?></th>
117
+							'Notes / Extra&nbsp;Accounting',
118
+							'event_espresso'
119
+						); ?></th>
120 120
                         <!--<th class="jst-left"><?php esc_html_e('Details', 'event_espresso'); ?></th>-->
121 121
                         <th class="jst-cntr"><?php esc_html_e('Amount', 'event_espresso'); ?></th>
122 122
                     </tr>
@@ -125,15 +125,15 @@  discard block
 block discarded – undo
125 125
                     <?php if ($payments) : ?>
126 126
                         <?php $payment_total = 0; ?>
127 127
                         <?php foreach ($payments as $PAY_ID => $payment) :
128
-                            if (! $payment instanceof EE_Payment) {
129
-                                continue;
130
-                            }
131
-                            $PAY_ID = absint($PAY_ID);
132
-                            $existing_reg_payment_json = isset($existing_reg_payments[ $PAY_ID ])
133
-                                ? wp_json_encode($existing_reg_payments[ $PAY_ID ])
134
-                                : '{}';
135
-                            $escaped_pay_id = esc_attr($PAY_ID);
136
-                            ?>
128
+							if (! $payment instanceof EE_Payment) {
129
+								continue;
130
+							}
131
+							$PAY_ID = absint($PAY_ID);
132
+							$existing_reg_payment_json = isset($existing_reg_payments[ $PAY_ID ])
133
+								? wp_json_encode($existing_reg_payments[ $PAY_ID ])
134
+								: '{}';
135
+							$escaped_pay_id = esc_attr($PAY_ID);
136
+							?>
137 137
                             <tr id="txn-admin-payment-tr-<?php echo $escaped_pay_id; ?>">
138 138
                                 <td>
139 139
                 <span id="payment-status-<?php echo $escaped_pay_id; ?>"
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
                                 <td class=" jst-rght">
175 175
                                     <div id="payment-id-<?php echo $escaped_pay_id; ?>">
176 176
                                         <?php echo $PAY_ID; // sanitized
177
-                                        ?>
177
+										?>
178 178
                                     </div>
179 179
                                 </td>
180 180
                                 <td class=" jst-left">
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
                                     </div>
189 189
                                     <div id="payment-gateway-<?php echo $escaped_pay_id; ?>">
190 190
                                         <?php echo $payment->payment_method() instanceof EE_Payment_Method
191
-                                            ? esc_html($payment->payment_method()->admin_name())
192
-                                            : esc_html__("Unknown", 'event_espresso'); ?>
191
+											? esc_html($payment->payment_method()->admin_name())
192
+											: esc_html__("Unknown", 'event_espresso'); ?>
193 193
                                     </div>
194 194
                                     <div id="payment-gateway-id-<?php echo $escaped_pay_id; ?>"
195 195
                                          class="hidden"
196 196
                                     >
197 197
                                         <?php echo $payment->payment_method() instanceof EE_Payment_Method
198
-                                            ? esc_html($payment->payment_method()->ID())
199
-                                            : 0; ?>
198
+											? esc_html($payment->payment_method()->ID())
199
+											: 0; ?>
200 200
                                     </div>
201 201
                                 </td>
202 202
                                 <td class=" jst-left">
@@ -221,18 +221,18 @@  discard block
 block discarded – undo
221 221
                                 </td>
222 222
                                 <td class=" jst-rght">
223 223
                                     <?php
224
-                                    $payment_class = $payment->amount() > 0
225
-                                        ? 'txn-admin-payment-status-' . $payment->STS_ID()
226
-                                        : 'txn-admin-payment-status-PDC';
227
-                                    ?>
224
+									$payment_class = $payment->amount() > 0
225
+										? 'txn-admin-payment-status-' . $payment->STS_ID()
226
+										: 'txn-admin-payment-status-PDC';
227
+									?>
228 228
                                     <span class="<?php echo esc_attr($payment_class); ?>">
229 229
                                         <span id="payment-amount-<?php echo $escaped_pay_id; ?>" style="display:inline;">
230 230
                                         <?php echo EEH_Template::format_currency(
231
-                                            $payment->amount(),
232
-                                            false,
233
-                                            false
234
-                                        ); // already escaped
235
-                                        ?>
231
+											$payment->amount(),
232
+											false,
233
+											false
234
+										); // already escaped
235
+										?>
236 236
                                         </span>
237 237
                                     </span>
238 238
                                 </td>
@@ -240,9 +240,9 @@  discard block
 block discarded – undo
240 240
                             <?php $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0; ?>
241 241
                         <?php endforeach; ?>
242 242
                         <?php $pay_totals_class = $payment_total > $grand_raw_total
243
-                            ? ' important-notice'
244
-                            : '';
245
-                        ?>
243
+							? ' important-notice'
244
+							: '';
245
+						?>
246 246
                         <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden">
247 247
                             <td class=" jst-rght" colspan="10">
248 248
                                 <span class="important-notice"><?php echo $no_payment_text; // already escaped ?></span>
@@ -254,28 +254,28 @@  discard block
 block discarded – undo
254 254
                             <th class=" jst-rght" colspan="9">
255 255
                         <span id="payments-total-spn">
256 256
                         <?php
257
-                        $overpaid = $payment_total > $grand_raw_total
258
-                            ? '<span id="overpaid">'
259
-                              . __('This transaction has been overpaid ! ', 'event_espresso')
260
-                              . '</span>'
261
-                            : '';
262
-                        echo esc_html(
263
-                            $overpaid
264
-                            . sprintf(
265
-                                __('Payments Total %s', 'event_espresso'),
266
-                                '(' . EE_Registry::instance()->CFG->currency->code . ')'
267
-                            )
268
-                        ); ?>
257
+						$overpaid = $payment_total > $grand_raw_total
258
+							? '<span id="overpaid">'
259
+							  . __('This transaction has been overpaid ! ', 'event_espresso')
260
+							  . '</span>'
261
+							: '';
262
+						echo esc_html(
263
+							$overpaid
264
+							. sprintf(
265
+								__('Payments Total %s', 'event_espresso'),
266
+								'(' . EE_Registry::instance()->CFG->currency->code . ')'
267
+							)
268
+						); ?>
269 269
                         </span>
270 270
                             </th>
271 271
                             <th class=" jst-rght">
272 272
                         <span id="txn-admin-payment-total">
273 273
                         <?php
274
-                        echo EEH_Template::format_currency(
275
-                            $payment_total,
276
-                            false,
277
-                            false
278
-                        ); // already escaped ?>
274
+						echo EEH_Template::format_currency(
275
+							$payment_total,
276
+							false,
277
+							false
278
+						); // already escaped ?>
279 279
                         </span>
280 280
                             </th>
281 281
                         </tr>
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 
359 359
         <ul id="txn-admin-payment-options-ul">
360 360
             <?php if ($can_edit_payments) :
361
-                ?>
361
+				?>
362 362
                 <li>
363 363
                     <a id="display-txn-admin-apply-payment"
364 364
                        class="button-primary no-icon no-hide"
@@ -383,12 +383,12 @@  discard block
 block discarded – undo
383 383
                 </li>
384 384
             <?php endif; ?>
385 385
             <?php
386
-            // Allows extend the fields at actions area.
387
-            do_action(
388
-                'AHEE__txn_admin_details_main_meta_box_txn_details__after_actions_buttons',
389
-                $can_edit_payments
390
-            );
391
-            ?>
386
+			// Allows extend the fields at actions area.
387
+			do_action(
388
+				'AHEE__txn_admin_details_main_meta_box_txn_details__after_actions_buttons',
389
+				$can_edit_payments
390
+			);
391
+			?>
392 392
         </ul>
393 393
         <br class="clear" />
394 394
 
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
             >
400 400
                 <div class="ee-icon ee-icon-cash-add float-left"></div>
401 401
                 <?php
402
-                echo esc_html__('Apply a Payment to Transaction #', 'event_espresso') . esc_html($txn_nmbr['value']); ?>
402
+				echo esc_html__('Apply a Payment to Transaction #', 'event_espresso') . esc_html($txn_nmbr['value']); ?>
403 403
             </h2>
404 404
 
405 405
             <h2 id="admin-modal-dialog-edit-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon"
@@ -407,23 +407,23 @@  discard block
 block discarded – undo
407 407
             >
408 408
                 <div class="ee-icon ee-icon-cash-edit float-left"></div>
409 409
                 <?php
410
-                printf(
411
-                    esc_html__('Edit Payment #%s for Transaction #%s', 'event_espresso'),
412
-                    '<span></span>',
413
-                    $txn_nmbr['value']
414
-                );
415
-                ?>
410
+				printf(
411
+					esc_html__('Edit Payment #%s for Transaction #%s', 'event_espresso'),
412
+					'<span></span>',
413
+					$txn_nmbr['value']
414
+				);
415
+				?>
416 416
             </h2>
417 417
 
418 418
             <h2 id="admin-modal-dialog-edit-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;">
419 419
                 <div class="ee-icon ee-icon-cash-edit float-left"></div>
420 420
                 <?php
421
-                printf(
422
-                    esc_html__('Edit Refund #%s for Transaction #%s', 'event_espresso'),
423
-                    '<span></span>',
424
-                    $txn_nmbr['value']
425
-                );
426
-                ?>
421
+				printf(
422
+					esc_html__('Edit Refund #%s for Transaction #%s', 'event_espresso'),
423
+					'<span></span>',
424
+					$txn_nmbr['value']
425
+				);
426
+				?>
427 427
             </h2>
428 428
 
429 429
             <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon"
@@ -431,9 +431,9 @@  discard block
 block discarded – undo
431 431
             >
432 432
                 <div class="ee-icon ee-icon-cash-remove float-left"></div>
433 433
                 <?php
434
-                echo esc_html__('Apply a Refund to Transaction #', 'event_espresso');
435
-                echo esc_html($txn_nmbr['value']);
436
-                ?>
434
+				echo esc_html__('Apply a Refund to Transaction #', 'event_espresso');
435
+				echo esc_html($txn_nmbr['value']);
436
+				?>
437 437
             </h2>
438 438
 
439 439
             <form name="txn-admin-apply-payment-frm"
@@ -532,29 +532,29 @@  discard block
 block discarded – undo
532 532
                             >
533 533
                                 <?php foreach ($payment_methods as $method) : ?>
534 534
                                     <?php
535
-                                    $selected = $method->slug() == 'cash'
536
-                                        ? ' selected="selected"'
537
-                                        : '';
538
-                                    ?>
535
+									$selected = $method->slug() == 'cash'
536
+										? ' selected="selected"'
537
+										: '';
538
+									?>
539 539
                                     <option id="payment-method-opt-<?php echo esc_attr($method->slug()); ?>"
540 540
                                             value="<?php echo esc_attr($method->ID()); ?>"
541 541
                                         <?php echo $selected; ?>
542 542
                                     >
543 543
                                         <?php
544
-                                        echo esc_html(
545
-                                            sanitize_key($method->admin_desc())
546
-                                                ? substr($method->admin_desc(), 0, 128)
547
-                                                : $method->admin_name()
548
-                                        );
549
-                                        ?>&nbsp;&nbsp;
544
+										echo esc_html(
545
+											sanitize_key($method->admin_desc())
546
+												? substr($method->admin_desc(), 0, 128)
547
+												: $method->admin_name()
548
+										);
549
+										?>&nbsp;&nbsp;
550 550
                                     </option>
551 551
                                 <?php endforeach; ?>
552 552
                             </select>
553 553
                             <p class="description">
554 554
                                 <?php esc_html_e(
555
-                                    'Whether the payment was made via PayPal, Credit Card, Cheque, or Cash',
556
-                                    'event_espresso'
557
-                                ); ?>
555
+									'Whether the payment was made via PayPal, Credit Card, Cheque, or Cash',
556
+									'event_espresso'
557
+								); ?>
558 558
                             </p>
559 559
                         </div>
560 560
 
@@ -562,9 +562,9 @@  discard block
 block discarded – undo
562 562
                             <div class="txn-admin-apply-payment-gw-txn-id-dv admin-modal-dialog-row">
563 563
                                 <label for="txn-admin-payment-txn-id-chq-nmbr-inp" class="">
564 564
                                     <?php esc_html_e(
565
-                                        'TXN ID / CHQ #',
566
-                                        'event_espresso'
567
-                                    ); ?>
565
+										'TXN ID / CHQ #',
566
+										'event_espresso'
567
+									); ?>
568 568
                                 </label>
569 569
                                 <input name="txn_admin_payment[txn_id_chq_nmbr]"
570 570
                                        id="txn-admin-payment-txn-id-chq-nmbr-inp"
@@ -573,9 +573,9 @@  discard block
 block discarded – undo
573 573
                                 />
574 574
                                 <p class="description">
575 575
                                     <?php esc_html_e(
576
-                                        'The Transaction ID sent back from the payment gateway, or the Cheque #',
577
-                                        'event_espresso'
578
-                                    ); ?>
576
+										'The Transaction ID sent back from the payment gateway, or the Cheque #',
577
+										'event_espresso'
578
+									); ?>
579 579
                                 </p>
580 580
                             </div>
581 581
                         </div>
@@ -592,9 +592,9 @@  discard block
 block discarded – undo
592 592
                                 />
593 593
                                 <p class="description">
594 594
                                     <?php esc_html_e(
595
-                                        'The gateway response string (optional)',
596
-                                        'event_espresso'
597
-                                    ); ?>
595
+										'The gateway response string (optional)',
596
+										'event_espresso'
597
+									); ?>
598 598
                                 </p>
599 599
                             </div>
600 600
                         </div>
@@ -603,9 +603,9 @@  discard block
 block discarded – undo
603 603
                             <div class="txn-admin-apply-payment-status-dv admin-modal-dialog-row">
604 604
                                 <label for="txn-admin-payment-status-slct" class="">
605 605
                                     <?php esc_html_e(
606
-                                        'Payment Status',
607
-                                        'event_espresso'
608
-                                    ); ?>
606
+										'Payment Status',
607
+										'event_espresso'
608
+									); ?>
609 609
                                 </label>
610 610
                                 <select name="txn_admin_payment[status]"
611 611
                                         id="txn-admin-payment-status-slct"
@@ -614,10 +614,10 @@  discard block
 block discarded – undo
614 614
                                 >
615 615
                                     <?php foreach ($payment_status as $STS_ID => $STS_code) : ?>
616 616
                                         <?php
617
-                                        $selected = $STS_ID == 'PAP'
618
-                                            ? ' selected="selected"'
619
-                                            : '';
620
-                                        ?>
617
+										$selected = $STS_ID == 'PAP'
618
+											? ' selected="selected"'
619
+											: '';
620
+										?>
621 621
                                         <option id="payment-status-opt-<?php echo esc_attr($STS_ID); ?>"
622 622
                                                 value="<?php echo esc_attr($STS_ID); ?>"
623 623
                                             <?php echo $selected; ?>
@@ -628,10 +628,10 @@  discard block
 block discarded – undo
628 628
                                 </select>
629 629
                                 <p class="description">
630 630
                                     <?php
631
-                                    esc_html_e(
632
-                                        'Whether the payment was approved, cancelled, declined or failed after submission to the gateway',
633
-                                        'event_espresso'
634
-                                    ); ?>
631
+									esc_html_e(
632
+										'Whether the payment was approved, cancelled, declined or failed after submission to the gateway',
633
+										'event_espresso'
634
+									); ?>
635 635
                                 </p>
636 636
                             </div>
637 637
                         </div>
@@ -648,9 +648,9 @@  discard block
 block discarded – undo
648 648
                             />
649 649
                             <p class="description">
650 650
                                 <?php esc_html_e(
651
-                                    'The Purchase or Sales Order Number if any (optional)',
652
-                                    'event_espresso'
653
-                                ); ?>
651
+									'The Purchase or Sales Order Number if any (optional)',
652
+									'event_espresso'
653
+								); ?>
654 654
                             </p>
655 655
                         </div>
656 656
 
@@ -671,9 +671,9 @@  discard block
 block discarded – undo
671 671
                             />
672 672
                             <p class="description">
673 673
                                 <?php esc_html_e(
674
-                                    'An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.',
675
-                                    'event_espresso'
676
-                                ); ?>
674
+									'An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.',
675
+									'event_espresso'
676
+								); ?>
677 677
                             </p>
678 678
                         </div>
679 679
 
@@ -706,12 +706,12 @@  discard block
 block discarded – undo
706 706
                                 <?php esc_html_e('Change Registration Status?', 'event_espresso'); ?>
707 707
                             </label>
708 708
                             <?php
709
-                            echo $status_change_select; // already escaped ?>
709
+							echo $status_change_select; // already escaped ?>
710 710
                             <p class="description">
711 711
                                 <?php esc_html_e(
712
-                                    'If you wish to change the status for the registrations selected above, then select which status from this dropdown.',
713
-                                    'event_espresso'
714
-                                ); ?>
712
+									'If you wish to change the status for the registrations selected above, then select which status from this dropdown.',
713
+									'event_espresso'
714
+								); ?>
715 715
                             </p>
716 716
                             <br />
717 717
                         </div>
@@ -742,14 +742,14 @@  discard block
 block discarded – undo
742 742
                             <br class="clear-float" />
743 743
                             <p class="description">
744 744
                                 <?php printf(
745
-                                    esc_html__(
746
-                                        'By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.',
747
-                                        'event_espresso'
748
-                                    ),
749
-                                    '<strong>',
750
-                                    '</strong>',
751
-                                    '<br />'
752
-                                ); ?>
745
+									esc_html__(
746
+										'By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.',
747
+										'event_espresso'
748
+									),
749
+									'<strong>',
750
+									'</strong>',
751
+									'<br />'
752
+								); ?>
753 753
                             </p>
754 754
                         </div>
755 755
                         <div class="clear"></div>
@@ -814,10 +814,10 @@  discard block
 block discarded – undo
814 814
             >
815 815
                 <span class="ee-icon ee-icon-cash-add"></span>
816 816
                 <?php printf(
817
-                    esc_html__('Delete Payment/Refund for Transaction #', 'event_espresso'),
818
-                    $txn_nmbr['value']
819
-                );
820
-                ?>
817
+					esc_html__('Delete Payment/Refund for Transaction #', 'event_espresso'),
818
+					$txn_nmbr['value']
819
+				);
820
+				?>
821 821
             </h2>
822 822
 
823 823
             <form name="txn-admin-delete-payment-frm"
@@ -853,13 +853,13 @@  discard block
 block discarded – undo
853 853
                             <?php echo $delete_status_change_select; // already escaped ?>
854 854
                             <p class="description">
855 855
                                 <?php printf(
856
-                                    esc_html__(
857
-                                        'If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s',
858
-                                        'event_espresso'
859
-                                    ),
860
-                                    '<strong>',
861
-                                    '</strong>'
862
-                                ); ?>
856
+									esc_html__(
857
+										'If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s',
858
+										'event_espresso'
859
+									),
860
+									'<strong>',
861
+									'</strong>'
862
+								); ?>
863 863
                             </p>
864 864
                         </div>
865 865
 
@@ -874,10 +874,10 @@  discard block
 block discarded – undo
874 874
                             />
875 875
                             <p class="description">
876 876
                                 <?php
877
-                                esc_html_e(
878
-                                    'If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.',
879
-                                    'event_espresso'
880
-                                ); ?>
877
+								esc_html_e(
878
+									'If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.',
879
+									'event_espresso'
880
+								); ?>
881 881
                             </p>
882 882
                         </div>
883 883
                         <div class="clear"></div>
@@ -910,8 +910,8 @@  discard block
 block discarded – undo
910 910
     <?php endif; // $grand_raw_total > 0?>
911 911
 
912 912
     <?php if (WP_DEBUG) {
913
-        $delivered_messages = get_option('EED_Messages__payment', []);
914
-        if (isset($delivered_messages[ $TXN_ID ])) { ?>
913
+		$delivered_messages = get_option('EED_Messages__payment', []);
914
+		if (isset($delivered_messages[ $TXN_ID ])) { ?>
915 915
             <h4 class="admin-primary-mbox-h4 hdr-has-icon">
916 916
                 <span class="dashicons dashicons-email-alt"></span>
917 917
                 <?php esc_html_e('Messages Sent to Primary Registrant', 'event_espresso'); ?>
@@ -923,39 +923,39 @@  discard block
 block discarded – undo
923 923
                             <th class="jst-left"><?php esc_html_e('Date & Time', 'event_espresso'); ?></th>
924 924
                             <th class="jst-left"><?php esc_html_e('Message Type', 'event_espresso'); ?></th>
925 925
                             <th class="jst-left"><?php esc_html_e(
926
-                                'Payment Status Upon Sending',
927
-                                'event_espresso'
928
-                            ); ?></th>
926
+								'Payment Status Upon Sending',
927
+								'event_espresso'
928
+							); ?></th>
929 929
                             <th class="jst-left"><?php esc_html_e('TXN Status Upon Sending', 'event_espresso'); ?></th>
930 930
                         </tr>
931 931
                     </thead>
932 932
                     <tbody>
933 933
                         <?php
934
-                        foreach ($delivered_messages[ $TXN_ID ] as $timestamp => $delivered_message) :
935
-                            ?>
934
+						foreach ($delivered_messages[ $TXN_ID ] as $timestamp => $delivered_message) :
935
+							?>
936 936
                             <tr>
937 937
                                 <td class="jst-left">
938 938
                                     <?php echo esc_html(
939
-                                        date(
940
-                                            get_option('date_format') . ' ' . get_option('time_format'),
941
-                                            ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))
942
-                                        )
943
-                                    ); ?>
939
+										date(
940
+											get_option('date_format') . ' ' . get_option('time_format'),
941
+											($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))
942
+										)
943
+									); ?>
944 944
                                 </td>
945 945
                                 <td class="jst-left"><?php
946
-                                    echo isset($delivered_message['message_type'])
947
-                                        ? esc_html($delivered_message['message_type'])
948
-                                        : ''; ?>
946
+									echo isset($delivered_message['message_type'])
947
+										? esc_html($delivered_message['message_type'])
948
+										: ''; ?>
949 949
                                 </td>
950 950
                                 <td class="jst-left"><?php
951
-                                    echo isset($delivered_message['pay_status'])
952
-                                        ? esc_html($delivered_message['pay_status'])
953
-                                        : ''; ?>
951
+									echo isset($delivered_message['pay_status'])
952
+										? esc_html($delivered_message['pay_status'])
953
+										: ''; ?>
954 954
                                 </td>
955 955
                                 <td class="jst-left"><?php
956
-                                    echo isset($delivered_message['txn_status'])
957
-                                        ? esc_html($delivered_message['txn_status'])
958
-                                        : ''; ?>
956
+									echo isset($delivered_message['txn_status'])
957
+										? esc_html($delivered_message['txn_status'])
958
+										: ''; ?>
959 959
                                 </td>
960 960
                             </tr>
961 961
                         <?php endforeach; // $delivered_messages?>
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
                 </table>
964 964
             </div>
965 965
             <?php
966
-        }
967
-    }
968
-    ?>
966
+		}
967
+	}
968
+	?>
969 969
 </div>
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Indentation   +4640 added lines, -4640 removed lines patch added patch discarded remove patch
@@ -16,2683 +16,2683 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class Messages_Admin_Page extends EE_Admin_Page
18 18
 {
19
-    /**
20
-     * @var EEM_Message
21
-     */
22
-    private $MSG_MODEL;
23
-
24
-    /**
25
-     * @var EEM_Message_Template
26
-     */
27
-    private $MTP_MODEL;
28
-
29
-    /**
30
-     * @var EEM_Message_Template_Group
31
-     */
32
-    private $MTG_MODEL;
33
-
34
-    /**
35
-     * @var EE_Message_Resource_Manager $_message_resource_manager
36
-     */
37
-    protected $_message_resource_manager;
38
-
39
-    /**
40
-     * @var string
41
-     */
42
-    protected $_active_message_type_name = '';
43
-
44
-    /**
45
-     * @var string
46
-     */
47
-    protected $_active_messenger_name = '';
48
-
49
-    /**
50
-     * @var EE_messenger $_active_messenger
51
-     */
52
-    protected $_active_messenger;
53
-
54
-    protected $_activate_meta_box_type;
55
-
56
-    protected $_current_message_meta_box;
57
-
58
-    protected $_current_message_meta_box_object;
59
-
60
-    protected $_context_switcher;
61
-
62
-    protected $_shortcodes           = [];
63
-
64
-    protected $_active_messengers    = [];
65
-
66
-    protected $_active_message_types = [];
67
-
68
-    /**
69
-     * @var EE_Message_Template_Group $_message_template_group
70
-     */
71
-    protected $_message_template_group;
72
-
73
-    protected $_m_mt_settings = [];
74
-
75
-
76
-    /**
77
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
78
-     * IF there is no group then it gets automatically set to the Default template pack.
79
-     *
80
-     * @since 4.5.0
81
-     *
82
-     * @var EE_Messages_Template_Pack
83
-     */
84
-    protected $_template_pack;
85
-
86
-
87
-    /**
88
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
89
-     * group is.  If there is no group then it automatically gets set to default.
90
-     *
91
-     * @since 4.5.0
92
-     *
93
-     * @var string
94
-     */
95
-    protected $_variation;
96
-
97
-
98
-    /**
99
-     * @param bool $routing
100
-     * @throws EE_Error
101
-     * @throws ReflectionException
102
-     */
103
-    public function __construct($routing = true)
104
-    {
105
-        // make sure messages autoloader is running
106
-        EED_Messages::set_autoloaders();
107
-        parent::__construct($routing);
108
-    }
109
-
110
-
111
-    /**
112
-     * @return EEM_Message
113
-     * @throws EE_Error
114
-     */
115
-    public function getMsgModel()
116
-    {
117
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
118
-            $this->MSG_MODEL = EEM_Message::instance();
119
-        }
120
-        return $this->MSG_MODEL;
121
-    }
122
-
123
-
124
-    /**
125
-     * @return EEM_Message_Template
126
-     * @throws EE_Error
127
-     */
128
-    public function getMtpModel()
129
-    {
130
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
131
-            $this->MTP_MODEL = EEM_Message_Template::instance();
132
-        }
133
-        return $this->MTP_MODEL;
134
-    }
135
-
136
-
137
-    /**
138
-     * @return EEM_Message_Template_Group
139
-     * @throws EE_Error
140
-     */
141
-    public function getMtgModel()
142
-    {
143
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
144
-            $this->MTG_MODEL = EEM_Message_Template_Group::instance();
145
-        }
146
-        return $this->MTG_MODEL;
147
-    }
148
-
149
-
150
-    /**
151
-     * @throws EE_Error
152
-     * @throws ReflectionException
153
-     */
154
-    protected function _init_page_props()
155
-    {
156
-        $this->page_slug        = EE_MSG_PG_SLUG;
157
-        $this->page_label       = esc_html__('Messages Settings', 'event_espresso');
158
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
159
-        $this->_admin_base_path = EE_MSG_ADMIN;
160
-
161
-        $messenger    = $this->request->getRequestParam('messenger', '');
162
-        $message_type = $this->request->getRequestParam('message_type', '');
163
-        $this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
164
-        $this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
165
-
166
-        $this->_load_message_resource_manager();
167
-    }
168
-
169
-
170
-    /**
171
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
172
-     *
173
-     * @throws EE_Error
174
-     * @throws InvalidDataTypeException
175
-     * @throws InvalidInterfaceException
176
-     * @throws InvalidArgumentException
177
-     * @throws ReflectionException
178
-     */
179
-    protected function _load_message_resource_manager()
180
-    {
181
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
182
-    }
183
-
184
-
185
-    /**
186
-     * @return array
187
-     * @throws EE_Error
188
-     * @throws InvalidArgumentException
189
-     * @throws InvalidDataTypeException
190
-     * @throws InvalidInterfaceException
191
-     * @deprecated 4.9.9.rc.014
192
-     */
193
-    public function get_messengers_for_list_table()
194
-    {
195
-        EE_Error::doing_it_wrong(
196
-            __METHOD__,
197
-            sprintf(
198
-                esc_html__(
199
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
200
-                    'event_espresso'
201
-                ),
202
-                'Messages_Admin_Page::get_messengers_select_input()'
203
-            ),
204
-            '4.9.9.rc.014'
205
-        );
206
-
207
-        $m_values          = [];
208
-        $active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
209
-        // setup messengers for selects
210
-        $i = 1;
211
-        foreach ($active_messengers as $active_messenger) {
212
-            if ($active_messenger instanceof EE_Message) {
213
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
214
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
215
-                $i++;
216
-            }
217
-        }
218
-
219
-        return $m_values;
220
-    }
221
-
222
-
223
-    /**
224
-     * @return array
225
-     * @throws EE_Error
226
-     * @throws InvalidArgumentException
227
-     * @throws InvalidDataTypeException
228
-     * @throws InvalidInterfaceException
229
-     * @deprecated 4.9.9.rc.014
230
-     */
231
-    public function get_message_types_for_list_table()
232
-    {
233
-        EE_Error::doing_it_wrong(
234
-            __METHOD__,
235
-            sprintf(
236
-                esc_html__(
237
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
238
-                    'event_espresso'
239
-                ),
240
-                'Messages_Admin_Page::get_message_types_select_input()'
241
-            ),
242
-            '4.9.9.rc.014'
243
-        );
244
-
245
-        $mt_values       = [];
246
-        $active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
247
-        $i               = 1;
248
-        foreach ($active_messages as $active_message) {
249
-            if ($active_message instanceof EE_Message) {
250
-                $mt_values[ $i ]['id']   = $active_message->message_type();
251
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
252
-                $i++;
253
-            }
254
-        }
255
-
256
-        return $mt_values;
257
-    }
258
-
259
-
260
-    /**
261
-     * @return array
262
-     * @throws EE_Error
263
-     * @throws InvalidArgumentException
264
-     * @throws InvalidDataTypeException
265
-     * @throws InvalidInterfaceException
266
-     * @deprecated 4.9.9.rc.014
267
-     */
268
-    public function get_contexts_for_message_types_for_list_table()
269
-    {
270
-        EE_Error::doing_it_wrong(
271
-            __METHOD__,
272
-            sprintf(
273
-                esc_html__(
274
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
275
-                    'event_espresso'
276
-                ),
277
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
278
-            ),
279
-            '4.9.9.rc.014'
280
-        );
281
-
282
-        $contexts                = [];
283
-        $active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
284
-        foreach ($active_message_contexts as $active_message) {
285
-            if ($active_message instanceof EE_Message) {
286
-                $message_type = $active_message->message_type_object();
287
-                if ($message_type instanceof EE_message_type) {
288
-                    $message_type_contexts = $message_type->get_contexts();
289
-                    foreach ($message_type_contexts as $context => $context_details) {
290
-                        $contexts[ $context ] = $context_details['label'];
291
-                    }
292
-                }
293
-            }
294
-        }
295
-
296
-        return $contexts;
297
-    }
298
-
299
-
300
-    /**
301
-     * Generate select input with provided messenger options array.
302
-     *
303
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
304
-     *                                 labels.
305
-     * @return string
306
-     * @throws EE_Error
307
-     */
308
-    public function get_messengers_select_input($messenger_options)
309
-    {
310
-        // if empty or just one value then just return an empty string
311
-        if (
312
-            empty($messenger_options)
313
-            || ! is_array($messenger_options)
314
-            || count($messenger_options) === 1
315
-        ) {
316
-            return '';
317
-        }
318
-        // merge in default
319
-        $messenger_options = array_merge(
320
-            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
321
-            $messenger_options
322
-        );
323
-        $input             = new EE_Select_Input(
324
-            $messenger_options,
325
-            [
326
-                'html_name'  => 'ee_messenger_filter_by',
327
-                'html_id'    => 'ee_messenger_filter_by',
328
-                'html_class' => 'wide',
329
-                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
330
-            ]
331
-        );
332
-
333
-        return $input->get_html_for_input();
334
-    }
335
-
336
-
337
-    /**
338
-     * Generate select input with provided message type options array.
339
-     *
340
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
341
-     *                                    message type labels
342
-     * @return string
343
-     * @throws EE_Error
344
-     */
345
-    public function get_message_types_select_input($message_type_options)
346
-    {
347
-        // if empty or count of options is 1 then just return an empty string
348
-        if (
349
-            empty($message_type_options)
350
-            || ! is_array($message_type_options)
351
-            || count($message_type_options) === 1
352
-        ) {
353
-            return '';
354
-        }
355
-        // merge in default
356
-        $message_type_options = array_merge(
357
-            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
358
-            $message_type_options
359
-        );
360
-        $input                = new EE_Select_Input(
361
-            $message_type_options,
362
-            [
363
-                'html_name'  => 'ee_message_type_filter_by',
364
-                'html_id'    => 'ee_message_type_filter_by',
365
-                'html_class' => 'wide',
366
-                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
367
-            ]
368
-        );
369
-
370
-        return $input->get_html_for_input();
371
-    }
372
-
373
-
374
-    /**
375
-     * Generate select input with provide message type contexts array.
376
-     *
377
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
378
-     *                               context label.
379
-     * @return string
380
-     * @throws EE_Error
381
-     */
382
-    public function get_contexts_for_message_types_select_input($context_options)
383
-    {
384
-        // if empty or count of options is one then just return empty string
385
-        if (
386
-            empty($context_options)
387
-            || ! is_array($context_options)
388
-            || count($context_options) === 1
389
-        ) {
390
-            return '';
391
-        }
392
-        // merge in default
393
-        $context_options = array_merge(
394
-            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
395
-            $context_options
396
-        );
397
-        $input           = new EE_Select_Input(
398
-            $context_options,
399
-            [
400
-                'html_name'  => 'ee_context_filter_by',
401
-                'html_id'    => 'ee_context_filter_by',
402
-                'html_class' => 'wide',
403
-                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
404
-            ]
405
-        );
406
-
407
-        return $input->get_html_for_input();
408
-    }
409
-
410
-
411
-    protected function _ajax_hooks()
412
-    {
413
-        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
414
-        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
415
-        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
416
-        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
417
-        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
418
-        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
419
-    }
420
-
421
-
422
-    protected function _define_page_props()
423
-    {
424
-        $this->_admin_page_title = $this->page_label;
425
-        $this->_labels           = [
426
-            'buttons'    => [
427
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
428
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
429
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
430
-            ],
431
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
432
-        ];
433
-    }
434
-
435
-
436
-    /**
437
-     *        an array for storing key => value pairs of request actions and their corresponding methods
438
-     *
439
-     * @access protected
440
-     * @return void
441
-     */
442
-    protected function _set_page_routes()
443
-    {
444
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
445
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
446
-        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
447
-
448
-        $this->_page_routes = [
449
-            'default'                          => [
450
-                'func'       => '_message_queue_list_table',
451
-                'capability' => 'ee_read_global_messages',
452
-            ],
453
-            'global_mtps'                      => [
454
-                'func'       => '_ee_default_messages_overview_list_table',
455
-                'capability' => 'ee_read_global_messages',
456
-            ],
457
-            'custom_mtps'                      => [
458
-                'func'       => '_custom_mtps_preview',
459
-                'capability' => 'ee_read_messages',
460
-            ],
461
-            'add_new_message_template'         => [
462
-                'func'       => 'add_message_template',
463
-                'capability' => 'ee_edit_messages',
464
-                'noheader'   => true,
465
-            ],
466
-            'edit_message_template'            => [
467
-                'func'       => '_edit_message_template',
468
-                'capability' => 'ee_edit_message',
469
-                'obj_id'     => $GRP_ID,
470
-            ],
471
-            'preview_message'                  => [
472
-                'func'               => '_preview_message',
473
-                'capability'         => 'ee_read_message',
474
-                'obj_id'             => $GRP_ID,
475
-                'noheader'           => true,
476
-                'headers_sent_route' => 'display_preview_message',
477
-            ],
478
-            'display_preview_message'          => [
479
-                'func'       => '_display_preview_message',
480
-                'capability' => 'ee_read_message',
481
-                'obj_id'     => $GRP_ID,
482
-            ],
483
-            'insert_message_template'          => [
484
-                'func'       => '_insert_or_update_message_template',
485
-                'capability' => 'ee_edit_messages',
486
-                'args'       => ['new' => true],
487
-                'noheader'   => true,
488
-            ],
489
-            'update_message_template'          => [
490
-                'func'       => '_insert_or_update_message_template',
491
-                'capability' => 'ee_edit_message',
492
-                'obj_id'     => $GRP_ID,
493
-                'args'       => ['new' => false],
494
-                'noheader'   => true,
495
-            ],
496
-            'trash_message_template'           => [
497
-                'func'       => '_trash_or_restore_message_template',
498
-                'capability' => 'ee_delete_message',
499
-                'obj_id'     => $GRP_ID,
500
-                'args'       => ['trash' => true, 'all' => true],
501
-                'noheader'   => true,
502
-            ],
503
-            'trash_message_template_context'   => [
504
-                'func'       => '_trash_or_restore_message_template',
505
-                'capability' => 'ee_delete_message',
506
-                'obj_id'     => $GRP_ID,
507
-                'args'       => ['trash' => true],
508
-                'noheader'   => true,
509
-            ],
510
-            'restore_message_template'         => [
511
-                'func'       => '_trash_or_restore_message_template',
512
-                'capability' => 'ee_delete_message',
513
-                'obj_id'     => $GRP_ID,
514
-                'args'       => ['trash' => false, 'all' => true],
515
-                'noheader'   => true,
516
-            ],
517
-            'restore_message_template_context' => [
518
-                'func'       => '_trash_or_restore_message_template',
519
-                'capability' => 'ee_delete_message',
520
-                'obj_id'     => $GRP_ID,
521
-                'args'       => ['trash' => false],
522
-                'noheader'   => true,
523
-            ],
524
-            'delete_message_template'          => [
525
-                'func'       => '_delete_message_template',
526
-                'capability' => 'ee_delete_message',
527
-                'obj_id'     => $GRP_ID,
528
-                'noheader'   => true,
529
-            ],
530
-            'reset_to_default'                 => [
531
-                'func'       => '_reset_to_default_template',
532
-                'capability' => 'ee_edit_message',
533
-                'obj_id'     => $GRP_ID,
534
-                'noheader'   => true,
535
-            ],
536
-            'settings'                         => [
537
-                'func'       => '_settings',
538
-                'capability' => 'manage_options',
539
-            ],
540
-            'update_global_settings'           => [
541
-                'func'       => '_update_global_settings',
542
-                'capability' => 'manage_options',
543
-                'noheader'   => true,
544
-            ],
545
-            'generate_now'                     => [
546
-                'func'       => '_generate_now',
547
-                'capability' => 'ee_send_message',
548
-                'noheader'   => true,
549
-            ],
550
-            'generate_and_send_now'            => [
551
-                'func'       => '_generate_and_send_now',
552
-                'capability' => 'ee_send_message',
553
-                'noheader'   => true,
554
-            ],
555
-            'queue_for_resending'              => [
556
-                'func'       => '_queue_for_resending',
557
-                'capability' => 'ee_send_message',
558
-                'noheader'   => true,
559
-            ],
560
-            'send_now'                         => [
561
-                'func'       => '_send_now',
562
-                'capability' => 'ee_send_message',
563
-                'noheader'   => true,
564
-            ],
565
-            'delete_ee_message'                => [
566
-                'func'       => '_delete_ee_messages',
567
-                'capability' => 'ee_delete_messages',
568
-                'noheader'   => true,
569
-            ],
570
-            'delete_ee_messages'               => [
571
-                'func'       => '_delete_ee_messages',
572
-                'capability' => 'ee_delete_messages',
573
-                'noheader'   => true,
574
-                'obj_id'     => $MSG_ID,
575
-            ],
576
-        ];
577
-    }
578
-
579
-
580
-    protected function _set_page_config()
581
-    {
582
-        $this->_page_config = [
583
-            'default'                  => [
584
-                'nav'           => [
585
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
586
-                    'order' => 10,
587
-                ],
588
-                'list_table'    => 'EE_Message_List_Table',
589
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
590
-                'require_nonce' => false,
591
-            ],
592
-            'global_mtps'              => [
593
-                'nav'           => [
594
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
595
-                    'order' => 20,
596
-                ],
597
-                'list_table'    => 'Messages_Template_List_Table',
598
-                'help_tabs'     => [
599
-                    'messages_overview_help_tab'                                => [
600
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
601
-                        'filename' => 'messages_overview',
602
-                    ],
603
-                    'messages_overview_messages_table_column_headings_help_tab' => [
604
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
605
-                        'filename' => 'messages_overview_table_column_headings',
606
-                    ],
607
-                    'messages_overview_messages_filters_help_tab'               => [
608
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
609
-                        'filename' => 'messages_overview_filters',
610
-                    ],
611
-                    'messages_overview_messages_views_help_tab'                 => [
612
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
613
-                        'filename' => 'messages_overview_views',
614
-                    ],
615
-                    'message_overview_message_types_help_tab'                   => [
616
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
617
-                        'filename' => 'messages_overview_types',
618
-                    ],
619
-                    'messages_overview_messengers_help_tab'                     => [
620
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
621
-                        'filename' => 'messages_overview_messengers',
622
-                    ],
623
-                ],
624
-                'require_nonce' => false,
625
-            ],
626
-            'custom_mtps'              => [
627
-                'nav'           => [
628
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
629
-                    'order' => 30,
630
-                ],
631
-                'help_tabs'     => [],
632
-                'require_nonce' => false,
633
-            ],
634
-            'add_new_message_template' => [
635
-                'nav'           => [
636
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
637
-                    'order'      => 5,
638
-                    'persistent' => false,
639
-                ],
640
-                'require_nonce' => false,
641
-            ],
642
-            'edit_message_template'    => [
643
-                'labels'        => [
644
-                    'buttons'    => [
645
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
646
-                    ],
647
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
648
-                ],
649
-                'nav'           => [
650
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
651
-                    'order'      => 5,
652
-                    'persistent' => false,
653
-                    'url'        => '',
654
-                ],
655
-                'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
656
-                'has_metaboxes' => true,
657
-                'help_tabs'     => [
658
-                    'edit_message_template'            => [
659
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
660
-                        'callback' => 'edit_message_template_help_tab',
661
-                    ],
662
-                    'message_templates_help_tab'       => [
663
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
664
-                        'filename' => 'messages_templates',
665
-                    ],
666
-                    'message_template_shortcodes'      => [
667
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
668
-                        'callback' => 'message_template_shortcodes_help_tab',
669
-                    ],
670
-                    'message_preview_help_tab'         => [
671
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
672
-                        'filename' => 'messages_preview',
673
-                    ],
674
-                    'messages_overview_other_help_tab' => [
675
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
676
-                        'filename' => 'messages_overview_other',
677
-                    ],
678
-                ],
679
-                'require_nonce' => false,
680
-            ],
681
-            'display_preview_message'  => [
682
-                'nav'           => [
683
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
684
-                    'order'      => 5,
685
-                    'url'        => '',
686
-                    'persistent' => false,
687
-                ],
688
-                'help_tabs'     => [
689
-                    'preview_message' => [
690
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
691
-                        'callback' => 'preview_message_help_tab',
692
-                    ],
693
-                ],
694
-                'require_nonce' => false,
695
-            ],
696
-            'settings'                 => [
697
-                'nav'           => [
698
-                    'label' => esc_html__('Settings', 'event_espresso'),
699
-                    'order' => 40,
700
-                ],
701
-                'metaboxes'     => ['_messages_settings_metaboxes'],
702
-                'help_tabs'     => [
703
-                    'messages_settings_help_tab'               => [
704
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
705
-                        'filename' => 'messages_settings',
706
-                    ],
707
-                    'messages_settings_message_types_help_tab' => [
708
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
709
-                        'filename' => 'messages_settings_message_types',
710
-                    ],
711
-                    'messages_settings_messengers_help_tab'    => [
712
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
713
-                        'filename' => 'messages_settings_messengers',
714
-                    ],
715
-                ],
716
-                'require_nonce' => false,
717
-            ],
718
-        ];
719
-    }
720
-
721
-
722
-    protected function _add_screen_options()
723
-    {
724
-        // todo
725
-    }
726
-
727
-
728
-    protected function _add_screen_options_global_mtps()
729
-    {
730
-        /**
731
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
732
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
733
-         */
734
-        $page_title              = $this->_admin_page_title;
735
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
736
-        $this->_per_page_screen_option();
737
-        $this->_admin_page_title = $page_title;
738
-    }
739
-
740
-
741
-    protected function _add_screen_options_default()
742
-    {
743
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
744
-        $this->_per_page_screen_option();
745
-    }
746
-
747
-
748
-    // none of the below group are currently used for Messages
749
-    protected function _add_feature_pointers()
750
-    {
751
-    }
752
-
753
-
754
-    public function admin_init()
755
-    {
756
-    }
757
-
758
-
759
-    public function admin_notices()
760
-    {
761
-    }
762
-
763
-
764
-    public function admin_footer_scripts()
765
-    {
766
-    }
767
-
768
-
769
-    public function messages_help_tab()
770
-    {
771
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
772
-    }
773
-
774
-
775
-    public function messengers_help_tab()
776
-    {
777
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
778
-    }
779
-
780
-
781
-    public function message_types_help_tab()
782
-    {
783
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
784
-    }
785
-
786
-
787
-    public function messages_overview_help_tab()
788
-    {
789
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
790
-    }
791
-
792
-
793
-    public function message_templates_help_tab()
794
-    {
795
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
796
-    }
797
-
798
-
799
-    public function edit_message_template_help_tab()
800
-    {
801
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
802
-                        . esc_attr__('Editor Title', 'event_espresso')
803
-                        . '" />';
804
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
805
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
806
-                        . '" />';
807
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
808
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
809
-                        . '" />';
810
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
811
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
812
-                        . '" />';
813
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
814
-                        . esc_attr__('Publish Metabox', 'event_espresso')
815
-                        . '" />';
816
-        EEH_Template::display_template(
817
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
818
-            $args
819
-        );
820
-    }
821
-
822
-
823
-    /**
824
-     * @throws ReflectionException
825
-     * @throws EE_Error
826
-     */
827
-    public function message_template_shortcodes_help_tab()
828
-    {
829
-        $this->_set_shortcodes();
830
-        $args['shortcodes'] = $this->_shortcodes;
831
-        EEH_Template::display_template(
832
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
833
-            $args
834
-        );
835
-    }
836
-
837
-
838
-    public function preview_message_help_tab()
839
-    {
840
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
841
-    }
842
-
843
-
844
-    public function settings_help_tab()
845
-    {
846
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
847
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
848
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
849
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
850
-        $args['img3'] = '<div class="switch">'
851
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
852
-                        . ' type="checkbox" checked="checked">'
853
-                        . '<label for="ee-on-off-toggle-on"></label>'
854
-                        . '</div>';
855
-        $args['img4'] = '<div class="switch">'
856
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
857
-                        . ' type="checkbox">'
858
-                        . '<label for="ee-on-off-toggle-on"></label>'
859
-                        . '</div>';
860
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
861
-    }
862
-
863
-
864
-    public function load_scripts_styles()
865
-    {
866
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
867
-        wp_enqueue_style('espresso_ee_msg');
868
-
869
-        wp_register_script(
870
-            'ee-messages-settings',
871
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
872
-            ['jquery-ui-droppable', 'ee-serialize-full-array'],
873
-            EVENT_ESPRESSO_VERSION,
874
-            true
875
-        );
876
-        wp_register_script(
877
-            'ee-msg-list-table-js',
878
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
879
-            ['ee-dialog'],
880
-            EVENT_ESPRESSO_VERSION
881
-        );
882
-    }
883
-
884
-
885
-    public function load_scripts_styles_default()
886
-    {
887
-        wp_enqueue_script('ee-msg-list-table-js');
888
-    }
889
-
890
-
891
-    public function wp_editor_css($mce_css)
892
-    {
893
-        // if we're on the edit_message_template route
894
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
895
-            $message_type_name = $this->_active_message_type_name;
896
-
897
-            // we're going to REPLACE the existing mce css
898
-            // we need to get the css file location from the active messenger
899
-            $mce_css = $this->_active_messenger->get_variation(
900
-                $this->_template_pack,
901
-                $message_type_name,
902
-                true,
903
-                'wpeditor',
904
-                $this->_variation
905
-            );
906
-        }
907
-
908
-        return $mce_css;
909
-    }
910
-
911
-
912
-    /**
913
-     * @throws EE_Error
914
-     * @throws ReflectionException
915
-     */
916
-    public function load_scripts_styles_edit_message_template()
917
-    {
918
-
919
-        $this->_set_shortcodes();
920
-
921
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
922
-            esc_html__(
923
-                'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
924
-                'event_espresso'
925
-            ),
926
-            $this->_message_template_group->messenger_obj()->label['singular'],
927
-            $this->_message_template_group->message_type_obj()->label['singular']
928
-        );
929
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
930
-            'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
931
-            'event_espresso'
932
-        );
933
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
934
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
935
-            'event_espresso'
936
-        );
937
-
938
-        wp_register_script(
939
-            'ee_msgs_edit_js',
940
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
941
-            ['jquery'],
942
-            EVENT_ESPRESSO_VERSION
943
-        );
944
-
945
-        wp_enqueue_script('ee_admin_js');
946
-        wp_enqueue_script('ee_msgs_edit_js');
947
-
948
-        // add in special css for tiny_mce
949
-        add_filter('mce_css', [$this, 'wp_editor_css']);
950
-    }
951
-
952
-
953
-    /**
954
-     * @throws EE_Error
955
-     * @throws ReflectionException
956
-     */
957
-    public function load_scripts_styles_display_preview_message()
958
-    {
959
-        $this->_set_message_template_group();
960
-        if ($this->_active_messenger_name) {
961
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
962
-                $this->_active_messenger_name
963
-            );
964
-        }
965
-
966
-        wp_enqueue_style(
967
-            'espresso_preview_css',
968
-            $this->_active_messenger->get_variation(
969
-                $this->_template_pack,
970
-                $this->_active_message_type_name,
971
-                true,
972
-                'preview',
973
-                $this->_variation
974
-            )
975
-        );
976
-    }
977
-
978
-
979
-    public function load_scripts_styles_settings()
980
-    {
981
-        wp_register_style(
982
-            'ee-message-settings',
983
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
984
-            [],
985
-            EVENT_ESPRESSO_VERSION
986
-        );
987
-        wp_enqueue_style('ee-text-links');
988
-        wp_enqueue_style('ee-message-settings');
989
-        wp_enqueue_script('ee-messages-settings');
990
-    }
991
-
992
-
993
-    /**
994
-     * set views array for List Table
995
-     */
996
-    public function _set_list_table_views_global_mtps()
997
-    {
998
-        $this->_views = [
999
-            'in_use' => [
1000
-                'slug'  => 'in_use',
1001
-                'label' => esc_html__('In Use', 'event_espresso'),
1002
-                'count' => 0,
1003
-            ],
1004
-        ];
1005
-    }
1006
-
1007
-
1008
-    /**
1009
-     * Set views array for the Custom Template List Table
1010
-     */
1011
-    public function _set_list_table_views_custom_mtps()
1012
-    {
1013
-        $this->_set_list_table_views_global_mtps();
1014
-        $this->_views['in_use']['bulk_action'] = [
1015
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1016
-        ];
1017
-    }
1018
-
1019
-
1020
-    /**
1021
-     * set views array for message queue list table
1022
-     *
1023
-     * @throws InvalidDataTypeException
1024
-     * @throws InvalidInterfaceException
1025
-     * @throws InvalidArgumentException
1026
-     * @throws EE_Error
1027
-     * @throws ReflectionException
1028
-     */
1029
-    public function _set_list_table_views_default()
1030
-    {
1031
-        EE_Registry::instance()->load_helper('Template');
1032
-
1033
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1034
-            'ee_send_message',
1035
-            'message_list_table_bulk_actions'
1036
-        )
1037
-            ? [
1038
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1039
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1040
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1041
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
1042
-            ]
1043
-            : [];
1044
-
1045
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1046
-            'ee_delete_messages',
1047
-            'message_list_table_bulk_actions'
1048
-        )
1049
-            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1050
-            : [];
1051
-
1052
-
1053
-        $this->_views = [
1054
-            'all' => [
1055
-                'slug'        => 'all',
1056
-                'label'       => esc_html__('All', 'event_espresso'),
1057
-                'count'       => 0,
1058
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1059
-            ],
1060
-        ];
1061
-
1062
-
1063
-        foreach ($this->getMsgModel()->all_statuses() as $status) {
1064
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1065
-                continue;
1066
-            }
1067
-            $status_bulk_actions = $common_bulk_actions;
1068
-            // unset bulk actions not applying to status
1069
-            if (! empty($status_bulk_actions)) {
1070
-                switch ($status) {
1071
-                    case EEM_Message::status_idle:
1072
-                    case EEM_Message::status_resend:
1073
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1074
-                        break;
1075
-
1076
-                    case EEM_Message::status_failed:
1077
-                    case EEM_Message::status_debug_only:
1078
-                    case EEM_Message::status_messenger_executing:
1079
-                        $status_bulk_actions = [];
1080
-                        break;
1081
-
1082
-                    case EEM_Message::status_incomplete:
1083
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1084
-                        break;
1085
-
1086
-                    case EEM_Message::status_retry:
1087
-                    case EEM_Message::status_sent:
1088
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1089
-                        break;
1090
-                }
1091
-            }
1092
-
1093
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1094
-            if ($status === EEM_Message::status_messenger_executing) {
1095
-                continue;
1096
-            }
1097
-
1098
-            $this->_views[ strtolower($status) ] = [
1099
-                'slug'        => strtolower($status),
1100
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1101
-                'count'       => 0,
1102
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1103
-            ];
1104
-        }
1105
-    }
1106
-
1107
-
1108
-    /**
1109
-     * @throws EE_Error
1110
-     */
1111
-    protected function _ee_default_messages_overview_list_table()
1112
-    {
1113
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1114
-        $this->display_admin_list_table_page_with_no_sidebar();
1115
-    }
1116
-
1117
-
1118
-    /**
1119
-     * @throws EE_Error
1120
-     * @throws ReflectionException
1121
-     */
1122
-    protected function _message_queue_list_table()
1123
-    {
1124
-        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1125
-        $this->_template_args['per_column']        = 6;
1126
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1127
-        $this->_template_args['before_list_table'] = '<h3>'
1128
-                                                     . $this->getMsgModel()->get_pretty_label_for_results()
1129
-                                                     . '</h3>';
1130
-        $this->display_admin_list_table_page_with_no_sidebar();
1131
-    }
1132
-
1133
-
1134
-    /**
1135
-     * @throws EE_Error
1136
-     */
1137
-    protected function _message_legend_items()
1138
-    {
1139
-
1140
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1141
-        $action_items       = [];
1142
-
1143
-        foreach ($action_css_classes as $action_item => $action_details) {
1144
-            if ($action_item === 'see_notifications_for') {
1145
-                continue;
1146
-            }
1147
-            $action_items[ $action_item ] = [
1148
-                'class' => $action_details['css_class'],
1149
-                'desc'  => $action_details['label'],
1150
-            ];
1151
-        }
1152
-
1153
-        /** @var array $status_items status legend setup */
1154
-        $status_items = [
1155
-            'sent_status'                => [
1156
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1157
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1158
-            ],
1159
-            'idle_status'                => [
1160
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1161
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1162
-            ],
1163
-            'failed_status'              => [
1164
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1165
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1166
-            ],
1167
-            'messenger_executing_status' => [
1168
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1169
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1170
-            ],
1171
-            'resend_status'              => [
1172
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1173
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1174
-            ],
1175
-            'incomplete_status'          => [
1176
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1177
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1178
-            ],
1179
-            'retry_status'               => [
1180
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1181
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1182
-            ],
1183
-        ];
1184
-        if (EEM_Message::debug()) {
1185
-            $status_items['debug_only_status'] = [
1186
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1187
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1188
-            ];
1189
-        }
1190
-
1191
-        return array_merge($action_items, $status_items);
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * @throws EE_Error
1197
-     */
1198
-    protected function _custom_mtps_preview()
1199
-    {
1200
-        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1201
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1202
-                                                . ' alt="' . esc_attr__(
1203
-                                                    'Preview Custom Message Templates screenshot',
1204
-                                                    'event_espresso'
1205
-                                                ) . '" />';
1206
-        $this->_template_args['preview_text'] = '<strong>'
1207
-                                                . esc_html__(
1208
-                                                    'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1209
-                                                    'event_espresso'
1210
-                                                )
1211
-                                                . '</strong>';
1212
-
1213
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1214
-    }
1215
-
1216
-
1217
-    /**
1218
-     * get_message_templates
1219
-     * This gets all the message templates for listing on the overview list.
1220
-     *
1221
-     * @access public
1222
-     * @param int    $per_page the amount of templates groups to show per page
1223
-     * @param string $type     the current _view we're getting templates for
1224
-     * @param bool   $count    return count?
1225
-     * @param bool   $all      disregard any paging info (get all data);
1226
-     * @param bool   $global   whether to return just global (true) or custom templates (false)
1227
-     * @return array
1228
-     * @throws EE_Error
1229
-     * @throws InvalidArgumentException
1230
-     * @throws InvalidDataTypeException
1231
-     * @throws InvalidInterfaceException
1232
-     */
1233
-    public function get_message_templates(
1234
-        $per_page = 10,
1235
-        $type = 'in_use',
1236
-        $count = false,
1237
-        $all = false,
1238
-        $global = true
1239
-    ) {
1240
-        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1241
-        $this->request->setRequestParam('orderby', $orderby);
1242
-
1243
-        $order        = $this->request->getRequestParam('order', 'ASC');
1244
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1245
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1246
-
1247
-        $offset = ($current_page - 1) * $per_page;
1248
-        $limit  = $all ? null : [$offset, $per_page];
1249
-
1250
-        // options will match what is in the _views array property
1251
-        return $type === 'in_use'
1252
-            ? $this->getMtgModel()->get_all_active_message_templates(
1253
-                $orderby,
1254
-                $order,
1255
-                $limit,
1256
-                $count,
1257
-                $global,
1258
-                true
1259
-            )
1260
-            : $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1261
-                $orderby,
1262
-                $order,
1263
-                $limit,
1264
-                $count,
1265
-                $global
1266
-            );
1267
-    }
1268
-
1269
-
1270
-    /**
1271
-     * filters etc might need a list of installed message_types
1272
-     *
1273
-     * @return array an array of message type objects
1274
-     */
1275
-    public function get_installed_message_types()
1276
-    {
1277
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1278
-        $installed               = [];
1279
-
1280
-        foreach ($installed_message_types as $message_type) {
1281
-            $installed[ $message_type->name ] = $message_type;
1282
-        }
1283
-
1284
-        return $installed;
1285
-    }
1286
-
1287
-
1288
-    /**
1289
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1290
-     *
1291
-     * @param string $message_type
1292
-     * @param string $messenger
1293
-     * @param string $GRP_ID
1294
-     *
1295
-     * @throws EE_error
1296
-     * @throws ReflectionException
1297
-     */
1298
-    public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1299
-    {
1300
-        // set values override any request data
1301
-        $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1302
-        $messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1303
-        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1304
-
1305
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1306
-        if (empty($message_type) || empty($messenger)) {
1307
-            throw new EE_Error(
1308
-                esc_html__(
1309
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1310
-                    'event_espresso'
1311
-                )
1312
-            );
1313
-        }
1314
-
1315
-        // we need the GRP_ID for the template being used as the base for the new template
1316
-        if (empty($GRP_ID)) {
1317
-            throw new EE_Error(
1318
-                esc_html__(
1319
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1320
-                    'event_espresso'
1321
-                )
1322
-            );
1323
-        }
1324
-
1325
-        // let's just make sure the template gets generated!
1326
-
1327
-        // we need to reassign some variables for what the insert is expecting
1328
-        $this->request->setRequestParam('MTP_messenger', $messenger);
1329
-        $this->request->setRequestParam('MTP_message_type', $message_type);
1330
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
1331
-
1332
-        $this->_insert_or_update_message_template(true);
1333
-    }
1334
-
1335
-
1336
-    /**
1337
-     * @param string $message_type     message type slug
1338
-     * @param string $messenger        messenger slug
1339
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1340
-     *                                 off of.
1341
-     * @throws EE_error
1342
-     * @throws ReflectionException
1343
-     * @deprecated $VID:$
1344
-     */
1345
-    protected function _add_message_template($message_type, $messenger, $GRP_ID)
1346
-    {
1347
-        $this->add_message_template($message_type, $messenger, $GRP_ID);
1348
-    }
1349
-
1350
-
1351
-    /**
1352
-     * _edit_message_template
1353
-     *
1354
-     * @access protected
1355
-     * @return void
1356
-     * @throws InvalidIdentifierException
1357
-     * @throws DomainException
1358
-     * @throws EE_Error
1359
-     * @throws InvalidArgumentException
1360
-     * @throws ReflectionException
1361
-     * @throws InvalidDataTypeException
1362
-     * @throws InvalidInterfaceException
1363
-     */
1364
-    protected function _edit_message_template()
1365
-    {
1366
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1367
-        $template_fields = '';
1368
-        $sidebar_fields  = '';
1369
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1370
-        // valid html in the templates.
1371
-        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1372
-
1373
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1374
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1375
-
1376
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1377
-        $message_template_group = $this->_message_template_group;
1378
-        $c_label                = $message_template_group->context_label();
1379
-        $c_config               = $message_template_group->contexts_config();
1380
-
1381
-        reset($c_config);
1382
-        $context = $this->request->getRequestParam('context', key($c_config));
1383
-        $context = strtolower($context);
1384
-
1385
-        $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1386
-
1387
-        $edit_message_template_form_url = add_query_arg(
1388
-            ['action' => $action, 'noheader' => true],
1389
-            EE_MSG_ADMIN_URL
1390
-        );
1391
-
1392
-        // set active messenger for this view
1393
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1394
-            $message_template_group->messenger()
1395
-        );
1396
-        $this->_active_message_type_name = $message_template_group->message_type();
1397
-
1398
-
1399
-        // Do we have any validation errors?
1400
-        $validators = $this->_get_transient();
1401
-        $v_fields   = ! empty($validators) ? array_keys($validators) : [];
1402
-
1403
-
1404
-        // we need to assemble the title from Various details
1405
-        $context_label = sprintf(
1406
-            esc_html__('(%s %s)', 'event_espresso'),
1407
-            $c_config[ $context ]['label'],
1408
-            ucwords($c_label['label'])
1409
-        );
1410
-
1411
-        $title = sprintf(
1412
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1413
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1414
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1415
-            $context_label
1416
-        );
1417
-
1418
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1419
-        $this->_template_args['message_template'] = $message_template_group;
1420
-        $this->_template_args['is_extra_fields']  = false;
1421
-
1422
-
1423
-        // let's get EEH_MSG_Template so we can get template form fields
1424
-        $template_field_structure = EEH_MSG_Template::get_fields(
1425
-            $message_template_group->messenger(),
1426
-            $message_template_group->message_type()
1427
-        );
1428
-
1429
-        if (! $template_field_structure) {
1430
-            $template_field_structure = false;
1431
-            $template_fields          = esc_html__(
1432
-                'There was an error in assembling the fields for this display (you should see an error message)',
1433
-                'event_espresso'
1434
-            );
1435
-        }
1436
-
1437
-
1438
-        $message_templates = $message_template_group->context_templates();
1439
-
1440
-
1441
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1442
-        // will get handled in the "extra" array.
1443
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1444
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1445
-                unset($template_field_structure[ $context ][ $reference_field ]);
1446
-            }
1447
-        }
1448
-
1449
-        // let's loop through the template_field_structure and actually assemble the input fields!
1450
-        if (! empty($template_field_structure)) {
1451
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1452
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1453
-                // the extra array and reset them.
1454
-                if ($template_field === 'extra') {
1455
-                    $this->_template_args['is_extra_fields'] = true;
1456
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1457
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1458
-                        $content          = $message_template instanceof EE_Message_Template
1459
-                            ? $message_template->get('MTP_content')
1460
-                            : '';
1461
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1462
-                            // let's verify if we need this extra field via the shortcodes parameter.
1463
-                            $continue = false;
1464
-                            if (isset($extra_array['shortcodes_required'])) {
1465
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1466
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1467
-                                        $continue = true;
1468
-                                    }
1469
-                                }
1470
-                                if ($continue) {
1471
-                                    continue;
1472
-                                }
1473
-                            }
1474
-
1475
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1476
-
1477
-                            $template_form_fields[ $field_id ]         = $extra_array;
1478
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1479
-                                                                         . $reference_field
1480
-                                                                         . '][content]['
1481
-                                                                         . $extra_field . ']';
1482
-                            $css_class                                 = isset($extra_array['css_class'])
1483
-                                ? $extra_array['css_class']
1484
-                                : '';
1485
-
1486
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1487
-                                                                              && in_array($extra_field, $v_fields, true)
1488
-                                                                              && (
1489
-                                                                                  is_array($validators[ $extra_field ])
1490
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1491
-                                                                              )
1492
-                                ? 'validate-error ' . $css_class
1493
-                                : $css_class;
1494
-
1495
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1496
-                                                                          && isset($content[ $extra_field ])
1497
-                                ? $content[ $extra_field ]
1498
-                                : '';
1499
-
1500
-                            // do we have a validation error?  if we do then let's use that value instead
1501
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1502
-                                ? $validators[ $extra_field ]['value']
1503
-                                : $template_form_fields[ $field_id ]['value'];
1504
-
1505
-
1506
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1507
-
1508
-                            // shortcode selector
1509
-                            $field_name_to_use                                   = $extra_field === 'main'
1510
-                                ? 'content'
1511
-                                : $extra_field;
1512
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1513
-                                $field_name_to_use,
1514
-                                $field_id
1515
-                            );
1516
-                        }
1517
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1518
-                        $template_field_template_name_id = $reference_field . '-name';
1519
-
1520
-                        $template_form_fields[ $template_field_MTP_id ] = [
1521
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1522
-                            'label'      => null,
1523
-                            'input'      => 'hidden',
1524
-                            'type'       => 'int',
1525
-                            'required'   => false,
1526
-                            'validation' => false,
1527
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1528
-                            'css_class'  => '',
1529
-                            'format'     => '%d',
1530
-                            'db-col'     => 'MTP_ID',
1531
-                        ];
1532
-
1533
-                        $template_form_fields[ $template_field_template_name_id ] = [
1534
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1535
-                            'label'      => null,
1536
-                            'input'      => 'hidden',
1537
-                            'type'       => 'string',
1538
-                            'required'   => false,
1539
-                            'validation' => true,
1540
-                            'value'      => $reference_field,
1541
-                            'css_class'  => '',
1542
-                            'format'     => '%s',
1543
-                            'db-col'     => 'MTP_template_field',
1544
-                        ];
1545
-                    }
1546
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1547
-                } else {
1548
-                    $field_id                                   = $template_field . '-content';
1549
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1550
-                    $template_form_fields[ $field_id ]['name']  =
1551
-                        'MTP_template_fields[' . $template_field . '][content]';
1552
-                    $message_template                           =
1553
-                        isset($message_templates[ $context ][ $template_field ])
1554
-                            ? $message_templates[ $context ][ $template_field ]
1555
-                            : null;
1556
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1557
-                                                                  && is_array($message_templates[ $context ])
1558
-                                                                  && $message_template instanceof EE_Message_Template
1559
-                        ? $message_template->get('MTP_content')
1560
-                        : '';
1561
-
1562
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1563
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1564
-                        ? $validators[ $template_field ]['value']
1565
-                        : $template_form_fields[ $field_id ]['value'];
1566
-
1567
-
1568
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1569
-                    $css_class                                      = isset($field_setup_array['css_class'])
1570
-                        ? $field_setup_array['css_class']
1571
-                        : '';
1572
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1573
-                                                                      && in_array($template_field, $v_fields, true)
1574
-                                                                      && isset($validators[ $template_field ]['msg'])
1575
-                        ? 'validate-error ' . $css_class
1576
-                        : $css_class;
1577
-
1578
-                    // shortcode selector
1579
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1580
-                        $template_field,
1581
-                        $field_id
1582
-                    );
1583
-                }
1584
-
1585
-                // k took care of content field(s) now let's take care of others.
1586
-
1587
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1588
-                $template_field_field_template_name_id = $template_field . '-name';
1589
-
1590
-                // foreach template field there are actually two form fields created
1591
-                $template_form_fields[ $template_field_MTP_id ] = [
1592
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1593
-                    'label'      => null,
1594
-                    'input'      => 'hidden',
1595
-                    'type'       => 'int',
1596
-                    'required'   => false,
1597
-                    'validation' => true,
1598
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1599
-                    'css_class'  => '',
1600
-                    'format'     => '%d',
1601
-                    'db-col'     => 'MTP_ID',
1602
-                ];
1603
-
1604
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1605
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1606
-                    'label'      => null,
1607
-                    'input'      => 'hidden',
1608
-                    'type'       => 'string',
1609
-                    'required'   => false,
1610
-                    'validation' => true,
1611
-                    'value'      => $template_field,
1612
-                    'css_class'  => '',
1613
-                    'format'     => '%s',
1614
-                    'db-col'     => 'MTP_template_field',
1615
-                ];
1616
-            }
1617
-
1618
-            // add other fields
1619
-            $template_form_fields['ee-msg-current-context'] = [
1620
-                'name'       => 'MTP_context',
1621
-                'label'      => null,
1622
-                'input'      => 'hidden',
1623
-                'type'       => 'string',
1624
-                'required'   => false,
1625
-                'validation' => true,
1626
-                'value'      => $context,
1627
-                'css_class'  => '',
1628
-                'format'     => '%s',
1629
-                'db-col'     => 'MTP_context',
1630
-            ];
1631
-
1632
-            $template_form_fields['ee-msg-grp-id'] = [
1633
-                'name'       => 'GRP_ID',
1634
-                'label'      => null,
1635
-                'input'      => 'hidden',
1636
-                'type'       => 'int',
1637
-                'required'   => false,
1638
-                'validation' => true,
1639
-                'value'      => $GRP_ID,
1640
-                'css_class'  => '',
1641
-                'format'     => '%d',
1642
-                'db-col'     => 'GRP_ID',
1643
-            ];
1644
-
1645
-            $template_form_fields['ee-msg-messenger'] = [
1646
-                'name'       => 'MTP_messenger',
1647
-                'label'      => null,
1648
-                'input'      => 'hidden',
1649
-                'type'       => 'string',
1650
-                'required'   => false,
1651
-                'validation' => true,
1652
-                'value'      => $message_template_group->messenger(),
1653
-                'css_class'  => '',
1654
-                'format'     => '%s',
1655
-                'db-col'     => 'MTP_messenger',
1656
-            ];
1657
-
1658
-            $template_form_fields['ee-msg-message-type'] = [
1659
-                'name'       => 'MTP_message_type',
1660
-                'label'      => null,
1661
-                'input'      => 'hidden',
1662
-                'type'       => 'string',
1663
-                'required'   => false,
1664
-                'validation' => true,
1665
-                'value'      => $message_template_group->message_type(),
1666
-                'css_class'  => '',
1667
-                'format'     => '%s',
1668
-                'db-col'     => 'MTP_message_type',
1669
-            ];
1670
-
1671
-            $sidebar_form_fields['ee-msg-is-global'] = [
1672
-                'name'       => 'MTP_is_global',
1673
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1674
-                'input'      => 'hidden',
1675
-                'type'       => 'int',
1676
-                'required'   => false,
1677
-                'validation' => true,
1678
-                'value'      => $message_template_group->get('MTP_is_global'),
1679
-                'css_class'  => '',
1680
-                'format'     => '%d',
1681
-                'db-col'     => 'MTP_is_global',
1682
-            ];
1683
-
1684
-            $sidebar_form_fields['ee-msg-is-override'] = [
1685
-                'name'       => 'MTP_is_override',
1686
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1687
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1688
-                'type'       => 'int',
1689
-                'required'   => false,
1690
-                'validation' => true,
1691
-                'value'      => $message_template_group->get('MTP_is_override'),
1692
-                'css_class'  => '',
1693
-                'format'     => '%d',
1694
-                'db-col'     => 'MTP_is_override',
1695
-            ];
1696
-
1697
-            $sidebar_form_fields['ee-msg-is-active'] = [
1698
-                'name'       => 'MTP_is_active',
1699
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1700
-                'input'      => 'hidden',
1701
-                'type'       => 'int',
1702
-                'required'   => false,
1703
-                'validation' => true,
1704
-                'value'      => $message_template_group->is_active(),
1705
-                'css_class'  => '',
1706
-                'format'     => '%d',
1707
-                'db-col'     => 'MTP_is_active',
1708
-            ];
1709
-
1710
-            $sidebar_form_fields['ee-msg-deleted'] = [
1711
-                'name'       => 'MTP_deleted',
1712
-                'label'      => null,
1713
-                'input'      => 'hidden',
1714
-                'type'       => 'int',
1715
-                'required'   => false,
1716
-                'validation' => true,
1717
-                'value'      => $message_template_group->get('MTP_deleted'),
1718
-                'css_class'  => '',
1719
-                'format'     => '%d',
1720
-                'db-col'     => 'MTP_deleted',
1721
-            ];
1722
-            $sidebar_form_fields['ee-msg-author']  = [
1723
-                'name'       => 'MTP_user_id',
1724
-                'label'      => esc_html__('Author', 'event_espresso'),
1725
-                'input'      => 'hidden',
1726
-                'type'       => 'int',
1727
-                'required'   => false,
1728
-                'validation' => false,
1729
-                'value'      => $message_template_group->user(),
1730
-                'format'     => '%d',
1731
-                'db-col'     => 'MTP_user_id',
1732
-            ];
1733
-
1734
-            $sidebar_form_fields['ee-msg-route'] = [
1735
-                'name'  => 'action',
1736
-                'input' => 'hidden',
1737
-                'type'  => 'string',
1738
-                'value' => $action,
1739
-            ];
1740
-
1741
-            $sidebar_form_fields['ee-msg-id']        = [
1742
-                'name'  => 'id',
1743
-                'input' => 'hidden',
1744
-                'type'  => 'int',
1745
-                'value' => $GRP_ID,
1746
-            ];
1747
-            $sidebar_form_fields['ee-msg-evt-nonce'] = [
1748
-                'name'  => $action . '_nonce',
1749
-                'input' => 'hidden',
1750
-                'type'  => 'string',
1751
-                'value' => wp_create_nonce($action . '_nonce'),
1752
-            ];
1753
-
1754
-            $template_switch = $this->request->getRequestParam('template_switch');
1755
-            if ($template_switch) {
1756
-                $sidebar_form_fields['ee-msg-template-switch'] = [
1757
-                    'name'  => 'template_switch',
1758
-                    'input' => 'hidden',
1759
-                    'type'  => 'int',
1760
-                    'value' => 1,
1761
-                ];
1762
-            }
1763
-
1764
-
1765
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1766
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1767
-        } //end if ( !empty($template_field_structure) )
1768
-
1769
-        // set extra content for publish box
1770
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1771
-        $this->_set_publish_post_box_vars(
1772
-            'id',
1773
-            $GRP_ID,
1774
-            false,
1775
-            add_query_arg(
1776
-                ['action' => 'global_mtps'],
1777
-                $this->_admin_base_url
1778
-            )
1779
-        );
1780
-
1781
-        // add preview button
1782
-        $preview_url    = parent::add_query_args_and_nonce(
1783
-            [
1784
-                'message_type' => $message_template_group->message_type(),
1785
-                'messenger'    => $message_template_group->messenger(),
1786
-                'context'      => $context,
1787
-                'GRP_ID'       => $GRP_ID,
1788
-                'evt_id'       => $EVT_ID ?: false,
1789
-                'action'       => 'preview_message',
1790
-            ],
1791
-            $this->_admin_base_url
1792
-        );
1793
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1794
-                          . esc_html__('Preview', 'event_espresso')
1795
-                          . '</a>';
1796
-
1797
-
1798
-        // setup context switcher
1799
-        $this->_set_context_switcher(
1800
-            $message_template_group,
1801
-            [
1802
-                'page'    => 'espresso_messages',
1803
-                'action'  => 'edit_message_template',
1804
-                'id'      => $GRP_ID,
1805
-                'evt_id'  => $EVT_ID,
1806
-                'context' => $context,
1807
-                'extra'   => $preview_button,
1808
-            ]
1809
-        );
1810
-
1811
-
1812
-        // main box
1813
-        $this->_template_args['template_fields']                         = $template_fields;
1814
-        $this->_template_args['sidebar_box_id']                          = 'details';
1815
-        $this->_template_args['action']                                  = $action;
1816
-        $this->_template_args['context']                                 = $context;
1817
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1818
-        $this->_template_args['learn_more_about_message_templates_link'] =
1819
-            $this->_learn_more_about_message_templates_link();
1820
-
1821
-
1822
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1823
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1824
-            $message_template_group,
1825
-            $context,
1826
-            $context_label
1827
-        );
1828
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1829
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1830
-
1831
-        $this->_template_path = $this->_template_args['GRP_ID']
1832
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1833
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1834
-
1835
-        // send along EE_Message_Template_Group object for further template use.
1836
-        $this->_template_args['MTP'] = $message_template_group;
1837
-
1838
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1839
-            $this->_template_path,
1840
-            $this->_template_args,
1841
-            true
1842
-        );
1843
-
1844
-
1845
-        // finally, let's set the admin_page title
1846
-        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1847
-
1848
-
1849
-        // we need to take care of setting the shortcodes property for use elsewhere.
1850
-        $this->_set_shortcodes();
1851
-
1852
-
1853
-        // final template wrapper
1854
-        $this->display_admin_page_with_sidebar();
1855
-    }
1856
-
1857
-
1858
-    public function filter_tinymce_init($mceInit, $editor_id)
1859
-    {
1860
-        return $mceInit;
1861
-    }
1862
-
1863
-
1864
-    public function add_context_switcher()
1865
-    {
1866
-        return $this->_context_switcher;
1867
-    }
1868
-
1869
-
1870
-    /**
1871
-     * Adds the activation/deactivation toggle for the message template context.
1872
-     *
1873
-     * @param EE_Message_Template_Group $message_template_group
1874
-     * @param string                    $context
1875
-     * @param string                    $context_label
1876
-     * @return string
1877
-     * @throws DomainException
1878
-     * @throws EE_Error
1879
-     * @throws InvalidIdentifierException
1880
-     * @throws ReflectionException
1881
-     */
1882
-    protected function add_active_context_element(
1883
-        EE_Message_Template_Group $message_template_group,
1884
-        $context,
1885
-        $context_label
1886
-    ) {
1887
-        $template_args = [
1888
-            'context'                   => $context,
1889
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1890
-            'is_active'                 => $message_template_group->is_context_active($context),
1891
-            'on_off_action'             => $message_template_group->is_context_active($context)
1892
-                ? 'context-off'
1893
-                : 'context-on',
1894
-            'context_label'             => str_replace(['(', ')'], '', $context_label),
1895
-            'message_template_group_id' => $message_template_group->ID(),
1896
-        ];
1897
-        return EEH_Template::display_template(
1898
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1899
-            $template_args,
1900
-            true
1901
-        );
1902
-    }
1903
-
1904
-
1905
-    /**
1906
-     * Ajax callback for `toggle_context_template` ajax action.
1907
-     * Handles toggling the message context on or off.
1908
-     *
1909
-     * @throws EE_Error
1910
-     * @throws InvalidArgumentException
1911
-     * @throws InvalidDataTypeException
1912
-     * @throws InvalidIdentifierException
1913
-     * @throws InvalidInterfaceException
1914
-     */
1915
-    public function toggle_context_template()
1916
-    {
1917
-        $success = true;
1918
-        // check for required data
1919
-        if (
1920
-            ! (
1921
-                $this->request->requestParamIsSet('message_template_group_id')
1922
-                && $this->request->requestParamIsSet('context')
1923
-                && $this->request->requestParamIsSet('status')
1924
-            )
1925
-        ) {
1926
-            EE_Error::add_error(
1927
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1928
-                __FILE__,
1929
-                __FUNCTION__,
1930
-                __LINE__
1931
-            );
1932
-            $success = false;
1933
-        }
1934
-
1935
-        $nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1936
-        $context = $this->request->getRequestParam('context', '');
1937
-        $status  = $this->request->getRequestParam('status', '');
1938
-
1939
-        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1940
-
1941
-        if ($status !== 'off' && $status !== 'on') {
1942
-            EE_Error::add_error(
1943
-                sprintf(
1944
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1945
-                    $status
1946
-                ),
1947
-                __FILE__,
1948
-                __FUNCTION__,
1949
-                __LINE__
1950
-            );
1951
-            $success = false;
1952
-        }
1953
-        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1954
-        $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1955
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1956
-            EE_Error::add_error(
1957
-                sprintf(
1958
-                    esc_html__(
1959
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1960
-                        'event_espresso'
1961
-                    ),
1962
-                    $message_template_group_id,
1963
-                    'EE_Message_Template_Group'
1964
-                ),
1965
-                __FILE__,
1966
-                __FUNCTION__,
1967
-                __LINE__
1968
-            );
1969
-            $success = false;
1970
-        }
1971
-        if ($success) {
1972
-            $success = $status === 'off'
1973
-                ? $message_template_group->deactivate_context($context)
1974
-                : $message_template_group->activate_context($context);
1975
-        }
1976
-        $this->_template_args['success'] = $success;
1977
-        $this->_return_json();
1978
-    }
1979
-
1980
-
1981
-    public function _add_form_element_before()
1982
-    {
1983
-        return '<form method="post" action="'
1984
-               . $this->_template_args['edit_message_template_form_url']
1985
-               . '" id="ee-msg-edit-frm">';
1986
-    }
1987
-
1988
-
1989
-    public function _add_form_element_after()
1990
-    {
1991
-        return '</form>';
1992
-    }
1993
-
1994
-
1995
-    /**
1996
-     * This executes switching the template pack for a message template.
1997
-     *
1998
-     * @throws EE_Error
1999
-     * @throws InvalidDataTypeException
2000
-     * @throws InvalidInterfaceException
2001
-     * @throws InvalidArgumentException
2002
-     * @throws ReflectionException
2003
-     * @since 4.5.0
2004
-     */
2005
-    public function switch_template_pack()
2006
-    {
2007
-
2008
-        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2009
-        $template_pack = $this->request->getRequestParam('template_pack', '');
2010
-
2011
-        // verify we have needed values.
2012
-        if (empty($GRP_ID) || empty($template_pack)) {
2013
-            $this->_template_args['error'] = true;
2014
-            EE_Error::add_error(
2015
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2016
-                __FILE__,
2017
-                __FUNCTION__,
2018
-                __LINE__
2019
-            );
2020
-        } else {
2021
-            // get template, set the new template_pack and then reset to default
2022
-            /** @var EE_Message_Template_Group $message_template_group */
2023
-            $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2024
-
2025
-            $message_template_group->set_template_pack_name($template_pack);
2026
-            $this->request->setRequestParam('msgr', $message_template_group->messenger());
2027
-            $this->request->setRequestParam('mt', $message_template_group->message_type());
2028
-
2029
-            $query_args = $this->_reset_to_default_template();
2030
-
2031
-            if (empty($query_args['id'])) {
2032
-                EE_Error::add_error(
2033
-                    esc_html__(
2034
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
2035
-                        'event_espresso'
2036
-                    ),
2037
-                    __FILE__,
2038
-                    __FUNCTION__,
2039
-                    __LINE__
2040
-                );
2041
-                $this->_template_args['error'] = true;
2042
-            } else {
2043
-                $template_label       = $message_template_group->get_template_pack()->label;
2044
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2045
-                EE_Error::add_success(
2046
-                    sprintf(
2047
-                        esc_html__(
2048
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2049
-                            'event_espresso'
2050
-                        ),
2051
-                        $template_label,
2052
-                        $template_pack_labels->template_pack
2053
-                    )
2054
-                );
2055
-                // generate the redirect url for js.
2056
-                $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2057
-
2058
-                $this->_template_args['data']['redirect_url'] = $url;
2059
-                $this->_template_args['success']              = true;
2060
-            }
2061
-
2062
-            $this->_return_json();
2063
-        }
2064
-    }
2065
-
2066
-
2067
-    /**
2068
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2069
-     * they want.
2070
-     *
2071
-     * @access protected
2072
-     * @return array|void
2073
-     * @throws EE_Error
2074
-     * @throws InvalidArgumentException
2075
-     * @throws InvalidDataTypeException
2076
-     * @throws InvalidInterfaceException
2077
-     * @throws ReflectionException
2078
-     */
2079
-    protected function _reset_to_default_template()
2080
-    {
2081
-        $templates    = [];
2082
-        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2083
-        $messenger    = $this->request->getRequestParam('msgr');
2084
-        $message_type = $this->request->getRequestParam('mt');
2085
-        // we need to make sure we've got the info we need.
2086
-        if (! ($GRP_ID && $messenger && $message_type)) {
2087
-            EE_Error::add_error(
2088
-                esc_html__(
2089
-                    'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2090
-                    'event_espresso'
2091
-                ),
2092
-                __FILE__,
2093
-                __FUNCTION__,
2094
-                __LINE__
2095
-            );
2096
-        }
2097
-
2098
-        // all templates will be reset to whatever the defaults are
2099
-        // for the global template matching the messenger and message type.
2100
-        $success = ! empty($GRP_ID);
2101
-
2102
-        if ($success) {
2103
-            // let's first determine if the incoming template is a global template,
2104
-            // if it isn't then we need to get the global template matching messenger and message type.
2105
-            // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2106
-
2107
-
2108
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2109
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2110
-
2111
-            if ($success) {
2112
-                // if successfully deleted, lets generate the new ones.
2113
-                // Note. We set GLOBAL to true, because resets on ANY template
2114
-                // will use the related global template defaults for regeneration.
2115
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2116
-                // HOWEVER, we DO keep the template pack and template variation set
2117
-                // for the current custom template when resetting.
2118
-                $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2119
-            }
2120
-        }
2121
-
2122
-        // any error messages?
2123
-        if (! $success) {
2124
-            EE_Error::add_error(
2125
-                esc_html__(
2126
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2127
-                    'event_espresso'
2128
-                ),
2129
-                __FILE__,
2130
-                __FUNCTION__,
2131
-                __LINE__
2132
-            );
2133
-        }
2134
-
2135
-        // all good, let's add a success message!
2136
-        if ($success && ! empty($templates)) {
2137
-            // the info for the template we generated is the first element in the returned array
2138
-            EE_Error::overwrite_success();
2139
-            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2140
-        }
2141
-
2142
-
2143
-        $query_args = [
2144
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2145
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2146
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2147
-        ];
2148
-
2149
-        // if called via ajax then we return query args otherwise redirect
2150
-        if ($this->request->isAjax()) {
2151
-            return $query_args;
2152
-        }
2153
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2154
-    }
2155
-
2156
-
2157
-    /**
2158
-     * Retrieve and set the message preview for display.
2159
-     *
2160
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2161
-     * @return string
2162
-     * @throws ReflectionException
2163
-     * @throws EE_Error
2164
-     * @throws InvalidArgumentException
2165
-     * @throws InvalidDataTypeException
2166
-     * @throws InvalidInterfaceException
2167
-     */
2168
-    public function _preview_message($send = false)
2169
-    {
2170
-        // first make sure we've got the necessary parameters
2171
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2172
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2173
-            EE_Error::add_error(
2174
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2175
-                __FILE__,
2176
-                __FUNCTION__,
2177
-                __LINE__
2178
-            );
2179
-        }
2180
-
2181
-        $context = $this->request->getRequestParam('context');
2182
-        // get the preview!
2183
-        $preview = EED_Messages::preview_message(
2184
-            $this->_active_message_type_name,
2185
-            $context,
2186
-            $this->_active_messenger_name,
2187
-            $send
2188
-        );
2189
-
2190
-        if ($send) {
2191
-            return $preview;
2192
-        }
2193
-
2194
-        // if we have an evt_id set on the request, use it.
2195
-        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2196
-
2197
-        // let's add a button to go back to the edit view
2198
-        $query_args             = [
2199
-            'id'      => $GRP_ID,
2200
-            'evt_id'  => $EVT_ID,
2201
-            'context' => $context,
2202
-            'action'  => 'edit_message_template',
2203
-        ];
2204
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2205
-        $preview_button         = '<a href="'
2206
-                                  . $go_back_url
2207
-                                  . '" class="button-secondary messages-preview-go-back-button">'
2208
-                                  . esc_html__('Go Back to Edit', 'event_espresso')
2209
-                                  . '</a>';
2210
-        $message_types          = $this->get_installed_message_types();
2211
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2212
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2213
-            ? ucwords($active_messenger->label['singular'])
2214
-            : esc_html__('Unknown Messenger', 'event_espresso');
2215
-        // let's provide a helpful title for context
2216
-        $preview_title = sprintf(
2217
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2218
-            $active_messenger_label,
2219
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2220
-        );
2221
-        if (empty($preview)) {
2222
-            $this->noEventsErrorMessage();
2223
-        }
2224
-        // setup display of preview.
2225
-        $this->_admin_page_title                    = $preview_title;
2226
-        $this->_template_args['admin_page_title']   = $preview_title;
2227
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2228
-        $this->_template_args['data']['force_json'] = true;
2229
-
2230
-        return '';
2231
-    }
2232
-
2233
-
2234
-    /**
2235
-     * Used to set an error if there are no events available for generating a preview/test send.
2236
-     *
2237
-     * @param bool $test_send Whether the error should be generated for the context of a test send.
2238
-     */
2239
-    protected function noEventsErrorMessage($test_send = false)
2240
-    {
2241
-        $events_url = parent::add_query_args_and_nonce(
2242
-            [
2243
-                'action' => 'default',
2244
-                'page'   => 'espresso_events',
2245
-            ],
2246
-            admin_url('admin.php')
2247
-        );
2248
-        $message    = $test_send
2249
-            ? esc_html__(
2250
-                'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2251
-                'event_espresso'
2252
-            )
2253
-            : esc_html__(
2254
-                'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2255
-                'event_espresso'
2256
-            );
2257
-
2258
-        EE_Error::add_attention(
2259
-            sprintf(
2260
-                $message,
2261
-                "<a href='{$events_url}'>",
2262
-                '</a>'
2263
-            )
2264
-        );
2265
-    }
2266
-
2267
-
2268
-    /**
2269
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2270
-     * gets called automatically.
2271
-     *
2272
-     * @return void
2273
-     * @throws EE_Error
2274
-     * @since 4.5.0
2275
-     *
2276
-     */
2277
-    protected function _display_preview_message()
2278
-    {
2279
-        $this->display_admin_page_with_no_sidebar();
2280
-    }
2281
-
2282
-
2283
-    /**
2284
-     * registers metaboxes that should show up on the "edit_message_template" page
2285
-     *
2286
-     * @access protected
2287
-     * @return void
2288
-     */
2289
-    protected function _register_edit_meta_boxes()
2290
-    {
2291
-        add_meta_box(
2292
-            'mtp_valid_shortcodes',
2293
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2294
-            [$this, 'shortcode_meta_box'],
2295
-            $this->_current_screen->id,
2296
-            'side'
2297
-        );
2298
-        add_meta_box(
2299
-            'mtp_extra_actions',
2300
-            esc_html__('Extra Actions', 'event_espresso'),
2301
-            [$this, 'extra_actions_meta_box'],
2302
-            $this->_current_screen->id,
2303
-            'side',
2304
-            'high'
2305
-        );
2306
-        add_meta_box(
2307
-            'mtp_templates',
2308
-            esc_html__('Template Styles', 'event_espresso'),
2309
-            [$this, 'template_pack_meta_box'],
2310
-            $this->_current_screen->id,
2311
-            'side',
2312
-            'high'
2313
-        );
2314
-    }
2315
-
2316
-
2317
-    /**
2318
-     * metabox content for all template pack and variation selection.
2319
-     *
2320
-     * @return void
2321
-     * @throws DomainException
2322
-     * @throws EE_Error
2323
-     * @throws InvalidArgumentException
2324
-     * @throws ReflectionException
2325
-     * @throws InvalidDataTypeException
2326
-     * @throws InvalidInterfaceException
2327
-     * @since 4.5.0
2328
-     */
2329
-    public function template_pack_meta_box()
2330
-    {
2331
-        $this->_set_message_template_group();
2332
-
2333
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2334
-
2335
-        $tp_select_values = [];
2336
-
2337
-        foreach ($tp_collection as $tp) {
2338
-            // only include template packs that support this messenger and message type!
2339
-            $supports = $tp->get_supports();
2340
-            if (
2341
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2342
-                || ! in_array(
2343
-                    $this->_message_template_group->message_type(),
2344
-                    $supports[ $this->_message_template_group->messenger() ],
2345
-                    true
2346
-                )
2347
-            ) {
2348
-                // not supported
2349
-                continue;
2350
-            }
2351
-
2352
-            $tp_select_values[] = [
2353
-                'text' => $tp->label,
2354
-                'id'   => $tp->dbref,
2355
-            ];
2356
-        }
2357
-
2358
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2359
-        // the default template pack.  This still allows for the odd template pack to override.
2360
-        if (empty($tp_select_values)) {
2361
-            $tp_select_values[] = [
2362
-                'text' => esc_html__('Default', 'event_espresso'),
2363
-                'id'   => 'default',
2364
-            ];
2365
-        }
2366
-
2367
-        // setup variation select values for the currently selected template.
2368
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2369
-            $this->_message_template_group->messenger(),
2370
-            $this->_message_template_group->message_type()
2371
-        );
2372
-        $variations_select_values = [];
2373
-        foreach ($variations as $variation => $label) {
2374
-            $variations_select_values[] = [
2375
-                'text' => $label,
2376
-                'id'   => $variation,
2377
-            ];
2378
-        }
2379
-
2380
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2381
-
2382
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2383
-            'MTP_template_pack',
2384
-            $tp_select_values,
2385
-            $this->_message_template_group->get_template_pack_name()
2386
-        );
2387
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2388
-            'MTP_template_variation',
2389
-            $variations_select_values,
2390
-            $this->_message_template_group->get_template_pack_variation()
2391
-        );
2392
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
2393
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
2394
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2395
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2396
-
2397
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2398
-
2399
-        EEH_Template::display_template($template, $template_args);
2400
-    }
2401
-
2402
-
2403
-    /**
2404
-     * This meta box holds any extra actions related to Message Templates
2405
-     * For now, this includes Resetting templates to defaults and sending a test email.
2406
-     *
2407
-     * @access  public
2408
-     * @return void
2409
-     * @throws EE_Error
2410
-     */
2411
-    public function extra_actions_meta_box()
2412
-    {
2413
-        $template_form_fields = [];
2414
-
2415
-        $extra_args = [
2416
-            'msgr'   => $this->_message_template_group->messenger(),
2417
-            'mt'     => $this->_message_template_group->message_type(),
2418
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2419
-        ];
2420
-        // first we need to see if there are any fields
2421
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2422
-
2423
-        if (! empty($fields)) {
2424
-            // yup there be fields
2425
-            foreach ($fields as $field => $config) {
2426
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2427
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2428
-                $default  = isset($config['default']) ? $config['default'] : '';
2429
-                $default  = isset($config['value']) ? $config['value'] : $default;
2430
-
2431
-                // if type is hidden and the value is empty
2432
-                // something may have gone wrong so let's correct with the defaults
2433
-                $fix                = $config['input'] === 'hidden'
2434
-                                      && isset($existing[ $field ])
2435
-                                      && empty($existing[ $field ])
2436
-                    ? $default
2437
-                    : '';
2438
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2439
-                    ? $existing[ $field ]
2440
-                    : $fix;
2441
-
2442
-                $template_form_fields[ $field_id ] = [
2443
-                    'name'       => 'test_settings_fld[' . $field . ']',
2444
-                    'label'      => $config['label'],
2445
-                    'input'      => $config['input'],
2446
-                    'type'       => $config['type'],
2447
-                    'required'   => $config['required'],
2448
-                    'validation' => $config['validation'],
2449
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2450
-                    'css_class'  => $config['css_class'],
2451
-                    'options'    => isset($config['options']) ? $config['options'] : [],
2452
-                    'default'    => $default,
2453
-                    'format'     => $config['format'],
2454
-                ];
2455
-            }
2456
-        }
2457
-
2458
-        $test_settings_html = ! empty($template_form_fields)
2459
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2460
-            : '';
2461
-
2462
-        // print out $test_settings_fields
2463
-        if (! empty($test_settings_html)) {
2464
-            $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2465
-            $test_settings_html .= 'name="test_button" value="';
2466
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2467
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2468
-        }
2469
-
2470
-        // and button
2471
-        $test_settings_html .= '<p>';
2472
-        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2473
-        $test_settings_html .= '</p>';
2474
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2475
-        $test_settings_html .= $this->get_action_link_or_button(
2476
-            'reset_to_default',
2477
-            'reset',
2478
-            $extra_args,
2479
-            'button-primary reset-default-button'
2480
-        );
2481
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2482
-        echo $test_settings_html; // already escaped
2483
-    }
2484
-
2485
-
2486
-    /**
2487
-     * This returns the shortcode selector skeleton for a given context and field.
2488
-     *
2489
-     * @param string $field           The name of the field retrieving shortcodes for.
2490
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2491
-     * @return string
2492
-     * @throws DomainException
2493
-     * @throws EE_Error
2494
-     * @throws InvalidArgumentException
2495
-     * @throws ReflectionException
2496
-     * @throws InvalidDataTypeException
2497
-     * @throws InvalidInterfaceException
2498
-     * @since 4.9.rc.000
2499
-     */
2500
-    protected function _get_shortcode_selector($field, $linked_input_id)
2501
-    {
2502
-        $template_args = [
2503
-            'shortcodes'      => $this->_get_shortcodes([$field]),
2504
-            'fieldname'       => $field,
2505
-            'linked_input_id' => $linked_input_id,
2506
-        ];
2507
-
2508
-        return EEH_Template::display_template(
2509
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2510
-            $template_args,
2511
-            true
2512
-        );
2513
-    }
2514
-
2515
-
2516
-    /**
2517
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2518
-     * page)
2519
-     *
2520
-     * @access public
2521
-     * @return void
2522
-     * @throws EE_Error
2523
-     * @throws InvalidArgumentException
2524
-     * @throws ReflectionException
2525
-     * @throws InvalidDataTypeException
2526
-     * @throws InvalidInterfaceException
2527
-     */
2528
-    public function shortcode_meta_box()
2529
-    {
2530
-        $shortcodes = $this->_get_shortcodes([], false);
2531
-        // just make sure the shortcodes property is set
2532
-        // $messenger = $this->_message_template_group->messenger_obj();
2533
-        // now let's set the content depending on the status of the shortcodes array
2534
-        if (empty($shortcodes)) {
2535
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2536
-            return;
2537
-        }
2538
-        ?>
19
+	/**
20
+	 * @var EEM_Message
21
+	 */
22
+	private $MSG_MODEL;
23
+
24
+	/**
25
+	 * @var EEM_Message_Template
26
+	 */
27
+	private $MTP_MODEL;
28
+
29
+	/**
30
+	 * @var EEM_Message_Template_Group
31
+	 */
32
+	private $MTG_MODEL;
33
+
34
+	/**
35
+	 * @var EE_Message_Resource_Manager $_message_resource_manager
36
+	 */
37
+	protected $_message_resource_manager;
38
+
39
+	/**
40
+	 * @var string
41
+	 */
42
+	protected $_active_message_type_name = '';
43
+
44
+	/**
45
+	 * @var string
46
+	 */
47
+	protected $_active_messenger_name = '';
48
+
49
+	/**
50
+	 * @var EE_messenger $_active_messenger
51
+	 */
52
+	protected $_active_messenger;
53
+
54
+	protected $_activate_meta_box_type;
55
+
56
+	protected $_current_message_meta_box;
57
+
58
+	protected $_current_message_meta_box_object;
59
+
60
+	protected $_context_switcher;
61
+
62
+	protected $_shortcodes           = [];
63
+
64
+	protected $_active_messengers    = [];
65
+
66
+	protected $_active_message_types = [];
67
+
68
+	/**
69
+	 * @var EE_Message_Template_Group $_message_template_group
70
+	 */
71
+	protected $_message_template_group;
72
+
73
+	protected $_m_mt_settings = [];
74
+
75
+
76
+	/**
77
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
78
+	 * IF there is no group then it gets automatically set to the Default template pack.
79
+	 *
80
+	 * @since 4.5.0
81
+	 *
82
+	 * @var EE_Messages_Template_Pack
83
+	 */
84
+	protected $_template_pack;
85
+
86
+
87
+	/**
88
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
89
+	 * group is.  If there is no group then it automatically gets set to default.
90
+	 *
91
+	 * @since 4.5.0
92
+	 *
93
+	 * @var string
94
+	 */
95
+	protected $_variation;
96
+
97
+
98
+	/**
99
+	 * @param bool $routing
100
+	 * @throws EE_Error
101
+	 * @throws ReflectionException
102
+	 */
103
+	public function __construct($routing = true)
104
+	{
105
+		// make sure messages autoloader is running
106
+		EED_Messages::set_autoloaders();
107
+		parent::__construct($routing);
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return EEM_Message
113
+	 * @throws EE_Error
114
+	 */
115
+	public function getMsgModel()
116
+	{
117
+		if (! $this->MSG_MODEL instanceof EEM_Message) {
118
+			$this->MSG_MODEL = EEM_Message::instance();
119
+		}
120
+		return $this->MSG_MODEL;
121
+	}
122
+
123
+
124
+	/**
125
+	 * @return EEM_Message_Template
126
+	 * @throws EE_Error
127
+	 */
128
+	public function getMtpModel()
129
+	{
130
+		if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
131
+			$this->MTP_MODEL = EEM_Message_Template::instance();
132
+		}
133
+		return $this->MTP_MODEL;
134
+	}
135
+
136
+
137
+	/**
138
+	 * @return EEM_Message_Template_Group
139
+	 * @throws EE_Error
140
+	 */
141
+	public function getMtgModel()
142
+	{
143
+		if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
144
+			$this->MTG_MODEL = EEM_Message_Template_Group::instance();
145
+		}
146
+		return $this->MTG_MODEL;
147
+	}
148
+
149
+
150
+	/**
151
+	 * @throws EE_Error
152
+	 * @throws ReflectionException
153
+	 */
154
+	protected function _init_page_props()
155
+	{
156
+		$this->page_slug        = EE_MSG_PG_SLUG;
157
+		$this->page_label       = esc_html__('Messages Settings', 'event_espresso');
158
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
159
+		$this->_admin_base_path = EE_MSG_ADMIN;
160
+
161
+		$messenger    = $this->request->getRequestParam('messenger', '');
162
+		$message_type = $this->request->getRequestParam('message_type', '');
163
+		$this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger);
164
+		$this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type);
165
+
166
+		$this->_load_message_resource_manager();
167
+	}
168
+
169
+
170
+	/**
171
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
172
+	 *
173
+	 * @throws EE_Error
174
+	 * @throws InvalidDataTypeException
175
+	 * @throws InvalidInterfaceException
176
+	 * @throws InvalidArgumentException
177
+	 * @throws ReflectionException
178
+	 */
179
+	protected function _load_message_resource_manager()
180
+	{
181
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
182
+	}
183
+
184
+
185
+	/**
186
+	 * @return array
187
+	 * @throws EE_Error
188
+	 * @throws InvalidArgumentException
189
+	 * @throws InvalidDataTypeException
190
+	 * @throws InvalidInterfaceException
191
+	 * @deprecated 4.9.9.rc.014
192
+	 */
193
+	public function get_messengers_for_list_table()
194
+	{
195
+		EE_Error::doing_it_wrong(
196
+			__METHOD__,
197
+			sprintf(
198
+				esc_html__(
199
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
200
+					'event_espresso'
201
+				),
202
+				'Messages_Admin_Page::get_messengers_select_input()'
203
+			),
204
+			'4.9.9.rc.014'
205
+		);
206
+
207
+		$m_values          = [];
208
+		$active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);
209
+		// setup messengers for selects
210
+		$i = 1;
211
+		foreach ($active_messengers as $active_messenger) {
212
+			if ($active_messenger instanceof EE_Message) {
213
+				$m_values[ $i ]['id']   = $active_messenger->messenger();
214
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
215
+				$i++;
216
+			}
217
+		}
218
+
219
+		return $m_values;
220
+	}
221
+
222
+
223
+	/**
224
+	 * @return array
225
+	 * @throws EE_Error
226
+	 * @throws InvalidArgumentException
227
+	 * @throws InvalidDataTypeException
228
+	 * @throws InvalidInterfaceException
229
+	 * @deprecated 4.9.9.rc.014
230
+	 */
231
+	public function get_message_types_for_list_table()
232
+	{
233
+		EE_Error::doing_it_wrong(
234
+			__METHOD__,
235
+			sprintf(
236
+				esc_html__(
237
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
238
+					'event_espresso'
239
+				),
240
+				'Messages_Admin_Page::get_message_types_select_input()'
241
+			),
242
+			'4.9.9.rc.014'
243
+		);
244
+
245
+		$mt_values       = [];
246
+		$active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);
247
+		$i               = 1;
248
+		foreach ($active_messages as $active_message) {
249
+			if ($active_message instanceof EE_Message) {
250
+				$mt_values[ $i ]['id']   = $active_message->message_type();
251
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
252
+				$i++;
253
+			}
254
+		}
255
+
256
+		return $mt_values;
257
+	}
258
+
259
+
260
+	/**
261
+	 * @return array
262
+	 * @throws EE_Error
263
+	 * @throws InvalidArgumentException
264
+	 * @throws InvalidDataTypeException
265
+	 * @throws InvalidInterfaceException
266
+	 * @deprecated 4.9.9.rc.014
267
+	 */
268
+	public function get_contexts_for_message_types_for_list_table()
269
+	{
270
+		EE_Error::doing_it_wrong(
271
+			__METHOD__,
272
+			sprintf(
273
+				esc_html__(
274
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
275
+					'event_espresso'
276
+				),
277
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
278
+			),
279
+			'4.9.9.rc.014'
280
+		);
281
+
282
+		$contexts                = [];
283
+		$active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);
284
+		foreach ($active_message_contexts as $active_message) {
285
+			if ($active_message instanceof EE_Message) {
286
+				$message_type = $active_message->message_type_object();
287
+				if ($message_type instanceof EE_message_type) {
288
+					$message_type_contexts = $message_type->get_contexts();
289
+					foreach ($message_type_contexts as $context => $context_details) {
290
+						$contexts[ $context ] = $context_details['label'];
291
+					}
292
+				}
293
+			}
294
+		}
295
+
296
+		return $contexts;
297
+	}
298
+
299
+
300
+	/**
301
+	 * Generate select input with provided messenger options array.
302
+	 *
303
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
304
+	 *                                 labels.
305
+	 * @return string
306
+	 * @throws EE_Error
307
+	 */
308
+	public function get_messengers_select_input($messenger_options)
309
+	{
310
+		// if empty or just one value then just return an empty string
311
+		if (
312
+			empty($messenger_options)
313
+			|| ! is_array($messenger_options)
314
+			|| count($messenger_options) === 1
315
+		) {
316
+			return '';
317
+		}
318
+		// merge in default
319
+		$messenger_options = array_merge(
320
+			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
321
+			$messenger_options
322
+		);
323
+		$input             = new EE_Select_Input(
324
+			$messenger_options,
325
+			[
326
+				'html_name'  => 'ee_messenger_filter_by',
327
+				'html_id'    => 'ee_messenger_filter_by',
328
+				'html_class' => 'wide',
329
+				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'),
330
+			]
331
+		);
332
+
333
+		return $input->get_html_for_input();
334
+	}
335
+
336
+
337
+	/**
338
+	 * Generate select input with provided message type options array.
339
+	 *
340
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
341
+	 *                                    message type labels
342
+	 * @return string
343
+	 * @throws EE_Error
344
+	 */
345
+	public function get_message_types_select_input($message_type_options)
346
+	{
347
+		// if empty or count of options is 1 then just return an empty string
348
+		if (
349
+			empty($message_type_options)
350
+			|| ! is_array($message_type_options)
351
+			|| count($message_type_options) === 1
352
+		) {
353
+			return '';
354
+		}
355
+		// merge in default
356
+		$message_type_options = array_merge(
357
+			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
358
+			$message_type_options
359
+		);
360
+		$input                = new EE_Select_Input(
361
+			$message_type_options,
362
+			[
363
+				'html_name'  => 'ee_message_type_filter_by',
364
+				'html_id'    => 'ee_message_type_filter_by',
365
+				'html_class' => 'wide',
366
+				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'),
367
+			]
368
+		);
369
+
370
+		return $input->get_html_for_input();
371
+	}
372
+
373
+
374
+	/**
375
+	 * Generate select input with provide message type contexts array.
376
+	 *
377
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
378
+	 *                               context label.
379
+	 * @return string
380
+	 * @throws EE_Error
381
+	 */
382
+	public function get_contexts_for_message_types_select_input($context_options)
383
+	{
384
+		// if empty or count of options is one then just return empty string
385
+		if (
386
+			empty($context_options)
387
+			|| ! is_array($context_options)
388
+			|| count($context_options) === 1
389
+		) {
390
+			return '';
391
+		}
392
+		// merge in default
393
+		$context_options = array_merge(
394
+			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
395
+			$context_options
396
+		);
397
+		$input           = new EE_Select_Input(
398
+			$context_options,
399
+			[
400
+				'html_name'  => 'ee_context_filter_by',
401
+				'html_id'    => 'ee_context_filter_by',
402
+				'html_class' => 'wide',
403
+				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'),
404
+			]
405
+		);
406
+
407
+		return $input->get_html_for_input();
408
+	}
409
+
410
+
411
+	protected function _ajax_hooks()
412
+	{
413
+		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']);
414
+		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']);
415
+		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']);
416
+		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']);
417
+		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']);
418
+		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']);
419
+	}
420
+
421
+
422
+	protected function _define_page_props()
423
+	{
424
+		$this->_admin_page_title = $this->page_label;
425
+		$this->_labels           = [
426
+			'buttons'    => [
427
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
428
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
429
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
430
+			],
431
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
432
+		];
433
+	}
434
+
435
+
436
+	/**
437
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
438
+	 *
439
+	 * @access protected
440
+	 * @return void
441
+	 */
442
+	protected function _set_page_routes()
443
+	{
444
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
445
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
446
+		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int');
447
+
448
+		$this->_page_routes = [
449
+			'default'                          => [
450
+				'func'       => '_message_queue_list_table',
451
+				'capability' => 'ee_read_global_messages',
452
+			],
453
+			'global_mtps'                      => [
454
+				'func'       => '_ee_default_messages_overview_list_table',
455
+				'capability' => 'ee_read_global_messages',
456
+			],
457
+			'custom_mtps'                      => [
458
+				'func'       => '_custom_mtps_preview',
459
+				'capability' => 'ee_read_messages',
460
+			],
461
+			'add_new_message_template'         => [
462
+				'func'       => 'add_message_template',
463
+				'capability' => 'ee_edit_messages',
464
+				'noheader'   => true,
465
+			],
466
+			'edit_message_template'            => [
467
+				'func'       => '_edit_message_template',
468
+				'capability' => 'ee_edit_message',
469
+				'obj_id'     => $GRP_ID,
470
+			],
471
+			'preview_message'                  => [
472
+				'func'               => '_preview_message',
473
+				'capability'         => 'ee_read_message',
474
+				'obj_id'             => $GRP_ID,
475
+				'noheader'           => true,
476
+				'headers_sent_route' => 'display_preview_message',
477
+			],
478
+			'display_preview_message'          => [
479
+				'func'       => '_display_preview_message',
480
+				'capability' => 'ee_read_message',
481
+				'obj_id'     => $GRP_ID,
482
+			],
483
+			'insert_message_template'          => [
484
+				'func'       => '_insert_or_update_message_template',
485
+				'capability' => 'ee_edit_messages',
486
+				'args'       => ['new' => true],
487
+				'noheader'   => true,
488
+			],
489
+			'update_message_template'          => [
490
+				'func'       => '_insert_or_update_message_template',
491
+				'capability' => 'ee_edit_message',
492
+				'obj_id'     => $GRP_ID,
493
+				'args'       => ['new' => false],
494
+				'noheader'   => true,
495
+			],
496
+			'trash_message_template'           => [
497
+				'func'       => '_trash_or_restore_message_template',
498
+				'capability' => 'ee_delete_message',
499
+				'obj_id'     => $GRP_ID,
500
+				'args'       => ['trash' => true, 'all' => true],
501
+				'noheader'   => true,
502
+			],
503
+			'trash_message_template_context'   => [
504
+				'func'       => '_trash_or_restore_message_template',
505
+				'capability' => 'ee_delete_message',
506
+				'obj_id'     => $GRP_ID,
507
+				'args'       => ['trash' => true],
508
+				'noheader'   => true,
509
+			],
510
+			'restore_message_template'         => [
511
+				'func'       => '_trash_or_restore_message_template',
512
+				'capability' => 'ee_delete_message',
513
+				'obj_id'     => $GRP_ID,
514
+				'args'       => ['trash' => false, 'all' => true],
515
+				'noheader'   => true,
516
+			],
517
+			'restore_message_template_context' => [
518
+				'func'       => '_trash_or_restore_message_template',
519
+				'capability' => 'ee_delete_message',
520
+				'obj_id'     => $GRP_ID,
521
+				'args'       => ['trash' => false],
522
+				'noheader'   => true,
523
+			],
524
+			'delete_message_template'          => [
525
+				'func'       => '_delete_message_template',
526
+				'capability' => 'ee_delete_message',
527
+				'obj_id'     => $GRP_ID,
528
+				'noheader'   => true,
529
+			],
530
+			'reset_to_default'                 => [
531
+				'func'       => '_reset_to_default_template',
532
+				'capability' => 'ee_edit_message',
533
+				'obj_id'     => $GRP_ID,
534
+				'noheader'   => true,
535
+			],
536
+			'settings'                         => [
537
+				'func'       => '_settings',
538
+				'capability' => 'manage_options',
539
+			],
540
+			'update_global_settings'           => [
541
+				'func'       => '_update_global_settings',
542
+				'capability' => 'manage_options',
543
+				'noheader'   => true,
544
+			],
545
+			'generate_now'                     => [
546
+				'func'       => '_generate_now',
547
+				'capability' => 'ee_send_message',
548
+				'noheader'   => true,
549
+			],
550
+			'generate_and_send_now'            => [
551
+				'func'       => '_generate_and_send_now',
552
+				'capability' => 'ee_send_message',
553
+				'noheader'   => true,
554
+			],
555
+			'queue_for_resending'              => [
556
+				'func'       => '_queue_for_resending',
557
+				'capability' => 'ee_send_message',
558
+				'noheader'   => true,
559
+			],
560
+			'send_now'                         => [
561
+				'func'       => '_send_now',
562
+				'capability' => 'ee_send_message',
563
+				'noheader'   => true,
564
+			],
565
+			'delete_ee_message'                => [
566
+				'func'       => '_delete_ee_messages',
567
+				'capability' => 'ee_delete_messages',
568
+				'noheader'   => true,
569
+			],
570
+			'delete_ee_messages'               => [
571
+				'func'       => '_delete_ee_messages',
572
+				'capability' => 'ee_delete_messages',
573
+				'noheader'   => true,
574
+				'obj_id'     => $MSG_ID,
575
+			],
576
+		];
577
+	}
578
+
579
+
580
+	protected function _set_page_config()
581
+	{
582
+		$this->_page_config = [
583
+			'default'                  => [
584
+				'nav'           => [
585
+					'label' => esc_html__('Message Activity', 'event_espresso'),
586
+					'order' => 10,
587
+				],
588
+				'list_table'    => 'EE_Message_List_Table',
589
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
590
+				'require_nonce' => false,
591
+			],
592
+			'global_mtps'              => [
593
+				'nav'           => [
594
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
595
+					'order' => 20,
596
+				],
597
+				'list_table'    => 'Messages_Template_List_Table',
598
+				'help_tabs'     => [
599
+					'messages_overview_help_tab'                                => [
600
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
601
+						'filename' => 'messages_overview',
602
+					],
603
+					'messages_overview_messages_table_column_headings_help_tab' => [
604
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
605
+						'filename' => 'messages_overview_table_column_headings',
606
+					],
607
+					'messages_overview_messages_filters_help_tab'               => [
608
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
609
+						'filename' => 'messages_overview_filters',
610
+					],
611
+					'messages_overview_messages_views_help_tab'                 => [
612
+						'title'    => esc_html__('Message Views', 'event_espresso'),
613
+						'filename' => 'messages_overview_views',
614
+					],
615
+					'message_overview_message_types_help_tab'                   => [
616
+						'title'    => esc_html__('Message Types', 'event_espresso'),
617
+						'filename' => 'messages_overview_types',
618
+					],
619
+					'messages_overview_messengers_help_tab'                     => [
620
+						'title'    => esc_html__('Messengers', 'event_espresso'),
621
+						'filename' => 'messages_overview_messengers',
622
+					],
623
+				],
624
+				'require_nonce' => false,
625
+			],
626
+			'custom_mtps'              => [
627
+				'nav'           => [
628
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
629
+					'order' => 30,
630
+				],
631
+				'help_tabs'     => [],
632
+				'require_nonce' => false,
633
+			],
634
+			'add_new_message_template' => [
635
+				'nav'           => [
636
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
637
+					'order'      => 5,
638
+					'persistent' => false,
639
+				],
640
+				'require_nonce' => false,
641
+			],
642
+			'edit_message_template'    => [
643
+				'labels'        => [
644
+					'buttons'    => [
645
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
646
+					],
647
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
648
+				],
649
+				'nav'           => [
650
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
651
+					'order'      => 5,
652
+					'persistent' => false,
653
+					'url'        => '',
654
+				],
655
+				'metaboxes'     => ['_publish_post_box', '_register_edit_meta_boxes'],
656
+				'has_metaboxes' => true,
657
+				'help_tabs'     => [
658
+					'edit_message_template'            => [
659
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
660
+						'callback' => 'edit_message_template_help_tab',
661
+					],
662
+					'message_templates_help_tab'       => [
663
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
664
+						'filename' => 'messages_templates',
665
+					],
666
+					'message_template_shortcodes'      => [
667
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
668
+						'callback' => 'message_template_shortcodes_help_tab',
669
+					],
670
+					'message_preview_help_tab'         => [
671
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
672
+						'filename' => 'messages_preview',
673
+					],
674
+					'messages_overview_other_help_tab' => [
675
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
676
+						'filename' => 'messages_overview_other',
677
+					],
678
+				],
679
+				'require_nonce' => false,
680
+			],
681
+			'display_preview_message'  => [
682
+				'nav'           => [
683
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
684
+					'order'      => 5,
685
+					'url'        => '',
686
+					'persistent' => false,
687
+				],
688
+				'help_tabs'     => [
689
+					'preview_message' => [
690
+						'title'    => esc_html__('About Previews', 'event_espresso'),
691
+						'callback' => 'preview_message_help_tab',
692
+					],
693
+				],
694
+				'require_nonce' => false,
695
+			],
696
+			'settings'                 => [
697
+				'nav'           => [
698
+					'label' => esc_html__('Settings', 'event_espresso'),
699
+					'order' => 40,
700
+				],
701
+				'metaboxes'     => ['_messages_settings_metaboxes'],
702
+				'help_tabs'     => [
703
+					'messages_settings_help_tab'               => [
704
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
705
+						'filename' => 'messages_settings',
706
+					],
707
+					'messages_settings_message_types_help_tab' => [
708
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
709
+						'filename' => 'messages_settings_message_types',
710
+					],
711
+					'messages_settings_messengers_help_tab'    => [
712
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
713
+						'filename' => 'messages_settings_messengers',
714
+					],
715
+				],
716
+				'require_nonce' => false,
717
+			],
718
+		];
719
+	}
720
+
721
+
722
+	protected function _add_screen_options()
723
+	{
724
+		// todo
725
+	}
726
+
727
+
728
+	protected function _add_screen_options_global_mtps()
729
+	{
730
+		/**
731
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
732
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
733
+		 */
734
+		$page_title              = $this->_admin_page_title;
735
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
736
+		$this->_per_page_screen_option();
737
+		$this->_admin_page_title = $page_title;
738
+	}
739
+
740
+
741
+	protected function _add_screen_options_default()
742
+	{
743
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
744
+		$this->_per_page_screen_option();
745
+	}
746
+
747
+
748
+	// none of the below group are currently used for Messages
749
+	protected function _add_feature_pointers()
750
+	{
751
+	}
752
+
753
+
754
+	public function admin_init()
755
+	{
756
+	}
757
+
758
+
759
+	public function admin_notices()
760
+	{
761
+	}
762
+
763
+
764
+	public function admin_footer_scripts()
765
+	{
766
+	}
767
+
768
+
769
+	public function messages_help_tab()
770
+	{
771
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
772
+	}
773
+
774
+
775
+	public function messengers_help_tab()
776
+	{
777
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
778
+	}
779
+
780
+
781
+	public function message_types_help_tab()
782
+	{
783
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
784
+	}
785
+
786
+
787
+	public function messages_overview_help_tab()
788
+	{
789
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
790
+	}
791
+
792
+
793
+	public function message_templates_help_tab()
794
+	{
795
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
796
+	}
797
+
798
+
799
+	public function edit_message_template_help_tab()
800
+	{
801
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
802
+						. esc_attr__('Editor Title', 'event_espresso')
803
+						. '" />';
804
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
805
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
806
+						. '" />';
807
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
808
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
809
+						. '" />';
810
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
811
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
812
+						. '" />';
813
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
814
+						. esc_attr__('Publish Metabox', 'event_espresso')
815
+						. '" />';
816
+		EEH_Template::display_template(
817
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
818
+			$args
819
+		);
820
+	}
821
+
822
+
823
+	/**
824
+	 * @throws ReflectionException
825
+	 * @throws EE_Error
826
+	 */
827
+	public function message_template_shortcodes_help_tab()
828
+	{
829
+		$this->_set_shortcodes();
830
+		$args['shortcodes'] = $this->_shortcodes;
831
+		EEH_Template::display_template(
832
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
833
+			$args
834
+		);
835
+	}
836
+
837
+
838
+	public function preview_message_help_tab()
839
+	{
840
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
841
+	}
842
+
843
+
844
+	public function settings_help_tab()
845
+	{
846
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
847
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
848
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
849
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
850
+		$args['img3'] = '<div class="switch">'
851
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
852
+						. ' type="checkbox" checked="checked">'
853
+						. '<label for="ee-on-off-toggle-on"></label>'
854
+						. '</div>';
855
+		$args['img4'] = '<div class="switch">'
856
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
857
+						. ' type="checkbox">'
858
+						. '<label for="ee-on-off-toggle-on"></label>'
859
+						. '</div>';
860
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
861
+	}
862
+
863
+
864
+	public function load_scripts_styles()
865
+	{
866
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
867
+		wp_enqueue_style('espresso_ee_msg');
868
+
869
+		wp_register_script(
870
+			'ee-messages-settings',
871
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
872
+			['jquery-ui-droppable', 'ee-serialize-full-array'],
873
+			EVENT_ESPRESSO_VERSION,
874
+			true
875
+		);
876
+		wp_register_script(
877
+			'ee-msg-list-table-js',
878
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
879
+			['ee-dialog'],
880
+			EVENT_ESPRESSO_VERSION
881
+		);
882
+	}
883
+
884
+
885
+	public function load_scripts_styles_default()
886
+	{
887
+		wp_enqueue_script('ee-msg-list-table-js');
888
+	}
889
+
890
+
891
+	public function wp_editor_css($mce_css)
892
+	{
893
+		// if we're on the edit_message_template route
894
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
895
+			$message_type_name = $this->_active_message_type_name;
896
+
897
+			// we're going to REPLACE the existing mce css
898
+			// we need to get the css file location from the active messenger
899
+			$mce_css = $this->_active_messenger->get_variation(
900
+				$this->_template_pack,
901
+				$message_type_name,
902
+				true,
903
+				'wpeditor',
904
+				$this->_variation
905
+			);
906
+		}
907
+
908
+		return $mce_css;
909
+	}
910
+
911
+
912
+	/**
913
+	 * @throws EE_Error
914
+	 * @throws ReflectionException
915
+	 */
916
+	public function load_scripts_styles_edit_message_template()
917
+	{
918
+
919
+		$this->_set_shortcodes();
920
+
921
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
922
+			esc_html__(
923
+				'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
924
+				'event_espresso'
925
+			),
926
+			$this->_message_template_group->messenger_obj()->label['singular'],
927
+			$this->_message_template_group->message_type_obj()->label['singular']
928
+		);
929
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
930
+			'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
931
+			'event_espresso'
932
+		);
933
+		EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
934
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
935
+			'event_espresso'
936
+		);
937
+
938
+		wp_register_script(
939
+			'ee_msgs_edit_js',
940
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
941
+			['jquery'],
942
+			EVENT_ESPRESSO_VERSION
943
+		);
944
+
945
+		wp_enqueue_script('ee_admin_js');
946
+		wp_enqueue_script('ee_msgs_edit_js');
947
+
948
+		// add in special css for tiny_mce
949
+		add_filter('mce_css', [$this, 'wp_editor_css']);
950
+	}
951
+
952
+
953
+	/**
954
+	 * @throws EE_Error
955
+	 * @throws ReflectionException
956
+	 */
957
+	public function load_scripts_styles_display_preview_message()
958
+	{
959
+		$this->_set_message_template_group();
960
+		if ($this->_active_messenger_name) {
961
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
962
+				$this->_active_messenger_name
963
+			);
964
+		}
965
+
966
+		wp_enqueue_style(
967
+			'espresso_preview_css',
968
+			$this->_active_messenger->get_variation(
969
+				$this->_template_pack,
970
+				$this->_active_message_type_name,
971
+				true,
972
+				'preview',
973
+				$this->_variation
974
+			)
975
+		);
976
+	}
977
+
978
+
979
+	public function load_scripts_styles_settings()
980
+	{
981
+		wp_register_style(
982
+			'ee-message-settings',
983
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
984
+			[],
985
+			EVENT_ESPRESSO_VERSION
986
+		);
987
+		wp_enqueue_style('ee-text-links');
988
+		wp_enqueue_style('ee-message-settings');
989
+		wp_enqueue_script('ee-messages-settings');
990
+	}
991
+
992
+
993
+	/**
994
+	 * set views array for List Table
995
+	 */
996
+	public function _set_list_table_views_global_mtps()
997
+	{
998
+		$this->_views = [
999
+			'in_use' => [
1000
+				'slug'  => 'in_use',
1001
+				'label' => esc_html__('In Use', 'event_espresso'),
1002
+				'count' => 0,
1003
+			],
1004
+		];
1005
+	}
1006
+
1007
+
1008
+	/**
1009
+	 * Set views array for the Custom Template List Table
1010
+	 */
1011
+	public function _set_list_table_views_custom_mtps()
1012
+	{
1013
+		$this->_set_list_table_views_global_mtps();
1014
+		$this->_views['in_use']['bulk_action'] = [
1015
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
1016
+		];
1017
+	}
1018
+
1019
+
1020
+	/**
1021
+	 * set views array for message queue list table
1022
+	 *
1023
+	 * @throws InvalidDataTypeException
1024
+	 * @throws InvalidInterfaceException
1025
+	 * @throws InvalidArgumentException
1026
+	 * @throws EE_Error
1027
+	 * @throws ReflectionException
1028
+	 */
1029
+	public function _set_list_table_views_default()
1030
+	{
1031
+		EE_Registry::instance()->load_helper('Template');
1032
+
1033
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
1034
+			'ee_send_message',
1035
+			'message_list_table_bulk_actions'
1036
+		)
1037
+			? [
1038
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
1039
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
1040
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
1041
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
1042
+			]
1043
+			: [];
1044
+
1045
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
1046
+			'ee_delete_messages',
1047
+			'message_list_table_bulk_actions'
1048
+		)
1049
+			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')]
1050
+			: [];
1051
+
1052
+
1053
+		$this->_views = [
1054
+			'all' => [
1055
+				'slug'        => 'all',
1056
+				'label'       => esc_html__('All', 'event_espresso'),
1057
+				'count'       => 0,
1058
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1059
+			],
1060
+		];
1061
+
1062
+
1063
+		foreach ($this->getMsgModel()->all_statuses() as $status) {
1064
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1065
+				continue;
1066
+			}
1067
+			$status_bulk_actions = $common_bulk_actions;
1068
+			// unset bulk actions not applying to status
1069
+			if (! empty($status_bulk_actions)) {
1070
+				switch ($status) {
1071
+					case EEM_Message::status_idle:
1072
+					case EEM_Message::status_resend:
1073
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1074
+						break;
1075
+
1076
+					case EEM_Message::status_failed:
1077
+					case EEM_Message::status_debug_only:
1078
+					case EEM_Message::status_messenger_executing:
1079
+						$status_bulk_actions = [];
1080
+						break;
1081
+
1082
+					case EEM_Message::status_incomplete:
1083
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1084
+						break;
1085
+
1086
+					case EEM_Message::status_retry:
1087
+					case EEM_Message::status_sent:
1088
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1089
+						break;
1090
+				}
1091
+			}
1092
+
1093
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1094
+			if ($status === EEM_Message::status_messenger_executing) {
1095
+				continue;
1096
+			}
1097
+
1098
+			$this->_views[ strtolower($status) ] = [
1099
+				'slug'        => strtolower($status),
1100
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1101
+				'count'       => 0,
1102
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1103
+			];
1104
+		}
1105
+	}
1106
+
1107
+
1108
+	/**
1109
+	 * @throws EE_Error
1110
+	 */
1111
+	protected function _ee_default_messages_overview_list_table()
1112
+	{
1113
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1114
+		$this->display_admin_list_table_page_with_no_sidebar();
1115
+	}
1116
+
1117
+
1118
+	/**
1119
+	 * @throws EE_Error
1120
+	 * @throws ReflectionException
1121
+	 */
1122
+	protected function _message_queue_list_table()
1123
+	{
1124
+		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso');
1125
+		$this->_template_args['per_column']        = 6;
1126
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
1127
+		$this->_template_args['before_list_table'] = '<h3>'
1128
+													 . $this->getMsgModel()->get_pretty_label_for_results()
1129
+													 . '</h3>';
1130
+		$this->display_admin_list_table_page_with_no_sidebar();
1131
+	}
1132
+
1133
+
1134
+	/**
1135
+	 * @throws EE_Error
1136
+	 */
1137
+	protected function _message_legend_items()
1138
+	{
1139
+
1140
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1141
+		$action_items       = [];
1142
+
1143
+		foreach ($action_css_classes as $action_item => $action_details) {
1144
+			if ($action_item === 'see_notifications_for') {
1145
+				continue;
1146
+			}
1147
+			$action_items[ $action_item ] = [
1148
+				'class' => $action_details['css_class'],
1149
+				'desc'  => $action_details['label'],
1150
+			];
1151
+		}
1152
+
1153
+		/** @var array $status_items status legend setup */
1154
+		$status_items = [
1155
+			'sent_status'                => [
1156
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1157
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1158
+			],
1159
+			'idle_status'                => [
1160
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1161
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1162
+			],
1163
+			'failed_status'              => [
1164
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1165
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1166
+			],
1167
+			'messenger_executing_status' => [
1168
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1169
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1170
+			],
1171
+			'resend_status'              => [
1172
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1173
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1174
+			],
1175
+			'incomplete_status'          => [
1176
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1177
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1178
+			],
1179
+			'retry_status'               => [
1180
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1181
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1182
+			],
1183
+		];
1184
+		if (EEM_Message::debug()) {
1185
+			$status_items['debug_only_status'] = [
1186
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1187
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1188
+			];
1189
+		}
1190
+
1191
+		return array_merge($action_items, $status_items);
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * @throws EE_Error
1197
+	 */
1198
+	protected function _custom_mtps_preview()
1199
+	{
1200
+		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1201
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1202
+												. ' alt="' . esc_attr__(
1203
+													'Preview Custom Message Templates screenshot',
1204
+													'event_espresso'
1205
+												) . '" />';
1206
+		$this->_template_args['preview_text'] = '<strong>'
1207
+												. esc_html__(
1208
+													'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1209
+													'event_espresso'
1210
+												)
1211
+												. '</strong>';
1212
+
1213
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1214
+	}
1215
+
1216
+
1217
+	/**
1218
+	 * get_message_templates
1219
+	 * This gets all the message templates for listing on the overview list.
1220
+	 *
1221
+	 * @access public
1222
+	 * @param int    $per_page the amount of templates groups to show per page
1223
+	 * @param string $type     the current _view we're getting templates for
1224
+	 * @param bool   $count    return count?
1225
+	 * @param bool   $all      disregard any paging info (get all data);
1226
+	 * @param bool   $global   whether to return just global (true) or custom templates (false)
1227
+	 * @return array
1228
+	 * @throws EE_Error
1229
+	 * @throws InvalidArgumentException
1230
+	 * @throws InvalidDataTypeException
1231
+	 * @throws InvalidInterfaceException
1232
+	 */
1233
+	public function get_message_templates(
1234
+		$per_page = 10,
1235
+		$type = 'in_use',
1236
+		$count = false,
1237
+		$all = false,
1238
+		$global = true
1239
+	) {
1240
+		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID');
1241
+		$this->request->setRequestParam('orderby', $orderby);
1242
+
1243
+		$order        = $this->request->getRequestParam('order', 'ASC');
1244
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1245
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1246
+
1247
+		$offset = ($current_page - 1) * $per_page;
1248
+		$limit  = $all ? null : [$offset, $per_page];
1249
+
1250
+		// options will match what is in the _views array property
1251
+		return $type === 'in_use'
1252
+			? $this->getMtgModel()->get_all_active_message_templates(
1253
+				$orderby,
1254
+				$order,
1255
+				$limit,
1256
+				$count,
1257
+				$global,
1258
+				true
1259
+			)
1260
+			: $this->getMtgModel()->get_all_trashed_grouped_message_templates(
1261
+				$orderby,
1262
+				$order,
1263
+				$limit,
1264
+				$count,
1265
+				$global
1266
+			);
1267
+	}
1268
+
1269
+
1270
+	/**
1271
+	 * filters etc might need a list of installed message_types
1272
+	 *
1273
+	 * @return array an array of message type objects
1274
+	 */
1275
+	public function get_installed_message_types()
1276
+	{
1277
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1278
+		$installed               = [];
1279
+
1280
+		foreach ($installed_message_types as $message_type) {
1281
+			$installed[ $message_type->name ] = $message_type;
1282
+		}
1283
+
1284
+		return $installed;
1285
+	}
1286
+
1287
+
1288
+	/**
1289
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1290
+	 *
1291
+	 * @param string $message_type
1292
+	 * @param string $messenger
1293
+	 * @param string $GRP_ID
1294
+	 *
1295
+	 * @throws EE_error
1296
+	 * @throws ReflectionException
1297
+	 */
1298
+	public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1299
+	{
1300
+		// set values override any request data
1301
+		$message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;
1302
+		$messenger    = ! empty($messenger) ? $messenger : $this->_active_messenger_name;
1303
+		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int');
1304
+
1305
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1306
+		if (empty($message_type) || empty($messenger)) {
1307
+			throw new EE_Error(
1308
+				esc_html__(
1309
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1310
+					'event_espresso'
1311
+				)
1312
+			);
1313
+		}
1314
+
1315
+		// we need the GRP_ID for the template being used as the base for the new template
1316
+		if (empty($GRP_ID)) {
1317
+			throw new EE_Error(
1318
+				esc_html__(
1319
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1320
+					'event_espresso'
1321
+				)
1322
+			);
1323
+		}
1324
+
1325
+		// let's just make sure the template gets generated!
1326
+
1327
+		// we need to reassign some variables for what the insert is expecting
1328
+		$this->request->setRequestParam('MTP_messenger', $messenger);
1329
+		$this->request->setRequestParam('MTP_message_type', $message_type);
1330
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
1331
+
1332
+		$this->_insert_or_update_message_template(true);
1333
+	}
1334
+
1335
+
1336
+	/**
1337
+	 * @param string $message_type     message type slug
1338
+	 * @param string $messenger        messenger slug
1339
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1340
+	 *                                 off of.
1341
+	 * @throws EE_error
1342
+	 * @throws ReflectionException
1343
+	 * @deprecated $VID:$
1344
+	 */
1345
+	protected function _add_message_template($message_type, $messenger, $GRP_ID)
1346
+	{
1347
+		$this->add_message_template($message_type, $messenger, $GRP_ID);
1348
+	}
1349
+
1350
+
1351
+	/**
1352
+	 * _edit_message_template
1353
+	 *
1354
+	 * @access protected
1355
+	 * @return void
1356
+	 * @throws InvalidIdentifierException
1357
+	 * @throws DomainException
1358
+	 * @throws EE_Error
1359
+	 * @throws InvalidArgumentException
1360
+	 * @throws ReflectionException
1361
+	 * @throws InvalidDataTypeException
1362
+	 * @throws InvalidInterfaceException
1363
+	 */
1364
+	protected function _edit_message_template()
1365
+	{
1366
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1367
+		$template_fields = '';
1368
+		$sidebar_fields  = '';
1369
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1370
+		// valid html in the templates.
1371
+		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2);
1372
+
1373
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
1374
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
1375
+
1376
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1377
+		$message_template_group = $this->_message_template_group;
1378
+		$c_label                = $message_template_group->context_label();
1379
+		$c_config               = $message_template_group->contexts_config();
1380
+
1381
+		reset($c_config);
1382
+		$context = $this->request->getRequestParam('context', key($c_config));
1383
+		$context = strtolower($context);
1384
+
1385
+		$action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';
1386
+
1387
+		$edit_message_template_form_url = add_query_arg(
1388
+			['action' => $action, 'noheader' => true],
1389
+			EE_MSG_ADMIN_URL
1390
+		);
1391
+
1392
+		// set active messenger for this view
1393
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1394
+			$message_template_group->messenger()
1395
+		);
1396
+		$this->_active_message_type_name = $message_template_group->message_type();
1397
+
1398
+
1399
+		// Do we have any validation errors?
1400
+		$validators = $this->_get_transient();
1401
+		$v_fields   = ! empty($validators) ? array_keys($validators) : [];
1402
+
1403
+
1404
+		// we need to assemble the title from Various details
1405
+		$context_label = sprintf(
1406
+			esc_html__('(%s %s)', 'event_espresso'),
1407
+			$c_config[ $context ]['label'],
1408
+			ucwords($c_label['label'])
1409
+		);
1410
+
1411
+		$title = sprintf(
1412
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1413
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1414
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1415
+			$context_label
1416
+		);
1417
+
1418
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1419
+		$this->_template_args['message_template'] = $message_template_group;
1420
+		$this->_template_args['is_extra_fields']  = false;
1421
+
1422
+
1423
+		// let's get EEH_MSG_Template so we can get template form fields
1424
+		$template_field_structure = EEH_MSG_Template::get_fields(
1425
+			$message_template_group->messenger(),
1426
+			$message_template_group->message_type()
1427
+		);
1428
+
1429
+		if (! $template_field_structure) {
1430
+			$template_field_structure = false;
1431
+			$template_fields          = esc_html__(
1432
+				'There was an error in assembling the fields for this display (you should see an error message)',
1433
+				'event_espresso'
1434
+			);
1435
+		}
1436
+
1437
+
1438
+		$message_templates = $message_template_group->context_templates();
1439
+
1440
+
1441
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1442
+		// will get handled in the "extra" array.
1443
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1444
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1445
+				unset($template_field_structure[ $context ][ $reference_field ]);
1446
+			}
1447
+		}
1448
+
1449
+		// let's loop through the template_field_structure and actually assemble the input fields!
1450
+		if (! empty($template_field_structure)) {
1451
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1452
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1453
+				// the extra array and reset them.
1454
+				if ($template_field === 'extra') {
1455
+					$this->_template_args['is_extra_fields'] = true;
1456
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1457
+						$message_template = $message_templates[ $context ][ $reference_field ];
1458
+						$content          = $message_template instanceof EE_Message_Template
1459
+							? $message_template->get('MTP_content')
1460
+							: '';
1461
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1462
+							// let's verify if we need this extra field via the shortcodes parameter.
1463
+							$continue = false;
1464
+							if (isset($extra_array['shortcodes_required'])) {
1465
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1466
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1467
+										$continue = true;
1468
+									}
1469
+								}
1470
+								if ($continue) {
1471
+									continue;
1472
+								}
1473
+							}
1474
+
1475
+							$field_id = $reference_field . '-' . $extra_field . '-content';
1476
+
1477
+							$template_form_fields[ $field_id ]         = $extra_array;
1478
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1479
+																		 . $reference_field
1480
+																		 . '][content]['
1481
+																		 . $extra_field . ']';
1482
+							$css_class                                 = isset($extra_array['css_class'])
1483
+								? $extra_array['css_class']
1484
+								: '';
1485
+
1486
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1487
+																			  && in_array($extra_field, $v_fields, true)
1488
+																			  && (
1489
+																				  is_array($validators[ $extra_field ])
1490
+																				  && isset($validators[ $extra_field ]['msg'])
1491
+																			  )
1492
+								? 'validate-error ' . $css_class
1493
+								: $css_class;
1494
+
1495
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1496
+																		  && isset($content[ $extra_field ])
1497
+								? $content[ $extra_field ]
1498
+								: '';
1499
+
1500
+							// do we have a validation error?  if we do then let's use that value instead
1501
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1502
+								? $validators[ $extra_field ]['value']
1503
+								: $template_form_fields[ $field_id ]['value'];
1504
+
1505
+
1506
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1507
+
1508
+							// shortcode selector
1509
+							$field_name_to_use                                   = $extra_field === 'main'
1510
+								? 'content'
1511
+								: $extra_field;
1512
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1513
+								$field_name_to_use,
1514
+								$field_id
1515
+							);
1516
+						}
1517
+						$template_field_MTP_id           = $reference_field . '-MTP_ID';
1518
+						$template_field_template_name_id = $reference_field . '-name';
1519
+
1520
+						$template_form_fields[ $template_field_MTP_id ] = [
1521
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1522
+							'label'      => null,
1523
+							'input'      => 'hidden',
1524
+							'type'       => 'int',
1525
+							'required'   => false,
1526
+							'validation' => false,
1527
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1528
+							'css_class'  => '',
1529
+							'format'     => '%d',
1530
+							'db-col'     => 'MTP_ID',
1531
+						];
1532
+
1533
+						$template_form_fields[ $template_field_template_name_id ] = [
1534
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1535
+							'label'      => null,
1536
+							'input'      => 'hidden',
1537
+							'type'       => 'string',
1538
+							'required'   => false,
1539
+							'validation' => true,
1540
+							'value'      => $reference_field,
1541
+							'css_class'  => '',
1542
+							'format'     => '%s',
1543
+							'db-col'     => 'MTP_template_field',
1544
+						];
1545
+					}
1546
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1547
+				} else {
1548
+					$field_id                                   = $template_field . '-content';
1549
+					$template_form_fields[ $field_id ]          = $field_setup_array;
1550
+					$template_form_fields[ $field_id ]['name']  =
1551
+						'MTP_template_fields[' . $template_field . '][content]';
1552
+					$message_template                           =
1553
+						isset($message_templates[ $context ][ $template_field ])
1554
+							? $message_templates[ $context ][ $template_field ]
1555
+							: null;
1556
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1557
+																  && is_array($message_templates[ $context ])
1558
+																  && $message_template instanceof EE_Message_Template
1559
+						? $message_template->get('MTP_content')
1560
+						: '';
1561
+
1562
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1563
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1564
+						? $validators[ $template_field ]['value']
1565
+						: $template_form_fields[ $field_id ]['value'];
1566
+
1567
+
1568
+					$template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1569
+					$css_class                                      = isset($field_setup_array['css_class'])
1570
+						? $field_setup_array['css_class']
1571
+						: '';
1572
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1573
+																	  && in_array($template_field, $v_fields, true)
1574
+																	  && isset($validators[ $template_field ]['msg'])
1575
+						? 'validate-error ' . $css_class
1576
+						: $css_class;
1577
+
1578
+					// shortcode selector
1579
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1580
+						$template_field,
1581
+						$field_id
1582
+					);
1583
+				}
1584
+
1585
+				// k took care of content field(s) now let's take care of others.
1586
+
1587
+				$template_field_MTP_id                 = $template_field . '-MTP_ID';
1588
+				$template_field_field_template_name_id = $template_field . '-name';
1589
+
1590
+				// foreach template field there are actually two form fields created
1591
+				$template_form_fields[ $template_field_MTP_id ] = [
1592
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1593
+					'label'      => null,
1594
+					'input'      => 'hidden',
1595
+					'type'       => 'int',
1596
+					'required'   => false,
1597
+					'validation' => true,
1598
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1599
+					'css_class'  => '',
1600
+					'format'     => '%d',
1601
+					'db-col'     => 'MTP_ID',
1602
+				];
1603
+
1604
+				$template_form_fields[ $template_field_field_template_name_id ] = [
1605
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1606
+					'label'      => null,
1607
+					'input'      => 'hidden',
1608
+					'type'       => 'string',
1609
+					'required'   => false,
1610
+					'validation' => true,
1611
+					'value'      => $template_field,
1612
+					'css_class'  => '',
1613
+					'format'     => '%s',
1614
+					'db-col'     => 'MTP_template_field',
1615
+				];
1616
+			}
1617
+
1618
+			// add other fields
1619
+			$template_form_fields['ee-msg-current-context'] = [
1620
+				'name'       => 'MTP_context',
1621
+				'label'      => null,
1622
+				'input'      => 'hidden',
1623
+				'type'       => 'string',
1624
+				'required'   => false,
1625
+				'validation' => true,
1626
+				'value'      => $context,
1627
+				'css_class'  => '',
1628
+				'format'     => '%s',
1629
+				'db-col'     => 'MTP_context',
1630
+			];
1631
+
1632
+			$template_form_fields['ee-msg-grp-id'] = [
1633
+				'name'       => 'GRP_ID',
1634
+				'label'      => null,
1635
+				'input'      => 'hidden',
1636
+				'type'       => 'int',
1637
+				'required'   => false,
1638
+				'validation' => true,
1639
+				'value'      => $GRP_ID,
1640
+				'css_class'  => '',
1641
+				'format'     => '%d',
1642
+				'db-col'     => 'GRP_ID',
1643
+			];
1644
+
1645
+			$template_form_fields['ee-msg-messenger'] = [
1646
+				'name'       => 'MTP_messenger',
1647
+				'label'      => null,
1648
+				'input'      => 'hidden',
1649
+				'type'       => 'string',
1650
+				'required'   => false,
1651
+				'validation' => true,
1652
+				'value'      => $message_template_group->messenger(),
1653
+				'css_class'  => '',
1654
+				'format'     => '%s',
1655
+				'db-col'     => 'MTP_messenger',
1656
+			];
1657
+
1658
+			$template_form_fields['ee-msg-message-type'] = [
1659
+				'name'       => 'MTP_message_type',
1660
+				'label'      => null,
1661
+				'input'      => 'hidden',
1662
+				'type'       => 'string',
1663
+				'required'   => false,
1664
+				'validation' => true,
1665
+				'value'      => $message_template_group->message_type(),
1666
+				'css_class'  => '',
1667
+				'format'     => '%s',
1668
+				'db-col'     => 'MTP_message_type',
1669
+			];
1670
+
1671
+			$sidebar_form_fields['ee-msg-is-global'] = [
1672
+				'name'       => 'MTP_is_global',
1673
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1674
+				'input'      => 'hidden',
1675
+				'type'       => 'int',
1676
+				'required'   => false,
1677
+				'validation' => true,
1678
+				'value'      => $message_template_group->get('MTP_is_global'),
1679
+				'css_class'  => '',
1680
+				'format'     => '%d',
1681
+				'db-col'     => 'MTP_is_global',
1682
+			];
1683
+
1684
+			$sidebar_form_fields['ee-msg-is-override'] = [
1685
+				'name'       => 'MTP_is_override',
1686
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1687
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1688
+				'type'       => 'int',
1689
+				'required'   => false,
1690
+				'validation' => true,
1691
+				'value'      => $message_template_group->get('MTP_is_override'),
1692
+				'css_class'  => '',
1693
+				'format'     => '%d',
1694
+				'db-col'     => 'MTP_is_override',
1695
+			];
1696
+
1697
+			$sidebar_form_fields['ee-msg-is-active'] = [
1698
+				'name'       => 'MTP_is_active',
1699
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1700
+				'input'      => 'hidden',
1701
+				'type'       => 'int',
1702
+				'required'   => false,
1703
+				'validation' => true,
1704
+				'value'      => $message_template_group->is_active(),
1705
+				'css_class'  => '',
1706
+				'format'     => '%d',
1707
+				'db-col'     => 'MTP_is_active',
1708
+			];
1709
+
1710
+			$sidebar_form_fields['ee-msg-deleted'] = [
1711
+				'name'       => 'MTP_deleted',
1712
+				'label'      => null,
1713
+				'input'      => 'hidden',
1714
+				'type'       => 'int',
1715
+				'required'   => false,
1716
+				'validation' => true,
1717
+				'value'      => $message_template_group->get('MTP_deleted'),
1718
+				'css_class'  => '',
1719
+				'format'     => '%d',
1720
+				'db-col'     => 'MTP_deleted',
1721
+			];
1722
+			$sidebar_form_fields['ee-msg-author']  = [
1723
+				'name'       => 'MTP_user_id',
1724
+				'label'      => esc_html__('Author', 'event_espresso'),
1725
+				'input'      => 'hidden',
1726
+				'type'       => 'int',
1727
+				'required'   => false,
1728
+				'validation' => false,
1729
+				'value'      => $message_template_group->user(),
1730
+				'format'     => '%d',
1731
+				'db-col'     => 'MTP_user_id',
1732
+			];
1733
+
1734
+			$sidebar_form_fields['ee-msg-route'] = [
1735
+				'name'  => 'action',
1736
+				'input' => 'hidden',
1737
+				'type'  => 'string',
1738
+				'value' => $action,
1739
+			];
1740
+
1741
+			$sidebar_form_fields['ee-msg-id']        = [
1742
+				'name'  => 'id',
1743
+				'input' => 'hidden',
1744
+				'type'  => 'int',
1745
+				'value' => $GRP_ID,
1746
+			];
1747
+			$sidebar_form_fields['ee-msg-evt-nonce'] = [
1748
+				'name'  => $action . '_nonce',
1749
+				'input' => 'hidden',
1750
+				'type'  => 'string',
1751
+				'value' => wp_create_nonce($action . '_nonce'),
1752
+			];
1753
+
1754
+			$template_switch = $this->request->getRequestParam('template_switch');
1755
+			if ($template_switch) {
1756
+				$sidebar_form_fields['ee-msg-template-switch'] = [
1757
+					'name'  => 'template_switch',
1758
+					'input' => 'hidden',
1759
+					'type'  => 'int',
1760
+					'value' => 1,
1761
+				];
1762
+			}
1763
+
1764
+
1765
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1766
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1767
+		} //end if ( !empty($template_field_structure) )
1768
+
1769
+		// set extra content for publish box
1770
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1771
+		$this->_set_publish_post_box_vars(
1772
+			'id',
1773
+			$GRP_ID,
1774
+			false,
1775
+			add_query_arg(
1776
+				['action' => 'global_mtps'],
1777
+				$this->_admin_base_url
1778
+			)
1779
+		);
1780
+
1781
+		// add preview button
1782
+		$preview_url    = parent::add_query_args_and_nonce(
1783
+			[
1784
+				'message_type' => $message_template_group->message_type(),
1785
+				'messenger'    => $message_template_group->messenger(),
1786
+				'context'      => $context,
1787
+				'GRP_ID'       => $GRP_ID,
1788
+				'evt_id'       => $EVT_ID ?: false,
1789
+				'action'       => 'preview_message',
1790
+			],
1791
+			$this->_admin_base_url
1792
+		);
1793
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1794
+						  . esc_html__('Preview', 'event_espresso')
1795
+						  . '</a>';
1796
+
1797
+
1798
+		// setup context switcher
1799
+		$this->_set_context_switcher(
1800
+			$message_template_group,
1801
+			[
1802
+				'page'    => 'espresso_messages',
1803
+				'action'  => 'edit_message_template',
1804
+				'id'      => $GRP_ID,
1805
+				'evt_id'  => $EVT_ID,
1806
+				'context' => $context,
1807
+				'extra'   => $preview_button,
1808
+			]
1809
+		);
1810
+
1811
+
1812
+		// main box
1813
+		$this->_template_args['template_fields']                         = $template_fields;
1814
+		$this->_template_args['sidebar_box_id']                          = 'details';
1815
+		$this->_template_args['action']                                  = $action;
1816
+		$this->_template_args['context']                                 = $context;
1817
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1818
+		$this->_template_args['learn_more_about_message_templates_link'] =
1819
+			$this->_learn_more_about_message_templates_link();
1820
+
1821
+
1822
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1823
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1824
+			$message_template_group,
1825
+			$context,
1826
+			$context_label
1827
+		);
1828
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1829
+		$this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1830
+
1831
+		$this->_template_path = $this->_template_args['GRP_ID']
1832
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1833
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1834
+
1835
+		// send along EE_Message_Template_Group object for further template use.
1836
+		$this->_template_args['MTP'] = $message_template_group;
1837
+
1838
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1839
+			$this->_template_path,
1840
+			$this->_template_args,
1841
+			true
1842
+		);
1843
+
1844
+
1845
+		// finally, let's set the admin_page title
1846
+		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title);
1847
+
1848
+
1849
+		// we need to take care of setting the shortcodes property for use elsewhere.
1850
+		$this->_set_shortcodes();
1851
+
1852
+
1853
+		// final template wrapper
1854
+		$this->display_admin_page_with_sidebar();
1855
+	}
1856
+
1857
+
1858
+	public function filter_tinymce_init($mceInit, $editor_id)
1859
+	{
1860
+		return $mceInit;
1861
+	}
1862
+
1863
+
1864
+	public function add_context_switcher()
1865
+	{
1866
+		return $this->_context_switcher;
1867
+	}
1868
+
1869
+
1870
+	/**
1871
+	 * Adds the activation/deactivation toggle for the message template context.
1872
+	 *
1873
+	 * @param EE_Message_Template_Group $message_template_group
1874
+	 * @param string                    $context
1875
+	 * @param string                    $context_label
1876
+	 * @return string
1877
+	 * @throws DomainException
1878
+	 * @throws EE_Error
1879
+	 * @throws InvalidIdentifierException
1880
+	 * @throws ReflectionException
1881
+	 */
1882
+	protected function add_active_context_element(
1883
+		EE_Message_Template_Group $message_template_group,
1884
+		$context,
1885
+		$context_label
1886
+	) {
1887
+		$template_args = [
1888
+			'context'                   => $context,
1889
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1890
+			'is_active'                 => $message_template_group->is_context_active($context),
1891
+			'on_off_action'             => $message_template_group->is_context_active($context)
1892
+				? 'context-off'
1893
+				: 'context-on',
1894
+			'context_label'             => str_replace(['(', ')'], '', $context_label),
1895
+			'message_template_group_id' => $message_template_group->ID(),
1896
+		];
1897
+		return EEH_Template::display_template(
1898
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1899
+			$template_args,
1900
+			true
1901
+		);
1902
+	}
1903
+
1904
+
1905
+	/**
1906
+	 * Ajax callback for `toggle_context_template` ajax action.
1907
+	 * Handles toggling the message context on or off.
1908
+	 *
1909
+	 * @throws EE_Error
1910
+	 * @throws InvalidArgumentException
1911
+	 * @throws InvalidDataTypeException
1912
+	 * @throws InvalidIdentifierException
1913
+	 * @throws InvalidInterfaceException
1914
+	 */
1915
+	public function toggle_context_template()
1916
+	{
1917
+		$success = true;
1918
+		// check for required data
1919
+		if (
1920
+			! (
1921
+				$this->request->requestParamIsSet('message_template_group_id')
1922
+				&& $this->request->requestParamIsSet('context')
1923
+				&& $this->request->requestParamIsSet('status')
1924
+			)
1925
+		) {
1926
+			EE_Error::add_error(
1927
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1928
+				__FILE__,
1929
+				__FUNCTION__,
1930
+				__LINE__
1931
+			);
1932
+			$success = false;
1933
+		}
1934
+
1935
+		$nonce   = $this->request->getRequestParam('toggle_context_nonce', '');
1936
+		$context = $this->request->getRequestParam('context', '');
1937
+		$status  = $this->request->getRequestParam('status', '');
1938
+
1939
+		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce");
1940
+
1941
+		if ($status !== 'off' && $status !== 'on') {
1942
+			EE_Error::add_error(
1943
+				sprintf(
1944
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1945
+					$status
1946
+				),
1947
+				__FILE__,
1948
+				__FUNCTION__,
1949
+				__LINE__
1950
+			);
1951
+			$success = false;
1952
+		}
1953
+		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1954
+		$message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1955
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1956
+			EE_Error::add_error(
1957
+				sprintf(
1958
+					esc_html__(
1959
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1960
+						'event_espresso'
1961
+					),
1962
+					$message_template_group_id,
1963
+					'EE_Message_Template_Group'
1964
+				),
1965
+				__FILE__,
1966
+				__FUNCTION__,
1967
+				__LINE__
1968
+			);
1969
+			$success = false;
1970
+		}
1971
+		if ($success) {
1972
+			$success = $status === 'off'
1973
+				? $message_template_group->deactivate_context($context)
1974
+				: $message_template_group->activate_context($context);
1975
+		}
1976
+		$this->_template_args['success'] = $success;
1977
+		$this->_return_json();
1978
+	}
1979
+
1980
+
1981
+	public function _add_form_element_before()
1982
+	{
1983
+		return '<form method="post" action="'
1984
+			   . $this->_template_args['edit_message_template_form_url']
1985
+			   . '" id="ee-msg-edit-frm">';
1986
+	}
1987
+
1988
+
1989
+	public function _add_form_element_after()
1990
+	{
1991
+		return '</form>';
1992
+	}
1993
+
1994
+
1995
+	/**
1996
+	 * This executes switching the template pack for a message template.
1997
+	 *
1998
+	 * @throws EE_Error
1999
+	 * @throws InvalidDataTypeException
2000
+	 * @throws InvalidInterfaceException
2001
+	 * @throws InvalidArgumentException
2002
+	 * @throws ReflectionException
2003
+	 * @since 4.5.0
2004
+	 */
2005
+	public function switch_template_pack()
2006
+	{
2007
+
2008
+		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int');
2009
+		$template_pack = $this->request->getRequestParam('template_pack', '');
2010
+
2011
+		// verify we have needed values.
2012
+		if (empty($GRP_ID) || empty($template_pack)) {
2013
+			$this->_template_args['error'] = true;
2014
+			EE_Error::add_error(
2015
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
2016
+				__FILE__,
2017
+				__FUNCTION__,
2018
+				__LINE__
2019
+			);
2020
+		} else {
2021
+			// get template, set the new template_pack and then reset to default
2022
+			/** @var EE_Message_Template_Group $message_template_group */
2023
+			$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
2024
+
2025
+			$message_template_group->set_template_pack_name($template_pack);
2026
+			$this->request->setRequestParam('msgr', $message_template_group->messenger());
2027
+			$this->request->setRequestParam('mt', $message_template_group->message_type());
2028
+
2029
+			$query_args = $this->_reset_to_default_template();
2030
+
2031
+			if (empty($query_args['id'])) {
2032
+				EE_Error::add_error(
2033
+					esc_html__(
2034
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
2035
+						'event_espresso'
2036
+					),
2037
+					__FILE__,
2038
+					__FUNCTION__,
2039
+					__LINE__
2040
+				);
2041
+				$this->_template_args['error'] = true;
2042
+			} else {
2043
+				$template_label       = $message_template_group->get_template_pack()->label;
2044
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2045
+				EE_Error::add_success(
2046
+					sprintf(
2047
+						esc_html__(
2048
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2049
+							'event_espresso'
2050
+						),
2051
+						$template_label,
2052
+						$template_pack_labels->template_pack
2053
+					)
2054
+				);
2055
+				// generate the redirect url for js.
2056
+				$url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2057
+
2058
+				$this->_template_args['data']['redirect_url'] = $url;
2059
+				$this->_template_args['success']              = true;
2060
+			}
2061
+
2062
+			$this->_return_json();
2063
+		}
2064
+	}
2065
+
2066
+
2067
+	/**
2068
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2069
+	 * they want.
2070
+	 *
2071
+	 * @access protected
2072
+	 * @return array|void
2073
+	 * @throws EE_Error
2074
+	 * @throws InvalidArgumentException
2075
+	 * @throws InvalidDataTypeException
2076
+	 * @throws InvalidInterfaceException
2077
+	 * @throws ReflectionException
2078
+	 */
2079
+	protected function _reset_to_default_template()
2080
+	{
2081
+		$templates    = [];
2082
+		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int');
2083
+		$messenger    = $this->request->getRequestParam('msgr');
2084
+		$message_type = $this->request->getRequestParam('mt');
2085
+		// we need to make sure we've got the info we need.
2086
+		if (! ($GRP_ID && $messenger && $message_type)) {
2087
+			EE_Error::add_error(
2088
+				esc_html__(
2089
+					'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2090
+					'event_espresso'
2091
+				),
2092
+				__FILE__,
2093
+				__FUNCTION__,
2094
+				__LINE__
2095
+			);
2096
+		}
2097
+
2098
+		// all templates will be reset to whatever the defaults are
2099
+		// for the global template matching the messenger and message type.
2100
+		$success = ! empty($GRP_ID);
2101
+
2102
+		if ($success) {
2103
+			// let's first determine if the incoming template is a global template,
2104
+			// if it isn't then we need to get the global template matching messenger and message type.
2105
+			// $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );
2106
+
2107
+
2108
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2109
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2110
+
2111
+			if ($success) {
2112
+				// if successfully deleted, lets generate the new ones.
2113
+				// Note. We set GLOBAL to true, because resets on ANY template
2114
+				// will use the related global template defaults for regeneration.
2115
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2116
+				// HOWEVER, we DO keep the template pack and template variation set
2117
+				// for the current custom template when resetting.
2118
+				$templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);
2119
+			}
2120
+		}
2121
+
2122
+		// any error messages?
2123
+		if (! $success) {
2124
+			EE_Error::add_error(
2125
+				esc_html__(
2126
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2127
+					'event_espresso'
2128
+				),
2129
+				__FILE__,
2130
+				__FUNCTION__,
2131
+				__LINE__
2132
+			);
2133
+		}
2134
+
2135
+		// all good, let's add a success message!
2136
+		if ($success && ! empty($templates)) {
2137
+			// the info for the template we generated is the first element in the returned array
2138
+			EE_Error::overwrite_success();
2139
+			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso'));
2140
+		}
2141
+
2142
+
2143
+		$query_args = [
2144
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
2145
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
2146
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2147
+		];
2148
+
2149
+		// if called via ajax then we return query args otherwise redirect
2150
+		if ($this->request->isAjax()) {
2151
+			return $query_args;
2152
+		}
2153
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2154
+	}
2155
+
2156
+
2157
+	/**
2158
+	 * Retrieve and set the message preview for display.
2159
+	 *
2160
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2161
+	 * @return string
2162
+	 * @throws ReflectionException
2163
+	 * @throws EE_Error
2164
+	 * @throws InvalidArgumentException
2165
+	 * @throws InvalidDataTypeException
2166
+	 * @throws InvalidInterfaceException
2167
+	 */
2168
+	public function _preview_message($send = false)
2169
+	{
2170
+		// first make sure we've got the necessary parameters
2171
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2172
+		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2173
+			EE_Error::add_error(
2174
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2175
+				__FILE__,
2176
+				__FUNCTION__,
2177
+				__LINE__
2178
+			);
2179
+		}
2180
+
2181
+		$context = $this->request->getRequestParam('context');
2182
+		// get the preview!
2183
+		$preview = EED_Messages::preview_message(
2184
+			$this->_active_message_type_name,
2185
+			$context,
2186
+			$this->_active_messenger_name,
2187
+			$send
2188
+		);
2189
+
2190
+		if ($send) {
2191
+			return $preview;
2192
+		}
2193
+
2194
+		// if we have an evt_id set on the request, use it.
2195
+		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2196
+
2197
+		// let's add a button to go back to the edit view
2198
+		$query_args             = [
2199
+			'id'      => $GRP_ID,
2200
+			'evt_id'  => $EVT_ID,
2201
+			'context' => $context,
2202
+			'action'  => 'edit_message_template',
2203
+		];
2204
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2205
+		$preview_button         = '<a href="'
2206
+								  . $go_back_url
2207
+								  . '" class="button-secondary messages-preview-go-back-button">'
2208
+								  . esc_html__('Go Back to Edit', 'event_espresso')
2209
+								  . '</a>';
2210
+		$message_types          = $this->get_installed_message_types();
2211
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
2212
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2213
+			? ucwords($active_messenger->label['singular'])
2214
+			: esc_html__('Unknown Messenger', 'event_espresso');
2215
+		// let's provide a helpful title for context
2216
+		$preview_title = sprintf(
2217
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2218
+			$active_messenger_label,
2219
+			ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2220
+		);
2221
+		if (empty($preview)) {
2222
+			$this->noEventsErrorMessage();
2223
+		}
2224
+		// setup display of preview.
2225
+		$this->_admin_page_title                    = $preview_title;
2226
+		$this->_template_args['admin_page_title']   = $preview_title;
2227
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2228
+		$this->_template_args['data']['force_json'] = true;
2229
+
2230
+		return '';
2231
+	}
2232
+
2233
+
2234
+	/**
2235
+	 * Used to set an error if there are no events available for generating a preview/test send.
2236
+	 *
2237
+	 * @param bool $test_send Whether the error should be generated for the context of a test send.
2238
+	 */
2239
+	protected function noEventsErrorMessage($test_send = false)
2240
+	{
2241
+		$events_url = parent::add_query_args_and_nonce(
2242
+			[
2243
+				'action' => 'default',
2244
+				'page'   => 'espresso_events',
2245
+			],
2246
+			admin_url('admin.php')
2247
+		);
2248
+		$message    = $test_send
2249
+			? esc_html__(
2250
+				'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2251
+				'event_espresso'
2252
+			)
2253
+			: esc_html__(
2254
+				'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2255
+				'event_espresso'
2256
+			);
2257
+
2258
+		EE_Error::add_attention(
2259
+			sprintf(
2260
+				$message,
2261
+				"<a href='{$events_url}'>",
2262
+				'</a>'
2263
+			)
2264
+		);
2265
+	}
2266
+
2267
+
2268
+	/**
2269
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2270
+	 * gets called automatically.
2271
+	 *
2272
+	 * @return void
2273
+	 * @throws EE_Error
2274
+	 * @since 4.5.0
2275
+	 *
2276
+	 */
2277
+	protected function _display_preview_message()
2278
+	{
2279
+		$this->display_admin_page_with_no_sidebar();
2280
+	}
2281
+
2282
+
2283
+	/**
2284
+	 * registers metaboxes that should show up on the "edit_message_template" page
2285
+	 *
2286
+	 * @access protected
2287
+	 * @return void
2288
+	 */
2289
+	protected function _register_edit_meta_boxes()
2290
+	{
2291
+		add_meta_box(
2292
+			'mtp_valid_shortcodes',
2293
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2294
+			[$this, 'shortcode_meta_box'],
2295
+			$this->_current_screen->id,
2296
+			'side'
2297
+		);
2298
+		add_meta_box(
2299
+			'mtp_extra_actions',
2300
+			esc_html__('Extra Actions', 'event_espresso'),
2301
+			[$this, 'extra_actions_meta_box'],
2302
+			$this->_current_screen->id,
2303
+			'side',
2304
+			'high'
2305
+		);
2306
+		add_meta_box(
2307
+			'mtp_templates',
2308
+			esc_html__('Template Styles', 'event_espresso'),
2309
+			[$this, 'template_pack_meta_box'],
2310
+			$this->_current_screen->id,
2311
+			'side',
2312
+			'high'
2313
+		);
2314
+	}
2315
+
2316
+
2317
+	/**
2318
+	 * metabox content for all template pack and variation selection.
2319
+	 *
2320
+	 * @return void
2321
+	 * @throws DomainException
2322
+	 * @throws EE_Error
2323
+	 * @throws InvalidArgumentException
2324
+	 * @throws ReflectionException
2325
+	 * @throws InvalidDataTypeException
2326
+	 * @throws InvalidInterfaceException
2327
+	 * @since 4.5.0
2328
+	 */
2329
+	public function template_pack_meta_box()
2330
+	{
2331
+		$this->_set_message_template_group();
2332
+
2333
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2334
+
2335
+		$tp_select_values = [];
2336
+
2337
+		foreach ($tp_collection as $tp) {
2338
+			// only include template packs that support this messenger and message type!
2339
+			$supports = $tp->get_supports();
2340
+			if (
2341
+				! isset($supports[ $this->_message_template_group->messenger() ])
2342
+				|| ! in_array(
2343
+					$this->_message_template_group->message_type(),
2344
+					$supports[ $this->_message_template_group->messenger() ],
2345
+					true
2346
+				)
2347
+			) {
2348
+				// not supported
2349
+				continue;
2350
+			}
2351
+
2352
+			$tp_select_values[] = [
2353
+				'text' => $tp->label,
2354
+				'id'   => $tp->dbref,
2355
+			];
2356
+		}
2357
+
2358
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2359
+		// the default template pack.  This still allows for the odd template pack to override.
2360
+		if (empty($tp_select_values)) {
2361
+			$tp_select_values[] = [
2362
+				'text' => esc_html__('Default', 'event_espresso'),
2363
+				'id'   => 'default',
2364
+			];
2365
+		}
2366
+
2367
+		// setup variation select values for the currently selected template.
2368
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
2369
+			$this->_message_template_group->messenger(),
2370
+			$this->_message_template_group->message_type()
2371
+		);
2372
+		$variations_select_values = [];
2373
+		foreach ($variations as $variation => $label) {
2374
+			$variations_select_values[] = [
2375
+				'text' => $label,
2376
+				'id'   => $variation,
2377
+			];
2378
+		}
2379
+
2380
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2381
+
2382
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2383
+			'MTP_template_pack',
2384
+			$tp_select_values,
2385
+			$this->_message_template_group->get_template_pack_name()
2386
+		);
2387
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
2388
+			'MTP_template_variation',
2389
+			$variations_select_values,
2390
+			$this->_message_template_group->get_template_pack_variation()
2391
+		);
2392
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
2393
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
2394
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2395
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2396
+
2397
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2398
+
2399
+		EEH_Template::display_template($template, $template_args);
2400
+	}
2401
+
2402
+
2403
+	/**
2404
+	 * This meta box holds any extra actions related to Message Templates
2405
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2406
+	 *
2407
+	 * @access  public
2408
+	 * @return void
2409
+	 * @throws EE_Error
2410
+	 */
2411
+	public function extra_actions_meta_box()
2412
+	{
2413
+		$template_form_fields = [];
2414
+
2415
+		$extra_args = [
2416
+			'msgr'   => $this->_message_template_group->messenger(),
2417
+			'mt'     => $this->_message_template_group->message_type(),
2418
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2419
+		];
2420
+		// first we need to see if there are any fields
2421
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2422
+
2423
+		if (! empty($fields)) {
2424
+			// yup there be fields
2425
+			foreach ($fields as $field => $config) {
2426
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2427
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2428
+				$default  = isset($config['default']) ? $config['default'] : '';
2429
+				$default  = isset($config['value']) ? $config['value'] : $default;
2430
+
2431
+				// if type is hidden and the value is empty
2432
+				// something may have gone wrong so let's correct with the defaults
2433
+				$fix                = $config['input'] === 'hidden'
2434
+									  && isset($existing[ $field ])
2435
+									  && empty($existing[ $field ])
2436
+					? $default
2437
+					: '';
2438
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2439
+					? $existing[ $field ]
2440
+					: $fix;
2441
+
2442
+				$template_form_fields[ $field_id ] = [
2443
+					'name'       => 'test_settings_fld[' . $field . ']',
2444
+					'label'      => $config['label'],
2445
+					'input'      => $config['input'],
2446
+					'type'       => $config['type'],
2447
+					'required'   => $config['required'],
2448
+					'validation' => $config['validation'],
2449
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2450
+					'css_class'  => $config['css_class'],
2451
+					'options'    => isset($config['options']) ? $config['options'] : [],
2452
+					'default'    => $default,
2453
+					'format'     => $config['format'],
2454
+				];
2455
+			}
2456
+		}
2457
+
2458
+		$test_settings_html = ! empty($template_form_fields)
2459
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2460
+			: '';
2461
+
2462
+		// print out $test_settings_fields
2463
+		if (! empty($test_settings_html)) {
2464
+			$test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2465
+			$test_settings_html .= 'name="test_button" value="';
2466
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2467
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2468
+		}
2469
+
2470
+		// and button
2471
+		$test_settings_html .= '<p>';
2472
+		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso');
2473
+		$test_settings_html .= '</p>';
2474
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2475
+		$test_settings_html .= $this->get_action_link_or_button(
2476
+			'reset_to_default',
2477
+			'reset',
2478
+			$extra_args,
2479
+			'button-primary reset-default-button'
2480
+		);
2481
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2482
+		echo $test_settings_html; // already escaped
2483
+	}
2484
+
2485
+
2486
+	/**
2487
+	 * This returns the shortcode selector skeleton for a given context and field.
2488
+	 *
2489
+	 * @param string $field           The name of the field retrieving shortcodes for.
2490
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2491
+	 * @return string
2492
+	 * @throws DomainException
2493
+	 * @throws EE_Error
2494
+	 * @throws InvalidArgumentException
2495
+	 * @throws ReflectionException
2496
+	 * @throws InvalidDataTypeException
2497
+	 * @throws InvalidInterfaceException
2498
+	 * @since 4.9.rc.000
2499
+	 */
2500
+	protected function _get_shortcode_selector($field, $linked_input_id)
2501
+	{
2502
+		$template_args = [
2503
+			'shortcodes'      => $this->_get_shortcodes([$field]),
2504
+			'fieldname'       => $field,
2505
+			'linked_input_id' => $linked_input_id,
2506
+		];
2507
+
2508
+		return EEH_Template::display_template(
2509
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2510
+			$template_args,
2511
+			true
2512
+		);
2513
+	}
2514
+
2515
+
2516
+	/**
2517
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2518
+	 * page)
2519
+	 *
2520
+	 * @access public
2521
+	 * @return void
2522
+	 * @throws EE_Error
2523
+	 * @throws InvalidArgumentException
2524
+	 * @throws ReflectionException
2525
+	 * @throws InvalidDataTypeException
2526
+	 * @throws InvalidInterfaceException
2527
+	 */
2528
+	public function shortcode_meta_box()
2529
+	{
2530
+		$shortcodes = $this->_get_shortcodes([], false);
2531
+		// just make sure the shortcodes property is set
2532
+		// $messenger = $this->_message_template_group->messenger_obj();
2533
+		// now let's set the content depending on the status of the shortcodes array
2534
+		if (empty($shortcodes)) {
2535
+			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2536
+			return;
2537
+		}
2538
+		?>
2539 2539
         <div style="float:right; margin-top:10px">
2540 2540
             <?php echo $this->_get_help_tab_link('message_template_shortcodes'); // already escaped
2541
-            ?>
2541
+			?>
2542 2542
         </div>
2543 2543
         <p class="small-text">
2544 2544
             <?php printf(
2545
-                esc_html__(
2546
-                    'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2547
-                    'event_espresso'
2548
-                ),
2549
-                '<span class="dashicons dashicons-menu"></span>'
2550
-            ); ?>
2545
+				esc_html__(
2546
+					'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2547
+					'event_espresso'
2548
+				),
2549
+				'<span class="dashicons dashicons-menu"></span>'
2550
+			); ?>
2551 2551
         </p>
2552 2552
         <?php
2553
-    }
2554
-
2555
-
2556
-    /**
2557
-     * used to set the $_shortcodes property for when its needed elsewhere.
2558
-     *
2559
-     * @access protected
2560
-     * @return void
2561
-     * @throws EE_Error
2562
-     * @throws InvalidArgumentException
2563
-     * @throws ReflectionException
2564
-     * @throws InvalidDataTypeException
2565
-     * @throws InvalidInterfaceException
2566
-     */
2567
-    protected function _set_shortcodes()
2568
-    {
2569
-
2570
-        // no need to run this if the property is already set
2571
-        if (! empty($this->_shortcodes)) {
2572
-            return;
2573
-        }
2574
-
2575
-        $this->_shortcodes = $this->_get_shortcodes();
2576
-    }
2577
-
2578
-
2579
-    /**
2580
-     * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2581
-     * property)
2582
-     *
2583
-     * @access  protected
2584
-     * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2585
-     *                         for. Defaults to all (for the given context)
2586
-     * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2587
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2588
-     *                         true just an array of shortcode/label pairs.
2589
-     * @throws EE_Error
2590
-     * @throws InvalidArgumentException
2591
-     * @throws ReflectionException
2592
-     * @throws InvalidDataTypeException
2593
-     * @throws InvalidInterfaceException
2594
-     */
2595
-    protected function _get_shortcodes($fields = [], $merged = true)
2596
-    {
2597
-        $this->_set_message_template_group();
2598
-
2599
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2600
-        $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2601
-        if (empty($GRP_ID)) {
2602
-            return [];
2603
-        }
2604
-        $context = $this->request->getRequestParam(
2605
-            'messenger',
2606
-            key($this->_message_template_group->contexts_config())
2607
-        );
2608
-        return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2609
-    }
2610
-
2611
-
2612
-    /**
2613
-     * This sets the _message_template property (containing the called message_template object)
2614
-     *
2615
-     * @access protected
2616
-     * @return void
2617
-     * @throws EE_Error
2618
-     * @throws InvalidArgumentException
2619
-     * @throws ReflectionException
2620
-     * @throws InvalidDataTypeException
2621
-     * @throws InvalidInterfaceException
2622
-     */
2623
-    protected function _set_message_template_group()
2624
-    {
2625
-        // get out if this is already set.
2626
-        if (! empty($this->_message_template_group)) {
2627
-            return;
2628
-        }
2629
-
2630
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2631
-        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2632
-
2633
-        // let's get the message templates
2634
-        $this->_message_template_group = ! empty($GRP_ID)
2635
-            ? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2636
-            : $this->getMtgModel()->create_default_object();
2637
-
2638
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2639
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2640
-    }
2641
-
2642
-
2643
-    /**
2644
-     * sets up a context switcher for edit forms
2645
-     *
2646
-     * @access  protected
2647
-     * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2648
-     * @param array                     $args                  various things the context switcher needs.
2649
-     * @throws EE_Error
2650
-     */
2651
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2652
-    {
2653
-        $context_details = $template_group_object->contexts_config();
2654
-        $context_label   = $template_group_object->context_label();
2655
-        ob_start();
2656
-        ?>
2553
+	}
2554
+
2555
+
2556
+	/**
2557
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2558
+	 *
2559
+	 * @access protected
2560
+	 * @return void
2561
+	 * @throws EE_Error
2562
+	 * @throws InvalidArgumentException
2563
+	 * @throws ReflectionException
2564
+	 * @throws InvalidDataTypeException
2565
+	 * @throws InvalidInterfaceException
2566
+	 */
2567
+	protected function _set_shortcodes()
2568
+	{
2569
+
2570
+		// no need to run this if the property is already set
2571
+		if (! empty($this->_shortcodes)) {
2572
+			return;
2573
+		}
2574
+
2575
+		$this->_shortcodes = $this->_get_shortcodes();
2576
+	}
2577
+
2578
+
2579
+	/**
2580
+	 * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2581
+	 * property)
2582
+	 *
2583
+	 * @access  protected
2584
+	 * @param array   $fields  include an array of specific field names that you want to be used to get the shortcodes
2585
+	 *                         for. Defaults to all (for the given context)
2586
+	 * @param boolean $merged  Whether to merge all the shortcodes into one list of unique shortcodes
2587
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2588
+	 *                         true just an array of shortcode/label pairs.
2589
+	 * @throws EE_Error
2590
+	 * @throws InvalidArgumentException
2591
+	 * @throws ReflectionException
2592
+	 * @throws InvalidDataTypeException
2593
+	 * @throws InvalidInterfaceException
2594
+	 */
2595
+	protected function _get_shortcodes($fields = [], $merged = true)
2596
+	{
2597
+		$this->_set_message_template_group();
2598
+
2599
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2600
+		$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
2601
+		if (empty($GRP_ID)) {
2602
+			return [];
2603
+		}
2604
+		$context = $this->request->getRequestParam(
2605
+			'messenger',
2606
+			key($this->_message_template_group->contexts_config())
2607
+		);
2608
+		return $this->_message_template_group->get_shortcodes($context, $fields, $merged);
2609
+	}
2610
+
2611
+
2612
+	/**
2613
+	 * This sets the _message_template property (containing the called message_template object)
2614
+	 *
2615
+	 * @access protected
2616
+	 * @return void
2617
+	 * @throws EE_Error
2618
+	 * @throws InvalidArgumentException
2619
+	 * @throws ReflectionException
2620
+	 * @throws InvalidDataTypeException
2621
+	 * @throws InvalidInterfaceException
2622
+	 */
2623
+	protected function _set_message_template_group()
2624
+	{
2625
+		// get out if this is already set.
2626
+		if (! empty($this->_message_template_group)) {
2627
+			return;
2628
+		}
2629
+
2630
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2631
+		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int');
2632
+
2633
+		// let's get the message templates
2634
+		$this->_message_template_group = ! empty($GRP_ID)
2635
+			? $this->getMtgModel()->get_one_by_ID($GRP_ID)
2636
+			: $this->getMtgModel()->create_default_object();
2637
+
2638
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2639
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2640
+	}
2641
+
2642
+
2643
+	/**
2644
+	 * sets up a context switcher for edit forms
2645
+	 *
2646
+	 * @access  protected
2647
+	 * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2648
+	 * @param array                     $args                  various things the context switcher needs.
2649
+	 * @throws EE_Error
2650
+	 */
2651
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2652
+	{
2653
+		$context_details = $template_group_object->contexts_config();
2654
+		$context_label   = $template_group_object->context_label();
2655
+		ob_start();
2656
+		?>
2657 2657
         <div class="ee-msg-switcher-container">
2658 2658
             <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">
2659 2659
                 <?php
2660
-                foreach ($args as $name => $value) {
2661
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2662
-                        continue;
2663
-                    }
2664
-                    ?>
2660
+				foreach ($args as $name => $value) {
2661
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2662
+						continue;
2663
+					}
2664
+					?>
2665 2665
                     <input type="hidden"
2666 2666
                            name="<?php echo esc_attr($name); ?>"
2667 2667
                            value="<?php echo esc_attr($value); ?>"
2668 2668
                     />
2669 2669
                     <?php
2670
-                }
2671
-                // setup nonce_url
2672
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2673
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2674
-                ?>
2670
+				}
2671
+				// setup nonce_url
2672
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2673
+				$id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2674
+				?>
2675 2675
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2676 2676
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
2677 2677
                 </label>
2678 2678
                 <select id="<?php echo esc_attr($id); ?>" name="context">
2679 2679
                     <?php
2680
-                    $context_templates = $template_group_object->context_templates();
2681
-                    if (is_array($context_templates)) :
2682
-                        foreach ($context_templates as $context => $template_fields) :
2683
-                            $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2684
-                            ?>
2680
+					$context_templates = $template_group_object->context_templates();
2681
+					if (is_array($context_templates)) :
2682
+						foreach ($context_templates as $context => $template_fields) :
2683
+							$checked = ($context === $args['context']) ? 'selected="selected"' : '';
2684
+							?>
2685 2685
                             <option value="<?php echo esc_attr($context); ?>" <?php echo $checked; ?>>
2686 2686
                                 <?php echo $context_details[ $context ]['label']; // already escaped
2687
-                                ?>
2687
+								?>
2688 2688
                             </option>
2689 2689
                         <?php endforeach;
2690
-                    endif; ?>
2690
+					endif; ?>
2691 2691
                 </select>
2692 2692
                 <?php $button_text = sprintf(
2693
-                    esc_html__('Switch %s', 'event_espresso'),
2694
-                    ucwords($context_label['label'])
2695
-                ); ?>
2693
+					esc_html__('Switch %s', 'event_espresso'),
2694
+					ucwords($context_label['label'])
2695
+				); ?>
2696 2696
                 <input class='button-secondary'
2697 2697
                        id="submit-msg-context-switcher-sbmt"
2698 2698
                        type="submit"
@@ -2700,1995 +2700,1995 @@  discard block
 block discarded – undo
2700 2700
                 />
2701 2701
             </form>
2702 2702
             <?php echo $args['extra']; // already escaped
2703
-            ?>
2703
+			?>
2704 2704
         </div> <!-- end .ee-msg-switcher-container -->
2705 2705
         <?php
2706
-        $this->_context_switcher = ob_get_clean();
2707
-    }
2708
-
2709
-
2710
-    /**
2711
-     * @param bool $new
2712
-     * @throws EE_Error
2713
-     * @throws ReflectionException
2714
-     */
2715
-    protected function _insert_or_update_message_template($new = false)
2716
-    {
2717
-        $form_data    = $this->getMessageTemplateFormData();
2718
-        $GRP_ID       = $form_data['GRP_ID'];
2719
-        $messenger    = $form_data['MTP_messenger'];
2720
-        $message_type = $form_data['MTP_message_type'];
2721
-        $context      = $form_data['MTP_context'];
2722
-
2723
-        // if this is "new" then we need to generate the default contexts
2724
-        // for the selected messenger/message_type for user to edit.
2725
-        list($success, $query_args) = $new
2726
-            ? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2727
-            : $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2728
-
2729
-        $success     = $success ? 1 : 0;
2730
-        $action_desc = $new ? 'created' : 'updated';
2731
-        $item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2732
-        $override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2733
-
2734
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2735
-    }
2736
-
2737
-
2738
-    /**
2739
-     * retrieve and sanitize form data
2740
-     *
2741
-     * @return array
2742
-     * @since $VID:$
2743
-     */
2744
-    protected function getMessageTemplateFormData()
2745
-    {
2746
-        return [
2747
-            'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2748
-            'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2749
-            'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2750
-            'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2751
-            'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2752
-            'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2753
-            'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2754
-            'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2755
-            'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2756
-        ];
2757
-    }
2758
-
2759
-
2760
-    /**
2761
-     * @param int    $GRP_ID
2762
-     * @param string $messenger
2763
-     * @param string $message_type
2764
-     * @return array no return on AJAX requests
2765
-     * @throws EE_Error
2766
-     * @throws ReflectionException
2767
-     * @since $VID:$
2768
-     */
2769
-    private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2770
-    {
2771
-        $new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2772
-        $success       = ! empty($new_templates);
2773
-
2774
-        // we return things differently if doing ajax
2775
-        if ($this->request->isAjax()) {
2776
-            $this->_template_args['success'] = $success;
2777
-            $this->_template_args['error']   = ! $success;
2778
-            $this->_template_args['content'] = '';
2779
-            $this->_template_args['data']    = [
2780
-                'grpID'        => $new_templates['GRP_ID'],
2781
-                'templateName' => $new_templates['template_name'],
2782
-            ];
2783
-            if ($success) {
2784
-                EE_Error::overwrite_success();
2785
-                EE_Error::add_success(
2786
-                    esc_html__(
2787
-                        'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2788
-                        'event_espresso'
2789
-                    )
2790
-                );
2791
-            }
2792
-            $this->_return_json();
2793
-        }
2794
-        return [
2795
-            $success,
2796
-            // 'query_args'
2797
-            [
2798
-                'id'      => $new_templates['GRP_ID'],
2799
-                'context' => $new_templates['MTP_context'],
2800
-                'action'  => 'edit_message_template',
2801
-            ],
2802
-        ];
2803
-    }
2804
-
2805
-
2806
-    /**
2807
-     * @param int    $GRP_ID
2808
-     * @param string $messenger
2809
-     * @param string $message_type
2810
-     * @param string $context
2811
-     * @param array  $form_data
2812
-     * @return array
2813
-     * @throws EE_Error
2814
-     * @since $VID:$
2815
-     */
2816
-    private function updateExistingTemplates(
2817
-        $GRP_ID,
2818
-        $messenger,
2819
-        $message_type,
2820
-        $context,
2821
-        array $form_data
2822
-    ) {
2823
-        $success         = false;
2824
-        $template_fields = $this->getTemplateFields();
2825
-        if ($template_fields) {
2826
-            // if field data is valid, then success will be true
2827
-            $success = $this->validateTemplateFields(
2828
-                $messenger,
2829
-                $message_type,
2830
-                $context,
2831
-                $template_fields
2832
-            );
2833
-            if ($success) {
2834
-                $field_data = [];
2835
-                foreach ($template_fields as $template_field => $content) {
2836
-                    // combine top-level form data with content for this field
2837
-                    $field_data = $this->getTemplateFieldFormData($content, $form_data);
2838
-                    $success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2839
-                }
2840
-                // we can use the last set_column_values for the MTPG update
2841
-                // (because its the same for all of these specific MTPs)
2842
-                $success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2843
-            }
2844
-        }
2845
-
2846
-        return [
2847
-            $success,
2848
-            // 'query_args'
2849
-            [
2850
-                'id'      => $GRP_ID,
2851
-                'context' => $context,
2852
-                'action'  => 'edit_message_template',
2853
-            ],
2854
-        ];
2855
-    }
2856
-
2857
-
2858
-    /**
2859
-     * @return array
2860
-     * @since $VID:$
2861
-     */
2862
-    private function getTemplateFields()
2863
-    {
2864
-        $template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2865
-        if (empty($template_fields)) {
2866
-            EE_Error::add_error(
2867
-                esc_html__(
2868
-                    'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2869
-                    'event_espresso'
2870
-                ),
2871
-                __FILE__,
2872
-                __FUNCTION__,
2873
-                __LINE__
2874
-            );
2875
-            return null;
2876
-        }
2877
-        // messages content is expected to be escaped
2878
-        return EEH_Array::addSlashesRecursively($template_fields);
2879
-    }
2880
-
2881
-
2882
-    /**
2883
-     * @param string $messenger
2884
-     * @param string $message_type
2885
-     * @param string $context
2886
-     * @param array  $template_fields
2887
-     * @return bool
2888
-     * @throws EE_Error
2889
-     * @since   $VID:$
2890
-     */
2891
-    private function validateTemplateFields(
2892
-        $messenger,
2893
-        $message_type,
2894
-        $context,
2895
-        array $template_fields
2896
-    ) {
2897
-        // first validate all fields!
2898
-        // this filter allows client code to add its own validation to the template fields as well.
2899
-        // returning an empty array means everything passed validation.
2900
-        // errors in validation should be represented in an array with the following shape:
2901
-        // array(
2902
-        //   'fieldname' => array(
2903
-        //          'msg' => 'error message'
2904
-        //          'value' => 'value for field producing error'
2905
-        // )
2906
-        $custom_validation = (array) apply_filters(
2907
-            'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2908
-            [],
2909
-            $template_fields,
2910
-            $context,
2911
-            $messenger,
2912
-            $message_type
2913
-        );
2914
-
2915
-        $system_validation = $this->getMtgModel()->validate(
2916
-            $template_fields,
2917
-            $context,
2918
-            $messenger,
2919
-            $message_type
2920
-        );
2921
-
2922
-        $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2923
-        $validates         = array_merge($custom_validation, $system_validation);
2924
-
2925
-        // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2926
-        // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2927
-        //  WE need to make sure there is no actual error messages in validates.
2928
-        if (empty($validates)) {
2929
-            return true;
2930
-        }
2931
-
2932
-        // add the transient so when the form loads we know which fields to highlight
2933
-        $this->_add_transient('edit_message_template', $validates);
2934
-        // setup notices
2935
-        foreach ($validates as $error) {
2936
-            if (isset($error['msg'])) {
2937
-                EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2938
-            }
2939
-        }
2940
-        return false;
2941
-    }
2942
-
2943
-
2944
-    /**
2945
-     * @param array $field_data
2946
-     * @param array $form_data
2947
-     * @return array
2948
-     * @since   $VID:$
2949
-     */
2950
-    private function getTemplateFieldFormData(array $field_data, array $form_data)
2951
-    {
2952
-        return $form_data + [
2953
-                'MTP_ID'             => $field_data['MTP_ID'],
2954
-                'MTP_template_field' => $field_data['name'],
2955
-                // if they aren't allowed to use all JS, restrict them to standard allowed post tags
2956
-                'MTP_content'        => ! current_user_can('unfiltered_html')
2957
-                    ? $this->sanitizeMessageTemplateContent($field_data['content'])
2958
-                    : $field_data['content'],
2959
-            ];
2960
-    }
2961
-
2962
-
2963
-    /**
2964
-     * @param string $template_field
2965
-     * @param array  $form_data
2966
-     * @return bool
2967
-     * @throws EE_Error
2968
-     * @since $VID:$
2969
-     */
2970
-    private function updateMessageTemplates($template_field, array $form_data)
2971
-    {
2972
-        $MTP_ID                  = $form_data['MTP_ID'];
2973
-        $message_template_fields = [
2974
-            'GRP_ID'             => $form_data['GRP_ID'],
2975
-            'MTP_template_field' => $form_data['MTP_template_field'],
2976
-            'MTP_context'        => $form_data['MTP_context'],
2977
-            'MTP_content'        => $form_data['MTP_content'],
2978
-        ];
2979
-
2980
-        $hasMtpID = ! empty($MTP_ID);
2981
-        // if we have a MTP_ID for this field then update it, otherwise insert.
2982
-        // this has already been through the template field validator and sanitized, so it will be
2983
-        // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2984
-        // message template field in a messenger/message type and existing users don't have the
2985
-        // default setup for it.
2986
-        // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2987
-        $updated = $hasMtpID
2988
-            ? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2989
-            : $this->getMtpModel()->insert($message_template_fields);
2990
-
2991
-        $insert_failed = ! $hasMtpID && ! $updated;
2992
-        // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2993
-        // but we won't consider that a problem, but if it returns false, then something went BOOM!
2994
-        $update_failed = $hasMtpID && $updated === false;
2995
-
2996
-        if ($insert_failed || $update_failed) {
2997
-            EE_Error::add_error(
2998
-                sprintf(
2999
-                    esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
3000
-                    $template_field
3001
-                ),
3002
-                __FILE__,
3003
-                __FUNCTION__,
3004
-                __LINE__
3005
-            );
3006
-            return false;
3007
-        }
3008
-        return true;
3009
-    }
3010
-
3011
-
3012
-    /**
3013
-     * @param array $form_data
3014
-     * @return bool
3015
-     * @throws EE_Error
3016
-     * @since $VID:$
3017
-     */
3018
-    private function updateMessageTemplateGroup(array $form_data)
3019
-    {
3020
-        $GRP_ID  = $form_data['GRP_ID'];
3021
-        $updated = $this->getMtgModel()->update(
3022
-        // fields and values
3023
-            [
3024
-                'MTP_user_id'      => $form_data['MTP_user_id'],
3025
-                'MTP_messenger'    => $form_data['MTP_messenger'],
3026
-                'MTP_message_type' => $form_data['MTP_message_type'],
3027
-                'MTP_is_global'    => $form_data['MTP_is_global'],
3028
-                'MTP_is_override'  => $form_data['MTP_is_override'],
3029
-                'MTP_deleted'      => $form_data['MTP_deleted'],
3030
-                'MTP_is_active'    => $form_data['MTP_is_active'],
3031
-                'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3032
-                'MTP_description'  => $this->request->getRequestParam(
3033
-                    'ee_msg_non_global_fields[MTP_description]',
3034
-                    ''
3035
-                ),
3036
-            ],
3037
-            // where
3038
-            [['GRP_ID' => $GRP_ID]]
3039
-        );
3040
-
3041
-        if ($updated === false) {
3042
-            EE_Error::add_error(
3043
-                sprintf(
3044
-                    esc_html__(
3045
-                        'The Message Template Group (%d) was NOT updated for some reason',
3046
-                        'event_espresso'
3047
-                    ),
3048
-                    $form_data['GRP_ID']
3049
-                ),
3050
-                __FILE__,
3051
-                __FUNCTION__,
3052
-                __LINE__
3053
-            );
3054
-            return false;
3055
-        }
3056
-        // k now we need to ensure the template_pack and template_variation fields are set.
3057
-        $template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3058
-        $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3059
-
3060
-        $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3061
-        if ($message_template_group instanceof EE_Message_Template_Group) {
3062
-            $message_template_group->set_template_pack_name($template_pack);
3063
-            $message_template_group->set_template_pack_variation($template_variation);
3064
-        }
3065
-        return true;
3066
-    }
3067
-
3068
-
3069
-    /**
3070
-     * recursively runs wp_kses() on message template content in a model safe manner
3071
-     *
3072
-     * @param array|string $content
3073
-     * @return array|string
3074
-     * @since   $VID:$
3075
-     */
3076
-    private function sanitizeMessageTemplateContent($content)
3077
-    {
3078
-        if (is_array($content)) {
3079
-            foreach ($content as $key => $value) {
3080
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3081
-            }
3082
-            return $content;
3083
-        }
3084
-        // remove slashes so wp_kses() works properly
3085
-        // wp_kses_stripslashes() only removes slashes from double-quotes,
3086
-        // so attributes using single quotes always appear invalid.
3087
-        $content = stripslashes($content);
3088
-        $content = wp_kses($content, wp_kses_allowed_html('post'));
3089
-        // But currently the models expect slashed data, so after wp_kses()
3090
-        // runs we need to re-slash the data. Sheesh.
3091
-        // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3092
-        return addslashes($content);
3093
-    }
3094
-
3095
-
3096
-    /**
3097
-     * @param string $messenger
3098
-     * @param string $message_type
3099
-     * @param string $context
3100
-     * @return string
3101
-     * @since $VID:$
3102
-     */
3103
-    private function generateUpdateDescription($messenger, $message_type, $context)
3104
-    {
3105
-        // need the message type and messenger objects to be able to use the labels for the notices
3106
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3107
-        $messenger_label  = $messenger_object instanceof EE_messenger
3108
-            ? ucwords($messenger_object->label['singular'])
3109
-            : '';
3110
-
3111
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3112
-        $message_type_label  = $message_type_object instanceof EE_message_type
3113
-            ? ucwords($message_type_object->label['singular'])
3114
-            : '';
3115
-
3116
-        $context   = ucwords(str_replace('_', ' ', $context));
3117
-        $item_desc = $messenger_label && $message_type_label
3118
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3119
-            : '';
3120
-        $item_desc .= 'Message Template';
3121
-        return $item_desc;
3122
-    }
3123
-
3124
-
3125
-    /**
3126
-     * @param string $messenger
3127
-     * @param string $message_type
3128
-     * @param string $context
3129
-     * @return bool
3130
-     * @throws EE_Error
3131
-     * @throws ReflectionException
3132
-     * @since $VID:$
3133
-     */
3134
-    private function performTestSendAfterUpdate($messenger, $message_type, $context)
3135
-    {
3136
-        // was a test send triggered?
3137
-        if ($this->request->requestParamIsSet('test_button')) {
3138
-            EE_Error::overwrite_success();
3139
-            $this->_do_test_send($context, $messenger, $message_type);
3140
-            return true;
3141
-        }
3142
-        return false;
3143
-    }
3144
-
3145
-
3146
-    /**
3147
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
3148
-     *
3149
-     * @param string $context      what context being tested
3150
-     * @param string $messenger    messenger being tested
3151
-     * @param string $message_type message type being tested
3152
-     * @throws EE_Error
3153
-     * @throws InvalidArgumentException
3154
-     * @throws InvalidDataTypeException
3155
-     * @throws InvalidInterfaceException
3156
-     * @throws ReflectionException
3157
-     */
3158
-    protected function _do_test_send($context, $messenger, $message_type)
3159
-    {
3160
-        // set things up for preview
3161
-        $this->request->setRequestParam('messenger', $messenger);
3162
-        $this->request->setRequestParam('message_type', $message_type);
3163
-        $this->request->setRequestParam('context', $context);
3164
-        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3165
-        $this->request->setRequestParam('GRP_ID', $GRP_ID);
3166
-
3167
-        $active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3168
-        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3169
-
3170
-        // let's save any existing fields that might be required by the messenger
3171
-        if (
3172
-            ! empty($test_settings_fld)
3173
-            && $active_messenger instanceof EE_messenger
3174
-            && apply_filters(
3175
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3176
-                true,
3177
-                $test_settings_fld,
3178
-                $active_messenger
3179
-            )
3180
-        ) {
3181
-            $active_messenger->set_existing_test_settings($test_settings_fld);
3182
-        }
3183
-
3184
-        /**
3185
-         * Use filter to add additional controls on whether message can send or not
3186
-         */
3187
-        if (
3188
-            apply_filters(
3189
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3190
-                true,
3191
-                $context,
3192
-                $this->request->requestParams(),
3193
-                $messenger,
3194
-                $message_type
3195
-            )
3196
-        ) {
3197
-            if (EEM_Event::instance()->count() > 0) {
3198
-                $success = $this->_preview_message(true);
3199
-                if ($success) {
3200
-                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3201
-                } else {
3202
-                    EE_Error::add_error(
3203
-                        esc_html__('The test message was not sent', 'event_espresso'),
3204
-                        __FILE__,
3205
-                        __FUNCTION__,
3206
-                        __LINE__
3207
-                    );
3208
-                }
3209
-            } else {
3210
-                $this->noEventsErrorMessage(true);
3211
-            }
3212
-        }
3213
-    }
3214
-
3215
-
3216
-    /**
3217
-     * _generate_new_templates
3218
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3219
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3220
-     * for the event.
3221
-     *
3222
-     *
3223
-     * @param string $messenger      the messenger we are generating templates for
3224
-     * @param array  $message_types  array of message types that the templates are generated for.
3225
-     * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3226
-     *                               indicate the message_template_group being used as the base.
3227
-     *
3228
-     * @param bool   $global
3229
-     *
3230
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3231
-     *                               encountering problems.
3232
-     * @throws EE_Error
3233
-     * @throws ReflectionException
3234
-     */
3235
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3236
-    {
3237
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3238
-        // just don't generate any templates.
3239
-        if (empty($message_types)) {
3240
-            return [];
3241
-        }
3242
-
3243
-        $templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3244
-        return $templates[0];
3245
-    }
3246
-
3247
-
3248
-    /**
3249
-     * [_trash_or_restore_message_template]
3250
-     *
3251
-     * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3252
-     * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3253
-     *                        an individual context (FALSE).
3254
-     * @return void
3255
-     * @throws EE_Error
3256
-     * @throws InvalidArgumentException
3257
-     * @throws InvalidDataTypeException
3258
-     * @throws InvalidInterfaceException
3259
-     */
3260
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3261
-    {
3262
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3263
-
3264
-        $success = 1;
3265
-
3266
-        // incoming GRP_IDs
3267
-        if ($all) {
3268
-            // Checkboxes
3269
-            $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3270
-            if (! empty($checkboxes)) {
3271
-                // if array has more than one element then success message should be plural.
3272
-                // todo: what about nonce?
3273
-                $success = count($checkboxes) > 1 ? 2 : 1;
3274
-
3275
-                // cycle through checkboxes
3276
-                while (list($GRP_ID, $value) = each($checkboxes)) {
3277
-                    $trashed_or_restored = $trash
3278
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3279
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3280
-                    if (! $trashed_or_restored) {
3281
-                        $success = 0;
3282
-                    }
3283
-                }
3284
-            } else {
3285
-                // grab single GRP_ID and handle
3286
-                $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3287
-                if (! empty($GRP_ID)) {
3288
-                    $trashed_or_restored = $trash
3289
-                        ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3290
-                        : $this->getMtgModel()->restore_by_ID($GRP_ID);
3291
-                    if (! $trashed_or_restored) {
3292
-                        $success = 0;
3293
-                    }
3294
-                } else {
3295
-                    $success = 0;
3296
-                }
3297
-            }
3298
-        }
3299
-
3300
-        $action_desc = $trash
3301
-            ? esc_html__('moved to the trash', 'event_espresso')
3302
-            : esc_html__('restored', 'event_espresso');
3303
-
3304
-        $template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3305
-        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3306
-
3307
-        $item_desc = $all ? _n(
3308
-            'Message Template Group',
3309
-            'Message Template Groups',
3310
-            $success,
3311
-            'event_espresso'
3312
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3313
-
3314
-        $item_desc = $template_switch
3315
-            ? _n('template', 'templates', $success, 'event_espresso')
3316
-            : $item_desc;
3317
-
3318
-        $this->_redirect_after_action($success, $item_desc, $action_desc, []);
3319
-    }
3320
-
3321
-
3322
-    /**
3323
-     * [_delete_message_template]
3324
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3325
-     *
3326
-     * @return void
3327
-     * @throws EE_Error
3328
-     * @throws InvalidArgumentException
3329
-     * @throws InvalidDataTypeException
3330
-     * @throws InvalidInterfaceException
3331
-     * @throws ReflectionException
3332
-     */
3333
-    protected function _delete_message_template()
3334
-    {
3335
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3336
-
3337
-        // checkboxes
3338
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3339
-        if (! empty($checkboxes)) {
3340
-            // if array has more than one element then success message should be plural
3341
-            $success = count($checkboxes) > 1 ? 2 : 1;
3342
-
3343
-            // cycle through bulk action checkboxes
3344
-            while (list($GRP_ID, $value) = each($checkboxes)) {
3345
-                $success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3346
-            }
3347
-        } else {
3348
-            // grab single grp_id and delete
3349
-            $GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3350
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3351
-        }
3352
-
3353
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3354
-    }
3355
-
3356
-
3357
-    /**
3358
-     * helper for permanently deleting a mtP group and all related message_templates
3359
-     *
3360
-     * @param int  $GRP_ID        The group being deleted
3361
-     * @param bool $include_group whether to delete the Message Template Group as well.
3362
-     * @return bool boolean to indicate the success of the deletes or not.
3363
-     * @throws EE_Error
3364
-     * @throws InvalidArgumentException
3365
-     * @throws InvalidDataTypeException
3366
-     * @throws InvalidInterfaceException
3367
-     * @throws ReflectionException
3368
-     * @throws ReflectionException
3369
-     */
3370
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3371
-    {
3372
-        $success = true;
3373
-        // first let's GET this group
3374
-        $MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3375
-        // then delete permanently all the related Message Templates
3376
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3377
-
3378
-        if ($deleted === 0) {
3379
-            $success = false;
3380
-        }
3381
-
3382
-        // now delete permanently this particular group
3383
-
3384
-        if ($include_group && ! $MTG->delete_permanently()) {
3385
-            $success = false;
3386
-        }
3387
-
3388
-        return $success;
3389
-    }
3390
-
3391
-
3392
-    /**
3393
-     *    _learn_more_about_message_templates_link
3394
-     *
3395
-     * @access protected
3396
-     * @return string
3397
-     */
3398
-    protected function _learn_more_about_message_templates_link()
3399
-    {
3400
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3401
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3402
-               . '</a>';
3403
-    }
3404
-
3405
-
3406
-    /**
3407
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3408
-     * ajax and other routes.
3409
-     *
3410
-     * @return void
3411
-     * @throws DomainException
3412
-     * @throws EE_Error
3413
-     */
3414
-    protected function _settings()
3415
-    {
3416
-        $this->_set_m_mt_settings();
3417
-
3418
-        // let's setup the messenger tabs
3419
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3420
-            $this->_m_mt_settings['messenger_tabs'],
3421
-            'messenger_links',
3422
-            '|',
3423
-            $this->request->getRequestParam('selected_messenger', 'email')
3424
-        );
3425
-
3426
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3427
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3428
-
3429
-        $this->display_admin_page_with_sidebar();
3430
-    }
3431
-
3432
-
3433
-    /**
3434
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3435
-     *
3436
-     * @access protected
3437
-     * @return void
3438
-     * @throws DomainException
3439
-     */
3440
-    protected function _set_m_mt_settings()
3441
-    {
3442
-        // first if this is already set then lets get out no need to regenerate data.
3443
-        if (! empty($this->_m_mt_settings)) {
3444
-            return;
3445
-        }
3446
-
3447
-        // get all installed messengers and message_types
3448
-        $messengers    = $this->_message_resource_manager->installed_messengers();
3449
-        $message_types = $this->_message_resource_manager->installed_message_types();
3450
-
3451
-
3452
-        // assemble the array for the _tab_text_links helper
3453
-
3454
-        foreach ($messengers as $messenger) {
3455
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3456
-                'label' => ucwords($messenger->label['singular']),
3457
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3458
-                    ? 'messenger-active'
3459
-                    : '',
3460
-                'href'  => $messenger->name,
3461
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3462
-                'slug'  => $messenger->name,
3463
-                'obj'   => $messenger,
3464
-            ];
3465
-
3466
-
3467
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3468
-
3469
-            foreach ($message_types as $message_type) {
3470
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3471
-                // it shouldn't show in either the inactive OR active metabox.
3472
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3473
-                    continue;
3474
-                }
3475
-
3476
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3477
-                    $messenger->name,
3478
-                    $message_type->name
3479
-                )
3480
-                    ? 'active'
3481
-                    : 'inactive';
3482
-
3483
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3484
-                    'label'    => ucwords($message_type->label['singular']),
3485
-                    'class'    => 'message-type-' . $a_or_i,
3486
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3487
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3488
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3489
-                    'title'    => $a_or_i === 'active'
3490
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3491
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3492
-                    'content'  => $a_or_i === 'active'
3493
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3494
-                        : $this->_message_type_settings_content($message_type, $messenger),
3495
-                    'slug'     => $message_type->name,
3496
-                    'active'   => $a_or_i === 'active',
3497
-                    'obj'      => $message_type,
3498
-                ];
3499
-            }
3500
-        }
3501
-    }
3502
-
3503
-
3504
-    /**
3505
-     * This just prepares the content for the message type settings
3506
-     *
3507
-     * @param EE_message_type $message_type The message type object
3508
-     * @param EE_messenger    $messenger    The messenger object
3509
-     * @param boolean         $active       Whether the message type is active or not
3510
-     * @return string html output for the content
3511
-     * @throws DomainException
3512
-     */
3513
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3514
-    {
3515
-        // get message type fields
3516
-        $fields                                         = $message_type->get_admin_settings_fields();
3517
-        $settings_template_args['template_form_fields'] = '';
3518
-
3519
-        if (! empty($fields) && $active) {
3520
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3521
-            foreach ($fields as $fldname => $fldprops) {
3522
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3523
-                $template_form_field[ $field_id ] = [
3524
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3525
-                    'label'      => $fldprops['label'],
3526
-                    'input'      => $fldprops['field_type'],
3527
-                    'type'       => $fldprops['value_type'],
3528
-                    'required'   => $fldprops['required'],
3529
-                    'validation' => $fldprops['validation'],
3530
-                    'value'      => isset($existing_settings[ $fldname ])
3531
-                        ? $existing_settings[ $fldname ]
3532
-                        : $fldprops['default'],
3533
-                    'options'    => isset($fldprops['options'])
3534
-                        ? $fldprops['options']
3535
-                        : [],
3536
-                    'default'    => isset($existing_settings[ $fldname ])
3537
-                        ? $existing_settings[ $fldname ]
3538
-                        : $fldprops['default'],
3539
-                    'css_class'  => 'no-drag',
3540
-                    'format'     => $fldprops['format'],
3541
-                ];
3542
-            }
3543
-
3544
-
3545
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3546
-                ? $this->_generate_admin_form_fields(
3547
-                    $template_form_field,
3548
-                    'string',
3549
-                    'ee_mt_activate_form'
3550
-                )
3551
-                : '';
3552
-        }
3553
-
3554
-        $settings_template_args['description'] = $message_type->description;
3555
-        // we also need some hidden fields
3556
-        $hidden_fields = [
3557
-            'message_type_settings[messenger]' . $message_type->name    => [
3558
-                'type'  => 'hidden',
3559
-                'value' => $messenger->name,
3560
-            ],
3561
-            'message_type_settings[message_type]' . $message_type->name => [
3562
-                'type'  => 'hidden',
3563
-                'value' => $message_type->name,
3564
-            ],
3565
-            'type' . $message_type->name                                => [
3566
-                'type'  => 'hidden',
3567
-                'value' => 'message_type',
3568
-            ],
3569
-        ];
3570
-
3571
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3572
-            $hidden_fields,
3573
-            'array'
3574
-        );
3575
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3576
-            ? ' hidden'
3577
-            : '';
3578
-
3579
-
3580
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3581
-        return EEH_Template::display_template($template, $settings_template_args, true);
3582
-    }
3583
-
3584
-
3585
-    /**
3586
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3587
-     *
3588
-     * @access protected
3589
-     * @return void
3590
-     * @throws DomainException
3591
-     */
3592
-    protected function _messages_settings_metaboxes()
3593
-    {
3594
-        $this->_set_m_mt_settings();
3595
-        $m_boxes         = $mt_boxes = [];
3596
-        $m_template_args = $mt_template_args = [];
3597
-
3598
-        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3599
-
3600
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3601
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3602
-                $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3603
-                $hide_on_message     = $is_messenger_active ? '' : 'hidden';
3604
-                $hide_off_message    = $is_messenger_active ? 'hidden' : '';
3605
-
3606
-                // messenger meta boxes
3607
-                $active         = $selected_messenger === $messenger;
3608
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3609
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3610
-                    : '';
3611
-
3612
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3613
-                    esc_html__('%s Settings', 'event_espresso'),
3614
-                    $tab_array['label']
3615
-                );
3616
-
3617
-                $m_template_args[ $messenger . '_a_box' ] = [
3618
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3619
-                    'inactive_message_types' => isset(
3620
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3621
-                    )
3622
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3623
-                        : '',
3624
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3625
-                    'hidden'                 => $active ? '' : ' hidden',
3626
-                    'hide_on_message'        => $hide_on_message,
3627
-                    'messenger'              => $messenger,
3628
-                    'active'                 => $active,
3629
-                ];
3630
-
3631
-                // message type meta boxes
3632
-                // (which is really just the inactive container for each messenger
3633
-                // showing inactive message types for that messenger)
3634
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3635
-                $mt_template_args[ $messenger . '_i_box' ] = [
3636
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3637
-                    'inactive_message_types' => isset(
3638
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3639
-                    )
3640
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3641
-                        : '',
3642
-                    'hidden'                 => $active ? '' : ' hidden',
3643
-                    'hide_on_message'        => $hide_on_message,
3644
-                    'hide_off_message'       => $hide_off_message,
3645
-                    'messenger'              => $messenger,
3646
-                    'active'                 => $active,
3647
-                ];
3648
-            }
3649
-        }
3650
-
3651
-
3652
-        // register messenger metaboxes
3653
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3654
-        foreach ($m_boxes as $box => $label) {
3655
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3656
-            $msgr          = str_replace('_a_box', '', $box);
3657
-            add_meta_box(
3658
-                'espresso_' . $msgr . '_settings',
3659
-                $label,
3660
-                function ($post, $metabox) {
3661
-                    EEH_Template::display_template(
3662
-                        $metabox['args']['template_path'],
3663
-                        $metabox['args']['template_args']
3664
-                    );
3665
-                },
3666
-                $this->_current_screen->id,
3667
-                'normal',
3668
-                'high',
3669
-                $callback_args
3670
-            );
3671
-        }
3672
-
3673
-        // register message type metaboxes
3674
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3675
-        foreach ($mt_boxes as $box => $label) {
3676
-            $callback_args = [
3677
-                'template_path' => $mt_template_path,
3678
-                'template_args' => $mt_template_args[ $box ],
3679
-            ];
3680
-            $mt            = str_replace('_i_box', '', $box);
3681
-            add_meta_box(
3682
-                'espresso_' . $mt . '_inactive_mts',
3683
-                $label,
3684
-                function ($post, $metabox) {
3685
-                    EEH_Template::display_template(
3686
-                        $metabox['args']['template_path'],
3687
-                        $metabox['args']['template_args']
3688
-                    );
3689
-                },
3690
-                $this->_current_screen->id,
3691
-                'side',
3692
-                'high',
3693
-                $callback_args
3694
-            );
3695
-        }
3696
-
3697
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3698
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3699
-        if (is_main_site()) {
3700
-            add_meta_box(
3701
-                'espresso_global_message_settings',
3702
-                esc_html__('Global Message Settings', 'event_espresso'),
3703
-                [$this, 'global_messages_settings_metabox_content'],
3704
-                $this->_current_screen->id,
3705
-                'normal',
3706
-                'low',
3707
-                []
3708
-            );
3709
-        }
3710
-    }
3711
-
3712
-
3713
-    /**
3714
-     *  This generates the content for the global messages settings metabox.
3715
-     *
3716
-     * @return void
3717
-     * @throws EE_Error
3718
-     * @throws InvalidArgumentException
3719
-     * @throws ReflectionException
3720
-     * @throws InvalidDataTypeException
3721
-     * @throws InvalidInterfaceException
3722
-     */
3723
-    public function global_messages_settings_metabox_content()
3724
-    {
3725
-        $form = $this->_generate_global_settings_form();
3726
-        // already escaped
3727
-        echo $form->form_open(
3728
-            $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3729
-            'POST'
3730
-        );
3731
-        echo $form->get_html();
3732
-        echo $form->form_close();
3733
-    }
3734
-
3735
-
3736
-    /**
3737
-     * This generates and returns the form object for the global messages settings.
3738
-     *
3739
-     * @return EE_Form_Section_Proper
3740
-     * @throws EE_Error
3741
-     * @throws InvalidArgumentException
3742
-     * @throws ReflectionException
3743
-     * @throws InvalidDataTypeException
3744
-     * @throws InvalidInterfaceException
3745
-     */
3746
-    protected function _generate_global_settings_form()
3747
-    {
3748
-        /** @var EE_Network_Core_Config $network_config */
3749
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3750
-
3751
-        return new EE_Form_Section_Proper(
3752
-            [
3753
-                'name'            => 'global_messages_settings',
3754
-                'html_id'         => 'global_messages_settings',
3755
-                'html_class'      => 'form-table',
3756
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3757
-                'subsections'     => apply_filters(
3758
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3759
-                    [
3760
-                        'do_messages_on_same_request' => new EE_Select_Input(
3761
-                            [
3762
-                                true  => esc_html__('On the same request', 'event_espresso'),
3763
-                                false => esc_html__('On a separate request', 'event_espresso'),
3764
-                            ],
3765
-                            [
3766
-                                'default'         => $network_config->do_messages_on_same_request,
3767
-                                'html_label_text' => esc_html__(
3768
-                                    'Generate and send all messages:',
3769
-                                    'event_espresso'
3770
-                                ),
3771
-                                'html_help_text'  => esc_html__(
3772
-                                    'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3773
-                                    'event_espresso'
3774
-                                ),
3775
-                            ]
3776
-                        ),
3777
-                        'delete_threshold'            => new EE_Select_Input(
3778
-                            [
3779
-                                0  => esc_html__('Forever', 'event_espresso'),
3780
-                                3  => esc_html__('3 Months', 'event_espresso'),
3781
-                                6  => esc_html__('6 Months', 'event_espresso'),
3782
-                                9  => esc_html__('9 Months', 'event_espresso'),
3783
-                                12 => esc_html__('12 Months', 'event_espresso'),
3784
-                                24 => esc_html__('24 Months', 'event_espresso'),
3785
-                                36 => esc_html__('36 Months', 'event_espresso'),
3786
-                            ],
3787
-                            [
3788
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3789
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3790
-                                'html_help_text'  => esc_html__(
3791
-                                    'You can control how long a record of processed messages is kept via this option.',
3792
-                                    'event_espresso'
3793
-                                ),
3794
-                            ]
3795
-                        ),
3796
-                        'update_settings'             => new EE_Submit_Input(
3797
-                            [
3798
-                                'default'         => esc_html__('Update', 'event_espresso'),
3799
-                                'html_label_text' => '&nbsp',
3800
-                            ]
3801
-                        ),
3802
-                    ]
3803
-                ),
3804
-            ]
3805
-        );
3806
-    }
3807
-
3808
-
3809
-    /**
3810
-     * This handles updating the global settings set on the admin page.
3811
-     *
3812
-     * @throws EE_Error
3813
-     * @throws InvalidDataTypeException
3814
-     * @throws InvalidInterfaceException
3815
-     * @throws InvalidArgumentException
3816
-     * @throws ReflectionException
3817
-     */
3818
-    protected function _update_global_settings()
3819
-    {
3820
-        /** @var EE_Network_Core_Config $network_config */
3821
-        $network_config  = EE_Registry::instance()->NET_CFG->core;
3822
-        $messages_config = EE_Registry::instance()->CFG->messages;
3823
-        $form            = $this->_generate_global_settings_form();
3824
-        if ($form->was_submitted()) {
3825
-            $form->receive_form_submission();
3826
-            if ($form->is_valid()) {
3827
-                $valid_data = $form->valid_data();
3828
-                foreach ($valid_data as $property => $value) {
3829
-                    $setter = 'set_' . $property;
3830
-                    if (method_exists($network_config, $setter)) {
3831
-                        $network_config->{$setter}($value);
3832
-                    } elseif (
3833
-                        property_exists($network_config, $property)
3834
-                        && $network_config->{$property} !== $value
3835
-                    ) {
3836
-                        $network_config->{$property} = $value;
3837
-                    } elseif (
3838
-                        property_exists($messages_config, $property)
3839
-                        && $messages_config->{$property} !== $value
3840
-                    ) {
3841
-                        $messages_config->{$property} = $value;
3842
-                    }
3843
-                }
3844
-                // only update if the form submission was valid!
3845
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3846
-                EE_Registry::instance()->CFG->update_espresso_config();
3847
-                EE_Error::overwrite_success();
3848
-                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3849
-            }
3850
-        }
3851
-        $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3852
-    }
3853
-
3854
-
3855
-    /**
3856
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3857
-     *
3858
-     * @param array $tab_array This is an array of message type tab details used to generate the tabs
3859
-     * @return string html formatted tabs
3860
-     * @throws DomainException
3861
-     */
3862
-    protected function _get_mt_tabs($tab_array)
3863
-    {
3864
-        $tab_array = (array) $tab_array;
3865
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3866
-        $tabs      = '';
3867
-
3868
-        foreach ($tab_array as $tab) {
3869
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3870
-        }
3871
-
3872
-        return $tabs;
3873
-    }
3874
-
3875
-
3876
-    /**
3877
-     * This prepares the content of the messenger meta box admin settings
3878
-     *
3879
-     * @param EE_messenger $messenger The messenger we're setting up content for
3880
-     * @return string html formatted content
3881
-     * @throws DomainException
3882
-     */
3883
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3884
-    {
3885
-
3886
-        $fields                                         = $messenger->get_admin_settings_fields();
3887
-        $settings_template_args['template_form_fields'] = '';
3888
-
3889
-        // is $messenger active?
3890
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3891
-
3892
-
3893
-        if (! empty($fields)) {
3894
-            $existing_settings = $messenger->get_existing_admin_settings();
3895
-
3896
-            foreach ($fields as $fldname => $fldprops) {
3897
-                $field_id                         = $messenger->name . '-' . $fldname;
3898
-                $template_form_field[ $field_id ] = [
3899
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3900
-                    'label'      => $fldprops['label'],
3901
-                    'input'      => $fldprops['field_type'],
3902
-                    'type'       => $fldprops['value_type'],
3903
-                    'required'   => $fldprops['required'],
3904
-                    'validation' => $fldprops['validation'],
3905
-                    'value'      => isset($existing_settings[ $field_id ])
3906
-                        ? $existing_settings[ $field_id ]
3907
-                        : $fldprops['default'],
3908
-                    'css_class'  => '',
3909
-                    'format'     => $fldprops['format'],
3910
-                ];
3911
-            }
3912
-
3913
-
3914
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3915
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3916
-                : '';
3917
-        }
3918
-
3919
-        // we also need some hidden fields
3920
-        $settings_template_args['hidden_fields'] = [
3921
-            'messenger_settings[messenger]' . $messenger->name => [
3922
-                'type'  => 'hidden',
3923
-                'value' => $messenger->name,
3924
-            ],
3925
-            'type' . $messenger->name                          => [
3926
-                'type'  => 'hidden',
3927
-                'value' => 'messenger',
3928
-            ],
3929
-        ];
3930
-
3931
-        // make sure any active message types that are existing are included in the hidden fields
3932
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3933
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3934
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3935
-                    'type'  => 'hidden',
3936
-                    'value' => $mt,
3937
-                ];
3938
-            }
3939
-        }
3940
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3941
-            $settings_template_args['hidden_fields'],
3942
-            'array'
3943
-        );
3944
-        $active                                  =
3945
-            $this->_message_resource_manager->is_messenger_active($messenger->name);
3946
-
3947
-        $settings_template_args['messenger']           = $messenger->name;
3948
-        $settings_template_args['description']         = $messenger->description;
3949
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3950
-
3951
-
3952
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3953
-            $messenger->name
3954
-        )
3955
-            ? $settings_template_args['show_hide_edit_form']
3956
-            : ' hidden';
3957
-
3958
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3959
-            ? ' hidden'
3960
-            : $settings_template_args['show_hide_edit_form'];
3961
-
3962
-
3963
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3964
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3965
-        $settings_template_args['on_off_status'] = $active;
3966
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3967
-        return EEH_Template::display_template(
3968
-            $template,
3969
-            $settings_template_args,
3970
-            true
3971
-        );
3972
-    }
3973
-
3974
-
3975
-    /**
3976
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3977
-     *
3978
-     * @throws DomainException
3979
-     * @throws EE_Error
3980
-     * @throws InvalidDataTypeException
3981
-     * @throws InvalidInterfaceException
3982
-     * @throws InvalidArgumentException
3983
-     * @throws ReflectionException
3984
-     */
3985
-    public function activate_messenger_toggle()
3986
-    {
3987
-        $success = true;
3988
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3989
-        // let's check that we have required data
3990
-
3991
-        if (! $this->_active_messenger_name) {
3992
-            EE_Error::add_error(
3993
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3994
-                __FILE__,
3995
-                __FUNCTION__,
3996
-                __LINE__
3997
-            );
3998
-            $success = false;
3999
-        }
4000
-
4001
-        // do a nonce check here since we're not arriving via a normal route
4002
-        $nonce     = $this->request->getRequestParam('activate_nonce', '');
4003
-        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4004
-
4005
-        $this->_verify_nonce($nonce, $nonce_ref);
4006
-
4007
-
4008
-        $status = $this->request->getRequestParam('status');
4009
-        if (! $status) {
4010
-            EE_Error::add_error(
4011
-                esc_html__(
4012
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4013
-                    'event_espresso'
4014
-                ),
4015
-                __FILE__,
4016
-                __FUNCTION__,
4017
-                __LINE__
4018
-            );
4019
-            $success = false;
4020
-        }
4021
-
4022
-        // do check to verify we have a valid status.
4023
-        if ($status !== 'off' && $status !== 'on') {
4024
-            EE_Error::add_error(
4025
-                sprintf(
4026
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4027
-                    $status
4028
-                ),
4029
-                __FILE__,
4030
-                __FUNCTION__,
4031
-                __LINE__
4032
-            );
4033
-            $success = false;
4034
-        }
4035
-
4036
-        if ($success) {
4037
-            // made it here?  Stop dawdling then!!
4038
-            $success = $status === 'off'
4039
-                ? $this->_deactivate_messenger($this->_active_messenger_name)
4040
-                : $this->_activate_messenger($this->_active_messenger_name);
4041
-        }
4042
-
4043
-        $this->_template_args['success'] = $success;
4044
-
4045
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
4046
-        $this->_return_json();
4047
-    }
4048
-
4049
-
4050
-    /**
4051
-     * used by ajax from the messages settings page to activate|deactivate a message type
4052
-     *
4053
-     * @throws DomainException
4054
-     * @throws EE_Error
4055
-     * @throws ReflectionException
4056
-     * @throws InvalidDataTypeException
4057
-     * @throws InvalidInterfaceException
4058
-     * @throws InvalidArgumentException
4059
-     */
4060
-    public function activate_mt_toggle()
4061
-    {
4062
-        $success = true;
4063
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
4064
-
4065
-        // let's make sure we have the necessary data
4066
-        if (! $this->_active_message_type_name) {
4067
-            EE_Error::add_error(
4068
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4069
-                __FILE__,
4070
-                __FUNCTION__,
4071
-                __LINE__
4072
-            );
4073
-            $success = false;
4074
-        }
4075
-
4076
-        if (! $this->_active_messenger_name) {
4077
-            EE_Error::add_error(
4078
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4079
-                __FILE__,
4080
-                __FUNCTION__,
4081
-                __LINE__
4082
-            );
4083
-            $success = false;
4084
-        }
4085
-
4086
-        $status = $this->request->getRequestParam('status');
4087
-        if (! $status) {
4088
-            EE_Error::add_error(
4089
-                esc_html__(
4090
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4091
-                    'event_espresso'
4092
-                ),
4093
-                __FILE__,
4094
-                __FUNCTION__,
4095
-                __LINE__
4096
-            );
4097
-            $success = false;
4098
-        }
4099
-
4100
-
4101
-        // do check to verify we have a valid status.
4102
-        if ($status !== 'activate' && $status !== 'deactivate') {
4103
-            EE_Error::add_error(
4104
-                sprintf(
4105
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4106
-                    $status
4107
-                ),
4108
-                __FILE__,
4109
-                __FUNCTION__,
4110
-                __LINE__
4111
-            );
4112
-            $success = false;
4113
-        }
4114
-
4115
-
4116
-        // do a nonce check here since we're not arriving via a normal route
4117
-        $nonce = $this->request->getRequestParam('mt_nonce', '');
4118
-        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4119
-
4120
-        if ($success) {
4121
-            // made it here? um, what are you waiting for then?
4122
-            $success = $status === 'deactivate'
4123
-                ? $this->_deactivate_message_type_for_messenger(
4124
-                    $this->_active_messenger_name,
4125
-                    $this->_active_message_type_name
4126
-                )
4127
-                : $this->_activate_message_type_for_messenger(
4128
-                    $this->_active_messenger_name,
4129
-                    $this->_active_message_type_name
4130
-                );
4131
-        }
4132
-
4133
-        $this->_template_args['success'] = $success;
4134
-        $this->_return_json();
4135
-    }
4136
-
4137
-
4138
-    /**
4139
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4140
-     *
4141
-     * @param string $messenger_name The name of the messenger being activated
4142
-     * @return bool
4143
-     * @throws DomainException
4144
-     * @throws EE_Error
4145
-     * @throws InvalidArgumentException
4146
-     * @throws ReflectionException
4147
-     * @throws InvalidDataTypeException
4148
-     * @throws InvalidInterfaceException
4149
-     */
4150
-    protected function _activate_messenger($messenger_name)
4151
-    {
4152
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4153
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4154
-            ? $active_messenger->get_default_message_types()
4155
-            : [];
4156
-
4157
-        // ensure is active
4158
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4159
-
4160
-        // set response_data for reload
4161
-        foreach ($message_types_to_activate as $message_type_name) {
4162
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4163
-            if (
4164
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4165
-                    $messenger_name,
4166
-                    $message_type_name
4167
-                )
4168
-                && $message_type instanceof EE_message_type
4169
-            ) {
4170
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4171
-                if ($message_type->get_admin_settings_fields()) {
4172
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4173
-                }
4174
-            }
4175
-        }
4176
-
4177
-        // add success message for activating messenger
4178
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4179
-    }
4180
-
4181
-
4182
-    /**
4183
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4184
-     *
4185
-     * @param string $messenger_name The name of the messenger being activated
4186
-     * @return bool
4187
-     * @throws DomainException
4188
-     * @throws EE_Error
4189
-     * @throws InvalidArgumentException
4190
-     * @throws ReflectionException
4191
-     * @throws InvalidDataTypeException
4192
-     * @throws InvalidInterfaceException
4193
-     */
4194
-    protected function _deactivate_messenger($messenger_name)
4195
-    {
4196
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4197
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4198
-
4199
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4200
-    }
4201
-
4202
-
4203
-    /**
4204
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4205
-     *
4206
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4207
-     * @param string $message_type_name The name of the message type being activated for the messenger
4208
-     * @return bool
4209
-     * @throws DomainException
4210
-     * @throws EE_Error
4211
-     * @throws InvalidArgumentException
4212
-     * @throws ReflectionException
4213
-     * @throws InvalidDataTypeException
4214
-     * @throws InvalidInterfaceException
4215
-     */
4216
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4217
-    {
4218
-        $active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4219
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4220
-
4221
-        // ensure is active
4222
-        $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4223
-
4224
-        // set response for load
4225
-        if (
4226
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4227
-                $messenger_name,
4228
-                $message_type_name
4229
-            )
4230
-        ) {
4231
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4232
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4233
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4234
-            }
4235
-        }
4236
-
4237
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4238
-            $active_messenger,
4239
-            $message_type_to_activate
4240
-        );
4241
-    }
4242
-
4243
-
4244
-    /**
4245
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4246
-     *
4247
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4248
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4249
-     * @return bool
4250
-     * @throws DomainException
4251
-     * @throws EE_Error
4252
-     * @throws InvalidArgumentException
4253
-     * @throws ReflectionException
4254
-     * @throws InvalidDataTypeException
4255
-     * @throws InvalidInterfaceException
4256
-     */
4257
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4258
-    {
4259
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4260
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4261
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4262
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4263
-
4264
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4265
-            $active_messenger,
4266
-            $message_type_to_deactivate
4267
-        );
4268
-    }
4269
-
4270
-
4271
-    /**
4272
-     * This just initializes the defaults for activating messenger and message type responses.
4273
-     */
4274
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4275
-    {
4276
-        $this->_template_args['data']['active_mts'] = [];
4277
-        $this->_template_args['data']['mt_reload']  = [];
4278
-    }
4279
-
4280
-
4281
-    /**
4282
-     * Setup appropriate response for activating a messenger and/or message types
4283
-     *
4284
-     * @param EE_messenger         $messenger
4285
-     * @param EE_message_type|null $message_type
4286
-     * @return bool
4287
-     * @throws DomainException
4288
-     * @throws EE_Error
4289
-     * @throws InvalidArgumentException
4290
-     * @throws ReflectionException
4291
-     * @throws InvalidDataTypeException
4292
-     * @throws InvalidInterfaceException
4293
-     */
4294
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4295
-        $messenger,
4296
-        EE_Message_Type $message_type = null
4297
-    ) {
4298
-        // if $messenger isn't a valid messenger object then get out.
4299
-        if (! $messenger instanceof EE_Messenger) {
4300
-            EE_Error::add_error(
4301
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4302
-                __FILE__,
4303
-                __FUNCTION__,
4304
-                __LINE__
4305
-            );
4306
-            return false;
4307
-        }
4308
-        // activated
4309
-        if ($this->_template_args['data']['active_mts']) {
4310
-            EE_Error::overwrite_success();
4311
-            // activated a message type with the messenger
4312
-            if ($message_type instanceof EE_message_type) {
4313
-                EE_Error::add_success(
4314
-                    sprintf(
4315
-                        esc_html__(
4316
-                            '%s message type has been successfully activated with the %s messenger',
4317
-                            'event_espresso'
4318
-                        ),
4319
-                        ucwords($message_type->label['singular']),
4320
-                        ucwords($messenger->label['singular'])
4321
-                    )
4322
-                );
4323
-
4324
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4325
-                if ($message_type->name === 'invoice') {
4326
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4327
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4328
-                    if ($pm instanceof EE_Payment_Method) {
4329
-                        EE_Error::add_attention(
4330
-                            esc_html__(
4331
-                                'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4332
-                                'event_espresso'
4333
-                            )
4334
-                        );
4335
-                    }
4336
-                }
4337
-                // just toggles the entire messenger
4338
-            } else {
4339
-                EE_Error::add_success(
4340
-                    sprintf(
4341
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4342
-                        ucwords($messenger->label['singular'])
4343
-                    )
4344
-                );
4345
-            }
4346
-
4347
-            return true;
4348
-
4349
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4350
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4351
-            // in which case we just give a success message for the messenger being successfully activated.
4352
-        } else {
4353
-            if (! $messenger->get_default_message_types()) {
4354
-                // messenger doesn't have any default message types so still a success.
4355
-                EE_Error::add_success(
4356
-                    sprintf(
4357
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4358
-                        ucwords($messenger->label['singular'])
4359
-                    )
4360
-                );
4361
-
4362
-                return true;
4363
-            } else {
4364
-                EE_Error::add_error(
4365
-                    $message_type instanceof EE_message_type
4366
-                    ? sprintf(
4367
-                        esc_html__(
4368
-                            '%s message type was not successfully activated with the %s messenger',
4369
-                            'event_espresso'
4370
-                        ),
4371
-                        ucwords($message_type->label['singular']),
4372
-                        ucwords($messenger->label['singular'])
4373
-                    )
4374
-                    : sprintf(
4375
-                        esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4376
-                        ucwords($messenger->label['singular'])
4377
-                    ),
4378
-                    __FILE__,
4379
-                    __FUNCTION__,
4380
-                    __LINE__
4381
-                );
4382
-
4383
-                return false;
4384
-            }
4385
-        }
4386
-    }
4387
-
4388
-
4389
-    /**
4390
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4391
-     *
4392
-     * @param EE_messenger         $messenger
4393
-     * @param EE_message_type|null $message_type
4394
-     * @return bool
4395
-     * @throws DomainException
4396
-     * @throws EE_Error
4397
-     * @throws InvalidArgumentException
4398
-     * @throws ReflectionException
4399
-     * @throws InvalidDataTypeException
4400
-     * @throws InvalidInterfaceException
4401
-     */
4402
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4403
-        $messenger,
4404
-        EE_message_type $message_type = null
4405
-    ) {
4406
-        EE_Error::overwrite_success();
4407
-
4408
-        // if $messenger isn't a valid messenger object then get out.
4409
-        if (! $messenger instanceof EE_Messenger) {
4410
-            EE_Error::add_error(
4411
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4412
-                __FILE__,
4413
-                __FUNCTION__,
4414
-                __LINE__
4415
-            );
4416
-
4417
-            return false;
4418
-        }
4419
-
4420
-        if ($message_type instanceof EE_message_type) {
4421
-            $message_type_name = $message_type->name;
4422
-            EE_Error::add_success(
4423
-                sprintf(
4424
-                    esc_html__(
4425
-                        '%s message type has been successfully deactivated for the %s messenger.',
4426
-                        'event_espresso'
4427
-                    ),
4428
-                    ucwords($message_type->label['singular']),
4429
-                    ucwords($messenger->label['singular'])
4430
-                )
4431
-            );
4432
-        } else {
4433
-            $message_type_name = '';
4434
-            EE_Error::add_success(
4435
-                sprintf(
4436
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4437
-                    ucwords($messenger->label['singular'])
4438
-                )
4439
-            );
4440
-        }
4441
-
4442
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4443
-        if (
4444
-            $messenger->name === 'html'
4445
-            && (
4446
-                is_null($message_type)
4447
-                || $message_type_name === 'invoice'
4448
-            )
4449
-        ) {
4450
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4451
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4452
-            if ($count_updated > 0) {
4453
-                $msg = $message_type_name === 'invoice'
4454
-                    ? esc_html__(
4455
-                        'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4456
-                        'event_espresso'
4457
-                    )
4458
-                    : esc_html__(
4459
-                        'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4460
-                        'event_espresso'
4461
-                    );
4462
-                EE_Error::add_attention($msg);
4463
-            }
4464
-        }
4465
-
4466
-        return true;
4467
-    }
4468
-
4469
-
4470
-    /**
4471
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4472
-     *
4473
-     * @throws DomainException
4474
-     * @throws EE_Error
4475
-     * @throws EE_Error
4476
-     */
4477
-    public function update_mt_form()
4478
-    {
4479
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4480
-            EE_Error::add_error(
4481
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4482
-                __FILE__,
4483
-                __FUNCTION__,
4484
-                __LINE__
4485
-            );
4486
-            $this->_return_json();
4487
-        }
4488
-
4489
-        $message_types = $this->get_installed_message_types();
4490
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4491
-        $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4492
-        $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4493
-
4494
-        $this->_template_args['success'] = true;
4495
-        $this->_template_args['content'] = $content;
4496
-        $this->_return_json();
4497
-    }
4498
-
4499
-
4500
-    /**
4501
-     * this handles saving the settings for a messenger or message type
4502
-     *
4503
-     * @throws EE_Error
4504
-     * @throws EE_Error
4505
-     */
4506
-    public function save_settings()
4507
-    {
4508
-        $type = $this->request->getRequestParam('type');
4509
-        if (! $type) {
4510
-            EE_Error::add_error(
4511
-                esc_html__(
4512
-                    'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4513
-                    'event_espresso'
4514
-                ),
4515
-                __FILE__,
4516
-                __FUNCTION__,
4517
-                __LINE__
4518
-            );
4519
-            $this->_template_args['error'] = true;
4520
-            $this->_return_json();
4521
-        }
4522
-
4523
-
4524
-        if ($type === 'messenger') {
4525
-            // this should be an array.
4526
-            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4527
-            $messenger = $settings['messenger'];
4528
-            // remove messenger and message_types from settings array
4529
-            unset($settings['messenger'], $settings['message_types']);
4530
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4531
-        } elseif ($type === 'message_type') {
4532
-            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4533
-            $messenger    = $settings['messenger'];
4534
-            $message_type = $settings['message_type'];
4535
-            // remove messenger and message_types from settings array
4536
-            unset($settings['messenger'], $settings['message_types']);
4537
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4538
-        }
4539
-
4540
-        // okay we should have the data all setup.  Now we just update!
4541
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4542
-
4543
-        if ($success) {
4544
-            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4545
-        } else {
4546
-            EE_Error::add_error(
4547
-                esc_html__('Settings did not get updated', 'event_espresso'),
4548
-                __FILE__,
4549
-                __FUNCTION__,
4550
-                __LINE__
4551
-            );
4552
-        }
4553
-
4554
-        $this->_template_args['success'] = $success;
4555
-        $this->_return_json();
4556
-    }
4557
-
4558
-
4559
-
4560
-
4561
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4562
-
4563
-
4564
-    /**
4565
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4566
-     * However, this does not send immediately, it just queues for sending.
4567
-     *
4568
-     * @throws EE_Error
4569
-     * @throws InvalidDataTypeException
4570
-     * @throws InvalidInterfaceException
4571
-     * @throws InvalidArgumentException
4572
-     * @throws ReflectionException
4573
-     * @since 4.9.0
4574
-     */
4575
-    protected function _generate_now()
4576
-    {
4577
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4578
-        $this->_redirect_after_action(false, '', '', [], true);
4579
-    }
4580
-
4581
-
4582
-    /**
4583
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4584
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4585
-     *
4586
-     * @throws EE_Error
4587
-     * @throws InvalidDataTypeException
4588
-     * @throws InvalidInterfaceException
4589
-     * @throws InvalidArgumentException
4590
-     * @throws ReflectionException
4591
-     * @since 4.9.0
4592
-     */
4593
-    protected function _generate_and_send_now()
4594
-    {
4595
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4596
-        $this->_redirect_after_action(false, '', '', [], true);
4597
-    }
4598
-
4599
-
4600
-    /**
4601
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4602
-     *
4603
-     * @throws EE_Error
4604
-     * @throws InvalidDataTypeException
4605
-     * @throws InvalidInterfaceException
4606
-     * @throws InvalidArgumentException
4607
-     * @throws ReflectionException
4608
-     * @since 4.9.0
4609
-     */
4610
-    protected function _queue_for_resending()
4611
-    {
4612
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4613
-        $this->_redirect_after_action(false, '', '', [], true);
4614
-    }
4615
-
4616
-
4617
-    /**
4618
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4619
-     *
4620
-     * @throws EE_Error
4621
-     * @throws InvalidDataTypeException
4622
-     * @throws InvalidInterfaceException
4623
-     * @throws InvalidArgumentException
4624
-     * @throws ReflectionException
4625
-     * @since 4.9.0
4626
-     */
4627
-    protected function _send_now()
4628
-    {
4629
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4630
-        $this->_redirect_after_action(false, '', '', [], true);
4631
-    }
4632
-
4633
-
4634
-    /**
4635
-     * Deletes EE_messages for IDs in the request.
4636
-     *
4637
-     * @throws EE_Error
4638
-     * @throws InvalidDataTypeException
4639
-     * @throws InvalidInterfaceException
4640
-     * @throws InvalidArgumentException
4641
-     * @since 4.9.0
4642
-     */
4643
-    protected function _delete_ee_messages()
4644
-    {
4645
-        $MSG_IDs       = $this->_get_msg_ids_from_request();
4646
-        $deleted_count = 0;
4647
-        foreach ($MSG_IDs as $MSG_ID) {
4648
-            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4649
-                $deleted_count++;
4650
-            }
4651
-        }
4652
-        if ($deleted_count) {
4653
-            EE_Error::add_success(
4654
-                esc_html(
4655
-                    _n(
4656
-                        'Message successfully deleted',
4657
-                        'Messages successfully deleted',
4658
-                        $deleted_count,
4659
-                        'event_espresso'
4660
-                    )
4661
-                )
4662
-            );
4663
-        } else {
4664
-            EE_Error::add_error(
4665
-                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4666
-                __FILE__,
4667
-                __FUNCTION__,
4668
-                __LINE__
4669
-            );
4670
-        }
4671
-        $this->_redirect_after_action(false, '', '', [], true);
4672
-    }
4673
-
4674
-
4675
-    /**
4676
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4677
-     *
4678
-     * @return array
4679
-     * @since 4.9.0
4680
-     */
4681
-    protected function _get_msg_ids_from_request()
4682
-    {
4683
-        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4684
-        if (empty($MSG_IDs)) {
4685
-            return [];
4686
-        }
4687
-        // if 'MSG_ID' was just a single ID (not an array)
4688
-        // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4689
-        // otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4690
-        return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4691
-            ? $MSG_IDs
4692
-            : array_keys($MSG_IDs);
4693
-    }
2706
+		$this->_context_switcher = ob_get_clean();
2707
+	}
2708
+
2709
+
2710
+	/**
2711
+	 * @param bool $new
2712
+	 * @throws EE_Error
2713
+	 * @throws ReflectionException
2714
+	 */
2715
+	protected function _insert_or_update_message_template($new = false)
2716
+	{
2717
+		$form_data    = $this->getMessageTemplateFormData();
2718
+		$GRP_ID       = $form_data['GRP_ID'];
2719
+		$messenger    = $form_data['MTP_messenger'];
2720
+		$message_type = $form_data['MTP_message_type'];
2721
+		$context      = $form_data['MTP_context'];
2722
+
2723
+		// if this is "new" then we need to generate the default contexts
2724
+		// for the selected messenger/message_type for user to edit.
2725
+		list($success, $query_args) = $new
2726
+			? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)
2727
+			: $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);
2728
+
2729
+		$success     = $success ? 1 : 0;
2730
+		$action_desc = $new ? 'created' : 'updated';
2731
+		$item_desc   = $this->generateUpdateDescription($messenger, $message_type, $context);
2732
+		$override    = $this->performTestSendAfterUpdate($messenger, $message_type, $context);
2733
+
2734
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2735
+	}
2736
+
2737
+
2738
+	/**
2739
+	 * retrieve and sanitize form data
2740
+	 *
2741
+	 * @return array
2742
+	 * @since $VID:$
2743
+	 */
2744
+	protected function getMessageTemplateFormData()
2745
+	{
2746
+		return [
2747
+			'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'),
2748
+			'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')),
2749
+			'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')),
2750
+			'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')),
2751
+			'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'),
2752
+			'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'),
2753
+			'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'),
2754
+			'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'),
2755
+			'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'),
2756
+		];
2757
+	}
2758
+
2759
+
2760
+	/**
2761
+	 * @param int    $GRP_ID
2762
+	 * @param string $messenger
2763
+	 * @param string $message_type
2764
+	 * @return array no return on AJAX requests
2765
+	 * @throws EE_Error
2766
+	 * @throws ReflectionException
2767
+	 * @since $VID:$
2768
+	 */
2769
+	private function generateNewTemplates($GRP_ID, $messenger, $message_type)
2770
+	{
2771
+		$new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);
2772
+		$success       = ! empty($new_templates);
2773
+
2774
+		// we return things differently if doing ajax
2775
+		if ($this->request->isAjax()) {
2776
+			$this->_template_args['success'] = $success;
2777
+			$this->_template_args['error']   = ! $success;
2778
+			$this->_template_args['content'] = '';
2779
+			$this->_template_args['data']    = [
2780
+				'grpID'        => $new_templates['GRP_ID'],
2781
+				'templateName' => $new_templates['template_name'],
2782
+			];
2783
+			if ($success) {
2784
+				EE_Error::overwrite_success();
2785
+				EE_Error::add_success(
2786
+					esc_html__(
2787
+						'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2788
+						'event_espresso'
2789
+					)
2790
+				);
2791
+			}
2792
+			$this->_return_json();
2793
+		}
2794
+		return [
2795
+			$success,
2796
+			// 'query_args'
2797
+			[
2798
+				'id'      => $new_templates['GRP_ID'],
2799
+				'context' => $new_templates['MTP_context'],
2800
+				'action'  => 'edit_message_template',
2801
+			],
2802
+		];
2803
+	}
2804
+
2805
+
2806
+	/**
2807
+	 * @param int    $GRP_ID
2808
+	 * @param string $messenger
2809
+	 * @param string $message_type
2810
+	 * @param string $context
2811
+	 * @param array  $form_data
2812
+	 * @return array
2813
+	 * @throws EE_Error
2814
+	 * @since $VID:$
2815
+	 */
2816
+	private function updateExistingTemplates(
2817
+		$GRP_ID,
2818
+		$messenger,
2819
+		$message_type,
2820
+		$context,
2821
+		array $form_data
2822
+	) {
2823
+		$success         = false;
2824
+		$template_fields = $this->getTemplateFields();
2825
+		if ($template_fields) {
2826
+			// if field data is valid, then success will be true
2827
+			$success = $this->validateTemplateFields(
2828
+				$messenger,
2829
+				$message_type,
2830
+				$context,
2831
+				$template_fields
2832
+			);
2833
+			if ($success) {
2834
+				$field_data = [];
2835
+				foreach ($template_fields as $template_field => $content) {
2836
+					// combine top-level form data with content for this field
2837
+					$field_data = $this->getTemplateFieldFormData($content, $form_data);
2838
+					$success    = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;
2839
+				}
2840
+				// we can use the last set_column_values for the MTPG update
2841
+				// (because its the same for all of these specific MTPs)
2842
+				$success = $this->updateMessageTemplateGroup($field_data) ? $success : false;
2843
+			}
2844
+		}
2845
+
2846
+		return [
2847
+			$success,
2848
+			// 'query_args'
2849
+			[
2850
+				'id'      => $GRP_ID,
2851
+				'context' => $context,
2852
+				'action'  => 'edit_message_template',
2853
+			],
2854
+		];
2855
+	}
2856
+
2857
+
2858
+	/**
2859
+	 * @return array
2860
+	 * @since $VID:$
2861
+	 */
2862
+	private function getTemplateFields()
2863
+	{
2864
+		$template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true);
2865
+		if (empty($template_fields)) {
2866
+			EE_Error::add_error(
2867
+				esc_html__(
2868
+					'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2869
+					'event_espresso'
2870
+				),
2871
+				__FILE__,
2872
+				__FUNCTION__,
2873
+				__LINE__
2874
+			);
2875
+			return null;
2876
+		}
2877
+		// messages content is expected to be escaped
2878
+		return EEH_Array::addSlashesRecursively($template_fields);
2879
+	}
2880
+
2881
+
2882
+	/**
2883
+	 * @param string $messenger
2884
+	 * @param string $message_type
2885
+	 * @param string $context
2886
+	 * @param array  $template_fields
2887
+	 * @return bool
2888
+	 * @throws EE_Error
2889
+	 * @since   $VID:$
2890
+	 */
2891
+	private function validateTemplateFields(
2892
+		$messenger,
2893
+		$message_type,
2894
+		$context,
2895
+		array $template_fields
2896
+	) {
2897
+		// first validate all fields!
2898
+		// this filter allows client code to add its own validation to the template fields as well.
2899
+		// returning an empty array means everything passed validation.
2900
+		// errors in validation should be represented in an array with the following shape:
2901
+		// array(
2902
+		//   'fieldname' => array(
2903
+		//          'msg' => 'error message'
2904
+		//          'value' => 'value for field producing error'
2905
+		// )
2906
+		$custom_validation = (array) apply_filters(
2907
+			'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2908
+			[],
2909
+			$template_fields,
2910
+			$context,
2911
+			$messenger,
2912
+			$message_type
2913
+		);
2914
+
2915
+		$system_validation = $this->getMtgModel()->validate(
2916
+			$template_fields,
2917
+			$context,
2918
+			$messenger,
2919
+			$message_type
2920
+		);
2921
+
2922
+		$system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;
2923
+		$validates         = array_merge($custom_validation, $system_validation);
2924
+
2925
+		// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2926
+		// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2927
+		//  WE need to make sure there is no actual error messages in validates.
2928
+		if (empty($validates)) {
2929
+			return true;
2930
+		}
2931
+
2932
+		// add the transient so when the form loads we know which fields to highlight
2933
+		$this->_add_transient('edit_message_template', $validates);
2934
+		// setup notices
2935
+		foreach ($validates as $error) {
2936
+			if (isset($error['msg'])) {
2937
+				EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2938
+			}
2939
+		}
2940
+		return false;
2941
+	}
2942
+
2943
+
2944
+	/**
2945
+	 * @param array $field_data
2946
+	 * @param array $form_data
2947
+	 * @return array
2948
+	 * @since   $VID:$
2949
+	 */
2950
+	private function getTemplateFieldFormData(array $field_data, array $form_data)
2951
+	{
2952
+		return $form_data + [
2953
+				'MTP_ID'             => $field_data['MTP_ID'],
2954
+				'MTP_template_field' => $field_data['name'],
2955
+				// if they aren't allowed to use all JS, restrict them to standard allowed post tags
2956
+				'MTP_content'        => ! current_user_can('unfiltered_html')
2957
+					? $this->sanitizeMessageTemplateContent($field_data['content'])
2958
+					: $field_data['content'],
2959
+			];
2960
+	}
2961
+
2962
+
2963
+	/**
2964
+	 * @param string $template_field
2965
+	 * @param array  $form_data
2966
+	 * @return bool
2967
+	 * @throws EE_Error
2968
+	 * @since $VID:$
2969
+	 */
2970
+	private function updateMessageTemplates($template_field, array $form_data)
2971
+	{
2972
+		$MTP_ID                  = $form_data['MTP_ID'];
2973
+		$message_template_fields = [
2974
+			'GRP_ID'             => $form_data['GRP_ID'],
2975
+			'MTP_template_field' => $form_data['MTP_template_field'],
2976
+			'MTP_context'        => $form_data['MTP_context'],
2977
+			'MTP_content'        => $form_data['MTP_content'],
2978
+		];
2979
+
2980
+		$hasMtpID = ! empty($MTP_ID);
2981
+		// if we have a MTP_ID for this field then update it, otherwise insert.
2982
+		// this has already been through the template field validator and sanitized, so it will be
2983
+		// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2984
+		// message template field in a messenger/message type and existing users don't have the
2985
+		// default setup for it.
2986
+		// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2987
+		$updated = $hasMtpID
2988
+			? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])
2989
+			: $this->getMtpModel()->insert($message_template_fields);
2990
+
2991
+		$insert_failed = ! $hasMtpID && ! $updated;
2992
+		// updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)
2993
+		// but we won't consider that a problem, but if it returns false, then something went BOOM!
2994
+		$update_failed = $hasMtpID && $updated === false;
2995
+
2996
+		if ($insert_failed || $update_failed) {
2997
+			EE_Error::add_error(
2998
+				sprintf(
2999
+					esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
3000
+					$template_field
3001
+				),
3002
+				__FILE__,
3003
+				__FUNCTION__,
3004
+				__LINE__
3005
+			);
3006
+			return false;
3007
+		}
3008
+		return true;
3009
+	}
3010
+
3011
+
3012
+	/**
3013
+	 * @param array $form_data
3014
+	 * @return bool
3015
+	 * @throws EE_Error
3016
+	 * @since $VID:$
3017
+	 */
3018
+	private function updateMessageTemplateGroup(array $form_data)
3019
+	{
3020
+		$GRP_ID  = $form_data['GRP_ID'];
3021
+		$updated = $this->getMtgModel()->update(
3022
+		// fields and values
3023
+			[
3024
+				'MTP_user_id'      => $form_data['MTP_user_id'],
3025
+				'MTP_messenger'    => $form_data['MTP_messenger'],
3026
+				'MTP_message_type' => $form_data['MTP_message_type'],
3027
+				'MTP_is_global'    => $form_data['MTP_is_global'],
3028
+				'MTP_is_override'  => $form_data['MTP_is_override'],
3029
+				'MTP_deleted'      => $form_data['MTP_deleted'],
3030
+				'MTP_is_active'    => $form_data['MTP_is_active'],
3031
+				'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''),
3032
+				'MTP_description'  => $this->request->getRequestParam(
3033
+					'ee_msg_non_global_fields[MTP_description]',
3034
+					''
3035
+				),
3036
+			],
3037
+			// where
3038
+			[['GRP_ID' => $GRP_ID]]
3039
+		);
3040
+
3041
+		if ($updated === false) {
3042
+			EE_Error::add_error(
3043
+				sprintf(
3044
+					esc_html__(
3045
+						'The Message Template Group (%d) was NOT updated for some reason',
3046
+						'event_espresso'
3047
+					),
3048
+					$form_data['GRP_ID']
3049
+				),
3050
+				__FILE__,
3051
+				__FUNCTION__,
3052
+				__LINE__
3053
+			);
3054
+			return false;
3055
+		}
3056
+		// k now we need to ensure the template_pack and template_variation fields are set.
3057
+		$template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default');
3058
+		$template_variation = $this->request->getRequestParam('MTP_template_variation', 'default');
3059
+
3060
+		$message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3061
+		if ($message_template_group instanceof EE_Message_Template_Group) {
3062
+			$message_template_group->set_template_pack_name($template_pack);
3063
+			$message_template_group->set_template_pack_variation($template_variation);
3064
+		}
3065
+		return true;
3066
+	}
3067
+
3068
+
3069
+	/**
3070
+	 * recursively runs wp_kses() on message template content in a model safe manner
3071
+	 *
3072
+	 * @param array|string $content
3073
+	 * @return array|string
3074
+	 * @since   $VID:$
3075
+	 */
3076
+	private function sanitizeMessageTemplateContent($content)
3077
+	{
3078
+		if (is_array($content)) {
3079
+			foreach ($content as $key => $value) {
3080
+				$content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3081
+			}
3082
+			return $content;
3083
+		}
3084
+		// remove slashes so wp_kses() works properly
3085
+		// wp_kses_stripslashes() only removes slashes from double-quotes,
3086
+		// so attributes using single quotes always appear invalid.
3087
+		$content = stripslashes($content);
3088
+		$content = wp_kses($content, wp_kses_allowed_html('post'));
3089
+		// But currently the models expect slashed data, so after wp_kses()
3090
+		// runs we need to re-slash the data. Sheesh.
3091
+		// See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
3092
+		return addslashes($content);
3093
+	}
3094
+
3095
+
3096
+	/**
3097
+	 * @param string $messenger
3098
+	 * @param string $message_type
3099
+	 * @param string $context
3100
+	 * @return string
3101
+	 * @since $VID:$
3102
+	 */
3103
+	private function generateUpdateDescription($messenger, $message_type, $context)
3104
+	{
3105
+		// need the message type and messenger objects to be able to use the labels for the notices
3106
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger);
3107
+		$messenger_label  = $messenger_object instanceof EE_messenger
3108
+			? ucwords($messenger_object->label['singular'])
3109
+			: '';
3110
+
3111
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type);
3112
+		$message_type_label  = $message_type_object instanceof EE_message_type
3113
+			? ucwords($message_type_object->label['singular'])
3114
+			: '';
3115
+
3116
+		$context   = ucwords(str_replace('_', ' ', $context));
3117
+		$item_desc = $messenger_label && $message_type_label
3118
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3119
+			: '';
3120
+		$item_desc .= 'Message Template';
3121
+		return $item_desc;
3122
+	}
3123
+
3124
+
3125
+	/**
3126
+	 * @param string $messenger
3127
+	 * @param string $message_type
3128
+	 * @param string $context
3129
+	 * @return bool
3130
+	 * @throws EE_Error
3131
+	 * @throws ReflectionException
3132
+	 * @since $VID:$
3133
+	 */
3134
+	private function performTestSendAfterUpdate($messenger, $message_type, $context)
3135
+	{
3136
+		// was a test send triggered?
3137
+		if ($this->request->requestParamIsSet('test_button')) {
3138
+			EE_Error::overwrite_success();
3139
+			$this->_do_test_send($context, $messenger, $message_type);
3140
+			return true;
3141
+		}
3142
+		return false;
3143
+	}
3144
+
3145
+
3146
+	/**
3147
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
3148
+	 *
3149
+	 * @param string $context      what context being tested
3150
+	 * @param string $messenger    messenger being tested
3151
+	 * @param string $message_type message type being tested
3152
+	 * @throws EE_Error
3153
+	 * @throws InvalidArgumentException
3154
+	 * @throws InvalidDataTypeException
3155
+	 * @throws InvalidInterfaceException
3156
+	 * @throws ReflectionException
3157
+	 */
3158
+	protected function _do_test_send($context, $messenger, $message_type)
3159
+	{
3160
+		// set things up for preview
3161
+		$this->request->setRequestParam('messenger', $messenger);
3162
+		$this->request->setRequestParam('message_type', $message_type);
3163
+		$this->request->setRequestParam('context', $context);
3164
+		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
3165
+		$this->request->setRequestParam('GRP_ID', $GRP_ID);
3166
+
3167
+		$active_messenger  = $this->_message_resource_manager->get_active_messenger($messenger);
3168
+		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true);
3169
+
3170
+		// let's save any existing fields that might be required by the messenger
3171
+		if (
3172
+			! empty($test_settings_fld)
3173
+			&& $active_messenger instanceof EE_messenger
3174
+			&& apply_filters(
3175
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3176
+				true,
3177
+				$test_settings_fld,
3178
+				$active_messenger
3179
+			)
3180
+		) {
3181
+			$active_messenger->set_existing_test_settings($test_settings_fld);
3182
+		}
3183
+
3184
+		/**
3185
+		 * Use filter to add additional controls on whether message can send or not
3186
+		 */
3187
+		if (
3188
+			apply_filters(
3189
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3190
+				true,
3191
+				$context,
3192
+				$this->request->requestParams(),
3193
+				$messenger,
3194
+				$message_type
3195
+			)
3196
+		) {
3197
+			if (EEM_Event::instance()->count() > 0) {
3198
+				$success = $this->_preview_message(true);
3199
+				if ($success) {
3200
+					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso'));
3201
+				} else {
3202
+					EE_Error::add_error(
3203
+						esc_html__('The test message was not sent', 'event_espresso'),
3204
+						__FILE__,
3205
+						__FUNCTION__,
3206
+						__LINE__
3207
+					);
3208
+				}
3209
+			} else {
3210
+				$this->noEventsErrorMessage(true);
3211
+			}
3212
+		}
3213
+	}
3214
+
3215
+
3216
+	/**
3217
+	 * _generate_new_templates
3218
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3219
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3220
+	 * for the event.
3221
+	 *
3222
+	 *
3223
+	 * @param string $messenger      the messenger we are generating templates for
3224
+	 * @param array  $message_types  array of message types that the templates are generated for.
3225
+	 * @param int    $GRP_ID         If this is a custom template being generated then a GRP_ID needs to be included to
3226
+	 *                               indicate the message_template_group being used as the base.
3227
+	 *
3228
+	 * @param bool   $global
3229
+	 *
3230
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3231
+	 *                               encountering problems.
3232
+	 * @throws EE_Error
3233
+	 * @throws ReflectionException
3234
+	 */
3235
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3236
+	{
3237
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3238
+		// just don't generate any templates.
3239
+		if (empty($message_types)) {
3240
+			return [];
3241
+		}
3242
+
3243
+		$templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3244
+		return $templates[0];
3245
+	}
3246
+
3247
+
3248
+	/**
3249
+	 * [_trash_or_restore_message_template]
3250
+	 *
3251
+	 * @param boolean $trash  whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3252
+	 * @param boolean $all    whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3253
+	 *                        an individual context (FALSE).
3254
+	 * @return void
3255
+	 * @throws EE_Error
3256
+	 * @throws InvalidArgumentException
3257
+	 * @throws InvalidDataTypeException
3258
+	 * @throws InvalidInterfaceException
3259
+	 */
3260
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3261
+	{
3262
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3263
+
3264
+		$success = 1;
3265
+
3266
+		// incoming GRP_IDs
3267
+		if ($all) {
3268
+			// Checkboxes
3269
+			$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3270
+			if (! empty($checkboxes)) {
3271
+				// if array has more than one element then success message should be plural.
3272
+				// todo: what about nonce?
3273
+				$success = count($checkboxes) > 1 ? 2 : 1;
3274
+
3275
+				// cycle through checkboxes
3276
+				while (list($GRP_ID, $value) = each($checkboxes)) {
3277
+					$trashed_or_restored = $trash
3278
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3279
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3280
+					if (! $trashed_or_restored) {
3281
+						$success = 0;
3282
+					}
3283
+				}
3284
+			} else {
3285
+				// grab single GRP_ID and handle
3286
+				$GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3287
+				if (! empty($GRP_ID)) {
3288
+					$trashed_or_restored = $trash
3289
+						? $this->getMtgModel()->delete_by_ID($GRP_ID)
3290
+						: $this->getMtgModel()->restore_by_ID($GRP_ID);
3291
+					if (! $trashed_or_restored) {
3292
+						$success = 0;
3293
+					}
3294
+				} else {
3295
+					$success = 0;
3296
+				}
3297
+			}
3298
+		}
3299
+
3300
+		$action_desc = $trash
3301
+			? esc_html__('moved to the trash', 'event_espresso')
3302
+			: esc_html__('restored', 'event_espresso');
3303
+
3304
+		$template_switch = $this->request->getRequestParam('template_switch', false, 'bool');
3305
+		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc;
3306
+
3307
+		$item_desc = $all ? _n(
3308
+			'Message Template Group',
3309
+			'Message Template Groups',
3310
+			$success,
3311
+			'event_espresso'
3312
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3313
+
3314
+		$item_desc = $template_switch
3315
+			? _n('template', 'templates', $success, 'event_espresso')
3316
+			: $item_desc;
3317
+
3318
+		$this->_redirect_after_action($success, $item_desc, $action_desc, []);
3319
+	}
3320
+
3321
+
3322
+	/**
3323
+	 * [_delete_message_template]
3324
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3325
+	 *
3326
+	 * @return void
3327
+	 * @throws EE_Error
3328
+	 * @throws InvalidArgumentException
3329
+	 * @throws InvalidDataTypeException
3330
+	 * @throws InvalidInterfaceException
3331
+	 * @throws ReflectionException
3332
+	 */
3333
+	protected function _delete_message_template()
3334
+	{
3335
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3336
+
3337
+		// checkboxes
3338
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3339
+		if (! empty($checkboxes)) {
3340
+			// if array has more than one element then success message should be plural
3341
+			$success = count($checkboxes) > 1 ? 2 : 1;
3342
+
3343
+			// cycle through bulk action checkboxes
3344
+			while (list($GRP_ID, $value) = each($checkboxes)) {
3345
+				$success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;
3346
+			}
3347
+		} else {
3348
+			// grab single grp_id and delete
3349
+			$GRP_ID  = $this->request->getRequestParam('id', 0, 'int');
3350
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3351
+		}
3352
+
3353
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', []);
3354
+	}
3355
+
3356
+
3357
+	/**
3358
+	 * helper for permanently deleting a mtP group and all related message_templates
3359
+	 *
3360
+	 * @param int  $GRP_ID        The group being deleted
3361
+	 * @param bool $include_group whether to delete the Message Template Group as well.
3362
+	 * @return bool boolean to indicate the success of the deletes or not.
3363
+	 * @throws EE_Error
3364
+	 * @throws InvalidArgumentException
3365
+	 * @throws InvalidDataTypeException
3366
+	 * @throws InvalidInterfaceException
3367
+	 * @throws ReflectionException
3368
+	 * @throws ReflectionException
3369
+	 */
3370
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3371
+	{
3372
+		$success = true;
3373
+		// first let's GET this group
3374
+		$MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);
3375
+		// then delete permanently all the related Message Templates
3376
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3377
+
3378
+		if ($deleted === 0) {
3379
+			$success = false;
3380
+		}
3381
+
3382
+		// now delete permanently this particular group
3383
+
3384
+		if ($include_group && ! $MTG->delete_permanently()) {
3385
+			$success = false;
3386
+		}
3387
+
3388
+		return $success;
3389
+	}
3390
+
3391
+
3392
+	/**
3393
+	 *    _learn_more_about_message_templates_link
3394
+	 *
3395
+	 * @access protected
3396
+	 * @return string
3397
+	 */
3398
+	protected function _learn_more_about_message_templates_link()
3399
+	{
3400
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3401
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3402
+			   . '</a>';
3403
+	}
3404
+
3405
+
3406
+	/**
3407
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3408
+	 * ajax and other routes.
3409
+	 *
3410
+	 * @return void
3411
+	 * @throws DomainException
3412
+	 * @throws EE_Error
3413
+	 */
3414
+	protected function _settings()
3415
+	{
3416
+		$this->_set_m_mt_settings();
3417
+
3418
+		// let's setup the messenger tabs
3419
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3420
+			$this->_m_mt_settings['messenger_tabs'],
3421
+			'messenger_links',
3422
+			'|',
3423
+			$this->request->getRequestParam('selected_messenger', 'email')
3424
+		);
3425
+
3426
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3427
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
3428
+
3429
+		$this->display_admin_page_with_sidebar();
3430
+	}
3431
+
3432
+
3433
+	/**
3434
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3435
+	 *
3436
+	 * @access protected
3437
+	 * @return void
3438
+	 * @throws DomainException
3439
+	 */
3440
+	protected function _set_m_mt_settings()
3441
+	{
3442
+		// first if this is already set then lets get out no need to regenerate data.
3443
+		if (! empty($this->_m_mt_settings)) {
3444
+			return;
3445
+		}
3446
+
3447
+		// get all installed messengers and message_types
3448
+		$messengers    = $this->_message_resource_manager->installed_messengers();
3449
+		$message_types = $this->_message_resource_manager->installed_message_types();
3450
+
3451
+
3452
+		// assemble the array for the _tab_text_links helper
3453
+
3454
+		foreach ($messengers as $messenger) {
3455
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3456
+				'label' => ucwords($messenger->label['singular']),
3457
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3458
+					? 'messenger-active'
3459
+					: '',
3460
+				'href'  => $messenger->name,
3461
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3462
+				'slug'  => $messenger->name,
3463
+				'obj'   => $messenger,
3464
+			];
3465
+
3466
+
3467
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3468
+
3469
+			foreach ($message_types as $message_type) {
3470
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3471
+				// it shouldn't show in either the inactive OR active metabox.
3472
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3473
+					continue;
3474
+				}
3475
+
3476
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3477
+					$messenger->name,
3478
+					$message_type->name
3479
+				)
3480
+					? 'active'
3481
+					: 'inactive';
3482
+
3483
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3484
+					'label'    => ucwords($message_type->label['singular']),
3485
+					'class'    => 'message-type-' . $a_or_i,
3486
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3487
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3488
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3489
+					'title'    => $a_or_i === 'active'
3490
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3491
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3492
+					'content'  => $a_or_i === 'active'
3493
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3494
+						: $this->_message_type_settings_content($message_type, $messenger),
3495
+					'slug'     => $message_type->name,
3496
+					'active'   => $a_or_i === 'active',
3497
+					'obj'      => $message_type,
3498
+				];
3499
+			}
3500
+		}
3501
+	}
3502
+
3503
+
3504
+	/**
3505
+	 * This just prepares the content for the message type settings
3506
+	 *
3507
+	 * @param EE_message_type $message_type The message type object
3508
+	 * @param EE_messenger    $messenger    The messenger object
3509
+	 * @param boolean         $active       Whether the message type is active or not
3510
+	 * @return string html output for the content
3511
+	 * @throws DomainException
3512
+	 */
3513
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3514
+	{
3515
+		// get message type fields
3516
+		$fields                                         = $message_type->get_admin_settings_fields();
3517
+		$settings_template_args['template_form_fields'] = '';
3518
+
3519
+		if (! empty($fields) && $active) {
3520
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3521
+			foreach ($fields as $fldname => $fldprops) {
3522
+				$field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3523
+				$template_form_field[ $field_id ] = [
3524
+					'name'       => 'message_type_settings[' . $fldname . ']',
3525
+					'label'      => $fldprops['label'],
3526
+					'input'      => $fldprops['field_type'],
3527
+					'type'       => $fldprops['value_type'],
3528
+					'required'   => $fldprops['required'],
3529
+					'validation' => $fldprops['validation'],
3530
+					'value'      => isset($existing_settings[ $fldname ])
3531
+						? $existing_settings[ $fldname ]
3532
+						: $fldprops['default'],
3533
+					'options'    => isset($fldprops['options'])
3534
+						? $fldprops['options']
3535
+						: [],
3536
+					'default'    => isset($existing_settings[ $fldname ])
3537
+						? $existing_settings[ $fldname ]
3538
+						: $fldprops['default'],
3539
+					'css_class'  => 'no-drag',
3540
+					'format'     => $fldprops['format'],
3541
+				];
3542
+			}
3543
+
3544
+
3545
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3546
+				? $this->_generate_admin_form_fields(
3547
+					$template_form_field,
3548
+					'string',
3549
+					'ee_mt_activate_form'
3550
+				)
3551
+				: '';
3552
+		}
3553
+
3554
+		$settings_template_args['description'] = $message_type->description;
3555
+		// we also need some hidden fields
3556
+		$hidden_fields = [
3557
+			'message_type_settings[messenger]' . $message_type->name    => [
3558
+				'type'  => 'hidden',
3559
+				'value' => $messenger->name,
3560
+			],
3561
+			'message_type_settings[message_type]' . $message_type->name => [
3562
+				'type'  => 'hidden',
3563
+				'value' => $message_type->name,
3564
+			],
3565
+			'type' . $message_type->name                                => [
3566
+				'type'  => 'hidden',
3567
+				'value' => 'message_type',
3568
+			],
3569
+		];
3570
+
3571
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3572
+			$hidden_fields,
3573
+			'array'
3574
+		);
3575
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3576
+			? ' hidden'
3577
+			: '';
3578
+
3579
+
3580
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3581
+		return EEH_Template::display_template($template, $settings_template_args, true);
3582
+	}
3583
+
3584
+
3585
+	/**
3586
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3587
+	 *
3588
+	 * @access protected
3589
+	 * @return void
3590
+	 * @throws DomainException
3591
+	 */
3592
+	protected function _messages_settings_metaboxes()
3593
+	{
3594
+		$this->_set_m_mt_settings();
3595
+		$m_boxes         = $mt_boxes = [];
3596
+		$m_template_args = $mt_template_args = [];
3597
+
3598
+		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email');
3599
+
3600
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3601
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3602
+				$is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);
3603
+				$hide_on_message     = $is_messenger_active ? '' : 'hidden';
3604
+				$hide_off_message    = $is_messenger_active ? 'hidden' : '';
3605
+
3606
+				// messenger meta boxes
3607
+				$active         = $selected_messenger === $messenger;
3608
+				$active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3609
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3610
+					: '';
3611
+
3612
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3613
+					esc_html__('%s Settings', 'event_espresso'),
3614
+					$tab_array['label']
3615
+				);
3616
+
3617
+				$m_template_args[ $messenger . '_a_box' ] = [
3618
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3619
+					'inactive_message_types' => isset(
3620
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3621
+					)
3622
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3623
+						: '',
3624
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3625
+					'hidden'                 => $active ? '' : ' hidden',
3626
+					'hide_on_message'        => $hide_on_message,
3627
+					'messenger'              => $messenger,
3628
+					'active'                 => $active,
3629
+				];
3630
+
3631
+				// message type meta boxes
3632
+				// (which is really just the inactive container for each messenger
3633
+				// showing inactive message types for that messenger)
3634
+				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3635
+				$mt_template_args[ $messenger . '_i_box' ] = [
3636
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3637
+					'inactive_message_types' => isset(
3638
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3639
+					)
3640
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3641
+						: '',
3642
+					'hidden'                 => $active ? '' : ' hidden',
3643
+					'hide_on_message'        => $hide_on_message,
3644
+					'hide_off_message'       => $hide_off_message,
3645
+					'messenger'              => $messenger,
3646
+					'active'                 => $active,
3647
+				];
3648
+			}
3649
+		}
3650
+
3651
+
3652
+		// register messenger metaboxes
3653
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3654
+		foreach ($m_boxes as $box => $label) {
3655
+			$callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3656
+			$msgr          = str_replace('_a_box', '', $box);
3657
+			add_meta_box(
3658
+				'espresso_' . $msgr . '_settings',
3659
+				$label,
3660
+				function ($post, $metabox) {
3661
+					EEH_Template::display_template(
3662
+						$metabox['args']['template_path'],
3663
+						$metabox['args']['template_args']
3664
+					);
3665
+				},
3666
+				$this->_current_screen->id,
3667
+				'normal',
3668
+				'high',
3669
+				$callback_args
3670
+			);
3671
+		}
3672
+
3673
+		// register message type metaboxes
3674
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3675
+		foreach ($mt_boxes as $box => $label) {
3676
+			$callback_args = [
3677
+				'template_path' => $mt_template_path,
3678
+				'template_args' => $mt_template_args[ $box ],
3679
+			];
3680
+			$mt            = str_replace('_i_box', '', $box);
3681
+			add_meta_box(
3682
+				'espresso_' . $mt . '_inactive_mts',
3683
+				$label,
3684
+				function ($post, $metabox) {
3685
+					EEH_Template::display_template(
3686
+						$metabox['args']['template_path'],
3687
+						$metabox['args']['template_args']
3688
+					);
3689
+				},
3690
+				$this->_current_screen->id,
3691
+				'side',
3692
+				'high',
3693
+				$callback_args
3694
+			);
3695
+		}
3696
+
3697
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3698
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3699
+		if (is_main_site()) {
3700
+			add_meta_box(
3701
+				'espresso_global_message_settings',
3702
+				esc_html__('Global Message Settings', 'event_espresso'),
3703
+				[$this, 'global_messages_settings_metabox_content'],
3704
+				$this->_current_screen->id,
3705
+				'normal',
3706
+				'low',
3707
+				[]
3708
+			);
3709
+		}
3710
+	}
3711
+
3712
+
3713
+	/**
3714
+	 *  This generates the content for the global messages settings metabox.
3715
+	 *
3716
+	 * @return void
3717
+	 * @throws EE_Error
3718
+	 * @throws InvalidArgumentException
3719
+	 * @throws ReflectionException
3720
+	 * @throws InvalidDataTypeException
3721
+	 * @throws InvalidInterfaceException
3722
+	 */
3723
+	public function global_messages_settings_metabox_content()
3724
+	{
3725
+		$form = $this->_generate_global_settings_form();
3726
+		// already escaped
3727
+		echo $form->form_open(
3728
+			$this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),
3729
+			'POST'
3730
+		);
3731
+		echo $form->get_html();
3732
+		echo $form->form_close();
3733
+	}
3734
+
3735
+
3736
+	/**
3737
+	 * This generates and returns the form object for the global messages settings.
3738
+	 *
3739
+	 * @return EE_Form_Section_Proper
3740
+	 * @throws EE_Error
3741
+	 * @throws InvalidArgumentException
3742
+	 * @throws ReflectionException
3743
+	 * @throws InvalidDataTypeException
3744
+	 * @throws InvalidInterfaceException
3745
+	 */
3746
+	protected function _generate_global_settings_form()
3747
+	{
3748
+		/** @var EE_Network_Core_Config $network_config */
3749
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3750
+
3751
+		return new EE_Form_Section_Proper(
3752
+			[
3753
+				'name'            => 'global_messages_settings',
3754
+				'html_id'         => 'global_messages_settings',
3755
+				'html_class'      => 'form-table',
3756
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3757
+				'subsections'     => apply_filters(
3758
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3759
+					[
3760
+						'do_messages_on_same_request' => new EE_Select_Input(
3761
+							[
3762
+								true  => esc_html__('On the same request', 'event_espresso'),
3763
+								false => esc_html__('On a separate request', 'event_espresso'),
3764
+							],
3765
+							[
3766
+								'default'         => $network_config->do_messages_on_same_request,
3767
+								'html_label_text' => esc_html__(
3768
+									'Generate and send all messages:',
3769
+									'event_espresso'
3770
+								),
3771
+								'html_help_text'  => esc_html__(
3772
+									'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3773
+									'event_espresso'
3774
+								),
3775
+							]
3776
+						),
3777
+						'delete_threshold'            => new EE_Select_Input(
3778
+							[
3779
+								0  => esc_html__('Forever', 'event_espresso'),
3780
+								3  => esc_html__('3 Months', 'event_espresso'),
3781
+								6  => esc_html__('6 Months', 'event_espresso'),
3782
+								9  => esc_html__('9 Months', 'event_espresso'),
3783
+								12 => esc_html__('12 Months', 'event_espresso'),
3784
+								24 => esc_html__('24 Months', 'event_espresso'),
3785
+								36 => esc_html__('36 Months', 'event_espresso'),
3786
+							],
3787
+							[
3788
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3789
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3790
+								'html_help_text'  => esc_html__(
3791
+									'You can control how long a record of processed messages is kept via this option.',
3792
+									'event_espresso'
3793
+								),
3794
+							]
3795
+						),
3796
+						'update_settings'             => new EE_Submit_Input(
3797
+							[
3798
+								'default'         => esc_html__('Update', 'event_espresso'),
3799
+								'html_label_text' => '&nbsp',
3800
+							]
3801
+						),
3802
+					]
3803
+				),
3804
+			]
3805
+		);
3806
+	}
3807
+
3808
+
3809
+	/**
3810
+	 * This handles updating the global settings set on the admin page.
3811
+	 *
3812
+	 * @throws EE_Error
3813
+	 * @throws InvalidDataTypeException
3814
+	 * @throws InvalidInterfaceException
3815
+	 * @throws InvalidArgumentException
3816
+	 * @throws ReflectionException
3817
+	 */
3818
+	protected function _update_global_settings()
3819
+	{
3820
+		/** @var EE_Network_Core_Config $network_config */
3821
+		$network_config  = EE_Registry::instance()->NET_CFG->core;
3822
+		$messages_config = EE_Registry::instance()->CFG->messages;
3823
+		$form            = $this->_generate_global_settings_form();
3824
+		if ($form->was_submitted()) {
3825
+			$form->receive_form_submission();
3826
+			if ($form->is_valid()) {
3827
+				$valid_data = $form->valid_data();
3828
+				foreach ($valid_data as $property => $value) {
3829
+					$setter = 'set_' . $property;
3830
+					if (method_exists($network_config, $setter)) {
3831
+						$network_config->{$setter}($value);
3832
+					} elseif (
3833
+						property_exists($network_config, $property)
3834
+						&& $network_config->{$property} !== $value
3835
+					) {
3836
+						$network_config->{$property} = $value;
3837
+					} elseif (
3838
+						property_exists($messages_config, $property)
3839
+						&& $messages_config->{$property} !== $value
3840
+					) {
3841
+						$messages_config->{$property} = $value;
3842
+					}
3843
+				}
3844
+				// only update if the form submission was valid!
3845
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3846
+				EE_Registry::instance()->CFG->update_espresso_config();
3847
+				EE_Error::overwrite_success();
3848
+				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso'));
3849
+			}
3850
+		}
3851
+		$this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);
3852
+	}
3853
+
3854
+
3855
+	/**
3856
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3857
+	 *
3858
+	 * @param array $tab_array This is an array of message type tab details used to generate the tabs
3859
+	 * @return string html formatted tabs
3860
+	 * @throws DomainException
3861
+	 */
3862
+	protected function _get_mt_tabs($tab_array)
3863
+	{
3864
+		$tab_array = (array) $tab_array;
3865
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3866
+		$tabs      = '';
3867
+
3868
+		foreach ($tab_array as $tab) {
3869
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3870
+		}
3871
+
3872
+		return $tabs;
3873
+	}
3874
+
3875
+
3876
+	/**
3877
+	 * This prepares the content of the messenger meta box admin settings
3878
+	 *
3879
+	 * @param EE_messenger $messenger The messenger we're setting up content for
3880
+	 * @return string html formatted content
3881
+	 * @throws DomainException
3882
+	 */
3883
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3884
+	{
3885
+
3886
+		$fields                                         = $messenger->get_admin_settings_fields();
3887
+		$settings_template_args['template_form_fields'] = '';
3888
+
3889
+		// is $messenger active?
3890
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3891
+
3892
+
3893
+		if (! empty($fields)) {
3894
+			$existing_settings = $messenger->get_existing_admin_settings();
3895
+
3896
+			foreach ($fields as $fldname => $fldprops) {
3897
+				$field_id                         = $messenger->name . '-' . $fldname;
3898
+				$template_form_field[ $field_id ] = [
3899
+					'name'       => 'messenger_settings[' . $field_id . ']',
3900
+					'label'      => $fldprops['label'],
3901
+					'input'      => $fldprops['field_type'],
3902
+					'type'       => $fldprops['value_type'],
3903
+					'required'   => $fldprops['required'],
3904
+					'validation' => $fldprops['validation'],
3905
+					'value'      => isset($existing_settings[ $field_id ])
3906
+						? $existing_settings[ $field_id ]
3907
+						: $fldprops['default'],
3908
+					'css_class'  => '',
3909
+					'format'     => $fldprops['format'],
3910
+				];
3911
+			}
3912
+
3913
+
3914
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3915
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3916
+				: '';
3917
+		}
3918
+
3919
+		// we also need some hidden fields
3920
+		$settings_template_args['hidden_fields'] = [
3921
+			'messenger_settings[messenger]' . $messenger->name => [
3922
+				'type'  => 'hidden',
3923
+				'value' => $messenger->name,
3924
+			],
3925
+			'type' . $messenger->name                          => [
3926
+				'type'  => 'hidden',
3927
+				'value' => 'messenger',
3928
+			],
3929
+		];
3930
+
3931
+		// make sure any active message types that are existing are included in the hidden fields
3932
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3933
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3934
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3935
+					'type'  => 'hidden',
3936
+					'value' => $mt,
3937
+				];
3938
+			}
3939
+		}
3940
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3941
+			$settings_template_args['hidden_fields'],
3942
+			'array'
3943
+		);
3944
+		$active                                  =
3945
+			$this->_message_resource_manager->is_messenger_active($messenger->name);
3946
+
3947
+		$settings_template_args['messenger']           = $messenger->name;
3948
+		$settings_template_args['description']         = $messenger->description;
3949
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3950
+
3951
+
3952
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3953
+			$messenger->name
3954
+		)
3955
+			? $settings_template_args['show_hide_edit_form']
3956
+			: ' hidden';
3957
+
3958
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3959
+			? ' hidden'
3960
+			: $settings_template_args['show_hide_edit_form'];
3961
+
3962
+
3963
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3964
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3965
+		$settings_template_args['on_off_status'] = $active;
3966
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3967
+		return EEH_Template::display_template(
3968
+			$template,
3969
+			$settings_template_args,
3970
+			true
3971
+		);
3972
+	}
3973
+
3974
+
3975
+	/**
3976
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3977
+	 *
3978
+	 * @throws DomainException
3979
+	 * @throws EE_Error
3980
+	 * @throws InvalidDataTypeException
3981
+	 * @throws InvalidInterfaceException
3982
+	 * @throws InvalidArgumentException
3983
+	 * @throws ReflectionException
3984
+	 */
3985
+	public function activate_messenger_toggle()
3986
+	{
3987
+		$success = true;
3988
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3989
+		// let's check that we have required data
3990
+
3991
+		if (! $this->_active_messenger_name) {
3992
+			EE_Error::add_error(
3993
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3994
+				__FILE__,
3995
+				__FUNCTION__,
3996
+				__LINE__
3997
+			);
3998
+			$success = false;
3999
+		}
4000
+
4001
+		// do a nonce check here since we're not arriving via a normal route
4002
+		$nonce     = $this->request->getRequestParam('activate_nonce', '');
4003
+		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce";
4004
+
4005
+		$this->_verify_nonce($nonce, $nonce_ref);
4006
+
4007
+
4008
+		$status = $this->request->getRequestParam('status');
4009
+		if (! $status) {
4010
+			EE_Error::add_error(
4011
+				esc_html__(
4012
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4013
+					'event_espresso'
4014
+				),
4015
+				__FILE__,
4016
+				__FUNCTION__,
4017
+				__LINE__
4018
+			);
4019
+			$success = false;
4020
+		}
4021
+
4022
+		// do check to verify we have a valid status.
4023
+		if ($status !== 'off' && $status !== 'on') {
4024
+			EE_Error::add_error(
4025
+				sprintf(
4026
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
4027
+					$status
4028
+				),
4029
+				__FILE__,
4030
+				__FUNCTION__,
4031
+				__LINE__
4032
+			);
4033
+			$success = false;
4034
+		}
4035
+
4036
+		if ($success) {
4037
+			// made it here?  Stop dawdling then!!
4038
+			$success = $status === 'off'
4039
+				? $this->_deactivate_messenger($this->_active_messenger_name)
4040
+				: $this->_activate_messenger($this->_active_messenger_name);
4041
+		}
4042
+
4043
+		$this->_template_args['success'] = $success;
4044
+
4045
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
4046
+		$this->_return_json();
4047
+	}
4048
+
4049
+
4050
+	/**
4051
+	 * used by ajax from the messages settings page to activate|deactivate a message type
4052
+	 *
4053
+	 * @throws DomainException
4054
+	 * @throws EE_Error
4055
+	 * @throws ReflectionException
4056
+	 * @throws InvalidDataTypeException
4057
+	 * @throws InvalidInterfaceException
4058
+	 * @throws InvalidArgumentException
4059
+	 */
4060
+	public function activate_mt_toggle()
4061
+	{
4062
+		$success = true;
4063
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
4064
+
4065
+		// let's make sure we have the necessary data
4066
+		if (! $this->_active_message_type_name) {
4067
+			EE_Error::add_error(
4068
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4069
+				__FILE__,
4070
+				__FUNCTION__,
4071
+				__LINE__
4072
+			);
4073
+			$success = false;
4074
+		}
4075
+
4076
+		if (! $this->_active_messenger_name) {
4077
+			EE_Error::add_error(
4078
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4079
+				__FILE__,
4080
+				__FUNCTION__,
4081
+				__LINE__
4082
+			);
4083
+			$success = false;
4084
+		}
4085
+
4086
+		$status = $this->request->getRequestParam('status');
4087
+		if (! $status) {
4088
+			EE_Error::add_error(
4089
+				esc_html__(
4090
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
4091
+					'event_espresso'
4092
+				),
4093
+				__FILE__,
4094
+				__FUNCTION__,
4095
+				__LINE__
4096
+			);
4097
+			$success = false;
4098
+		}
4099
+
4100
+
4101
+		// do check to verify we have a valid status.
4102
+		if ($status !== 'activate' && $status !== 'deactivate') {
4103
+			EE_Error::add_error(
4104
+				sprintf(
4105
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
4106
+					$status
4107
+				),
4108
+				__FILE__,
4109
+				__FUNCTION__,
4110
+				__LINE__
4111
+			);
4112
+			$success = false;
4113
+		}
4114
+
4115
+
4116
+		// do a nonce check here since we're not arriving via a normal route
4117
+		$nonce = $this->request->getRequestParam('mt_nonce', '');
4118
+		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce");
4119
+
4120
+		if ($success) {
4121
+			// made it here? um, what are you waiting for then?
4122
+			$success = $status === 'deactivate'
4123
+				? $this->_deactivate_message_type_for_messenger(
4124
+					$this->_active_messenger_name,
4125
+					$this->_active_message_type_name
4126
+				)
4127
+				: $this->_activate_message_type_for_messenger(
4128
+					$this->_active_messenger_name,
4129
+					$this->_active_message_type_name
4130
+				);
4131
+		}
4132
+
4133
+		$this->_template_args['success'] = $success;
4134
+		$this->_return_json();
4135
+	}
4136
+
4137
+
4138
+	/**
4139
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4140
+	 *
4141
+	 * @param string $messenger_name The name of the messenger being activated
4142
+	 * @return bool
4143
+	 * @throws DomainException
4144
+	 * @throws EE_Error
4145
+	 * @throws InvalidArgumentException
4146
+	 * @throws ReflectionException
4147
+	 * @throws InvalidDataTypeException
4148
+	 * @throws InvalidInterfaceException
4149
+	 */
4150
+	protected function _activate_messenger($messenger_name)
4151
+	{
4152
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
4153
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4154
+			? $active_messenger->get_default_message_types()
4155
+			: [];
4156
+
4157
+		// ensure is active
4158
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);
4159
+
4160
+		// set response_data for reload
4161
+		foreach ($message_types_to_activate as $message_type_name) {
4162
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4163
+			if (
4164
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4165
+					$messenger_name,
4166
+					$message_type_name
4167
+				)
4168
+				&& $message_type instanceof EE_message_type
4169
+			) {
4170
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4171
+				if ($message_type->get_admin_settings_fields()) {
4172
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4173
+				}
4174
+			}
4175
+		}
4176
+
4177
+		// add success message for activating messenger
4178
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4179
+	}
4180
+
4181
+
4182
+	/**
4183
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4184
+	 *
4185
+	 * @param string $messenger_name The name of the messenger being activated
4186
+	 * @return bool
4187
+	 * @throws DomainException
4188
+	 * @throws EE_Error
4189
+	 * @throws InvalidArgumentException
4190
+	 * @throws ReflectionException
4191
+	 * @throws InvalidDataTypeException
4192
+	 * @throws InvalidInterfaceException
4193
+	 */
4194
+	protected function _deactivate_messenger($messenger_name)
4195
+	{
4196
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4197
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4198
+
4199
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4200
+	}
4201
+
4202
+
4203
+	/**
4204
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4205
+	 *
4206
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4207
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4208
+	 * @return bool
4209
+	 * @throws DomainException
4210
+	 * @throws EE_Error
4211
+	 * @throws InvalidArgumentException
4212
+	 * @throws ReflectionException
4213
+	 * @throws InvalidDataTypeException
4214
+	 * @throws InvalidInterfaceException
4215
+	 */
4216
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4217
+	{
4218
+		$active_messenger         = $this->_message_resource_manager->get_messenger($messenger_name);
4219
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4220
+
4221
+		// ensure is active
4222
+		$this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);
4223
+
4224
+		// set response for load
4225
+		if (
4226
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4227
+				$messenger_name,
4228
+				$message_type_name
4229
+			)
4230
+		) {
4231
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4232
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4233
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4234
+			}
4235
+		}
4236
+
4237
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4238
+			$active_messenger,
4239
+			$message_type_to_activate
4240
+		);
4241
+	}
4242
+
4243
+
4244
+	/**
4245
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4246
+	 *
4247
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4248
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4249
+	 * @return bool
4250
+	 * @throws DomainException
4251
+	 * @throws EE_Error
4252
+	 * @throws InvalidArgumentException
4253
+	 * @throws ReflectionException
4254
+	 * @throws InvalidDataTypeException
4255
+	 * @throws InvalidInterfaceException
4256
+	 */
4257
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4258
+	{
4259
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4260
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4261
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4262
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4263
+
4264
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4265
+			$active_messenger,
4266
+			$message_type_to_deactivate
4267
+		);
4268
+	}
4269
+
4270
+
4271
+	/**
4272
+	 * This just initializes the defaults for activating messenger and message type responses.
4273
+	 */
4274
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4275
+	{
4276
+		$this->_template_args['data']['active_mts'] = [];
4277
+		$this->_template_args['data']['mt_reload']  = [];
4278
+	}
4279
+
4280
+
4281
+	/**
4282
+	 * Setup appropriate response for activating a messenger and/or message types
4283
+	 *
4284
+	 * @param EE_messenger         $messenger
4285
+	 * @param EE_message_type|null $message_type
4286
+	 * @return bool
4287
+	 * @throws DomainException
4288
+	 * @throws EE_Error
4289
+	 * @throws InvalidArgumentException
4290
+	 * @throws ReflectionException
4291
+	 * @throws InvalidDataTypeException
4292
+	 * @throws InvalidInterfaceException
4293
+	 */
4294
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4295
+		$messenger,
4296
+		EE_Message_Type $message_type = null
4297
+	) {
4298
+		// if $messenger isn't a valid messenger object then get out.
4299
+		if (! $messenger instanceof EE_Messenger) {
4300
+			EE_Error::add_error(
4301
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4302
+				__FILE__,
4303
+				__FUNCTION__,
4304
+				__LINE__
4305
+			);
4306
+			return false;
4307
+		}
4308
+		// activated
4309
+		if ($this->_template_args['data']['active_mts']) {
4310
+			EE_Error::overwrite_success();
4311
+			// activated a message type with the messenger
4312
+			if ($message_type instanceof EE_message_type) {
4313
+				EE_Error::add_success(
4314
+					sprintf(
4315
+						esc_html__(
4316
+							'%s message type has been successfully activated with the %s messenger',
4317
+							'event_espresso'
4318
+						),
4319
+						ucwords($message_type->label['singular']),
4320
+						ucwords($messenger->label['singular'])
4321
+					)
4322
+				);
4323
+
4324
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4325
+				if ($message_type->name === 'invoice') {
4326
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4327
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4328
+					if ($pm instanceof EE_Payment_Method) {
4329
+						EE_Error::add_attention(
4330
+							esc_html__(
4331
+								'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4332
+								'event_espresso'
4333
+							)
4334
+						);
4335
+					}
4336
+				}
4337
+				// just toggles the entire messenger
4338
+			} else {
4339
+				EE_Error::add_success(
4340
+					sprintf(
4341
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4342
+						ucwords($messenger->label['singular'])
4343
+					)
4344
+				);
4345
+			}
4346
+
4347
+			return true;
4348
+
4349
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4350
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4351
+			// in which case we just give a success message for the messenger being successfully activated.
4352
+		} else {
4353
+			if (! $messenger->get_default_message_types()) {
4354
+				// messenger doesn't have any default message types so still a success.
4355
+				EE_Error::add_success(
4356
+					sprintf(
4357
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4358
+						ucwords($messenger->label['singular'])
4359
+					)
4360
+				);
4361
+
4362
+				return true;
4363
+			} else {
4364
+				EE_Error::add_error(
4365
+					$message_type instanceof EE_message_type
4366
+					? sprintf(
4367
+						esc_html__(
4368
+							'%s message type was not successfully activated with the %s messenger',
4369
+							'event_espresso'
4370
+						),
4371
+						ucwords($message_type->label['singular']),
4372
+						ucwords($messenger->label['singular'])
4373
+					)
4374
+					: sprintf(
4375
+						esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4376
+						ucwords($messenger->label['singular'])
4377
+					),
4378
+					__FILE__,
4379
+					__FUNCTION__,
4380
+					__LINE__
4381
+				);
4382
+
4383
+				return false;
4384
+			}
4385
+		}
4386
+	}
4387
+
4388
+
4389
+	/**
4390
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4391
+	 *
4392
+	 * @param EE_messenger         $messenger
4393
+	 * @param EE_message_type|null $message_type
4394
+	 * @return bool
4395
+	 * @throws DomainException
4396
+	 * @throws EE_Error
4397
+	 * @throws InvalidArgumentException
4398
+	 * @throws ReflectionException
4399
+	 * @throws InvalidDataTypeException
4400
+	 * @throws InvalidInterfaceException
4401
+	 */
4402
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4403
+		$messenger,
4404
+		EE_message_type $message_type = null
4405
+	) {
4406
+		EE_Error::overwrite_success();
4407
+
4408
+		// if $messenger isn't a valid messenger object then get out.
4409
+		if (! $messenger instanceof EE_Messenger) {
4410
+			EE_Error::add_error(
4411
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4412
+				__FILE__,
4413
+				__FUNCTION__,
4414
+				__LINE__
4415
+			);
4416
+
4417
+			return false;
4418
+		}
4419
+
4420
+		if ($message_type instanceof EE_message_type) {
4421
+			$message_type_name = $message_type->name;
4422
+			EE_Error::add_success(
4423
+				sprintf(
4424
+					esc_html__(
4425
+						'%s message type has been successfully deactivated for the %s messenger.',
4426
+						'event_espresso'
4427
+					),
4428
+					ucwords($message_type->label['singular']),
4429
+					ucwords($messenger->label['singular'])
4430
+				)
4431
+			);
4432
+		} else {
4433
+			$message_type_name = '';
4434
+			EE_Error::add_success(
4435
+				sprintf(
4436
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4437
+					ucwords($messenger->label['singular'])
4438
+				)
4439
+			);
4440
+		}
4441
+
4442
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4443
+		if (
4444
+			$messenger->name === 'html'
4445
+			&& (
4446
+				is_null($message_type)
4447
+				|| $message_type_name === 'invoice'
4448
+			)
4449
+		) {
4450
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4451
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4452
+			if ($count_updated > 0) {
4453
+				$msg = $message_type_name === 'invoice'
4454
+					? esc_html__(
4455
+						'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4456
+						'event_espresso'
4457
+					)
4458
+					: esc_html__(
4459
+						'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4460
+						'event_espresso'
4461
+					);
4462
+				EE_Error::add_attention($msg);
4463
+			}
4464
+		}
4465
+
4466
+		return true;
4467
+	}
4468
+
4469
+
4470
+	/**
4471
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4472
+	 *
4473
+	 * @throws DomainException
4474
+	 * @throws EE_Error
4475
+	 * @throws EE_Error
4476
+	 */
4477
+	public function update_mt_form()
4478
+	{
4479
+		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4480
+			EE_Error::add_error(
4481
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4482
+				__FILE__,
4483
+				__FUNCTION__,
4484
+				__LINE__
4485
+			);
4486
+			$this->_return_json();
4487
+		}
4488
+
4489
+		$message_types = $this->get_installed_message_types();
4490
+		$message_type  = $message_types[ $this->_active_message_type_name ];
4491
+		$messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4492
+		$content       = $this->_message_type_settings_content($message_type, $messenger, true);
4493
+
4494
+		$this->_template_args['success'] = true;
4495
+		$this->_template_args['content'] = $content;
4496
+		$this->_return_json();
4497
+	}
4498
+
4499
+
4500
+	/**
4501
+	 * this handles saving the settings for a messenger or message type
4502
+	 *
4503
+	 * @throws EE_Error
4504
+	 * @throws EE_Error
4505
+	 */
4506
+	public function save_settings()
4507
+	{
4508
+		$type = $this->request->getRequestParam('type');
4509
+		if (! $type) {
4510
+			EE_Error::add_error(
4511
+				esc_html__(
4512
+					'Cannot save settings because type is unknown (messenger settings or message type settings?)',
4513
+					'event_espresso'
4514
+				),
4515
+				__FILE__,
4516
+				__FUNCTION__,
4517
+				__LINE__
4518
+			);
4519
+			$this->_template_args['error'] = true;
4520
+			$this->_return_json();
4521
+		}
4522
+
4523
+
4524
+		if ($type === 'messenger') {
4525
+			// this should be an array.
4526
+			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true);
4527
+			$messenger = $settings['messenger'];
4528
+			// remove messenger and message_types from settings array
4529
+			unset($settings['messenger'], $settings['message_types']);
4530
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4531
+		} elseif ($type === 'message_type') {
4532
+			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true);
4533
+			$messenger    = $settings['messenger'];
4534
+			$message_type = $settings['message_type'];
4535
+			// remove messenger and message_types from settings array
4536
+			unset($settings['messenger'], $settings['message_types']);
4537
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4538
+		}
4539
+
4540
+		// okay we should have the data all setup.  Now we just update!
4541
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4542
+
4543
+		if ($success) {
4544
+			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso'));
4545
+		} else {
4546
+			EE_Error::add_error(
4547
+				esc_html__('Settings did not get updated', 'event_espresso'),
4548
+				__FILE__,
4549
+				__FUNCTION__,
4550
+				__LINE__
4551
+			);
4552
+		}
4553
+
4554
+		$this->_template_args['success'] = $success;
4555
+		$this->_return_json();
4556
+	}
4557
+
4558
+
4559
+
4560
+
4561
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4562
+
4563
+
4564
+	/**
4565
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4566
+	 * However, this does not send immediately, it just queues for sending.
4567
+	 *
4568
+	 * @throws EE_Error
4569
+	 * @throws InvalidDataTypeException
4570
+	 * @throws InvalidInterfaceException
4571
+	 * @throws InvalidArgumentException
4572
+	 * @throws ReflectionException
4573
+	 * @since 4.9.0
4574
+	 */
4575
+	protected function _generate_now()
4576
+	{
4577
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4578
+		$this->_redirect_after_action(false, '', '', [], true);
4579
+	}
4580
+
4581
+
4582
+	/**
4583
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4584
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4585
+	 *
4586
+	 * @throws EE_Error
4587
+	 * @throws InvalidDataTypeException
4588
+	 * @throws InvalidInterfaceException
4589
+	 * @throws InvalidArgumentException
4590
+	 * @throws ReflectionException
4591
+	 * @since 4.9.0
4592
+	 */
4593
+	protected function _generate_and_send_now()
4594
+	{
4595
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4596
+		$this->_redirect_after_action(false, '', '', [], true);
4597
+	}
4598
+
4599
+
4600
+	/**
4601
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4602
+	 *
4603
+	 * @throws EE_Error
4604
+	 * @throws InvalidDataTypeException
4605
+	 * @throws InvalidInterfaceException
4606
+	 * @throws InvalidArgumentException
4607
+	 * @throws ReflectionException
4608
+	 * @since 4.9.0
4609
+	 */
4610
+	protected function _queue_for_resending()
4611
+	{
4612
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4613
+		$this->_redirect_after_action(false, '', '', [], true);
4614
+	}
4615
+
4616
+
4617
+	/**
4618
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4619
+	 *
4620
+	 * @throws EE_Error
4621
+	 * @throws InvalidDataTypeException
4622
+	 * @throws InvalidInterfaceException
4623
+	 * @throws InvalidArgumentException
4624
+	 * @throws ReflectionException
4625
+	 * @since 4.9.0
4626
+	 */
4627
+	protected function _send_now()
4628
+	{
4629
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4630
+		$this->_redirect_after_action(false, '', '', [], true);
4631
+	}
4632
+
4633
+
4634
+	/**
4635
+	 * Deletes EE_messages for IDs in the request.
4636
+	 *
4637
+	 * @throws EE_Error
4638
+	 * @throws InvalidDataTypeException
4639
+	 * @throws InvalidInterfaceException
4640
+	 * @throws InvalidArgumentException
4641
+	 * @since 4.9.0
4642
+	 */
4643
+	protected function _delete_ee_messages()
4644
+	{
4645
+		$MSG_IDs       = $this->_get_msg_ids_from_request();
4646
+		$deleted_count = 0;
4647
+		foreach ($MSG_IDs as $MSG_ID) {
4648
+			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) {
4649
+				$deleted_count++;
4650
+			}
4651
+		}
4652
+		if ($deleted_count) {
4653
+			EE_Error::add_success(
4654
+				esc_html(
4655
+					_n(
4656
+						'Message successfully deleted',
4657
+						'Messages successfully deleted',
4658
+						$deleted_count,
4659
+						'event_espresso'
4660
+					)
4661
+				)
4662
+			);
4663
+		} else {
4664
+			EE_Error::add_error(
4665
+				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'),
4666
+				__FILE__,
4667
+				__FUNCTION__,
4668
+				__LINE__
4669
+			);
4670
+		}
4671
+		$this->_redirect_after_action(false, '', '', [], true);
4672
+	}
4673
+
4674
+
4675
+	/**
4676
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4677
+	 *
4678
+	 * @return array
4679
+	 * @since 4.9.0
4680
+	 */
4681
+	protected function _get_msg_ids_from_request()
4682
+	{
4683
+		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true);
4684
+		if (empty($MSG_IDs)) {
4685
+			return [];
4686
+		}
4687
+		// if 'MSG_ID' was just a single ID (not an array)
4688
+		// then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123
4689
+		// otherwise, $MSG_IDs was already an array where message IDs were used as the keys
4690
+		return count($MSG_IDs) === 1 && isset($MSG_IDs[0])
4691
+			? $MSG_IDs
4692
+			: array_keys($MSG_IDs);
4693
+	}
4694 4694
 }
Please login to merge, or discard this patch.
Spacing   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      */
115 115
     public function getMsgModel()
116 116
     {
117
-        if (! $this->MSG_MODEL instanceof EEM_Message) {
117
+        if ( ! $this->MSG_MODEL instanceof EEM_Message) {
118 118
             $this->MSG_MODEL = EEM_Message::instance();
119 119
         }
120 120
         return $this->MSG_MODEL;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function getMtpModel()
129 129
     {
130
-        if (! $this->MTP_MODEL instanceof EEM_Message_Template) {
130
+        if ( ! $this->MTP_MODEL instanceof EEM_Message_Template) {
131 131
             $this->MTP_MODEL = EEM_Message_Template::instance();
132 132
         }
133 133
         return $this->MTP_MODEL;
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      */
141 141
     public function getMtgModel()
142 142
     {
143
-        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
143
+        if ( ! $this->MTG_MODEL instanceof EEM_Message_Template_Group) {
144 144
             $this->MTG_MODEL = EEM_Message_Template_Group::instance();
145 145
         }
146 146
         return $this->MTG_MODEL;
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
         $i = 1;
211 211
         foreach ($active_messengers as $active_messenger) {
212 212
             if ($active_messenger instanceof EE_Message) {
213
-                $m_values[ $i ]['id']   = $active_messenger->messenger();
214
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
213
+                $m_values[$i]['id']   = $active_messenger->messenger();
214
+                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
215 215
                 $i++;
216 216
             }
217 217
         }
@@ -247,8 +247,8 @@  discard block
 block discarded – undo
247 247
         $i               = 1;
248 248
         foreach ($active_messages as $active_message) {
249 249
             if ($active_message instanceof EE_Message) {
250
-                $mt_values[ $i ]['id']   = $active_message->message_type();
251
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
250
+                $mt_values[$i]['id']   = $active_message->message_type();
251
+                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
252 252
                 $i++;
253 253
             }
254 254
         }
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
                 if ($message_type instanceof EE_message_type) {
288 288
                     $message_type_contexts = $message_type->get_contexts();
289 289
                     foreach ($message_type_contexts as $context => $context_details) {
290
-                        $contexts[ $context ] = $context_details['label'];
290
+                        $contexts[$context] = $context_details['label'];
291 291
                     }
292 292
                 }
293 293
             }
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
             ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')],
321 321
             $messenger_options
322 322
         );
323
-        $input             = new EE_Select_Input(
323
+        $input = new EE_Select_Input(
324 324
             $messenger_options,
325 325
             [
326 326
                 'html_name'  => 'ee_messenger_filter_by',
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
             ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')],
358 358
             $message_type_options
359 359
         );
360
-        $input                = new EE_Select_Input(
360
+        $input = new EE_Select_Input(
361 361
             $message_type_options,
362 362
             [
363 363
                 'html_name'  => 'ee_message_type_filter_by',
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
             ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')],
395 395
             $context_options
396 396
         );
397
-        $input           = new EE_Select_Input(
397
+        $input = new EE_Select_Input(
398 398
             $context_options,
399 399
             [
400 400
                 'html_name'  => 'ee_context_filter_by',
@@ -768,53 +768,53 @@  discard block
 block discarded – undo
768 768
 
769 769
     public function messages_help_tab()
770 770
     {
771
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
771
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
772 772
     }
773 773
 
774 774
 
775 775
     public function messengers_help_tab()
776 776
     {
777
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
777
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
778 778
     }
779 779
 
780 780
 
781 781
     public function message_types_help_tab()
782 782
     {
783
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
783
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
784 784
     }
785 785
 
786 786
 
787 787
     public function messages_overview_help_tab()
788 788
     {
789
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
789
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
790 790
     }
791 791
 
792 792
 
793 793
     public function message_templates_help_tab()
794 794
     {
795
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
795
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
796 796
     }
797 797
 
798 798
 
799 799
     public function edit_message_template_help_tab()
800 800
     {
801
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
801
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'
802 802
                         . esc_attr__('Editor Title', 'event_espresso')
803 803
                         . '" />';
804
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
804
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'
805 805
                         . esc_attr__('Context Switcher and Preview', 'event_espresso')
806 806
                         . '" />';
807
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
807
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'
808 808
                         . esc_attr__('Message Template Form Fields', 'event_espresso')
809 809
                         . '" />';
810
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
810
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'
811 811
                         . esc_attr__('Shortcodes Metabox', 'event_espresso')
812 812
                         . '" />';
813
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
813
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'
814 814
                         . esc_attr__('Publish Metabox', 'event_espresso')
815 815
                         . '" />';
816 816
         EEH_Template::display_template(
817
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
817
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
818 818
             $args
819 819
         );
820 820
     }
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
         $this->_set_shortcodes();
830 830
         $args['shortcodes'] = $this->_shortcodes;
831 831
         EEH_Template::display_template(
832
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
832
+            EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
833 833
             $args
834 834
         );
835 835
     }
@@ -837,16 +837,16 @@  discard block
 block discarded – undo
837 837
 
838 838
     public function preview_message_help_tab()
839 839
     {
840
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
840
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
841 841
     }
842 842
 
843 843
 
844 844
     public function settings_help_tab()
845 845
     {
846
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
847
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
848
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
849
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
846
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'
847
+                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />';
848
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
849
+                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />';
850 850
         $args['img3'] = '<div class="switch">'
851 851
                         . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
852 852
                         . ' type="checkbox" checked="checked">'
@@ -857,25 +857,25 @@  discard block
 block discarded – undo
857 857
                         . ' type="checkbox">'
858 858
                         . '<label for="ee-on-off-toggle-on"></label>'
859 859
                         . '</div>';
860
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
860
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
861 861
     }
862 862
 
863 863
 
864 864
     public function load_scripts_styles()
865 865
     {
866
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
866
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
867 867
         wp_enqueue_style('espresso_ee_msg');
868 868
 
869 869
         wp_register_script(
870 870
             'ee-messages-settings',
871
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
871
+            EE_MSG_ASSETS_URL.'ee-messages-settings.js',
872 872
             ['jquery-ui-droppable', 'ee-serialize-full-array'],
873 873
             EVENT_ESPRESSO_VERSION,
874 874
             true
875 875
         );
876 876
         wp_register_script(
877 877
             'ee-msg-list-table-js',
878
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
878
+            EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
879 879
             ['ee-dialog'],
880 880
             EVENT_ESPRESSO_VERSION
881 881
         );
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
 
919 919
         $this->_set_shortcodes();
920 920
 
921
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
921
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
922 922
             esc_html__(
923 923
                 'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
924 924
                 'event_espresso'
@@ -930,14 +930,14 @@  discard block
 block discarded – undo
930 930
             'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
931 931
             'event_espresso'
932 932
         );
933
-        EE_Registry::$i18n_js_strings['server_error']                 = esc_html__(
933
+        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
934 934
             'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
935 935
             'event_espresso'
936 936
         );
937 937
 
938 938
         wp_register_script(
939 939
             'ee_msgs_edit_js',
940
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
940
+            EE_MSG_ASSETS_URL.'ee_message_editor.js',
941 941
             ['jquery'],
942 942
             EVENT_ESPRESSO_VERSION
943 943
         );
@@ -980,7 +980,7 @@  discard block
 block discarded – undo
980 980
     {
981 981
         wp_register_style(
982 982
             'ee-message-settings',
983
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
983
+            EE_MSG_ASSETS_URL.'ee_message_settings.css',
984 984
             [],
985 985
             EVENT_ESPRESSO_VERSION
986 986
         );
@@ -1066,7 +1066,7 @@  discard block
 block discarded – undo
1066 1066
             }
1067 1067
             $status_bulk_actions = $common_bulk_actions;
1068 1068
             // unset bulk actions not applying to status
1069
-            if (! empty($status_bulk_actions)) {
1069
+            if ( ! empty($status_bulk_actions)) {
1070 1070
                 switch ($status) {
1071 1071
                     case EEM_Message::status_idle:
1072 1072
                     case EEM_Message::status_resend:
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
                 continue;
1096 1096
             }
1097 1097
 
1098
-            $this->_views[ strtolower($status) ] = [
1098
+            $this->_views[strtolower($status)] = [
1099 1099
                 'slug'        => strtolower($status),
1100 1100
                 'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1101 1101
                 'count'       => 0,
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
             if ($action_item === 'see_notifications_for') {
1145 1145
                 continue;
1146 1146
             }
1147
-            $action_items[ $action_item ] = [
1147
+            $action_items[$action_item] = [
1148 1148
                 'class' => $action_details['css_class'],
1149 1149
                 'desc'  => $action_details['label'],
1150 1150
             ];
@@ -1153,37 +1153,37 @@  discard block
 block discarded – undo
1153 1153
         /** @var array $status_items status legend setup */
1154 1154
         $status_items = [
1155 1155
             'sent_status'                => [
1156
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1156
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,
1157 1157
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1158 1158
             ],
1159 1159
             'idle_status'                => [
1160
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1160
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,
1161 1161
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1162 1162
             ],
1163 1163
             'failed_status'              => [
1164
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1164
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,
1165 1165
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1166 1166
             ],
1167 1167
             'messenger_executing_status' => [
1168
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1168
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,
1169 1169
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1170 1170
             ],
1171 1171
             'resend_status'              => [
1172
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1172
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,
1173 1173
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1174 1174
             ],
1175 1175
             'incomplete_status'          => [
1176
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1176
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,
1177 1177
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1178 1178
             ],
1179 1179
             'retry_status'               => [
1180
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1180
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,
1181 1181
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1182 1182
             ],
1183 1183
         ];
1184 1184
         if (EEM_Message::debug()) {
1185 1185
             $status_items['debug_only_status'] = [
1186
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1186
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,
1187 1187
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1188 1188
             ];
1189 1189
         }
@@ -1198,11 +1198,11 @@  discard block
 block discarded – undo
1198 1198
     protected function _custom_mtps_preview()
1199 1199
     {
1200 1200
         $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1201
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1202
-                                                . ' alt="' . esc_attr__(
1201
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'
1202
+                                                . ' alt="'.esc_attr__(
1203 1203
                                                     'Preview Custom Message Templates screenshot',
1204 1204
                                                     'event_espresso'
1205
-                                                ) . '" />';
1205
+                                                ).'" />';
1206 1206
         $this->_template_args['preview_text'] = '<strong>'
1207 1207
                                                 . esc_html__(
1208 1208
                                                     'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
@@ -1278,7 +1278,7 @@  discard block
 block discarded – undo
1278 1278
         $installed               = [];
1279 1279
 
1280 1280
         foreach ($installed_message_types as $message_type) {
1281
-            $installed[ $message_type->name ] = $message_type;
1281
+            $installed[$message_type->name] = $message_type;
1282 1282
         }
1283 1283
 
1284 1284
         return $installed;
@@ -1404,7 +1404,7 @@  discard block
 block discarded – undo
1404 1404
         // we need to assemble the title from Various details
1405 1405
         $context_label = sprintf(
1406 1406
             esc_html__('(%s %s)', 'event_espresso'),
1407
-            $c_config[ $context ]['label'],
1407
+            $c_config[$context]['label'],
1408 1408
             ucwords($c_label['label'])
1409 1409
         );
1410 1410
 
@@ -1426,7 +1426,7 @@  discard block
 block discarded – undo
1426 1426
             $message_template_group->message_type()
1427 1427
         );
1428 1428
 
1429
-        if (! $template_field_structure) {
1429
+        if ( ! $template_field_structure) {
1430 1430
             $template_field_structure = false;
1431 1431
             $template_fields          = esc_html__(
1432 1432
                 'There was an error in assembling the fields for this display (you should see an error message)',
@@ -1440,21 +1440,21 @@  discard block
 block discarded – undo
1440 1440
 
1441 1441
         // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1442 1442
         // will get handled in the "extra" array.
1443
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1444
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1445
-                unset($template_field_structure[ $context ][ $reference_field ]);
1443
+        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1444
+            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1445
+                unset($template_field_structure[$context][$reference_field]);
1446 1446
             }
1447 1447
         }
1448 1448
 
1449 1449
         // let's loop through the template_field_structure and actually assemble the input fields!
1450
-        if (! empty($template_field_structure)) {
1451
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1450
+        if ( ! empty($template_field_structure)) {
1451
+            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1452 1452
                 // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1453 1453
                 // the extra array and reset them.
1454 1454
                 if ($template_field === 'extra') {
1455 1455
                     $this->_template_args['is_extra_fields'] = true;
1456 1456
                     foreach ($field_setup_array as $reference_field => $new_fields_array) {
1457
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1457
+                        $message_template = $message_templates[$context][$reference_field];
1458 1458
                         $content          = $message_template instanceof EE_Message_Template
1459 1459
                             ? $message_template->get('MTP_content')
1460 1460
                             : '';
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
                             $continue = false;
1464 1464
                             if (isset($extra_array['shortcodes_required'])) {
1465 1465
                                 foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1466
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1466
+                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1467 1467
                                         $continue = true;
1468 1468
                                     }
1469 1469
                                 }
@@ -1472,53 +1472,53 @@  discard block
 block discarded – undo
1472 1472
                                 }
1473 1473
                             }
1474 1474
 
1475
-                            $field_id = $reference_field . '-' . $extra_field . '-content';
1475
+                            $field_id = $reference_field.'-'.$extra_field.'-content';
1476 1476
 
1477
-                            $template_form_fields[ $field_id ]         = $extra_array;
1478
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1477
+                            $template_form_fields[$field_id]         = $extra_array;
1478
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['
1479 1479
                                                                          . $reference_field
1480 1480
                                                                          . '][content]['
1481
-                                                                         . $extra_field . ']';
1482
-                            $css_class                                 = isset($extra_array['css_class'])
1481
+                                                                         . $extra_field.']';
1482
+                            $css_class = isset($extra_array['css_class'])
1483 1483
                                 ? $extra_array['css_class']
1484 1484
                                 : '';
1485 1485
 
1486
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1486
+                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1487 1487
                                                                               && in_array($extra_field, $v_fields, true)
1488 1488
                                                                               && (
1489
-                                                                                  is_array($validators[ $extra_field ])
1490
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1489
+                                                                                  is_array($validators[$extra_field])
1490
+                                                                                  && isset($validators[$extra_field]['msg'])
1491 1491
                                                                               )
1492
-                                ? 'validate-error ' . $css_class
1492
+                                ? 'validate-error '.$css_class
1493 1493
                                 : $css_class;
1494 1494
 
1495
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1496
-                                                                          && isset($content[ $extra_field ])
1497
-                                ? $content[ $extra_field ]
1495
+                            $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1496
+                                                                          && isset($content[$extra_field])
1497
+                                ? $content[$extra_field]
1498 1498
                                 : '';
1499 1499
 
1500 1500
                             // do we have a validation error?  if we do then let's use that value instead
1501
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1502
-                                ? $validators[ $extra_field ]['value']
1503
-                                : $template_form_fields[ $field_id ]['value'];
1501
+                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])
1502
+                                ? $validators[$extra_field]['value']
1503
+                                : $template_form_fields[$field_id]['value'];
1504 1504
 
1505 1505
 
1506
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1506
+                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1507 1507
 
1508 1508
                             // shortcode selector
1509 1509
                             $field_name_to_use                                   = $extra_field === 'main'
1510 1510
                                 ? 'content'
1511 1511
                                 : $extra_field;
1512
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1512
+                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1513 1513
                                 $field_name_to_use,
1514 1514
                                 $field_id
1515 1515
                             );
1516 1516
                         }
1517
-                        $template_field_MTP_id           = $reference_field . '-MTP_ID';
1518
-                        $template_field_template_name_id = $reference_field . '-name';
1517
+                        $template_field_MTP_id           = $reference_field.'-MTP_ID';
1518
+                        $template_field_template_name_id = $reference_field.'-name';
1519 1519
 
1520
-                        $template_form_fields[ $template_field_MTP_id ] = [
1521
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1520
+                        $template_form_fields[$template_field_MTP_id] = [
1521
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1522 1522
                             'label'      => null,
1523 1523
                             'input'      => 'hidden',
1524 1524
                             'type'       => 'int',
@@ -1530,8 +1530,8 @@  discard block
 block discarded – undo
1530 1530
                             'db-col'     => 'MTP_ID',
1531 1531
                         ];
1532 1532
 
1533
-                        $template_form_fields[ $template_field_template_name_id ] = [
1534
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1533
+                        $template_form_fields[$template_field_template_name_id] = [
1534
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1535 1535
                             'label'      => null,
1536 1536
                             'input'      => 'hidden',
1537 1537
                             'type'       => 'string',
@@ -1545,38 +1545,38 @@  discard block
 block discarded – undo
1545 1545
                     }
1546 1546
                     continue; // skip the next stuff, we got the necessary fields here for this dataset.
1547 1547
                 } else {
1548
-                    $field_id                                   = $template_field . '-content';
1549
-                    $template_form_fields[ $field_id ]          = $field_setup_array;
1550
-                    $template_form_fields[ $field_id ]['name']  =
1551
-                        'MTP_template_fields[' . $template_field . '][content]';
1548
+                    $field_id                                   = $template_field.'-content';
1549
+                    $template_form_fields[$field_id]          = $field_setup_array;
1550
+                    $template_form_fields[$field_id]['name']  =
1551
+                        'MTP_template_fields['.$template_field.'][content]';
1552 1552
                     $message_template                           =
1553
-                        isset($message_templates[ $context ][ $template_field ])
1554
-                            ? $message_templates[ $context ][ $template_field ]
1553
+                        isset($message_templates[$context][$template_field])
1554
+                            ? $message_templates[$context][$template_field]
1555 1555
                             : null;
1556
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1557
-                                                                  && is_array($message_templates[ $context ])
1556
+                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1557
+                                                                  && is_array($message_templates[$context])
1558 1558
                                                                   && $message_template instanceof EE_Message_Template
1559 1559
                         ? $message_template->get('MTP_content')
1560 1560
                         : '';
1561 1561
 
1562 1562
                     // do we have a validator error for this field?  if we do then we'll use that value instead
1563
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1564
-                        ? $validators[ $template_field ]['value']
1565
-                        : $template_form_fields[ $field_id ]['value'];
1563
+                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1564
+                        ? $validators[$template_field]['value']
1565
+                        : $template_form_fields[$field_id]['value'];
1566 1566
 
1567 1567
 
1568
-                    $template_form_fields[ $field_id ]['db-col']    = 'MTP_content';
1568
+                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1569 1569
                     $css_class                                      = isset($field_setup_array['css_class'])
1570 1570
                         ? $field_setup_array['css_class']
1571 1571
                         : '';
1572
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1572
+                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1573 1573
                                                                       && in_array($template_field, $v_fields, true)
1574
-                                                                      && isset($validators[ $template_field ]['msg'])
1575
-                        ? 'validate-error ' . $css_class
1574
+                                                                      && isset($validators[$template_field]['msg'])
1575
+                        ? 'validate-error '.$css_class
1576 1576
                         : $css_class;
1577 1577
 
1578 1578
                     // shortcode selector
1579
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1579
+                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1580 1580
                         $template_field,
1581 1581
                         $field_id
1582 1582
                     );
@@ -1584,12 +1584,12 @@  discard block
 block discarded – undo
1584 1584
 
1585 1585
                 // k took care of content field(s) now let's take care of others.
1586 1586
 
1587
-                $template_field_MTP_id                 = $template_field . '-MTP_ID';
1588
-                $template_field_field_template_name_id = $template_field . '-name';
1587
+                $template_field_MTP_id                 = $template_field.'-MTP_ID';
1588
+                $template_field_field_template_name_id = $template_field.'-name';
1589 1589
 
1590 1590
                 // foreach template field there are actually two form fields created
1591
-                $template_form_fields[ $template_field_MTP_id ] = [
1592
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1591
+                $template_form_fields[$template_field_MTP_id] = [
1592
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1593 1593
                     'label'      => null,
1594 1594
                     'input'      => 'hidden',
1595 1595
                     'type'       => 'int',
@@ -1601,8 +1601,8 @@  discard block
 block discarded – undo
1601 1601
                     'db-col'     => 'MTP_ID',
1602 1602
                 ];
1603 1603
 
1604
-                $template_form_fields[ $template_field_field_template_name_id ] = [
1605
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1604
+                $template_form_fields[$template_field_field_template_name_id] = [
1605
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1606 1606
                     'label'      => null,
1607 1607
                     'input'      => 'hidden',
1608 1608
                     'type'       => 'string',
@@ -1719,7 +1719,7 @@  discard block
 block discarded – undo
1719 1719
                 'format'     => '%d',
1720 1720
                 'db-col'     => 'MTP_deleted',
1721 1721
             ];
1722
-            $sidebar_form_fields['ee-msg-author']  = [
1722
+            $sidebar_form_fields['ee-msg-author'] = [
1723 1723
                 'name'       => 'MTP_user_id',
1724 1724
                 'label'      => esc_html__('Author', 'event_espresso'),
1725 1725
                 'input'      => 'hidden',
@@ -1738,17 +1738,17 @@  discard block
 block discarded – undo
1738 1738
                 'value' => $action,
1739 1739
             ];
1740 1740
 
1741
-            $sidebar_form_fields['ee-msg-id']        = [
1741
+            $sidebar_form_fields['ee-msg-id'] = [
1742 1742
                 'name'  => 'id',
1743 1743
                 'input' => 'hidden',
1744 1744
                 'type'  => 'int',
1745 1745
                 'value' => $GRP_ID,
1746 1746
             ];
1747 1747
             $sidebar_form_fields['ee-msg-evt-nonce'] = [
1748
-                'name'  => $action . '_nonce',
1748
+                'name'  => $action.'_nonce',
1749 1749
                 'input' => 'hidden',
1750 1750
                 'type'  => 'string',
1751
-                'value' => wp_create_nonce($action . '_nonce'),
1751
+                'value' => wp_create_nonce($action.'_nonce'),
1752 1752
             ];
1753 1753
 
1754 1754
             $template_switch = $this->request->getRequestParam('template_switch');
@@ -1779,7 +1779,7 @@  discard block
 block discarded – undo
1779 1779
         );
1780 1780
 
1781 1781
         // add preview button
1782
-        $preview_url    = parent::add_query_args_and_nonce(
1782
+        $preview_url = parent::add_query_args_and_nonce(
1783 1783
             [
1784 1784
                 'message_type' => $message_template_group->message_type(),
1785 1785
                 'messenger'    => $message_template_group->messenger(),
@@ -1790,7 +1790,7 @@  discard block
 block discarded – undo
1790 1790
             ],
1791 1791
             $this->_admin_base_url
1792 1792
         );
1793
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1793
+        $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'
1794 1794
                           . esc_html__('Preview', 'event_espresso')
1795 1795
                           . '</a>';
1796 1796
 
@@ -1826,11 +1826,11 @@  discard block
 block discarded – undo
1826 1826
             $context_label
1827 1827
         );
1828 1828
         $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1829
-        $this->_template_args['after_admin_page_content']  = $this->_add_form_element_after();
1829
+        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1830 1830
 
1831 1831
         $this->_template_path = $this->_template_args['GRP_ID']
1832 1832
             ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1833
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1833
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1834 1834
 
1835 1835
         // send along EE_Message_Template_Group object for further template use.
1836 1836
         $this->_template_args['MTP'] = $message_template_group;
@@ -1886,7 +1886,7 @@  discard block
 block discarded – undo
1886 1886
     ) {
1887 1887
         $template_args = [
1888 1888
             'context'                   => $context,
1889
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1889
+            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'),
1890 1890
             'is_active'                 => $message_template_group->is_context_active($context),
1891 1891
             'on_off_action'             => $message_template_group->is_context_active($context)
1892 1892
                 ? 'context-off'
@@ -1895,7 +1895,7 @@  discard block
 block discarded – undo
1895 1895
             'message_template_group_id' => $message_template_group->ID(),
1896 1896
         ];
1897 1897
         return EEH_Template::display_template(
1898
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1898
+            EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',
1899 1899
             $template_args,
1900 1900
             true
1901 1901
         );
@@ -1952,7 +1952,7 @@  discard block
 block discarded – undo
1952 1952
         }
1953 1953
         $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int');
1954 1954
         $message_template_group    = $this->getMtgModel()->get_one_by_ID($message_template_group_id);
1955
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1955
+        if ( ! $message_template_group instanceof EE_Message_Template_Group) {
1956 1956
             EE_Error::add_error(
1957 1957
                 sprintf(
1958 1958
                     esc_html__(
@@ -2083,7 +2083,7 @@  discard block
 block discarded – undo
2083 2083
         $messenger    = $this->request->getRequestParam('msgr');
2084 2084
         $message_type = $this->request->getRequestParam('mt');
2085 2085
         // we need to make sure we've got the info we need.
2086
-        if (! ($GRP_ID && $messenger && $message_type)) {
2086
+        if ( ! ($GRP_ID && $messenger && $message_type)) {
2087 2087
             EE_Error::add_error(
2088 2088
                 esc_html__(
2089 2089
                     'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
@@ -2120,7 +2120,7 @@  discard block
 block discarded – undo
2120 2120
         }
2121 2121
 
2122 2122
         // any error messages?
2123
-        if (! $success) {
2123
+        if ( ! $success) {
2124 2124
             EE_Error::add_error(
2125 2125
                 esc_html__(
2126 2126
                     'Something went wrong with deleting existing templates. Unable to reset to default',
@@ -2169,7 +2169,7 @@  discard block
 block discarded – undo
2169 2169
     {
2170 2170
         // first make sure we've got the necessary parameters
2171 2171
         $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int');
2172
-        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2172
+        if ( ! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) {
2173 2173
             EE_Error::add_error(
2174 2174
                 esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2175 2175
                 __FILE__,
@@ -2195,7 +2195,7 @@  discard block
 block discarded – undo
2195 2195
         $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int');
2196 2196
 
2197 2197
         // let's add a button to go back to the edit view
2198
-        $query_args             = [
2198
+        $query_args = [
2199 2199
             'id'      => $GRP_ID,
2200 2200
             'evt_id'  => $EVT_ID,
2201 2201
             'context' => $context,
@@ -2216,7 +2216,7 @@  discard block
 block discarded – undo
2216 2216
         $preview_title = sprintf(
2217 2217
             esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2218 2218
             $active_messenger_label,
2219
-            ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])
2219
+            ucwords($message_types[$this->_active_message_type_name]->label['singular'])
2220 2220
         );
2221 2221
         if (empty($preview)) {
2222 2222
             $this->noEventsErrorMessage();
@@ -2224,7 +2224,7 @@  discard block
 block discarded – undo
2224 2224
         // setup display of preview.
2225 2225
         $this->_admin_page_title                    = $preview_title;
2226 2226
         $this->_template_args['admin_page_title']   = $preview_title;
2227
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2227
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;
2228 2228
         $this->_template_args['data']['force_json'] = true;
2229 2229
 
2230 2230
         return '';
@@ -2245,7 +2245,7 @@  discard block
 block discarded – undo
2245 2245
             ],
2246 2246
             admin_url('admin.php')
2247 2247
         );
2248
-        $message    = $test_send
2248
+        $message = $test_send
2249 2249
             ? esc_html__(
2250 2250
                 'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2251 2251
                 'event_espresso'
@@ -2338,10 +2338,10 @@  discard block
 block discarded – undo
2338 2338
             // only include template packs that support this messenger and message type!
2339 2339
             $supports = $tp->get_supports();
2340 2340
             if (
2341
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2341
+                ! isset($supports[$this->_message_template_group->messenger()])
2342 2342
                 || ! in_array(
2343 2343
                     $this->_message_template_group->message_type(),
2344
-                    $supports[ $this->_message_template_group->messenger() ],
2344
+                    $supports[$this->_message_template_group->messenger()],
2345 2345
                     true
2346 2346
                 )
2347 2347
             ) {
@@ -2365,7 +2365,7 @@  discard block
 block discarded – undo
2365 2365
         }
2366 2366
 
2367 2367
         // setup variation select values for the currently selected template.
2368
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
2368
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2369 2369
             $this->_message_template_group->messenger(),
2370 2370
             $this->_message_template_group->message_type()
2371 2371
         );
@@ -2379,12 +2379,12 @@  discard block
 block discarded – undo
2379 2379
 
2380 2380
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2381 2381
 
2382
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
2382
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2383 2383
             'MTP_template_pack',
2384 2384
             $tp_select_values,
2385 2385
             $this->_message_template_group->get_template_pack_name()
2386 2386
         );
2387
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
2387
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2388 2388
             'MTP_template_variation',
2389 2389
             $variations_select_values,
2390 2390
             $this->_message_template_group->get_template_pack_variation()
@@ -2394,7 +2394,7 @@  discard block
 block discarded – undo
2394 2394
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
2395 2395
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2396 2396
 
2397
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2397
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
2398 2398
 
2399 2399
         EEH_Template::display_template($template, $template_args);
2400 2400
     }
@@ -2420,33 +2420,33 @@  discard block
 block discarded – undo
2420 2420
         // first we need to see if there are any fields
2421 2421
         $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2422 2422
 
2423
-        if (! empty($fields)) {
2423
+        if ( ! empty($fields)) {
2424 2424
             // yup there be fields
2425 2425
             foreach ($fields as $field => $config) {
2426
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2426
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2427 2427
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2428 2428
                 $default  = isset($config['default']) ? $config['default'] : '';
2429 2429
                 $default  = isset($config['value']) ? $config['value'] : $default;
2430 2430
 
2431 2431
                 // if type is hidden and the value is empty
2432 2432
                 // something may have gone wrong so let's correct with the defaults
2433
-                $fix                = $config['input'] === 'hidden'
2434
-                                      && isset($existing[ $field ])
2435
-                                      && empty($existing[ $field ])
2433
+                $fix = $config['input'] === 'hidden'
2434
+                                      && isset($existing[$field])
2435
+                                      && empty($existing[$field])
2436 2436
                     ? $default
2437 2437
                     : '';
2438
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2439
-                    ? $existing[ $field ]
2438
+                $existing[$field] = isset($existing[$field]) && empty($fix)
2439
+                    ? $existing[$field]
2440 2440
                     : $fix;
2441 2441
 
2442
-                $template_form_fields[ $field_id ] = [
2443
-                    'name'       => 'test_settings_fld[' . $field . ']',
2442
+                $template_form_fields[$field_id] = [
2443
+                    'name'       => 'test_settings_fld['.$field.']',
2444 2444
                     'label'      => $config['label'],
2445 2445
                     'input'      => $config['input'],
2446 2446
                     'type'       => $config['type'],
2447 2447
                     'required'   => $config['required'],
2448 2448
                     'validation' => $config['validation'],
2449
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2449
+                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2450 2450
                     'css_class'  => $config['css_class'],
2451 2451
                     'options'    => isset($config['options']) ? $config['options'] : [],
2452 2452
                     'default'    => $default,
@@ -2460,7 +2460,7 @@  discard block
 block discarded – undo
2460 2460
             : '';
2461 2461
 
2462 2462
         // print out $test_settings_fields
2463
-        if (! empty($test_settings_html)) {
2463
+        if ( ! empty($test_settings_html)) {
2464 2464
             $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" ';
2465 2465
             $test_settings_html .= 'name="test_button" value="';
2466 2466
             $test_settings_html .= esc_html__('Test Send', 'event_espresso');
@@ -2506,7 +2506,7 @@  discard block
 block discarded – undo
2506 2506
         ];
2507 2507
 
2508 2508
         return EEH_Template::display_template(
2509
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2509
+            EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2510 2510
             $template_args,
2511 2511
             true
2512 2512
         );
@@ -2532,7 +2532,7 @@  discard block
 block discarded – undo
2532 2532
         // $messenger = $this->_message_template_group->messenger_obj();
2533 2533
         // now let's set the content depending on the status of the shortcodes array
2534 2534
         if (empty($shortcodes)) {
2535
-            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2535
+            echo '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>';
2536 2536
             return;
2537 2537
         }
2538 2538
         ?>
@@ -2568,7 +2568,7 @@  discard block
 block discarded – undo
2568 2568
     {
2569 2569
 
2570 2570
         // no need to run this if the property is already set
2571
-        if (! empty($this->_shortcodes)) {
2571
+        if ( ! empty($this->_shortcodes)) {
2572 2572
             return;
2573 2573
         }
2574 2574
 
@@ -2623,7 +2623,7 @@  discard block
 block discarded – undo
2623 2623
     protected function _set_message_template_group()
2624 2624
     {
2625 2625
         // get out if this is already set.
2626
-        if (! empty($this->_message_template_group)) {
2626
+        if ( ! empty($this->_message_template_group)) {
2627 2627
             return;
2628 2628
         }
2629 2629
 
@@ -2669,8 +2669,8 @@  discard block
 block discarded – undo
2669 2669
                     <?php
2670 2670
                 }
2671 2671
                 // setup nonce_url
2672
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2673
-                $id = 'ee-' . sanitize_key($context_label['label']) . '-select';
2672
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2673
+                $id = 'ee-'.sanitize_key($context_label['label']).'-select';
2674 2674
                 ?>
2675 2675
                 <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>
2676 2676
                     <?php esc_html_e('message context options', 'event_espresso'); ?>
@@ -2683,7 +2683,7 @@  discard block
 block discarded – undo
2683 2683
                             $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2684 2684
                             ?>
2685 2685
                             <option value="<?php echo esc_attr($context); ?>" <?php echo $checked; ?>>
2686
-                                <?php echo $context_details[ $context ]['label']; // already escaped
2686
+                                <?php echo $context_details[$context]['label']; // already escaped
2687 2687
                                 ?>
2688 2688
                             </option>
2689 2689
                         <?php endforeach;
@@ -3077,7 +3077,7 @@  discard block
 block discarded – undo
3077 3077
     {
3078 3078
         if (is_array($content)) {
3079 3079
             foreach ($content as $key => $value) {
3080
-                $content[ $key ] = $this->sanitizeMessageTemplateContent($value);
3080
+                $content[$key] = $this->sanitizeMessageTemplateContent($value);
3081 3081
             }
3082 3082
             return $content;
3083 3083
         }
@@ -3115,7 +3115,7 @@  discard block
 block discarded – undo
3115 3115
 
3116 3116
         $context   = ucwords(str_replace('_', ' ', $context));
3117 3117
         $item_desc = $messenger_label && $message_type_label
3118
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
3118
+            ? $messenger_label.' '.$message_type_label.' '.$context.' '
3119 3119
             : '';
3120 3120
         $item_desc .= 'Message Template';
3121 3121
         return $item_desc;
@@ -3267,7 +3267,7 @@  discard block
 block discarded – undo
3267 3267
         if ($all) {
3268 3268
             // Checkboxes
3269 3269
             $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3270
-            if (! empty($checkboxes)) {
3270
+            if ( ! empty($checkboxes)) {
3271 3271
                 // if array has more than one element then success message should be plural.
3272 3272
                 // todo: what about nonce?
3273 3273
                 $success = count($checkboxes) > 1 ? 2 : 1;
@@ -3277,18 +3277,18 @@  discard block
 block discarded – undo
3277 3277
                     $trashed_or_restored = $trash
3278 3278
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3279 3279
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3280
-                    if (! $trashed_or_restored) {
3280
+                    if ( ! $trashed_or_restored) {
3281 3281
                         $success = 0;
3282 3282
                     }
3283 3283
                 }
3284 3284
             } else {
3285 3285
                 // grab single GRP_ID and handle
3286 3286
                 $GRP_ID = $this->request->getRequestParam('id', 0, 'int');
3287
-                if (! empty($GRP_ID)) {
3287
+                if ( ! empty($GRP_ID)) {
3288 3288
                     $trashed_or_restored = $trash
3289 3289
                         ? $this->getMtgModel()->delete_by_ID($GRP_ID)
3290 3290
                         : $this->getMtgModel()->restore_by_ID($GRP_ID);
3291
-                    if (! $trashed_or_restored) {
3291
+                    if ( ! $trashed_or_restored) {
3292 3292
                         $success = 0;
3293 3293
                     }
3294 3294
                 } else {
@@ -3336,7 +3336,7 @@  discard block
 block discarded – undo
3336 3336
 
3337 3337
         // checkboxes
3338 3338
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
3339
-        if (! empty($checkboxes)) {
3339
+        if ( ! empty($checkboxes)) {
3340 3340
             // if array has more than one element then success message should be plural
3341 3341
             $success = count($checkboxes) > 1 ? 2 : 1;
3342 3342
 
@@ -3440,7 +3440,7 @@  discard block
 block discarded – undo
3440 3440
     protected function _set_m_mt_settings()
3441 3441
     {
3442 3442
         // first if this is already set then lets get out no need to regenerate data.
3443
-        if (! empty($this->_m_mt_settings)) {
3443
+        if ( ! empty($this->_m_mt_settings)) {
3444 3444
             return;
3445 3445
         }
3446 3446
 
@@ -3452,7 +3452,7 @@  discard block
 block discarded – undo
3452 3452
         // assemble the array for the _tab_text_links helper
3453 3453
 
3454 3454
         foreach ($messengers as $messenger) {
3455
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [
3455
+            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = [
3456 3456
                 'label' => ucwords($messenger->label['singular']),
3457 3457
                 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3458 3458
                     ? 'messenger-active'
@@ -3469,7 +3469,7 @@  discard block
 block discarded – undo
3469 3469
             foreach ($message_types as $message_type) {
3470 3470
                 // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3471 3471
                 // it shouldn't show in either the inactive OR active metabox.
3472
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3472
+                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) {
3473 3473
                     continue;
3474 3474
                 }
3475 3475
 
@@ -3480,12 +3480,12 @@  discard block
 block discarded – undo
3480 3480
                     ? 'active'
3481 3481
                     : 'inactive';
3482 3482
 
3483
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [
3483
+                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = [
3484 3484
                     'label'    => ucwords($message_type->label['singular']),
3485
-                    'class'    => 'message-type-' . $a_or_i,
3486
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3487
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3488
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3485
+                    'class'    => 'message-type-'.$a_or_i,
3486
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
3487
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
3488
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
3489 3489
                     'title'    => $a_or_i === 'active'
3490 3490
                         ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3491 3491
                         : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -3516,25 +3516,25 @@  discard block
 block discarded – undo
3516 3516
         $fields                                         = $message_type->get_admin_settings_fields();
3517 3517
         $settings_template_args['template_form_fields'] = '';
3518 3518
 
3519
-        if (! empty($fields) && $active) {
3519
+        if ( ! empty($fields) && $active) {
3520 3520
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3521 3521
             foreach ($fields as $fldname => $fldprops) {
3522
-                $field_id                         = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3523
-                $template_form_field[ $field_id ] = [
3524
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3522
+                $field_id                         = $messenger->name.'-'.$message_type->name.'-'.$fldname;
3523
+                $template_form_field[$field_id] = [
3524
+                    'name'       => 'message_type_settings['.$fldname.']',
3525 3525
                     'label'      => $fldprops['label'],
3526 3526
                     'input'      => $fldprops['field_type'],
3527 3527
                     'type'       => $fldprops['value_type'],
3528 3528
                     'required'   => $fldprops['required'],
3529 3529
                     'validation' => $fldprops['validation'],
3530
-                    'value'      => isset($existing_settings[ $fldname ])
3531
-                        ? $existing_settings[ $fldname ]
3530
+                    'value'      => isset($existing_settings[$fldname])
3531
+                        ? $existing_settings[$fldname]
3532 3532
                         : $fldprops['default'],
3533 3533
                     'options'    => isset($fldprops['options'])
3534 3534
                         ? $fldprops['options']
3535 3535
                         : [],
3536
-                    'default'    => isset($existing_settings[ $fldname ])
3537
-                        ? $existing_settings[ $fldname ]
3536
+                    'default'    => isset($existing_settings[$fldname])
3537
+                        ? $existing_settings[$fldname]
3538 3538
                         : $fldprops['default'],
3539 3539
                     'css_class'  => 'no-drag',
3540 3540
                     'format'     => $fldprops['format'],
@@ -3554,15 +3554,15 @@  discard block
 block discarded – undo
3554 3554
         $settings_template_args['description'] = $message_type->description;
3555 3555
         // we also need some hidden fields
3556 3556
         $hidden_fields = [
3557
-            'message_type_settings[messenger]' . $message_type->name    => [
3557
+            'message_type_settings[messenger]'.$message_type->name    => [
3558 3558
                 'type'  => 'hidden',
3559 3559
                 'value' => $messenger->name,
3560 3560
             ],
3561
-            'message_type_settings[message_type]' . $message_type->name => [
3561
+            'message_type_settings[message_type]'.$message_type->name => [
3562 3562
                 'type'  => 'hidden',
3563 3563
                 'value' => $message_type->name,
3564 3564
             ],
3565
-            'type' . $message_type->name                                => [
3565
+            'type'.$message_type->name                                => [
3566 3566
                 'type'  => 'hidden',
3567 3567
                 'value' => 'message_type',
3568 3568
             ],
@@ -3572,12 +3572,12 @@  discard block
 block discarded – undo
3572 3572
             $hidden_fields,
3573 3573
             'array'
3574 3574
         );
3575
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields'])
3575
+        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3576 3576
             ? ' hidden'
3577 3577
             : '';
3578 3578
 
3579 3579
 
3580
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3580
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
3581 3581
         return EEH_Template::display_template($template, $settings_template_args, true);
3582 3582
     }
3583 3583
 
@@ -3605,21 +3605,21 @@  discard block
 block discarded – undo
3605 3605
 
3606 3606
                 // messenger meta boxes
3607 3607
                 $active         = $selected_messenger === $messenger;
3608
-                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])
3609
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3608
+                $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
3609
+                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
3610 3610
                     : '';
3611 3611
 
3612
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3612
+                $m_boxes[$messenger.'_a_box'] = sprintf(
3613 3613
                     esc_html__('%s Settings', 'event_espresso'),
3614 3614
                     $tab_array['label']
3615 3615
                 );
3616 3616
 
3617
-                $m_template_args[ $messenger . '_a_box' ] = [
3617
+                $m_template_args[$messenger.'_a_box'] = [
3618 3618
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3619 3619
                     'inactive_message_types' => isset(
3620
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3620
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3621 3621
                     )
3622
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3622
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3623 3623
                         : '',
3624 3624
                     'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3625 3625
                     'hidden'                 => $active ? '' : ' hidden',
@@ -3631,13 +3631,13 @@  discard block
 block discarded – undo
3631 3631
                 // message type meta boxes
3632 3632
                 // (which is really just the inactive container for each messenger
3633 3633
                 // showing inactive message types for that messenger)
3634
-                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso');
3635
-                $mt_template_args[ $messenger . '_i_box' ] = [
3634
+                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso');
3635
+                $mt_template_args[$messenger.'_i_box'] = [
3636 3636
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3637 3637
                     'inactive_message_types' => isset(
3638
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3638
+                        $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']
3639 3639
                     )
3640
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3640
+                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
3641 3641
                         : '',
3642 3642
                     'hidden'                 => $active ? '' : ' hidden',
3643 3643
                     'hide_on_message'        => $hide_on_message,
@@ -3650,14 +3650,14 @@  discard block
 block discarded – undo
3650 3650
 
3651 3651
 
3652 3652
         // register messenger metaboxes
3653
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3653
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
3654 3654
         foreach ($m_boxes as $box => $label) {
3655
-            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];
3655
+            $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[$box]];
3656 3656
             $msgr          = str_replace('_a_box', '', $box);
3657 3657
             add_meta_box(
3658
-                'espresso_' . $msgr . '_settings',
3658
+                'espresso_'.$msgr.'_settings',
3659 3659
                 $label,
3660
-                function ($post, $metabox) {
3660
+                function($post, $metabox) {
3661 3661
                     EEH_Template::display_template(
3662 3662
                         $metabox['args']['template_path'],
3663 3663
                         $metabox['args']['template_args']
@@ -3671,17 +3671,17 @@  discard block
 block discarded – undo
3671 3671
         }
3672 3672
 
3673 3673
         // register message type metaboxes
3674
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3674
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
3675 3675
         foreach ($mt_boxes as $box => $label) {
3676 3676
             $callback_args = [
3677 3677
                 'template_path' => $mt_template_path,
3678
-                'template_args' => $mt_template_args[ $box ],
3678
+                'template_args' => $mt_template_args[$box],
3679 3679
             ];
3680
-            $mt            = str_replace('_i_box', '', $box);
3680
+            $mt = str_replace('_i_box', '', $box);
3681 3681
             add_meta_box(
3682
-                'espresso_' . $mt . '_inactive_mts',
3682
+                'espresso_'.$mt.'_inactive_mts',
3683 3683
                 $label,
3684
-                function ($post, $metabox) {
3684
+                function($post, $metabox) {
3685 3685
                     EEH_Template::display_template(
3686 3686
                         $metabox['args']['template_path'],
3687 3687
                         $metabox['args']['template_args']
@@ -3826,7 +3826,7 @@  discard block
 block discarded – undo
3826 3826
             if ($form->is_valid()) {
3827 3827
                 $valid_data = $form->valid_data();
3828 3828
                 foreach ($valid_data as $property => $value) {
3829
-                    $setter = 'set_' . $property;
3829
+                    $setter = 'set_'.$property;
3830 3830
                     if (method_exists($network_config, $setter)) {
3831 3831
                         $network_config->{$setter}($value);
3832 3832
                     } elseif (
@@ -3862,7 +3862,7 @@  discard block
 block discarded – undo
3862 3862
     protected function _get_mt_tabs($tab_array)
3863 3863
     {
3864 3864
         $tab_array = (array) $tab_array;
3865
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3865
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3866 3866
         $tabs      = '';
3867 3867
 
3868 3868
         foreach ($tab_array as $tab) {
@@ -3890,20 +3890,20 @@  discard block
 block discarded – undo
3890 3890
         $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3891 3891
 
3892 3892
 
3893
-        if (! empty($fields)) {
3893
+        if ( ! empty($fields)) {
3894 3894
             $existing_settings = $messenger->get_existing_admin_settings();
3895 3895
 
3896 3896
             foreach ($fields as $fldname => $fldprops) {
3897
-                $field_id                         = $messenger->name . '-' . $fldname;
3898
-                $template_form_field[ $field_id ] = [
3899
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3897
+                $field_id                         = $messenger->name.'-'.$fldname;
3898
+                $template_form_field[$field_id] = [
3899
+                    'name'       => 'messenger_settings['.$field_id.']',
3900 3900
                     'label'      => $fldprops['label'],
3901 3901
                     'input'      => $fldprops['field_type'],
3902 3902
                     'type'       => $fldprops['value_type'],
3903 3903
                     'required'   => $fldprops['required'],
3904 3904
                     'validation' => $fldprops['validation'],
3905
-                    'value'      => isset($existing_settings[ $field_id ])
3906
-                        ? $existing_settings[ $field_id ]
3905
+                    'value'      => isset($existing_settings[$field_id])
3906
+                        ? $existing_settings[$field_id]
3907 3907
                         : $fldprops['default'],
3908 3908
                     'css_class'  => '',
3909 3909
                     'format'     => $fldprops['format'],
@@ -3918,20 +3918,20 @@  discard block
 block discarded – undo
3918 3918
 
3919 3919
         // we also need some hidden fields
3920 3920
         $settings_template_args['hidden_fields'] = [
3921
-            'messenger_settings[messenger]' . $messenger->name => [
3921
+            'messenger_settings[messenger]'.$messenger->name => [
3922 3922
                 'type'  => 'hidden',
3923 3923
                 'value' => $messenger->name,
3924 3924
             ],
3925
-            'type' . $messenger->name                          => [
3925
+            'type'.$messenger->name                          => [
3926 3926
                 'type'  => 'hidden',
3927 3927
                 'value' => 'messenger',
3928 3928
             ],
3929 3929
         ];
3930 3930
 
3931 3931
         // make sure any active message types that are existing are included in the hidden fields
3932
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3933
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3934
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [
3932
+        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3933
+            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3934
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = [
3935 3935
                     'type'  => 'hidden',
3936 3936
                     'value' => $mt,
3937 3937
                 ];
@@ -3941,7 +3941,7 @@  discard block
 block discarded – undo
3941 3941
             $settings_template_args['hidden_fields'],
3942 3942
             'array'
3943 3943
         );
3944
-        $active                                  =
3944
+        $active =
3945 3945
             $this->_message_resource_manager->is_messenger_active($messenger->name);
3946 3946
 
3947 3947
         $settings_template_args['messenger']           = $messenger->name;
@@ -3961,9 +3961,9 @@  discard block
 block discarded – undo
3961 3961
 
3962 3962
 
3963 3963
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3964
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3964
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3965 3965
         $settings_template_args['on_off_status'] = $active;
3966
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3966
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3967 3967
         return EEH_Template::display_template(
3968 3968
             $template,
3969 3969
             $settings_template_args,
@@ -3988,7 +3988,7 @@  discard block
 block discarded – undo
3988 3988
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
3989 3989
         // let's check that we have required data
3990 3990
 
3991
-        if (! $this->_active_messenger_name) {
3991
+        if ( ! $this->_active_messenger_name) {
3992 3992
             EE_Error::add_error(
3993 3993
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3994 3994
                 __FILE__,
@@ -4006,7 +4006,7 @@  discard block
 block discarded – undo
4006 4006
 
4007 4007
 
4008 4008
         $status = $this->request->getRequestParam('status');
4009
-        if (! $status) {
4009
+        if ( ! $status) {
4010 4010
             EE_Error::add_error(
4011 4011
                 esc_html__(
4012 4012
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4063,7 +4063,7 @@  discard block
 block discarded – undo
4063 4063
         $this->_prep_default_response_for_messenger_or_message_type_toggle();
4064 4064
 
4065 4065
         // let's make sure we have the necessary data
4066
-        if (! $this->_active_message_type_name) {
4066
+        if ( ! $this->_active_message_type_name) {
4067 4067
             EE_Error::add_error(
4068 4068
                 esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
4069 4069
                 __FILE__,
@@ -4073,7 +4073,7 @@  discard block
 block discarded – undo
4073 4073
             $success = false;
4074 4074
         }
4075 4075
 
4076
-        if (! $this->_active_messenger_name) {
4076
+        if ( ! $this->_active_messenger_name) {
4077 4077
             EE_Error::add_error(
4078 4078
                 esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
4079 4079
                 __FILE__,
@@ -4084,7 +4084,7 @@  discard block
 block discarded – undo
4084 4084
         }
4085 4085
 
4086 4086
         $status = $this->request->getRequestParam('status');
4087
-        if (! $status) {
4087
+        if ( ! $status) {
4088 4088
             EE_Error::add_error(
4089 4089
                 esc_html__(
4090 4090
                     'Messenger status needed to know whether activation or deactivation is happening. No status is given',
@@ -4296,7 +4296,7 @@  discard block
 block discarded – undo
4296 4296
         EE_Message_Type $message_type = null
4297 4297
     ) {
4298 4298
         // if $messenger isn't a valid messenger object then get out.
4299
-        if (! $messenger instanceof EE_Messenger) {
4299
+        if ( ! $messenger instanceof EE_Messenger) {
4300 4300
             EE_Error::add_error(
4301 4301
                 esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4302 4302
                 __FILE__,
@@ -4350,7 +4350,7 @@  discard block
 block discarded – undo
4350 4350
             // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4351 4351
             // in which case we just give a success message for the messenger being successfully activated.
4352 4352
         } else {
4353
-            if (! $messenger->get_default_message_types()) {
4353
+            if ( ! $messenger->get_default_message_types()) {
4354 4354
                 // messenger doesn't have any default message types so still a success.
4355 4355
                 EE_Error::add_success(
4356 4356
                     sprintf(
@@ -4406,7 +4406,7 @@  discard block
 block discarded – undo
4406 4406
         EE_Error::overwrite_success();
4407 4407
 
4408 4408
         // if $messenger isn't a valid messenger object then get out.
4409
-        if (! $messenger instanceof EE_Messenger) {
4409
+        if ( ! $messenger instanceof EE_Messenger) {
4410 4410
             EE_Error::add_error(
4411 4411
                 esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4412 4412
                 __FILE__,
@@ -4476,7 +4476,7 @@  discard block
 block discarded – undo
4476 4476
      */
4477 4477
     public function update_mt_form()
4478 4478
     {
4479
-        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4479
+        if ( ! $this->_active_messenger_name || ! $this->_active_message_type_name) {
4480 4480
             EE_Error::add_error(
4481 4481
                 esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4482 4482
                 __FILE__,
@@ -4487,7 +4487,7 @@  discard block
 block discarded – undo
4487 4487
         }
4488 4488
 
4489 4489
         $message_types = $this->get_installed_message_types();
4490
-        $message_type  = $message_types[ $this->_active_message_type_name ];
4490
+        $message_type  = $message_types[$this->_active_message_type_name];
4491 4491
         $messenger     = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);
4492 4492
         $content       = $this->_message_type_settings_content($message_type, $messenger, true);
4493 4493
 
@@ -4506,7 +4506,7 @@  discard block
 block discarded – undo
4506 4506
     public function save_settings()
4507 4507
     {
4508 4508
         $type = $this->request->getRequestParam('type');
4509
-        if (! $type) {
4509
+        if ( ! $type) {
4510 4510
             EE_Error::add_error(
4511 4511
                 esc_html__(
4512 4512
                     'Cannot save settings because type is unknown (messenger settings or message type settings?)',
Please login to merge, or discard this patch.
registration_form/espresso_events_Registration_Form_Hooks.class.php 2 patches
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -15,95 +15,95 @@  discard block
 block discarded – undo
15 15
 class espresso_events_Registration_Form_Hooks extends EE_Admin_Hooks
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Event|null
20
-     */
21
-    protected $_event;
22
-
23
-
24
-    protected function _set_hooks_properties()
25
-    {
26
-
27
-        $this->_name      = 'registration_form';
28
-        $this->_metaboxes = [
29
-            0 => [
30
-                'page_route' => ['edit', 'create_new'],
31
-                'func'       => 'primary_questions',
32
-                'label'      => esc_html__('Questions for Primary Registrant', 'event_espresso'),
33
-                'priority'   => 'default',
34
-                'context'    => 'side',
35
-            ],
36
-        ];
37
-
38
-        // hook into the handler for saving question groups
39
-        add_filter(
40
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
41
-            [$this, 'modify_callbacks'],
42
-            10
43
-        );
44
-
45
-        // hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already
46
-        // restricted by page)
47
-        add_action('AHEE_EE_Admin_Page_CPT__restore_revision', [$this, 'restore_revision'], 10, 2);
48
-    }
49
-
50
-
51
-    /**
52
-     * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook
53
-     *
54
-     * @param $callbacks
55
-     * @return array
56
-     */
57
-    public function modify_callbacks($callbacks)
58
-    {
59
-        // now let's add the question group callback
60
-        $callbacks[] = [$this, 'primary_question_group_update'];
61
-        return $callbacks;
62
-    }
63
-
64
-
65
-    /**
66
-     * Hooked into revision restores.
67
-     *
68
-     * @param $post_id
69
-     * @param $revision_id
70
-     * @return EE_Base_Class
71
-     * @throws EE_Error
72
-     * @throws InvalidArgumentException
73
-     * @throws InvalidDataTypeException
74
-     * @throws InvalidInterfaceException
75
-     */
76
-    public function restore_revision($post_id, $revision_id)
77
-    {
78
-        $post_evt = EEM_Event::instance()->get_one_by_ID($post_id);
79
-        // restore revision for primary questions
80
-        if ($post_evt instanceof EE_Event) {
81
-            $post_evt->restore_revision(
82
-                $revision_id,
83
-                ['Question_Group'],
84
-                ['Question_Group' => ['Event_Question_Group.EQG_primary' => true]]
85
-            );
86
-        }
87
-        return $post_evt;
88
-    }
89
-
90
-
91
-    /**
92
-     * Content of metabox.
93
-     *
94
-     * @param $post_id
95
-     * @param $post
96
-     * @throws EE_Error
97
-     * @throws InvalidArgumentException
98
-     * @throws InvalidDataTypeException
99
-     * @throws InvalidInterfaceException
100
-     * @throws ReflectionException
101
-     */
102
-    public function primary_questions($post_id, $post)
103
-    {
104
-        $this->_event = $this->_adminpage_obj->get_event_object();
105
-        $event_id     = $this->_event->ID();
106
-        ?>
18
+	/**
19
+	 * @var EE_Event|null
20
+	 */
21
+	protected $_event;
22
+
23
+
24
+	protected function _set_hooks_properties()
25
+	{
26
+
27
+		$this->_name      = 'registration_form';
28
+		$this->_metaboxes = [
29
+			0 => [
30
+				'page_route' => ['edit', 'create_new'],
31
+				'func'       => 'primary_questions',
32
+				'label'      => esc_html__('Questions for Primary Registrant', 'event_espresso'),
33
+				'priority'   => 'default',
34
+				'context'    => 'side',
35
+			],
36
+		];
37
+
38
+		// hook into the handler for saving question groups
39
+		add_filter(
40
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
41
+			[$this, 'modify_callbacks'],
42
+			10
43
+		);
44
+
45
+		// hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already
46
+		// restricted by page)
47
+		add_action('AHEE_EE_Admin_Page_CPT__restore_revision', [$this, 'restore_revision'], 10, 2);
48
+	}
49
+
50
+
51
+	/**
52
+	 * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook
53
+	 *
54
+	 * @param $callbacks
55
+	 * @return array
56
+	 */
57
+	public function modify_callbacks($callbacks)
58
+	{
59
+		// now let's add the question group callback
60
+		$callbacks[] = [$this, 'primary_question_group_update'];
61
+		return $callbacks;
62
+	}
63
+
64
+
65
+	/**
66
+	 * Hooked into revision restores.
67
+	 *
68
+	 * @param $post_id
69
+	 * @param $revision_id
70
+	 * @return EE_Base_Class
71
+	 * @throws EE_Error
72
+	 * @throws InvalidArgumentException
73
+	 * @throws InvalidDataTypeException
74
+	 * @throws InvalidInterfaceException
75
+	 */
76
+	public function restore_revision($post_id, $revision_id)
77
+	{
78
+		$post_evt = EEM_Event::instance()->get_one_by_ID($post_id);
79
+		// restore revision for primary questions
80
+		if ($post_evt instanceof EE_Event) {
81
+			$post_evt->restore_revision(
82
+				$revision_id,
83
+				['Question_Group'],
84
+				['Question_Group' => ['Event_Question_Group.EQG_primary' => true]]
85
+			);
86
+		}
87
+		return $post_evt;
88
+	}
89
+
90
+
91
+	/**
92
+	 * Content of metabox.
93
+	 *
94
+	 * @param $post_id
95
+	 * @param $post
96
+	 * @throws EE_Error
97
+	 * @throws InvalidArgumentException
98
+	 * @throws InvalidDataTypeException
99
+	 * @throws InvalidInterfaceException
100
+	 * @throws ReflectionException
101
+	 */
102
+	public function primary_questions($post_id, $post)
103
+	{
104
+		$this->_event = $this->_adminpage_obj->get_event_object();
105
+		$event_id     = $this->_event->ID();
106
+		?>
107 107
         <div class="inside">
108 108
             <p>
109 109
                 <strong>
@@ -111,64 +111,64 @@  discard block
 block discarded – undo
111 111
                 </strong>
112 112
                 <br />
113 113
                 <?php
114
-                printf(
115
-                    esc_html__(
116
-                        'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events',
117
-                        'event_espresso'
118
-                    ),
119
-                    '<a href="admin.php?page=espresso_registration_form" target="_blank">',
120
-                    '</a>'
121
-                )
122
-                ?>
114
+				printf(
115
+					esc_html__(
116
+						'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events',
117
+						'event_espresso'
118
+					),
119
+					'<a href="admin.php?page=espresso_registration_form" target="_blank">',
120
+					'</a>'
121
+				)
122
+				?>
123 123
             </p>
124 124
             <?php
125 125
 
126
-            $qsg_where['QSG_deleted'] = false;
127
-            $query_params             = apply_filters(
128
-                'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters',
129
-                [$qsg_where, 'order_by' => ['QSG_order' => 'ASC']]
130
-            );
131
-            $QSGs                     = EEM_Question_Group::instance()->get_all($query_params);
132
-            $EQGs                     = ! empty($event_id)
133
-                ? $this->_event->get_many_related(
134
-                    'Question_Group',
135
-                    [['Event_Question_Group.EQG_primary' => true]]
136
-                )
137
-                : [];
138
-            $EQGids                   = array_keys($EQGs);
139
-
140
-            if (! empty($QSGs)) {
141
-                $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
142
-                foreach ($QSGs as $QSG) {
143
-                    $QSG_ID          = absint($QSG->ID());
144
-                    $checked         = in_array($QSG_ID, $EQGids, true) || $QSG->get('QSG_system') === 1
145
-                        ? ' checked="checked"'
146
-                        : '';
147
-                    $visibility      = $QSG->get('QSG_system') === 1
148
-                        ? ' style="visibility:hidden"'
149
-                        : '';
150
-                    $edit_query_args = $this->_adminpage_obj->is_caf()
151
-                        ? [
152
-                            'action' => 'edit_question_group',
153
-                            'QSG_ID' => $QSG_ID,
154
-                        ]
155
-                        : ['action' => 'question_groups'];
156
-                    $edit_link       = EE_Admin_Page::add_query_args_and_nonce(
157
-                        $edit_query_args,
158
-                        EE_FORMS_ADMIN_URL
159
-                    );
160
-                    $edit_link_title = sprintf(
161
-                        esc_attr__('Edit %s Group', 'event_espresso'),
162
-                        $QSG->get('QSG_name')
163
-                    );
164
-
165
-                    $html .= '
126
+			$qsg_where['QSG_deleted'] = false;
127
+			$query_params             = apply_filters(
128
+				'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters',
129
+				[$qsg_where, 'order_by' => ['QSG_order' => 'ASC']]
130
+			);
131
+			$QSGs                     = EEM_Question_Group::instance()->get_all($query_params);
132
+			$EQGs                     = ! empty($event_id)
133
+				? $this->_event->get_many_related(
134
+					'Question_Group',
135
+					[['Event_Question_Group.EQG_primary' => true]]
136
+				)
137
+				: [];
138
+			$EQGids                   = array_keys($EQGs);
139
+
140
+			if (! empty($QSGs)) {
141
+				$html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
142
+				foreach ($QSGs as $QSG) {
143
+					$QSG_ID          = absint($QSG->ID());
144
+					$checked         = in_array($QSG_ID, $EQGids, true) || $QSG->get('QSG_system') === 1
145
+						? ' checked="checked"'
146
+						: '';
147
+					$visibility      = $QSG->get('QSG_system') === 1
148
+						? ' style="visibility:hidden"'
149
+						: '';
150
+					$edit_query_args = $this->_adminpage_obj->is_caf()
151
+						? [
152
+							'action' => 'edit_question_group',
153
+							'QSG_ID' => $QSG_ID,
154
+						]
155
+						: ['action' => 'question_groups'];
156
+					$edit_link       = EE_Admin_Page::add_query_args_and_nonce(
157
+						$edit_query_args,
158
+						EE_FORMS_ADMIN_URL
159
+					);
160
+					$edit_link_title = sprintf(
161
+						esc_attr__('Edit %s Group', 'event_espresso'),
162
+						$QSG->get('QSG_name')
163
+					);
164
+
165
+					$html .= '
166 166
 					<p id="event-question-group-' . $QSG_ID . '">
167 167
 						<input value="' . $QSG_ID . '" 
168 168
 						    type="checkbox"
169 169
 						    name="question_groups[' . $QSG_ID . ']" '
170
-                             . $visibility
171
-                             . $checked . ' 
170
+							 . $visibility
171
+							 . $checked . ' 
172 172
                         />
173 173
 						<a href="' . esc_url_raw($edit_link) . '" 
174 174
 						    title="' . esc_attr($edit_link_title) . '" 
@@ -177,63 +177,63 @@  discard block
 block discarded – undo
177 177
 						    ' . $QSG->get('QSG_name') . '
178 178
                         </a>
179 179
 					</p>';
180
-                }
181
-                $html .= count($QSGs) > 10 ? '</div>' : '';
182
-
183
-                echo $html; // already escaped
184
-            } else {
185
-                esc_html_e(
186
-                    'There seems to be a problem with your questions. Please contact [email protected]',
187
-                    'event_espresso'
188
-                );
189
-            }
190
-            do_action('AHEE_event_editor_questions_notice');
191
-            ?>
180
+				}
181
+				$html .= count($QSGs) > 10 ? '</div>' : '';
182
+
183
+				echo $html; // already escaped
184
+			} else {
185
+				esc_html_e(
186
+					'There seems to be a problem with your questions. Please contact [email protected]',
187
+					'event_espresso'
188
+				);
189
+			}
190
+			do_action('AHEE_event_editor_questions_notice');
191
+			?>
192 192
         </div>
193 193
         <?php
194
-    }
195
-
196
-
197
-    /**
198
-     * @param EE_Event $event
199
-     * @param array    $data
200
-     * @return bool
201
-     * @throws EE_Error
202
-     * @throws ReflectionException
203
-     */
204
-    public function primary_question_group_update($event, $data)
205
-    {
206
-        $question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : [];
207
-        $added_qgs       = array_keys($question_groups);
208
-        $success         = true;
209
-
210
-        // let's get all current question groups associated with this event.
211
-        $current_qgs = $event->get_many_related(
212
-            'Question_Group',
213
-            [['Event_Question_Group.EQG_primary' => true]]
214
-        );
215
-        $current_qgs = array_keys($current_qgs); // we just want the ids
216
-
217
-        // now let's get the groups selected in the editor and update (IF we have data)
218
-        if (! empty($question_groups)) {
219
-            foreach ($question_groups as $QSG_ID => $val) {
220
-                // add to event
221
-                if ($val) {
222
-                    $qg = $event->_add_relation_to($QSG_ID, 'Question_Group', ['EQG_primary' => true]);
223
-                }
224
-                // trip success to false if result is empty
225
-                $success = ! empty($qg) ? $success : false;
226
-            }
227
-        }
228
-
229
-        // wait a minute... are there question groups missing in the saved groups that ARE with the current event?
230
-        $removed_qgs = array_diff($current_qgs, $added_qgs);
231
-
232
-        foreach ($removed_qgs as $QSG_ID) {
233
-            $qg = $event->_remove_relation_to($QSG_ID, 'Question_Group', ['EQG_primary' => true]);
234
-            // trip success to false if result is empty
235
-            $success = ! empty($qg) ? $success : false;
236
-        }
237
-        return $success;
238
-    }
194
+	}
195
+
196
+
197
+	/**
198
+	 * @param EE_Event $event
199
+	 * @param array    $data
200
+	 * @return bool
201
+	 * @throws EE_Error
202
+	 * @throws ReflectionException
203
+	 */
204
+	public function primary_question_group_update($event, $data)
205
+	{
206
+		$question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : [];
207
+		$added_qgs       = array_keys($question_groups);
208
+		$success         = true;
209
+
210
+		// let's get all current question groups associated with this event.
211
+		$current_qgs = $event->get_many_related(
212
+			'Question_Group',
213
+			[['Event_Question_Group.EQG_primary' => true]]
214
+		);
215
+		$current_qgs = array_keys($current_qgs); // we just want the ids
216
+
217
+		// now let's get the groups selected in the editor and update (IF we have data)
218
+		if (! empty($question_groups)) {
219
+			foreach ($question_groups as $QSG_ID => $val) {
220
+				// add to event
221
+				if ($val) {
222
+					$qg = $event->_add_relation_to($QSG_ID, 'Question_Group', ['EQG_primary' => true]);
223
+				}
224
+				// trip success to false if result is empty
225
+				$success = ! empty($qg) ? $success : false;
226
+			}
227
+		}
228
+
229
+		// wait a minute... are there question groups missing in the saved groups that ARE with the current event?
230
+		$removed_qgs = array_diff($current_qgs, $added_qgs);
231
+
232
+		foreach ($removed_qgs as $QSG_ID) {
233
+			$qg = $event->_remove_relation_to($QSG_ID, 'Question_Group', ['EQG_primary' => true]);
234
+			// trip success to false if result is empty
235
+			$success = ! empty($qg) ? $success : false;
236
+		}
237
+		return $success;
238
+	}
239 239
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
                     [['Event_Question_Group.EQG_primary' => true]]
136 136
                 )
137 137
                 : [];
138
-            $EQGids                   = array_keys($EQGs);
138
+            $EQGids = array_keys($EQGs);
139 139
 
140
-            if (! empty($QSGs)) {
140
+            if ( ! empty($QSGs)) {
141 141
                 $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : '';
142 142
                 foreach ($QSGs as $QSG) {
143 143
                     $QSG_ID          = absint($QSG->ID());
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
                             'QSG_ID' => $QSG_ID,
154 154
                         ]
155 155
                         : ['action' => 'question_groups'];
156
-                    $edit_link       = EE_Admin_Page::add_query_args_and_nonce(
156
+                    $edit_link = EE_Admin_Page::add_query_args_and_nonce(
157 157
                         $edit_query_args,
158 158
                         EE_FORMS_ADMIN_URL
159 159
                     );
@@ -163,18 +163,18 @@  discard block
 block discarded – undo
163 163
                     );
164 164
 
165 165
                     $html .= '
166
-					<p id="event-question-group-' . $QSG_ID . '">
167
-						<input value="' . $QSG_ID . '" 
166
+					<p id="event-question-group-' . $QSG_ID.'">
167
+						<input value="' . $QSG_ID.'" 
168 168
 						    type="checkbox"
169
-						    name="question_groups[' . $QSG_ID . ']" '
169
+						    name="question_groups[' . $QSG_ID.']" '
170 170
                              . $visibility
171
-                             . $checked . ' 
171
+                             . $checked.' 
172 172
                         />
173
-						<a href="' . esc_url_raw($edit_link) . '" 
174
-						    title="' . esc_attr($edit_link_title) . '" 
173
+						<a href="' . esc_url_raw($edit_link).'" 
174
+						    title="' . esc_attr($edit_link_title).'" 
175 175
 						    target="_blank"
176 176
 						    >
177
-						    ' . $QSG->get('QSG_name') . '
177
+						    ' . $QSG->get('QSG_name').'
178 178
                         </a>
179 179
 					</p>';
180 180
                 }
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
         $current_qgs = array_keys($current_qgs); // we just want the ids
216 216
 
217 217
         // now let's get the groups selected in the editor and update (IF we have data)
218
-        if (! empty($question_groups)) {
218
+        if ( ! empty($question_groups)) {
219 219
             foreach ($question_groups as $QSG_ID => $val) {
220 220
                 // add to event
221 221
                 if ($val) {
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.29.rc.021');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.29.rc.021');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.