Completed
Branch BUG/escape-localized-variables (d40cc7)
by
unknown
09:56 queued 08:24
created
core/libraries/plugin_api/EE_Register_Addon.lib.php 2 patches
Indentation   +1233 added lines, -1233 removed lines patch added patch discarded remove patch
@@ -22,1237 +22,1237 @@
 block discarded – undo
22 22
 class EE_Register_Addon implements EEI_Plugin_API
23 23
 {
24 24
 
25
-    /**
26
-     * possibly truncated version of the EE core version string
27
-     *
28
-     * @var string
29
-     */
30
-    protected static $_core_version = '';
31
-
32
-    /**
33
-     * Holds values for registered addons
34
-     *
35
-     * @var array
36
-     */
37
-    protected static $_settings = array();
38
-
39
-    /**
40
-     * @var  array $_incompatible_addons keys are addon SLUGS
41
-     * (first argument passed to EE_Register_Addon::register()), keys are
42
-     * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
43
-     * Generally this should be used sparingly, as we don't want to muddle up
44
-     * EE core with knowledge of ALL the addons out there.
45
-     * If you want NO versions of an addon to run with a certain version of core,
46
-     * it's usually best to define the addon's "min_core_version" as part of its call
47
-     * to EE_Register_Addon::register(), rather than using this array with a super high value for its
48
-     * minimum plugin version.
49
-     * @access    protected
50
-     */
51
-    protected static $_incompatible_addons = array(
52
-        'Multi_Event_Registration' => '2.0.11.rc.002',
53
-        'Promotions'               => '1.0.0.rc.084',
54
-    );
55
-
56
-
57
-    /**
58
-     * We should always be comparing core to a version like '4.3.0.rc.000',
59
-     * not just '4.3.0'.
60
-     * So if the addon developer doesn't provide that full version string,
61
-     * fill in the blanks for them
62
-     *
63
-     * @param string $min_core_version
64
-     * @return string always like '4.3.0.rc.000'
65
-     */
66
-    protected static function _effective_version($min_core_version)
67
-    {
68
-        // versions: 4 . 3 . 1 . p . 123
69
-        // offsets:    0 . 1 . 2 . 3 . 4
70
-        $version_parts = explode('.', $min_core_version);
71
-        // check they specified the micro version (after 2nd period)
72
-        if (! isset($version_parts[2])) {
73
-            $version_parts[2] = '0';
74
-        }
75
-        // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
76
-        // soon we can assume that's 'rc', but this current version is 'alpha'
77
-        if (! isset($version_parts[3])) {
78
-            $version_parts[3] = 'dev';
79
-        }
80
-        if (! isset($version_parts[4])) {
81
-            $version_parts[4] = '000';
82
-        }
83
-        return implode('.', $version_parts);
84
-    }
85
-
86
-
87
-    /**
88
-     * Returns whether or not the min core version requirement of the addon is met
89
-     *
90
-     * @param string $min_core_version    the minimum core version required by the addon
91
-     * @param string $actual_core_version the actual core version, optional
92
-     * @return boolean
93
-     */
94
-    public static function _meets_min_core_version_requirement(
95
-        $min_core_version,
96
-        $actual_core_version = EVENT_ESPRESSO_VERSION
97
-    ) {
98
-        return version_compare(
99
-            self::_effective_version($actual_core_version),
100
-            self::_effective_version($min_core_version),
101
-            '>='
102
-        );
103
-    }
104
-
105
-
106
-    /**
107
-     * Method for registering new EE_Addons.
108
-     * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
109
-     * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
110
-     * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
111
-     * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
112
-     * 'activate_plugin', it registers the addon still, but its components are not registered
113
-     * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
114
-     * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
115
-     * (so that we can detect that the addon has activated on the subsequent request)
116
-     *
117
-     * @since    4.3.0
118
-     * @param string                  $addon_name                       [Required] the EE_Addon's name.
119
-     * @param  array                  $setup_args                       {
120
-     *                                                                  An array of arguments provided for registering
121
-     *                                                                  the message type.
122
-     * @type  string                  $class_name                       the addon's main file name.
123
-     *                                                                  If left blank, generated from the addon name,
124
-     *                                                                  changes something like "calendar" to
125
-     *                                                                  "EE_Calendar"
126
-     * @type string                   $min_core_version                 the minimum version of EE Core that the
127
-     *                                                                  addon will work with. eg "4.8.1.rc.084"
128
-     * @type string                   $version                          the "software" version for the addon. eg
129
-     *                                                                  "1.0.0.p" for a first stable release, or
130
-     *                                                                  "1.0.0.rc.043" for a version in progress
131
-     * @type string                   $main_file_path                   the full server path to the main file
132
-     *                                                                  loaded directly by WP
133
-     * @type DomainInterface $domain                                    child class of
134
-     *                                                                  EventEspresso\core\domain\DomainBase
135
-     * @type string                   $domain_fqcn                      Fully Qualified Class Name
136
-     *                                                                  for the addon's Domain class
137
-     *                                                                  (see EventEspresso\core\domain\Domain)
138
-     * @type string                   $admin_path                       full server path to the folder where the
139
-     *                                                                  addon\'s admin files reside
140
-     * @type string                   $admin_callback                   a method to be called when the EE Admin is
141
-     *                                                                  first invoked, can be used for hooking into
142
-     *                                                                  any admin page
143
-     * @type string                   $config_section                   the section name for this addon's
144
-     *                                                                  configuration settings section
145
-     *                                                                  (defaults to "addons")
146
-     * @type string                   $config_class                     the class name for this addon's
147
-     *                                                                  configuration settings object
148
-     * @type string                   $config_name                      the class name for this addon's
149
-     *                                                                  configuration settings object
150
-     * @type string                   $autoloader_paths                 [Required] an array of class names and the full
151
-     *                                                                  server paths to those files.
152
-     * @type string                   $autoloader_folders               an array of  "full server paths" for any
153
-     *                                                                  folders containing classes that might be
154
-     *                                                                  invoked by the addon
155
-     * @type string                   $dms_paths                        [Required] an array of full server paths to
156
-     *                                                                  folders that contain data migration scripts.
157
-     *                                                                  The key should be the EE_Addon class name that
158
-     *                                                                  this set of data migration scripts belongs to.
159
-     *                                                                  If the EE_Addon class is namespaced, then this
160
-     *                                                                  needs to be the Fully Qualified Class Name
161
-     * @type string                   $module_paths                     an array of full server paths to any
162
-     *                                                                  EED_Modules used by the addon
163
-     * @type string                   $shortcode_paths                  an array of full server paths to folders
164
-     *                                                                  that contain EES_Shortcodes
165
-     * @type string                   $widget_paths                     an array of full server paths to folders
166
-     *                                                                  that contain WP_Widgets
167
-     * @type string                   $pue_options
168
-     * @type array                    $capabilities                     an array indexed by role name
169
-     *                                                                  (i.e administrator,author ) and the values
170
-     *                                                                  are an array of caps to add to the role.
171
-     *                                                                  'administrator' => array(
172
-     *                                                                  'read_addon',
173
-     *                                                                  'edit_addon',
174
-     *                                                                  etc.
175
-     *                                                                  ).
176
-     * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
177
-     *                                                                  for any addons that need to register any
178
-     *                                                                  special meta mapped capabilities.  Should
179
-     *                                                                  be indexed where the key is the
180
-     *                                                                  EE_Meta_Capability_Map class name and the
181
-     *                                                                  values are the arguments sent to the class.
182
-     * @type array                    $model_paths                      array of folders containing DB models
183
-     * @see      EE_Register_Model
184
-     * @type array                    $class_paths                      array of folders containing DB classes
185
-     * @see      EE_Register_Model
186
-     * @type array                    $model_extension_paths            array of folders containing DB model
187
-     *                                                                  extensions
188
-     * @see      EE_Register_Model_Extension
189
-     * @type array                    $class_extension_paths            array of folders containing DB class
190
-     *                                                                  extensions
191
-     * @see      EE_Register_Model_Extension
192
-     * @type array message_types {
193
-     *                                                                  An array of message types with the key as
194
-     *                                                                  the message type name and the values as
195
-     *                                                                  below:
196
-     * @type string                   $mtfilename                       [Required] The filename of the message type
197
-     *                                                                  being registered. This will be the main
198
-     *                                                                  EE_{Message Type Name}_message_type class.
199
-     *                                                                  for example:
200
-     *                                                                  EE_Declined_Registration_message_type.class.php
201
-     * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
202
-     *                                                                  messages autoloader for the new message type.
203
-     * @type array                    $messengers_to_activate_with      An array of messengers that this message
204
-     *                                                                  type should activate with. Each value in
205
-     *                                                                  the
206
-     *                                                                  array
207
-     *                                                                  should match the name property of a
208
-     *                                                                  EE_messenger. Optional.
209
-     * @type array                    $messengers_to_validate_with      An array of messengers that this message
210
-     *                                                                  type should validate with. Each value in
211
-     *                                                                  the
212
-     *                                                                  array
213
-     *                                                                  should match the name property of an
214
-     *                                                                  EE_messenger.
215
-     *                                                                  Optional.
216
-     *                                                                  }
217
-     * @type array                    $custom_post_types
218
-     * @type array                    $custom_taxonomies
219
-     * @type array                    $payment_method_paths             each element is the folder containing the
220
-     *                                                                  EE_PMT_Base child class
221
-     *                                                                  (eg,
222
-     *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
223
-     *                                                                  which contains the files
224
-     *                                                                  EE_PMT_Payomatic.pm.php)
225
-     * @type array                    $default_terms
226
-     * @type array                    $namespace                        {
227
-     *                                                                  An array with two items for registering the
228
-     *                                                                  addon's namespace. (If, for some reason, you
229
-     *                                                                  require additional namespaces,
230
-     *                                                                  use
231
-     *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
232
-     *                                                                  directly)
233
-     * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
234
-     * @type string                   $FQNS                             the namespace prefix
235
-     * @type string                   $DIR                              a base directory for class files in the
236
-     *                                                                  namespace.
237
-     *                                                                  }
238
-     *                                                                  }
239
-     * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
240
-     *                                                                  privacy policy classes) or FQCNs (specific
241
-     *                                                                  classnames of privacy policy classes)
242
-     * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
243
-     *                                                                  privacy policy classes) or FQCNs (specific
244
-     *                                                                  classnames of privacy policy classes)
245
-     * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
246
-     *                                                                  privacy policy classes) or FQCNs (specific
247
-     *                                                                  classnames of privacy policy classes)
248
-     * @return void
249
-     * @throws DomainException
250
-     * @throws EE_Error
251
-     * @throws InvalidArgumentException
252
-     * @throws InvalidDataTypeException
253
-     * @throws InvalidInterfaceException
254
-     */
255
-    public static function register($addon_name = '', array $setup_args = array())
256
-    {
257
-        // required fields MUST be present, so let's make sure they are.
258
-        EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
259
-        // get class name for addon
260
-        $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
261
-        // setup $_settings array from incoming values.
262
-        $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
263
-        // setup PUE
264
-        EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
265
-        // does this addon work with this version of core or WordPress ?
266
-        // does this addon work with this version of core or WordPress ?
267
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
268
-            return;
269
-        }
270
-        // register namespaces
271
-        EE_Register_Addon::_setup_namespaces($addon_settings);
272
-        // check if this is an activation request
273
-        if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
274
-            // dont bother setting up the rest of the addon atm
275
-            return;
276
-        }
277
-        // we need cars
278
-        EE_Register_Addon::_setup_autoloaders($addon_name);
279
-        // register new models and extensions
280
-        EE_Register_Addon::_register_models_and_extensions($addon_name);
281
-        // setup DMS
282
-        EE_Register_Addon::_register_data_migration_scripts($addon_name);
283
-        // if config_class is present let's register config.
284
-        EE_Register_Addon::_register_config($addon_name);
285
-        // register admin pages
286
-        EE_Register_Addon::_register_admin_pages($addon_name);
287
-        // add to list of modules to be registered
288
-        EE_Register_Addon::_register_modules($addon_name);
289
-        // add to list of shortcodes to be registered
290
-        EE_Register_Addon::_register_shortcodes($addon_name);
291
-        // add to list of widgets to be registered
292
-        EE_Register_Addon::_register_widgets($addon_name);
293
-        // register capability related stuff.
294
-        EE_Register_Addon::_register_capabilities($addon_name);
295
-        // any message type to register?
296
-        EE_Register_Addon::_register_message_types($addon_name);
297
-        // any custom post type/ custom capabilities or default terms to register
298
-        EE_Register_Addon::_register_custom_post_types($addon_name);
299
-        // and any payment methods
300
-        EE_Register_Addon::_register_payment_methods($addon_name);
301
-        // and privacy policy generators
302
-        EE_Register_Addon::registerPrivacyPolicies($addon_name);
303
-        // and privacy policy generators
304
-        EE_Register_Addon::registerPersonalDataExporters($addon_name);
305
-        // and privacy policy generators
306
-        EE_Register_Addon::registerPersonalDataErasers($addon_name);
307
-        // load and instantiate main addon class
308
-        $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
309
-        // delay calling after_registration hook on each addon until after all add-ons have been registered.
310
-        add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999);
311
-    }
312
-
313
-
314
-    /**
315
-     * @param string $addon_name
316
-     * @param array  $setup_args
317
-     * @return void
318
-     * @throws EE_Error
319
-     */
320
-    private static function _verify_parameters($addon_name, array $setup_args)
321
-    {
322
-        // required fields MUST be present, so let's make sure they are.
323
-        if (empty($addon_name) || ! is_array($setup_args)) {
324
-            throw new EE_Error(
325
-                __(
326
-                    'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
327
-                    'event_espresso'
328
-                )
329
-            );
330
-        }
331
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
332
-            throw new EE_Error(
333
-                sprintf(
334
-                    __(
335
-                        'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
336
-                        'event_espresso'
337
-                    ),
338
-                    implode(',', array_keys($setup_args))
339
-                )
340
-            );
341
-        }
342
-        // check that addon has not already been registered with that name
343
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
344
-            throw new EE_Error(
345
-                sprintf(
346
-                    __(
347
-                        'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
348
-                        'event_espresso'
349
-                    ),
350
-                    $addon_name
351
-                )
352
-            );
353
-        }
354
-    }
355
-
356
-
357
-    /**
358
-     * @param string $addon_name
359
-     * @param array  $setup_args
360
-     * @return string
361
-     */
362
-    private static function _parse_class_name($addon_name, array $setup_args)
363
-    {
364
-        if (empty($setup_args['class_name'])) {
365
-            // generate one by first separating name with spaces
366
-            $class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
367
-            // capitalize, then replace spaces with underscores
368
-            $class_name = str_replace(' ', '_', ucwords($class_name));
369
-        } else {
370
-            $class_name = $setup_args['class_name'];
371
-        }
372
-        // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
373
-        return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
374
-            ? $class_name
375
-            : 'EE_' . $class_name;
376
-    }
377
-
378
-
379
-    /**
380
-     * @param string $class_name
381
-     * @param array  $setup_args
382
-     * @return array
383
-     */
384
-    private static function _get_addon_settings($class_name, array $setup_args)
385
-    {
386
-        // setup $_settings array from incoming values.
387
-        $addon_settings = array(
388
-            // generated from the addon name, changes something like "calendar" to "EE_Calendar"
389
-            'class_name'            => $class_name,
390
-            // the addon slug for use in URLs, etc
391
-            'plugin_slug'           => isset($setup_args['plugin_slug'])
392
-                ? (string) $setup_args['plugin_slug']
393
-                : '',
394
-            // page slug to be used when generating the "Settings" link on the WP plugin page
395
-            'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
396
-                ? (string) $setup_args['plugin_action_slug']
397
-                : '',
398
-            // the "software" version for the addon
399
-            'version'               => isset($setup_args['version'])
400
-                ? (string) $setup_args['version']
401
-                : '',
402
-            // the minimum version of EE Core that the addon will work with
403
-            'min_core_version'      => isset($setup_args['min_core_version'])
404
-                ? (string) $setup_args['min_core_version']
405
-                : '',
406
-            // the minimum version of WordPress that the addon will work with
407
-            'min_wp_version'        => isset($setup_args['min_wp_version'])
408
-                ? (string) $setup_args['min_wp_version']
409
-                : EE_MIN_WP_VER_REQUIRED,
410
-            // full server path to main file (file loaded directly by WP)
411
-            'main_file_path'        => isset($setup_args['main_file_path'])
412
-                ? (string) $setup_args['main_file_path']
413
-                : '',
414
-            // instance of \EventEspresso\core\domain\DomainInterface
415
-            'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
416
-                ? $setup_args['domain']
417
-                : null,
418
-            // Fully Qualified Class Name for the addon's Domain class
419
-            'domain_fqcn'           => isset($setup_args['domain_fqcn'])
420
-                ? (string) $setup_args['domain_fqcn']
421
-                : '',
422
-            // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
423
-            'admin_path'            => isset($setup_args['admin_path'])
424
-                ? (string) $setup_args['admin_path'] : '',
425
-            // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
426
-            'admin_callback'        => isset($setup_args['admin_callback'])
427
-                ? (string) $setup_args['admin_callback']
428
-                : '',
429
-            // the section name for this addon's configuration settings section (defaults to "addons")
430
-            'config_section'        => isset($setup_args['config_section'])
431
-                ? (string) $setup_args['config_section']
432
-                : 'addons',
433
-            // the class name for this addon's configuration settings object
434
-            'config_class'          => isset($setup_args['config_class'])
435
-                ? (string) $setup_args['config_class'] : '',
436
-            // the name given to the config for this addons' configuration settings object (optional)
437
-            'config_name'           => isset($setup_args['config_name'])
438
-                ? (string) $setup_args['config_name'] : '',
439
-            // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
440
-            'autoloader_paths'      => isset($setup_args['autoloader_paths'])
441
-                ? (array) $setup_args['autoloader_paths']
442
-                : array(),
443
-            // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
444
-            'autoloader_folders'    => isset($setup_args['autoloader_folders'])
445
-                ? (array) $setup_args['autoloader_folders']
446
-                : array(),
447
-            // array of full server paths to any EE_DMS data migration scripts used by the addon.
448
-            // The key should be the EE_Addon class name that this set of data migration scripts belongs to.
449
-            // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
450
-            'dms_paths'             => isset($setup_args['dms_paths'])
451
-                ? (array) $setup_args['dms_paths']
452
-                : array(),
453
-            // array of full server paths to any EED_Modules used by the addon
454
-            'module_paths'          => isset($setup_args['module_paths'])
455
-                ? (array) $setup_args['module_paths']
456
-                : array(),
457
-            // array of full server paths to any EES_Shortcodes used by the addon
458
-            'shortcode_paths'       => isset($setup_args['shortcode_paths'])
459
-                ? (array) $setup_args['shortcode_paths']
460
-                : array(),
461
-            'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
462
-                ? (array) $setup_args['shortcode_fqcns']
463
-                : array(),
464
-            // array of full server paths to any WP_Widgets used by the addon
465
-            'widget_paths'          => isset($setup_args['widget_paths'])
466
-                ? (array) $setup_args['widget_paths']
467
-                : array(),
468
-            // array of PUE options used by the addon
469
-            'pue_options'           => isset($setup_args['pue_options'])
470
-                ? (array) $setup_args['pue_options']
471
-                : array(),
472
-            'message_types'         => isset($setup_args['message_types'])
473
-                ? (array) $setup_args['message_types']
474
-                : array(),
475
-            'capabilities'          => isset($setup_args['capabilities'])
476
-                ? (array) $setup_args['capabilities']
477
-                : array(),
478
-            'capability_maps'       => isset($setup_args['capability_maps'])
479
-                ? (array) $setup_args['capability_maps']
480
-                : array(),
481
-            'model_paths'           => isset($setup_args['model_paths'])
482
-                ? (array) $setup_args['model_paths']
483
-                : array(),
484
-            'class_paths'           => isset($setup_args['class_paths'])
485
-                ? (array) $setup_args['class_paths']
486
-                : array(),
487
-            'model_extension_paths' => isset($setup_args['model_extension_paths'])
488
-                ? (array) $setup_args['model_extension_paths']
489
-                : array(),
490
-            'class_extension_paths' => isset($setup_args['class_extension_paths'])
491
-                ? (array) $setup_args['class_extension_paths']
492
-                : array(),
493
-            'custom_post_types'     => isset($setup_args['custom_post_types'])
494
-                ? (array) $setup_args['custom_post_types']
495
-                : array(),
496
-            'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
497
-                ? (array) $setup_args['custom_taxonomies']
498
-                : array(),
499
-            'payment_method_paths'  => isset($setup_args['payment_method_paths'])
500
-                ? (array) $setup_args['payment_method_paths']
501
-                : array(),
502
-            'default_terms'         => isset($setup_args['default_terms'])
503
-                ? (array) $setup_args['default_terms']
504
-                : array(),
505
-            // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
506
-            // that can be used for adding upgrading/marketing info
507
-            'plugins_page_row'      => isset($setup_args['plugins_page_row']) ? $setup_args['plugins_page_row'] : '',
508
-            'namespace'             => isset(
509
-                $setup_args['namespace']['FQNS'],
510
-                $setup_args['namespace']['DIR']
511
-            )
512
-                ? (array) $setup_args['namespace']
513
-                : array(),
514
-            'privacy_policies'      => isset($setup_args['privacy_policies'])
515
-                ? (array) $setup_args['privacy_policies']
516
-                : '',
517
-        );
518
-        // if plugin_action_slug is NOT set, but an admin page path IS set,
519
-        // then let's just use the plugin_slug since that will be used for linking to the admin page
520
-        $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
521
-                                                && ! empty($addon_settings['admin_path'])
522
-            ? $addon_settings['plugin_slug']
523
-            : $addon_settings['plugin_action_slug'];
524
-        // full server path to main file (file loaded directly by WP)
525
-        $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
526
-        return $addon_settings;
527
-    }
528
-
529
-
530
-    /**
531
-     * @param string $addon_name
532
-     * @param array  $addon_settings
533
-     * @return boolean
534
-     */
535
-    private static function _addon_is_compatible($addon_name, array $addon_settings)
536
-    {
537
-        global $wp_version;
538
-        $incompatibility_message = '';
539
-        // check whether this addon version is compatible with EE core
540
-        if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
541
-            && ! self::_meets_min_core_version_requirement(
542
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
543
-                $addon_settings['version']
544
-            )
545
-        ) {
546
-            $incompatibility_message = sprintf(
547
-                __(
548
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
549
-                    'event_espresso'
550
-                ),
551
-                $addon_name,
552
-                '<br />',
553
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
554
-                '<span style="font-weight: bold; color: #D54E21;">',
555
-                '</span><br />'
556
-            );
557
-        } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
558
-        ) {
559
-            $incompatibility_message = sprintf(
560
-                __(
561
-                    '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
562
-                    'event_espresso'
563
-                ),
564
-                $addon_name,
565
-                self::_effective_version($addon_settings['min_core_version']),
566
-                self::_effective_version(espresso_version()),
567
-                '<br />',
568
-                '<span style="font-weight: bold; color: #D54E21;">',
569
-                '</span><br />'
570
-            );
571
-        } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
572
-            $incompatibility_message = sprintf(
573
-                __(
574
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
575
-                    'event_espresso'
576
-                ),
577
-                $addon_name,
578
-                $addon_settings['min_wp_version'],
579
-                '<br />',
580
-                '<span style="font-weight: bold; color: #D54E21;">',
581
-                '</span><br />'
582
-            );
583
-        }
584
-        if (! empty($incompatibility_message)) {
585
-            // remove 'activate' from the REQUEST
586
-            // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
587
-            unset($_GET['activate'], $_REQUEST['activate']);
588
-            if (current_user_can('activate_plugins')) {
589
-                // show an error message indicating the plugin didn't activate properly
590
-                EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
591
-            }
592
-            // BAIL FROM THE ADDON REGISTRATION PROCESS
593
-            return false;
594
-        }
595
-        // addon IS compatible
596
-        return true;
597
-    }
598
-
599
-
600
-    /**
601
-     * if plugin update engine is being used for auto-updates,
602
-     * then let's set that up now before going any further so that ALL addons can be updated
603
-     * (not needed if PUE is not being used)
604
-     *
605
-     * @param string $addon_name
606
-     * @param string $class_name
607
-     * @param array  $setup_args
608
-     * @return void
609
-     */
610
-    private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
611
-    {
612
-        if (! empty($setup_args['pue_options'])) {
613
-            self::$_settings[ $addon_name ]['pue_options'] = array(
614
-                'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
615
-                    ? (string) $setup_args['pue_options']['pue_plugin_slug']
616
-                    : 'espresso_' . strtolower($class_name),
617
-                'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
618
-                    ? (string) $setup_args['pue_options']['plugin_basename']
619
-                    : plugin_basename($setup_args['main_file_path']),
620
-                'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
621
-                    ? (string) $setup_args['pue_options']['checkPeriod']
622
-                    : '24',
623
-                'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
624
-                    ? (string) $setup_args['pue_options']['use_wp_update']
625
-                    : false,
626
-            );
627
-            add_action(
628
-                'AHEE__EE_System__brew_espresso__after_pue_init',
629
-                array('EE_Register_Addon', 'load_pue_update')
630
-            );
631
-        }
632
-    }
633
-
634
-
635
-    /**
636
-     * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
637
-     *
638
-     * @param array $addon_settings
639
-     * @return void
640
-     */
641
-    private static function _setup_namespaces(array $addon_settings)
642
-    {
643
-        //
644
-        if (isset(
645
-            $addon_settings['namespace']['FQNS'],
646
-            $addon_settings['namespace']['DIR']
647
-        )) {
648
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
649
-                $addon_settings['namespace']['FQNS'],
650
-                $addon_settings['namespace']['DIR']
651
-            );
652
-        }
653
-    }
654
-
655
-
656
-    /**
657
-     * @param string $addon_name
658
-     * @param array  $addon_settings
659
-     * @return bool
660
-     * @throws InvalidArgumentException
661
-     * @throws InvalidDataTypeException
662
-     * @throws InvalidInterfaceException
663
-     */
664
-    private static function _addon_activation($addon_name, array $addon_settings)
665
-    {
666
-        // this is an activation request
667
-        if (did_action('activate_plugin')) {
668
-            // to find if THIS is the addon that was activated, just check if we have already registered it or not
669
-            // (as the newly-activated addon wasn't around the first time addons were registered).
670
-            // Note: the presence of pue_options in the addon registration options will initialize the $_settings
671
-            // property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
672
-            if (! isset(self::$_settings[ $addon_name ])
673
-                || (isset(self::$_settings[ $addon_name ])
674
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
675
-                )
676
-            ) {
677
-                self::$_settings[ $addon_name ] = $addon_settings;
678
-                $addon = self::_load_and_init_addon_class($addon_name);
679
-                $addon->set_activation_indicator_option();
680
-                // dont bother setting up the rest of the addon.
681
-                // we know it was just activated and the request will end soon
682
-            }
683
-            return true;
684
-        }
685
-        // make sure this was called in the right place!
686
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
687
-            || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
688
-        ) {
689
-            EE_Error::doing_it_wrong(
690
-                __METHOD__,
691
-                sprintf(
692
-                    __(
693
-                        'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
694
-                        'event_espresso'
695
-                    ),
696
-                    $addon_name
697
-                ),
698
-                '4.3.0'
699
-            );
700
-        }
701
-        // make sure addon settings are set correctly without overwriting anything existing
702
-        if (isset(self::$_settings[ $addon_name ])) {
703
-            self::$_settings[ $addon_name ] += $addon_settings;
704
-        } else {
705
-            self::$_settings[ $addon_name ] = $addon_settings;
706
-        }
707
-        return false;
708
-    }
709
-
710
-
711
-    /**
712
-     * @param string $addon_name
713
-     * @return void
714
-     * @throws EE_Error
715
-     */
716
-    private static function _setup_autoloaders($addon_name)
717
-    {
718
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
719
-            // setup autoloader for single file
720
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
721
-        }
722
-        // setup autoloaders for folders
723
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
724
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
725
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
726
-            }
727
-        }
728
-    }
729
-
730
-
731
-    /**
732
-     * register new models and extensions
733
-     *
734
-     * @param string $addon_name
735
-     * @return void
736
-     * @throws EE_Error
737
-     */
738
-    private static function _register_models_and_extensions($addon_name)
739
-    {
740
-        // register new models
741
-        if (! empty(self::$_settings[ $addon_name ]['model_paths'])
742
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
743
-        ) {
744
-            EE_Register_Model::register(
745
-                $addon_name,
746
-                array(
747
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
748
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
749
-                )
750
-            );
751
-        }
752
-        // register model extensions
753
-        if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
754
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
755
-        ) {
756
-            EE_Register_Model_Extensions::register(
757
-                $addon_name,
758
-                array(
759
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
760
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
761
-                )
762
-            );
763
-        }
764
-    }
765
-
766
-
767
-    /**
768
-     * @param string $addon_name
769
-     * @return void
770
-     * @throws EE_Error
771
-     */
772
-    private static function _register_data_migration_scripts($addon_name)
773
-    {
774
-        // setup DMS
775
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
776
-            EE_Register_Data_Migration_Scripts::register(
777
-                $addon_name,
778
-                array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
779
-            );
780
-        }
781
-    }
782
-
783
-
784
-    /**
785
-     * @param string $addon_name
786
-     * @return void
787
-     * @throws EE_Error
788
-     */
789
-    private static function _register_config($addon_name)
790
-    {
791
-        // if config_class is present let's register config.
792
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
793
-            EE_Register_Config::register(
794
-                self::$_settings[ $addon_name ]['config_class'],
795
-                array(
796
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
797
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
798
-                )
799
-            );
800
-        }
801
-    }
802
-
803
-
804
-    /**
805
-     * @param string $addon_name
806
-     * @return void
807
-     * @throws EE_Error
808
-     */
809
-    private static function _register_admin_pages($addon_name)
810
-    {
811
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
812
-            EE_Register_Admin_Page::register(
813
-                $addon_name,
814
-                array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
815
-            );
816
-        }
817
-    }
818
-
819
-
820
-    /**
821
-     * @param string $addon_name
822
-     * @return void
823
-     * @throws EE_Error
824
-     */
825
-    private static function _register_modules($addon_name)
826
-    {
827
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
828
-            EE_Register_Module::register(
829
-                $addon_name,
830
-                array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
831
-            );
832
-        }
833
-    }
834
-
835
-
836
-    /**
837
-     * @param string $addon_name
838
-     * @return void
839
-     * @throws EE_Error
840
-     */
841
-    private static function _register_shortcodes($addon_name)
842
-    {
843
-        if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
844
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
845
-        ) {
846
-            EE_Register_Shortcode::register(
847
-                $addon_name,
848
-                array(
849
-                    'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
850
-                        ? self::$_settings[ $addon_name ]['shortcode_paths'] : array(),
851
-                    'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
852
-                        ? self::$_settings[ $addon_name ]['shortcode_fqcns'] : array(),
853
-                )
854
-            );
855
-        }
856
-    }
857
-
858
-
859
-    /**
860
-     * @param string $addon_name
861
-     * @return void
862
-     * @throws EE_Error
863
-     */
864
-    private static function _register_widgets($addon_name)
865
-    {
866
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
867
-            EE_Register_Widget::register(
868
-                $addon_name,
869
-                array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
870
-            );
871
-        }
872
-    }
873
-
874
-
875
-    /**
876
-     * @param string $addon_name
877
-     * @return void
878
-     * @throws EE_Error
879
-     */
880
-    private static function _register_capabilities($addon_name)
881
-    {
882
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
883
-            EE_Register_Capabilities::register(
884
-                $addon_name,
885
-                array(
886
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
887
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
888
-                )
889
-            );
890
-        }
891
-    }
892
-
893
-
894
-    /**
895
-     * @param string $addon_name
896
-     * @return void
897
-     */
898
-    private static function _register_message_types($addon_name)
899
-    {
900
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
901
-            add_action(
902
-                'EE_Brewing_Regular___messages_caf',
903
-                array('EE_Register_Addon', 'register_message_types')
904
-            );
905
-        }
906
-    }
907
-
908
-
909
-    /**
910
-     * @param string $addon_name
911
-     * @return void
912
-     * @throws EE_Error
913
-     */
914
-    private static function _register_custom_post_types($addon_name)
915
-    {
916
-        if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])
917
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
918
-        ) {
919
-            EE_Register_CPT::register(
920
-                $addon_name,
921
-                array(
922
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
923
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
924
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
925
-                )
926
-            );
927
-        }
928
-    }
929
-
930
-
931
-    /**
932
-     * @param string $addon_name
933
-     * @return void
934
-     * @throws InvalidArgumentException
935
-     * @throws InvalidInterfaceException
936
-     * @throws InvalidDataTypeException
937
-     * @throws DomainException
938
-     * @throws EE_Error
939
-     */
940
-    private static function _register_payment_methods($addon_name)
941
-    {
942
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
943
-            EE_Register_Payment_Method::register(
944
-                $addon_name,
945
-                array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
946
-            );
947
-        }
948
-    }
949
-
950
-
951
-    /**
952
-     * @param string $addon_name
953
-     * @return void
954
-     * @throws InvalidArgumentException
955
-     * @throws InvalidInterfaceException
956
-     * @throws InvalidDataTypeException
957
-     * @throws DomainException
958
-     */
959
-    private static function registerPrivacyPolicies($addon_name)
960
-    {
961
-        if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
962
-            EE_Register_Privacy_Policy::register(
963
-                $addon_name,
964
-                self::$_settings[ $addon_name ]['privacy_policies']
965
-            );
966
-        }
967
-    }
968
-
969
-
970
-    /**
971
-     * @param string $addon_name
972
-     * @return void
973
-     */
974
-    private static function registerPersonalDataExporters($addon_name)
975
-    {
976
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
977
-            EE_Register_Personal_Data_Eraser::register(
978
-                $addon_name,
979
-                self::$_settings[ $addon_name ]['personal_data_exporters']
980
-            );
981
-        }
982
-    }
983
-
984
-
985
-    /**
986
-     * @param string $addon_name
987
-     * @return void
988
-     */
989
-    private static function registerPersonalDataErasers($addon_name)
990
-    {
991
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
992
-            EE_Register_Personal_Data_Eraser::register(
993
-                $addon_name,
994
-                self::$_settings[ $addon_name ]['personal_data_erasers']
995
-            );
996
-        }
997
-    }
998
-
999
-
1000
-    /**
1001
-     * Loads and instantiates the EE_Addon class and adds it onto the registry
1002
-     *
1003
-     * @param string $addon_name
1004
-     * @return EE_Addon
1005
-     * @throws InvalidArgumentException
1006
-     * @throws InvalidInterfaceException
1007
-     * @throws InvalidDataTypeException
1008
-     */
1009
-    private static function _load_and_init_addon_class($addon_name)
1010
-    {
1011
-        $addon = LoaderFactory::getLoader()->getShared(
1012
-            self::$_settings[ $addon_name ]['class_name'],
1013
-            array('EE_Registry::create(addon)' => true)
1014
-        );
1015
-        if (! $addon instanceof EE_Addon) {
1016
-            throw new DomainException(
1017
-                sprintf(
1018
-                    esc_html__(
1019
-                        'Failed to instantiate the %1$s class. PLease check that the class exists.',
1020
-                        'event_espresso'
1021
-                    ),
1022
-                    $addon_name
1023
-                )
1024
-            );
1025
-        }
1026
-        // setter inject dep map if required
1027
-        if ($addon->dependencyMap() === null) {
1028
-            $addon->setDependencyMap(LoaderFactory::getLoader()->getShared('EE_Dependency_Map'));
1029
-        }
1030
-        // setter inject domain if required
1031
-        EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1032
-
1033
-        $addon->set_name($addon_name);
1034
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1035
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1036
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1037
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1038
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1039
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
1040
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1041
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1042
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1043
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1044
-        // setup the add-on's pue_slug if we have one.
1045
-        if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) {
1046
-            $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']);
1047
-        }
1048
-        // unfortunately this can't be hooked in upon construction,
1049
-        // because we don't have the plugin's mainfile path upon construction.
1050
-        register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
1051
-        // call any additional admin_callback functions during load_admin_controller hook
1052
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1053
-            add_action(
1054
-                'AHEE__EE_System__load_controllers__load_admin_controllers',
1055
-                array($addon, self::$_settings[ $addon_name ]['admin_callback'])
1056
-            );
1057
-        }
1058
-        return $addon;
1059
-    }
1060
-
1061
-
1062
-    /**
1063
-     * @param string   $addon_name
1064
-     * @param EE_Addon $addon
1065
-     * @since   $VID:$
1066
-     */
1067
-    private static function injectAddonDomain($addon_name, EE_Addon $addon)
1068
-    {
1069
-        if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1070
-            // using supplied Domain object
1071
-            $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1072
-                ? self::$_settings[ $addon_name ]['domain']
1073
-                : null;
1074
-            // or construct one using Domain FQCN
1075
-            if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1076
-                $domain = LoaderFactory::getLoader()->getShared(
1077
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
1078
-                    [
1079
-                        new EventEspresso\core\domain\values\FilePath(
1080
-                            self::$_settings[ $addon_name ]['main_file_path']
1081
-                        ),
1082
-                        EventEspresso\core\domain\values\Version::fromString(
1083
-                            self::$_settings[ $addon_name ]['version']
1084
-                        ),
1085
-                    ]
1086
-                );
1087
-            }
1088
-            if ($domain instanceof DomainInterface) {
1089
-                $addon->setDomain($domain);
1090
-            }
1091
-        }
1092
-    }
1093
-
1094
-
1095
-    /**
1096
-     *    load_pue_update - Update notifications
1097
-     *
1098
-     * @return void
1099
-     * @throws InvalidArgumentException
1100
-     * @throws InvalidDataTypeException
1101
-     * @throws InvalidInterfaceException
1102
-     */
1103
-    public static function load_pue_update()
1104
-    {
1105
-        // load PUE client
1106
-        require_once EE_THIRD_PARTY . 'pue/pue-client.php';
1107
-        $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
1108
-        // cycle thru settings
1109
-        foreach (self::$_settings as $settings) {
1110
-            if (! empty($settings['pue_options'])) {
1111
-                // initiate the class and start the plugin update engine!
1112
-                new PluginUpdateEngineChecker(
1113
-                    // host file URL
1114
-                    $license_server,
1115
-                    // plugin slug(s)
1116
-                    array(
1117
-                        'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1118
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1119
-                    ),
1120
-                    // options
1121
-                    array(
1122
-                        'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
1123
-                        'lang_domain'       => 'event_espresso',
1124
-                        'checkPeriod'       => $settings['pue_options']['checkPeriod'],
1125
-                        'option_key'        => 'ee_site_license_key',
1126
-                        'options_page_slug' => 'event_espresso',
1127
-                        'plugin_basename'   => $settings['pue_options']['plugin_basename'],
1128
-                        // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
1129
-                        'use_wp_update'     => $settings['pue_options']['use_wp_update'],
1130
-                    )
1131
-                );
1132
-            }
1133
-        }
1134
-    }
1135
-
1136
-
1137
-    /**
1138
-     * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1139
-     *
1140
-     * @since 4.4.0
1141
-     * @return void
1142
-     * @throws EE_Error
1143
-     */
1144
-    public static function register_message_types()
1145
-    {
1146
-        foreach (self::$_settings as $settings) {
1147
-            if (! empty($settings['message_types'])) {
1148
-                foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1149
-                    EE_Register_Message_Type::register($message_type, $message_type_settings);
1150
-                }
1151
-            }
1152
-        }
1153
-    }
1154
-
1155
-
1156
-    /**
1157
-     * This deregisters an addon that was previously registered with a specific addon_name.
1158
-     *
1159
-     * @param string $addon_name the name for the addon that was previously registered
1160
-     * @throws DomainException
1161
-     * @throws InvalidArgumentException
1162
-     * @throws InvalidDataTypeException
1163
-     * @throws InvalidInterfaceException
1164
-     *@since    4.3.0
1165
-     */
1166
-    public static function deregister($addon_name = '')
1167
-    {
1168
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1169
-            try {
1170
-                do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1171
-                $class_name = self::$_settings[ $addon_name ]['class_name'];
1172
-                if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1173
-                    // setup DMS
1174
-                    EE_Register_Data_Migration_Scripts::deregister($addon_name);
1175
-                }
1176
-                if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1177
-                    // register admin page
1178
-                    EE_Register_Admin_Page::deregister($addon_name);
1179
-                }
1180
-                if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1181
-                    // add to list of modules to be registered
1182
-                    EE_Register_Module::deregister($addon_name);
1183
-                }
1184
-                if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1185
-                    || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1186
-                ) {
1187
-                    // add to list of shortcodes to be registered
1188
-                    EE_Register_Shortcode::deregister($addon_name);
1189
-                }
1190
-                if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1191
-                    // if config_class present let's register config.
1192
-                    EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1193
-                }
1194
-                if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1195
-                    // add to list of widgets to be registered
1196
-                    EE_Register_Widget::deregister($addon_name);
1197
-                }
1198
-                if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1199
-                    || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1200
-                ) {
1201
-                    // add to list of shortcodes to be registered
1202
-                    EE_Register_Model::deregister($addon_name);
1203
-                }
1204
-                if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1205
-                    || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1206
-                ) {
1207
-                    // add to list of shortcodes to be registered
1208
-                    EE_Register_Model_Extensions::deregister($addon_name);
1209
-                }
1210
-                if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1211
-                    foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1212
-                        EE_Register_Message_Type::deregister($message_type);
1213
-                    }
1214
-                }
1215
-                // deregister capabilities for addon
1216
-                if (! empty(self::$_settings[ $addon_name ]['capabilities'])
1217
-                    || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1218
-                ) {
1219
-                    EE_Register_Capabilities::deregister($addon_name);
1220
-                }
1221
-                // deregister custom_post_types for addon
1222
-                if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1223
-                    EE_Register_CPT::deregister($addon_name);
1224
-                }
1225
-                if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1226
-                    EE_Register_Payment_Method::deregister($addon_name);
1227
-                }
1228
-                $addon = EE_Registry::instance()->getAddon($class_name);
1229
-                if ($addon instanceof EE_Addon) {
1230
-                    remove_action(
1231
-                        'deactivate_' . $addon->get_main_plugin_file_basename(),
1232
-                        array($addon, 'deactivation')
1233
-                    );
1234
-                    remove_action(
1235
-                        'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1236
-                        array($addon, 'initialize_db_if_no_migrations_required')
1237
-                    );
1238
-                    // remove `after_registration` call
1239
-                    remove_action(
1240
-                        'AHEE__EE_System__load_espresso_addons__complete',
1241
-                        array($addon, 'after_registration'),
1242
-                        999
1243
-                    );
1244
-                }
1245
-                EE_Registry::instance()->removeAddon($class_name);
1246
-            } catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1247
-                // the add-on was not yet registered in the registry,
1248
-                // so RegistryContainer::__get() throws this exception.
1249
-                // also no need to worry about this or log it,
1250
-                // it's ok to deregister an add-on before its registered in the registry
1251
-            } catch (Exception $e) {
1252
-                new ExceptionLogger($e);
1253
-            }
1254
-            unset(self::$_settings[ $addon_name ]);
1255
-            do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1256
-        }
1257
-    }
25
+	/**
26
+	 * possibly truncated version of the EE core version string
27
+	 *
28
+	 * @var string
29
+	 */
30
+	protected static $_core_version = '';
31
+
32
+	/**
33
+	 * Holds values for registered addons
34
+	 *
35
+	 * @var array
36
+	 */
37
+	protected static $_settings = array();
38
+
39
+	/**
40
+	 * @var  array $_incompatible_addons keys are addon SLUGS
41
+	 * (first argument passed to EE_Register_Addon::register()), keys are
42
+	 * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
43
+	 * Generally this should be used sparingly, as we don't want to muddle up
44
+	 * EE core with knowledge of ALL the addons out there.
45
+	 * If you want NO versions of an addon to run with a certain version of core,
46
+	 * it's usually best to define the addon's "min_core_version" as part of its call
47
+	 * to EE_Register_Addon::register(), rather than using this array with a super high value for its
48
+	 * minimum plugin version.
49
+	 * @access    protected
50
+	 */
51
+	protected static $_incompatible_addons = array(
52
+		'Multi_Event_Registration' => '2.0.11.rc.002',
53
+		'Promotions'               => '1.0.0.rc.084',
54
+	);
55
+
56
+
57
+	/**
58
+	 * We should always be comparing core to a version like '4.3.0.rc.000',
59
+	 * not just '4.3.0'.
60
+	 * So if the addon developer doesn't provide that full version string,
61
+	 * fill in the blanks for them
62
+	 *
63
+	 * @param string $min_core_version
64
+	 * @return string always like '4.3.0.rc.000'
65
+	 */
66
+	protected static function _effective_version($min_core_version)
67
+	{
68
+		// versions: 4 . 3 . 1 . p . 123
69
+		// offsets:    0 . 1 . 2 . 3 . 4
70
+		$version_parts = explode('.', $min_core_version);
71
+		// check they specified the micro version (after 2nd period)
72
+		if (! isset($version_parts[2])) {
73
+			$version_parts[2] = '0';
74
+		}
75
+		// if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
76
+		// soon we can assume that's 'rc', but this current version is 'alpha'
77
+		if (! isset($version_parts[3])) {
78
+			$version_parts[3] = 'dev';
79
+		}
80
+		if (! isset($version_parts[4])) {
81
+			$version_parts[4] = '000';
82
+		}
83
+		return implode('.', $version_parts);
84
+	}
85
+
86
+
87
+	/**
88
+	 * Returns whether or not the min core version requirement of the addon is met
89
+	 *
90
+	 * @param string $min_core_version    the minimum core version required by the addon
91
+	 * @param string $actual_core_version the actual core version, optional
92
+	 * @return boolean
93
+	 */
94
+	public static function _meets_min_core_version_requirement(
95
+		$min_core_version,
96
+		$actual_core_version = EVENT_ESPRESSO_VERSION
97
+	) {
98
+		return version_compare(
99
+			self::_effective_version($actual_core_version),
100
+			self::_effective_version($min_core_version),
101
+			'>='
102
+		);
103
+	}
104
+
105
+
106
+	/**
107
+	 * Method for registering new EE_Addons.
108
+	 * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
109
+	 * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
110
+	 * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
111
+	 * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
112
+	 * 'activate_plugin', it registers the addon still, but its components are not registered
113
+	 * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
114
+	 * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
115
+	 * (so that we can detect that the addon has activated on the subsequent request)
116
+	 *
117
+	 * @since    4.3.0
118
+	 * @param string                  $addon_name                       [Required] the EE_Addon's name.
119
+	 * @param  array                  $setup_args                       {
120
+	 *                                                                  An array of arguments provided for registering
121
+	 *                                                                  the message type.
122
+	 * @type  string                  $class_name                       the addon's main file name.
123
+	 *                                                                  If left blank, generated from the addon name,
124
+	 *                                                                  changes something like "calendar" to
125
+	 *                                                                  "EE_Calendar"
126
+	 * @type string                   $min_core_version                 the minimum version of EE Core that the
127
+	 *                                                                  addon will work with. eg "4.8.1.rc.084"
128
+	 * @type string                   $version                          the "software" version for the addon. eg
129
+	 *                                                                  "1.0.0.p" for a first stable release, or
130
+	 *                                                                  "1.0.0.rc.043" for a version in progress
131
+	 * @type string                   $main_file_path                   the full server path to the main file
132
+	 *                                                                  loaded directly by WP
133
+	 * @type DomainInterface $domain                                    child class of
134
+	 *                                                                  EventEspresso\core\domain\DomainBase
135
+	 * @type string                   $domain_fqcn                      Fully Qualified Class Name
136
+	 *                                                                  for the addon's Domain class
137
+	 *                                                                  (see EventEspresso\core\domain\Domain)
138
+	 * @type string                   $admin_path                       full server path to the folder where the
139
+	 *                                                                  addon\'s admin files reside
140
+	 * @type string                   $admin_callback                   a method to be called when the EE Admin is
141
+	 *                                                                  first invoked, can be used for hooking into
142
+	 *                                                                  any admin page
143
+	 * @type string                   $config_section                   the section name for this addon's
144
+	 *                                                                  configuration settings section
145
+	 *                                                                  (defaults to "addons")
146
+	 * @type string                   $config_class                     the class name for this addon's
147
+	 *                                                                  configuration settings object
148
+	 * @type string                   $config_name                      the class name for this addon's
149
+	 *                                                                  configuration settings object
150
+	 * @type string                   $autoloader_paths                 [Required] an array of class names and the full
151
+	 *                                                                  server paths to those files.
152
+	 * @type string                   $autoloader_folders               an array of  "full server paths" for any
153
+	 *                                                                  folders containing classes that might be
154
+	 *                                                                  invoked by the addon
155
+	 * @type string                   $dms_paths                        [Required] an array of full server paths to
156
+	 *                                                                  folders that contain data migration scripts.
157
+	 *                                                                  The key should be the EE_Addon class name that
158
+	 *                                                                  this set of data migration scripts belongs to.
159
+	 *                                                                  If the EE_Addon class is namespaced, then this
160
+	 *                                                                  needs to be the Fully Qualified Class Name
161
+	 * @type string                   $module_paths                     an array of full server paths to any
162
+	 *                                                                  EED_Modules used by the addon
163
+	 * @type string                   $shortcode_paths                  an array of full server paths to folders
164
+	 *                                                                  that contain EES_Shortcodes
165
+	 * @type string                   $widget_paths                     an array of full server paths to folders
166
+	 *                                                                  that contain WP_Widgets
167
+	 * @type string                   $pue_options
168
+	 * @type array                    $capabilities                     an array indexed by role name
169
+	 *                                                                  (i.e administrator,author ) and the values
170
+	 *                                                                  are an array of caps to add to the role.
171
+	 *                                                                  'administrator' => array(
172
+	 *                                                                  'read_addon',
173
+	 *                                                                  'edit_addon',
174
+	 *                                                                  etc.
175
+	 *                                                                  ).
176
+	 * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
177
+	 *                                                                  for any addons that need to register any
178
+	 *                                                                  special meta mapped capabilities.  Should
179
+	 *                                                                  be indexed where the key is the
180
+	 *                                                                  EE_Meta_Capability_Map class name and the
181
+	 *                                                                  values are the arguments sent to the class.
182
+	 * @type array                    $model_paths                      array of folders containing DB models
183
+	 * @see      EE_Register_Model
184
+	 * @type array                    $class_paths                      array of folders containing DB classes
185
+	 * @see      EE_Register_Model
186
+	 * @type array                    $model_extension_paths            array of folders containing DB model
187
+	 *                                                                  extensions
188
+	 * @see      EE_Register_Model_Extension
189
+	 * @type array                    $class_extension_paths            array of folders containing DB class
190
+	 *                                                                  extensions
191
+	 * @see      EE_Register_Model_Extension
192
+	 * @type array message_types {
193
+	 *                                                                  An array of message types with the key as
194
+	 *                                                                  the message type name and the values as
195
+	 *                                                                  below:
196
+	 * @type string                   $mtfilename                       [Required] The filename of the message type
197
+	 *                                                                  being registered. This will be the main
198
+	 *                                                                  EE_{Message Type Name}_message_type class.
199
+	 *                                                                  for example:
200
+	 *                                                                  EE_Declined_Registration_message_type.class.php
201
+	 * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
202
+	 *                                                                  messages autoloader for the new message type.
203
+	 * @type array                    $messengers_to_activate_with      An array of messengers that this message
204
+	 *                                                                  type should activate with. Each value in
205
+	 *                                                                  the
206
+	 *                                                                  array
207
+	 *                                                                  should match the name property of a
208
+	 *                                                                  EE_messenger. Optional.
209
+	 * @type array                    $messengers_to_validate_with      An array of messengers that this message
210
+	 *                                                                  type should validate with. Each value in
211
+	 *                                                                  the
212
+	 *                                                                  array
213
+	 *                                                                  should match the name property of an
214
+	 *                                                                  EE_messenger.
215
+	 *                                                                  Optional.
216
+	 *                                                                  }
217
+	 * @type array                    $custom_post_types
218
+	 * @type array                    $custom_taxonomies
219
+	 * @type array                    $payment_method_paths             each element is the folder containing the
220
+	 *                                                                  EE_PMT_Base child class
221
+	 *                                                                  (eg,
222
+	 *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
223
+	 *                                                                  which contains the files
224
+	 *                                                                  EE_PMT_Payomatic.pm.php)
225
+	 * @type array                    $default_terms
226
+	 * @type array                    $namespace                        {
227
+	 *                                                                  An array with two items for registering the
228
+	 *                                                                  addon's namespace. (If, for some reason, you
229
+	 *                                                                  require additional namespaces,
230
+	 *                                                                  use
231
+	 *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
232
+	 *                                                                  directly)
233
+	 * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
234
+	 * @type string                   $FQNS                             the namespace prefix
235
+	 * @type string                   $DIR                              a base directory for class files in the
236
+	 *                                                                  namespace.
237
+	 *                                                                  }
238
+	 *                                                                  }
239
+	 * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
240
+	 *                                                                  privacy policy classes) or FQCNs (specific
241
+	 *                                                                  classnames of privacy policy classes)
242
+	 * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
243
+	 *                                                                  privacy policy classes) or FQCNs (specific
244
+	 *                                                                  classnames of privacy policy classes)
245
+	 * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
246
+	 *                                                                  privacy policy classes) or FQCNs (specific
247
+	 *                                                                  classnames of privacy policy classes)
248
+	 * @return void
249
+	 * @throws DomainException
250
+	 * @throws EE_Error
251
+	 * @throws InvalidArgumentException
252
+	 * @throws InvalidDataTypeException
253
+	 * @throws InvalidInterfaceException
254
+	 */
255
+	public static function register($addon_name = '', array $setup_args = array())
256
+	{
257
+		// required fields MUST be present, so let's make sure they are.
258
+		EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
259
+		// get class name for addon
260
+		$class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
261
+		// setup $_settings array from incoming values.
262
+		$addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
263
+		// setup PUE
264
+		EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
265
+		// does this addon work with this version of core or WordPress ?
266
+		// does this addon work with this version of core or WordPress ?
267
+		if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
268
+			return;
269
+		}
270
+		// register namespaces
271
+		EE_Register_Addon::_setup_namespaces($addon_settings);
272
+		// check if this is an activation request
273
+		if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
274
+			// dont bother setting up the rest of the addon atm
275
+			return;
276
+		}
277
+		// we need cars
278
+		EE_Register_Addon::_setup_autoloaders($addon_name);
279
+		// register new models and extensions
280
+		EE_Register_Addon::_register_models_and_extensions($addon_name);
281
+		// setup DMS
282
+		EE_Register_Addon::_register_data_migration_scripts($addon_name);
283
+		// if config_class is present let's register config.
284
+		EE_Register_Addon::_register_config($addon_name);
285
+		// register admin pages
286
+		EE_Register_Addon::_register_admin_pages($addon_name);
287
+		// add to list of modules to be registered
288
+		EE_Register_Addon::_register_modules($addon_name);
289
+		// add to list of shortcodes to be registered
290
+		EE_Register_Addon::_register_shortcodes($addon_name);
291
+		// add to list of widgets to be registered
292
+		EE_Register_Addon::_register_widgets($addon_name);
293
+		// register capability related stuff.
294
+		EE_Register_Addon::_register_capabilities($addon_name);
295
+		// any message type to register?
296
+		EE_Register_Addon::_register_message_types($addon_name);
297
+		// any custom post type/ custom capabilities or default terms to register
298
+		EE_Register_Addon::_register_custom_post_types($addon_name);
299
+		// and any payment methods
300
+		EE_Register_Addon::_register_payment_methods($addon_name);
301
+		// and privacy policy generators
302
+		EE_Register_Addon::registerPrivacyPolicies($addon_name);
303
+		// and privacy policy generators
304
+		EE_Register_Addon::registerPersonalDataExporters($addon_name);
305
+		// and privacy policy generators
306
+		EE_Register_Addon::registerPersonalDataErasers($addon_name);
307
+		// load and instantiate main addon class
308
+		$addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
309
+		// delay calling after_registration hook on each addon until after all add-ons have been registered.
310
+		add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999);
311
+	}
312
+
313
+
314
+	/**
315
+	 * @param string $addon_name
316
+	 * @param array  $setup_args
317
+	 * @return void
318
+	 * @throws EE_Error
319
+	 */
320
+	private static function _verify_parameters($addon_name, array $setup_args)
321
+	{
322
+		// required fields MUST be present, so let's make sure they are.
323
+		if (empty($addon_name) || ! is_array($setup_args)) {
324
+			throw new EE_Error(
325
+				__(
326
+					'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
327
+					'event_espresso'
328
+				)
329
+			);
330
+		}
331
+		if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
332
+			throw new EE_Error(
333
+				sprintf(
334
+					__(
335
+						'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
336
+						'event_espresso'
337
+					),
338
+					implode(',', array_keys($setup_args))
339
+				)
340
+			);
341
+		}
342
+		// check that addon has not already been registered with that name
343
+		if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
344
+			throw new EE_Error(
345
+				sprintf(
346
+					__(
347
+						'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
348
+						'event_espresso'
349
+					),
350
+					$addon_name
351
+				)
352
+			);
353
+		}
354
+	}
355
+
356
+
357
+	/**
358
+	 * @param string $addon_name
359
+	 * @param array  $setup_args
360
+	 * @return string
361
+	 */
362
+	private static function _parse_class_name($addon_name, array $setup_args)
363
+	{
364
+		if (empty($setup_args['class_name'])) {
365
+			// generate one by first separating name with spaces
366
+			$class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
367
+			// capitalize, then replace spaces with underscores
368
+			$class_name = str_replace(' ', '_', ucwords($class_name));
369
+		} else {
370
+			$class_name = $setup_args['class_name'];
371
+		}
372
+		// check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
373
+		return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
374
+			? $class_name
375
+			: 'EE_' . $class_name;
376
+	}
377
+
378
+
379
+	/**
380
+	 * @param string $class_name
381
+	 * @param array  $setup_args
382
+	 * @return array
383
+	 */
384
+	private static function _get_addon_settings($class_name, array $setup_args)
385
+	{
386
+		// setup $_settings array from incoming values.
387
+		$addon_settings = array(
388
+			// generated from the addon name, changes something like "calendar" to "EE_Calendar"
389
+			'class_name'            => $class_name,
390
+			// the addon slug for use in URLs, etc
391
+			'plugin_slug'           => isset($setup_args['plugin_slug'])
392
+				? (string) $setup_args['plugin_slug']
393
+				: '',
394
+			// page slug to be used when generating the "Settings" link on the WP plugin page
395
+			'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
396
+				? (string) $setup_args['plugin_action_slug']
397
+				: '',
398
+			// the "software" version for the addon
399
+			'version'               => isset($setup_args['version'])
400
+				? (string) $setup_args['version']
401
+				: '',
402
+			// the minimum version of EE Core that the addon will work with
403
+			'min_core_version'      => isset($setup_args['min_core_version'])
404
+				? (string) $setup_args['min_core_version']
405
+				: '',
406
+			// the minimum version of WordPress that the addon will work with
407
+			'min_wp_version'        => isset($setup_args['min_wp_version'])
408
+				? (string) $setup_args['min_wp_version']
409
+				: EE_MIN_WP_VER_REQUIRED,
410
+			// full server path to main file (file loaded directly by WP)
411
+			'main_file_path'        => isset($setup_args['main_file_path'])
412
+				? (string) $setup_args['main_file_path']
413
+				: '',
414
+			// instance of \EventEspresso\core\domain\DomainInterface
415
+			'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
416
+				? $setup_args['domain']
417
+				: null,
418
+			// Fully Qualified Class Name for the addon's Domain class
419
+			'domain_fqcn'           => isset($setup_args['domain_fqcn'])
420
+				? (string) $setup_args['domain_fqcn']
421
+				: '',
422
+			// path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
423
+			'admin_path'            => isset($setup_args['admin_path'])
424
+				? (string) $setup_args['admin_path'] : '',
425
+			// a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
426
+			'admin_callback'        => isset($setup_args['admin_callback'])
427
+				? (string) $setup_args['admin_callback']
428
+				: '',
429
+			// the section name for this addon's configuration settings section (defaults to "addons")
430
+			'config_section'        => isset($setup_args['config_section'])
431
+				? (string) $setup_args['config_section']
432
+				: 'addons',
433
+			// the class name for this addon's configuration settings object
434
+			'config_class'          => isset($setup_args['config_class'])
435
+				? (string) $setup_args['config_class'] : '',
436
+			// the name given to the config for this addons' configuration settings object (optional)
437
+			'config_name'           => isset($setup_args['config_name'])
438
+				? (string) $setup_args['config_name'] : '',
439
+			// an array of "class names" => "full server paths" for any classes that might be invoked by the addon
440
+			'autoloader_paths'      => isset($setup_args['autoloader_paths'])
441
+				? (array) $setup_args['autoloader_paths']
442
+				: array(),
443
+			// an array of  "full server paths" for any folders containing classes that might be invoked by the addon
444
+			'autoloader_folders'    => isset($setup_args['autoloader_folders'])
445
+				? (array) $setup_args['autoloader_folders']
446
+				: array(),
447
+			// array of full server paths to any EE_DMS data migration scripts used by the addon.
448
+			// The key should be the EE_Addon class name that this set of data migration scripts belongs to.
449
+			// If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
450
+			'dms_paths'             => isset($setup_args['dms_paths'])
451
+				? (array) $setup_args['dms_paths']
452
+				: array(),
453
+			// array of full server paths to any EED_Modules used by the addon
454
+			'module_paths'          => isset($setup_args['module_paths'])
455
+				? (array) $setup_args['module_paths']
456
+				: array(),
457
+			// array of full server paths to any EES_Shortcodes used by the addon
458
+			'shortcode_paths'       => isset($setup_args['shortcode_paths'])
459
+				? (array) $setup_args['shortcode_paths']
460
+				: array(),
461
+			'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
462
+				? (array) $setup_args['shortcode_fqcns']
463
+				: array(),
464
+			// array of full server paths to any WP_Widgets used by the addon
465
+			'widget_paths'          => isset($setup_args['widget_paths'])
466
+				? (array) $setup_args['widget_paths']
467
+				: array(),
468
+			// array of PUE options used by the addon
469
+			'pue_options'           => isset($setup_args['pue_options'])
470
+				? (array) $setup_args['pue_options']
471
+				: array(),
472
+			'message_types'         => isset($setup_args['message_types'])
473
+				? (array) $setup_args['message_types']
474
+				: array(),
475
+			'capabilities'          => isset($setup_args['capabilities'])
476
+				? (array) $setup_args['capabilities']
477
+				: array(),
478
+			'capability_maps'       => isset($setup_args['capability_maps'])
479
+				? (array) $setup_args['capability_maps']
480
+				: array(),
481
+			'model_paths'           => isset($setup_args['model_paths'])
482
+				? (array) $setup_args['model_paths']
483
+				: array(),
484
+			'class_paths'           => isset($setup_args['class_paths'])
485
+				? (array) $setup_args['class_paths']
486
+				: array(),
487
+			'model_extension_paths' => isset($setup_args['model_extension_paths'])
488
+				? (array) $setup_args['model_extension_paths']
489
+				: array(),
490
+			'class_extension_paths' => isset($setup_args['class_extension_paths'])
491
+				? (array) $setup_args['class_extension_paths']
492
+				: array(),
493
+			'custom_post_types'     => isset($setup_args['custom_post_types'])
494
+				? (array) $setup_args['custom_post_types']
495
+				: array(),
496
+			'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
497
+				? (array) $setup_args['custom_taxonomies']
498
+				: array(),
499
+			'payment_method_paths'  => isset($setup_args['payment_method_paths'])
500
+				? (array) $setup_args['payment_method_paths']
501
+				: array(),
502
+			'default_terms'         => isset($setup_args['default_terms'])
503
+				? (array) $setup_args['default_terms']
504
+				: array(),
505
+			// if not empty, inserts a new table row after this plugin's row on the WP Plugins page
506
+			// that can be used for adding upgrading/marketing info
507
+			'plugins_page_row'      => isset($setup_args['plugins_page_row']) ? $setup_args['plugins_page_row'] : '',
508
+			'namespace'             => isset(
509
+				$setup_args['namespace']['FQNS'],
510
+				$setup_args['namespace']['DIR']
511
+			)
512
+				? (array) $setup_args['namespace']
513
+				: array(),
514
+			'privacy_policies'      => isset($setup_args['privacy_policies'])
515
+				? (array) $setup_args['privacy_policies']
516
+				: '',
517
+		);
518
+		// if plugin_action_slug is NOT set, but an admin page path IS set,
519
+		// then let's just use the plugin_slug since that will be used for linking to the admin page
520
+		$addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
521
+												&& ! empty($addon_settings['admin_path'])
522
+			? $addon_settings['plugin_slug']
523
+			: $addon_settings['plugin_action_slug'];
524
+		// full server path to main file (file loaded directly by WP)
525
+		$addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
526
+		return $addon_settings;
527
+	}
528
+
529
+
530
+	/**
531
+	 * @param string $addon_name
532
+	 * @param array  $addon_settings
533
+	 * @return boolean
534
+	 */
535
+	private static function _addon_is_compatible($addon_name, array $addon_settings)
536
+	{
537
+		global $wp_version;
538
+		$incompatibility_message = '';
539
+		// check whether this addon version is compatible with EE core
540
+		if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
541
+			&& ! self::_meets_min_core_version_requirement(
542
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
543
+				$addon_settings['version']
544
+			)
545
+		) {
546
+			$incompatibility_message = sprintf(
547
+				__(
548
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
549
+					'event_espresso'
550
+				),
551
+				$addon_name,
552
+				'<br />',
553
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
554
+				'<span style="font-weight: bold; color: #D54E21;">',
555
+				'</span><br />'
556
+			);
557
+		} elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
558
+		) {
559
+			$incompatibility_message = sprintf(
560
+				__(
561
+					'%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
562
+					'event_espresso'
563
+				),
564
+				$addon_name,
565
+				self::_effective_version($addon_settings['min_core_version']),
566
+				self::_effective_version(espresso_version()),
567
+				'<br />',
568
+				'<span style="font-weight: bold; color: #D54E21;">',
569
+				'</span><br />'
570
+			);
571
+		} elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
572
+			$incompatibility_message = sprintf(
573
+				__(
574
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
575
+					'event_espresso'
576
+				),
577
+				$addon_name,
578
+				$addon_settings['min_wp_version'],
579
+				'<br />',
580
+				'<span style="font-weight: bold; color: #D54E21;">',
581
+				'</span><br />'
582
+			);
583
+		}
584
+		if (! empty($incompatibility_message)) {
585
+			// remove 'activate' from the REQUEST
586
+			// so WP doesn't erroneously tell the user the plugin activated fine when it didn't
587
+			unset($_GET['activate'], $_REQUEST['activate']);
588
+			if (current_user_can('activate_plugins')) {
589
+				// show an error message indicating the plugin didn't activate properly
590
+				EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
591
+			}
592
+			// BAIL FROM THE ADDON REGISTRATION PROCESS
593
+			return false;
594
+		}
595
+		// addon IS compatible
596
+		return true;
597
+	}
598
+
599
+
600
+	/**
601
+	 * if plugin update engine is being used for auto-updates,
602
+	 * then let's set that up now before going any further so that ALL addons can be updated
603
+	 * (not needed if PUE is not being used)
604
+	 *
605
+	 * @param string $addon_name
606
+	 * @param string $class_name
607
+	 * @param array  $setup_args
608
+	 * @return void
609
+	 */
610
+	private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
611
+	{
612
+		if (! empty($setup_args['pue_options'])) {
613
+			self::$_settings[ $addon_name ]['pue_options'] = array(
614
+				'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
615
+					? (string) $setup_args['pue_options']['pue_plugin_slug']
616
+					: 'espresso_' . strtolower($class_name),
617
+				'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
618
+					? (string) $setup_args['pue_options']['plugin_basename']
619
+					: plugin_basename($setup_args['main_file_path']),
620
+				'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
621
+					? (string) $setup_args['pue_options']['checkPeriod']
622
+					: '24',
623
+				'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
624
+					? (string) $setup_args['pue_options']['use_wp_update']
625
+					: false,
626
+			);
627
+			add_action(
628
+				'AHEE__EE_System__brew_espresso__after_pue_init',
629
+				array('EE_Register_Addon', 'load_pue_update')
630
+			);
631
+		}
632
+	}
633
+
634
+
635
+	/**
636
+	 * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
637
+	 *
638
+	 * @param array $addon_settings
639
+	 * @return void
640
+	 */
641
+	private static function _setup_namespaces(array $addon_settings)
642
+	{
643
+		//
644
+		if (isset(
645
+			$addon_settings['namespace']['FQNS'],
646
+			$addon_settings['namespace']['DIR']
647
+		)) {
648
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
649
+				$addon_settings['namespace']['FQNS'],
650
+				$addon_settings['namespace']['DIR']
651
+			);
652
+		}
653
+	}
654
+
655
+
656
+	/**
657
+	 * @param string $addon_name
658
+	 * @param array  $addon_settings
659
+	 * @return bool
660
+	 * @throws InvalidArgumentException
661
+	 * @throws InvalidDataTypeException
662
+	 * @throws InvalidInterfaceException
663
+	 */
664
+	private static function _addon_activation($addon_name, array $addon_settings)
665
+	{
666
+		// this is an activation request
667
+		if (did_action('activate_plugin')) {
668
+			// to find if THIS is the addon that was activated, just check if we have already registered it or not
669
+			// (as the newly-activated addon wasn't around the first time addons were registered).
670
+			// Note: the presence of pue_options in the addon registration options will initialize the $_settings
671
+			// property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
672
+			if (! isset(self::$_settings[ $addon_name ])
673
+				|| (isset(self::$_settings[ $addon_name ])
674
+					&& ! isset(self::$_settings[ $addon_name ]['class_name'])
675
+				)
676
+			) {
677
+				self::$_settings[ $addon_name ] = $addon_settings;
678
+				$addon = self::_load_and_init_addon_class($addon_name);
679
+				$addon->set_activation_indicator_option();
680
+				// dont bother setting up the rest of the addon.
681
+				// we know it was just activated and the request will end soon
682
+			}
683
+			return true;
684
+		}
685
+		// make sure this was called in the right place!
686
+		if (! did_action('AHEE__EE_System__load_espresso_addons')
687
+			|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
688
+		) {
689
+			EE_Error::doing_it_wrong(
690
+				__METHOD__,
691
+				sprintf(
692
+					__(
693
+						'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
694
+						'event_espresso'
695
+					),
696
+					$addon_name
697
+				),
698
+				'4.3.0'
699
+			);
700
+		}
701
+		// make sure addon settings are set correctly without overwriting anything existing
702
+		if (isset(self::$_settings[ $addon_name ])) {
703
+			self::$_settings[ $addon_name ] += $addon_settings;
704
+		} else {
705
+			self::$_settings[ $addon_name ] = $addon_settings;
706
+		}
707
+		return false;
708
+	}
709
+
710
+
711
+	/**
712
+	 * @param string $addon_name
713
+	 * @return void
714
+	 * @throws EE_Error
715
+	 */
716
+	private static function _setup_autoloaders($addon_name)
717
+	{
718
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
719
+			// setup autoloader for single file
720
+			EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
721
+		}
722
+		// setup autoloaders for folders
723
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
724
+			foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
725
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
726
+			}
727
+		}
728
+	}
729
+
730
+
731
+	/**
732
+	 * register new models and extensions
733
+	 *
734
+	 * @param string $addon_name
735
+	 * @return void
736
+	 * @throws EE_Error
737
+	 */
738
+	private static function _register_models_and_extensions($addon_name)
739
+	{
740
+		// register new models
741
+		if (! empty(self::$_settings[ $addon_name ]['model_paths'])
742
+			|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
743
+		) {
744
+			EE_Register_Model::register(
745
+				$addon_name,
746
+				array(
747
+					'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
748
+					'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
749
+				)
750
+			);
751
+		}
752
+		// register model extensions
753
+		if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
754
+			|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
755
+		) {
756
+			EE_Register_Model_Extensions::register(
757
+				$addon_name,
758
+				array(
759
+					'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
760
+					'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
761
+				)
762
+			);
763
+		}
764
+	}
765
+
766
+
767
+	/**
768
+	 * @param string $addon_name
769
+	 * @return void
770
+	 * @throws EE_Error
771
+	 */
772
+	private static function _register_data_migration_scripts($addon_name)
773
+	{
774
+		// setup DMS
775
+		if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
776
+			EE_Register_Data_Migration_Scripts::register(
777
+				$addon_name,
778
+				array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
779
+			);
780
+		}
781
+	}
782
+
783
+
784
+	/**
785
+	 * @param string $addon_name
786
+	 * @return void
787
+	 * @throws EE_Error
788
+	 */
789
+	private static function _register_config($addon_name)
790
+	{
791
+		// if config_class is present let's register config.
792
+		if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
793
+			EE_Register_Config::register(
794
+				self::$_settings[ $addon_name ]['config_class'],
795
+				array(
796
+					'config_section' => self::$_settings[ $addon_name ]['config_section'],
797
+					'config_name'    => self::$_settings[ $addon_name ]['config_name'],
798
+				)
799
+			);
800
+		}
801
+	}
802
+
803
+
804
+	/**
805
+	 * @param string $addon_name
806
+	 * @return void
807
+	 * @throws EE_Error
808
+	 */
809
+	private static function _register_admin_pages($addon_name)
810
+	{
811
+		if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
812
+			EE_Register_Admin_Page::register(
813
+				$addon_name,
814
+				array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
815
+			);
816
+		}
817
+	}
818
+
819
+
820
+	/**
821
+	 * @param string $addon_name
822
+	 * @return void
823
+	 * @throws EE_Error
824
+	 */
825
+	private static function _register_modules($addon_name)
826
+	{
827
+		if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
828
+			EE_Register_Module::register(
829
+				$addon_name,
830
+				array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
831
+			);
832
+		}
833
+	}
834
+
835
+
836
+	/**
837
+	 * @param string $addon_name
838
+	 * @return void
839
+	 * @throws EE_Error
840
+	 */
841
+	private static function _register_shortcodes($addon_name)
842
+	{
843
+		if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
844
+			|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
845
+		) {
846
+			EE_Register_Shortcode::register(
847
+				$addon_name,
848
+				array(
849
+					'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
850
+						? self::$_settings[ $addon_name ]['shortcode_paths'] : array(),
851
+					'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
852
+						? self::$_settings[ $addon_name ]['shortcode_fqcns'] : array(),
853
+				)
854
+			);
855
+		}
856
+	}
857
+
858
+
859
+	/**
860
+	 * @param string $addon_name
861
+	 * @return void
862
+	 * @throws EE_Error
863
+	 */
864
+	private static function _register_widgets($addon_name)
865
+	{
866
+		if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
867
+			EE_Register_Widget::register(
868
+				$addon_name,
869
+				array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
870
+			);
871
+		}
872
+	}
873
+
874
+
875
+	/**
876
+	 * @param string $addon_name
877
+	 * @return void
878
+	 * @throws EE_Error
879
+	 */
880
+	private static function _register_capabilities($addon_name)
881
+	{
882
+		if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
883
+			EE_Register_Capabilities::register(
884
+				$addon_name,
885
+				array(
886
+					'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
887
+					'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
888
+				)
889
+			);
890
+		}
891
+	}
892
+
893
+
894
+	/**
895
+	 * @param string $addon_name
896
+	 * @return void
897
+	 */
898
+	private static function _register_message_types($addon_name)
899
+	{
900
+		if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
901
+			add_action(
902
+				'EE_Brewing_Regular___messages_caf',
903
+				array('EE_Register_Addon', 'register_message_types')
904
+			);
905
+		}
906
+	}
907
+
908
+
909
+	/**
910
+	 * @param string $addon_name
911
+	 * @return void
912
+	 * @throws EE_Error
913
+	 */
914
+	private static function _register_custom_post_types($addon_name)
915
+	{
916
+		if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])
917
+			|| ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
918
+		) {
919
+			EE_Register_CPT::register(
920
+				$addon_name,
921
+				array(
922
+					'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
923
+					'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
924
+					'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
925
+				)
926
+			);
927
+		}
928
+	}
929
+
930
+
931
+	/**
932
+	 * @param string $addon_name
933
+	 * @return void
934
+	 * @throws InvalidArgumentException
935
+	 * @throws InvalidInterfaceException
936
+	 * @throws InvalidDataTypeException
937
+	 * @throws DomainException
938
+	 * @throws EE_Error
939
+	 */
940
+	private static function _register_payment_methods($addon_name)
941
+	{
942
+		if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
943
+			EE_Register_Payment_Method::register(
944
+				$addon_name,
945
+				array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
946
+			);
947
+		}
948
+	}
949
+
950
+
951
+	/**
952
+	 * @param string $addon_name
953
+	 * @return void
954
+	 * @throws InvalidArgumentException
955
+	 * @throws InvalidInterfaceException
956
+	 * @throws InvalidDataTypeException
957
+	 * @throws DomainException
958
+	 */
959
+	private static function registerPrivacyPolicies($addon_name)
960
+	{
961
+		if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
962
+			EE_Register_Privacy_Policy::register(
963
+				$addon_name,
964
+				self::$_settings[ $addon_name ]['privacy_policies']
965
+			);
966
+		}
967
+	}
968
+
969
+
970
+	/**
971
+	 * @param string $addon_name
972
+	 * @return void
973
+	 */
974
+	private static function registerPersonalDataExporters($addon_name)
975
+	{
976
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
977
+			EE_Register_Personal_Data_Eraser::register(
978
+				$addon_name,
979
+				self::$_settings[ $addon_name ]['personal_data_exporters']
980
+			);
981
+		}
982
+	}
983
+
984
+
985
+	/**
986
+	 * @param string $addon_name
987
+	 * @return void
988
+	 */
989
+	private static function registerPersonalDataErasers($addon_name)
990
+	{
991
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
992
+			EE_Register_Personal_Data_Eraser::register(
993
+				$addon_name,
994
+				self::$_settings[ $addon_name ]['personal_data_erasers']
995
+			);
996
+		}
997
+	}
998
+
999
+
1000
+	/**
1001
+	 * Loads and instantiates the EE_Addon class and adds it onto the registry
1002
+	 *
1003
+	 * @param string $addon_name
1004
+	 * @return EE_Addon
1005
+	 * @throws InvalidArgumentException
1006
+	 * @throws InvalidInterfaceException
1007
+	 * @throws InvalidDataTypeException
1008
+	 */
1009
+	private static function _load_and_init_addon_class($addon_name)
1010
+	{
1011
+		$addon = LoaderFactory::getLoader()->getShared(
1012
+			self::$_settings[ $addon_name ]['class_name'],
1013
+			array('EE_Registry::create(addon)' => true)
1014
+		);
1015
+		if (! $addon instanceof EE_Addon) {
1016
+			throw new DomainException(
1017
+				sprintf(
1018
+					esc_html__(
1019
+						'Failed to instantiate the %1$s class. PLease check that the class exists.',
1020
+						'event_espresso'
1021
+					),
1022
+					$addon_name
1023
+				)
1024
+			);
1025
+		}
1026
+		// setter inject dep map if required
1027
+		if ($addon->dependencyMap() === null) {
1028
+			$addon->setDependencyMap(LoaderFactory::getLoader()->getShared('EE_Dependency_Map'));
1029
+		}
1030
+		// setter inject domain if required
1031
+		EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1032
+
1033
+		$addon->set_name($addon_name);
1034
+		$addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1035
+		$addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1036
+		$addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1037
+		$addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1038
+		$addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1039
+		$addon->set_version(self::$_settings[ $addon_name ]['version']);
1040
+		$addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1041
+		$addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1042
+		$addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1043
+		$addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1044
+		// setup the add-on's pue_slug if we have one.
1045
+		if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) {
1046
+			$addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']);
1047
+		}
1048
+		// unfortunately this can't be hooked in upon construction,
1049
+		// because we don't have the plugin's mainfile path upon construction.
1050
+		register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
1051
+		// call any additional admin_callback functions during load_admin_controller hook
1052
+		if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1053
+			add_action(
1054
+				'AHEE__EE_System__load_controllers__load_admin_controllers',
1055
+				array($addon, self::$_settings[ $addon_name ]['admin_callback'])
1056
+			);
1057
+		}
1058
+		return $addon;
1059
+	}
1060
+
1061
+
1062
+	/**
1063
+	 * @param string   $addon_name
1064
+	 * @param EE_Addon $addon
1065
+	 * @since   $VID:$
1066
+	 */
1067
+	private static function injectAddonDomain($addon_name, EE_Addon $addon)
1068
+	{
1069
+		if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1070
+			// using supplied Domain object
1071
+			$domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1072
+				? self::$_settings[ $addon_name ]['domain']
1073
+				: null;
1074
+			// or construct one using Domain FQCN
1075
+			if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1076
+				$domain = LoaderFactory::getLoader()->getShared(
1077
+					self::$_settings[ $addon_name ]['domain_fqcn'],
1078
+					[
1079
+						new EventEspresso\core\domain\values\FilePath(
1080
+							self::$_settings[ $addon_name ]['main_file_path']
1081
+						),
1082
+						EventEspresso\core\domain\values\Version::fromString(
1083
+							self::$_settings[ $addon_name ]['version']
1084
+						),
1085
+					]
1086
+				);
1087
+			}
1088
+			if ($domain instanceof DomainInterface) {
1089
+				$addon->setDomain($domain);
1090
+			}
1091
+		}
1092
+	}
1093
+
1094
+
1095
+	/**
1096
+	 *    load_pue_update - Update notifications
1097
+	 *
1098
+	 * @return void
1099
+	 * @throws InvalidArgumentException
1100
+	 * @throws InvalidDataTypeException
1101
+	 * @throws InvalidInterfaceException
1102
+	 */
1103
+	public static function load_pue_update()
1104
+	{
1105
+		// load PUE client
1106
+		require_once EE_THIRD_PARTY . 'pue/pue-client.php';
1107
+		$license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
1108
+		// cycle thru settings
1109
+		foreach (self::$_settings as $settings) {
1110
+			if (! empty($settings['pue_options'])) {
1111
+				// initiate the class and start the plugin update engine!
1112
+				new PluginUpdateEngineChecker(
1113
+					// host file URL
1114
+					$license_server,
1115
+					// plugin slug(s)
1116
+					array(
1117
+						'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1118
+						'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1119
+					),
1120
+					// options
1121
+					array(
1122
+						'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
1123
+						'lang_domain'       => 'event_espresso',
1124
+						'checkPeriod'       => $settings['pue_options']['checkPeriod'],
1125
+						'option_key'        => 'ee_site_license_key',
1126
+						'options_page_slug' => 'event_espresso',
1127
+						'plugin_basename'   => $settings['pue_options']['plugin_basename'],
1128
+						// if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
1129
+						'use_wp_update'     => $settings['pue_options']['use_wp_update'],
1130
+					)
1131
+				);
1132
+			}
1133
+		}
1134
+	}
1135
+
1136
+
1137
+	/**
1138
+	 * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1139
+	 *
1140
+	 * @since 4.4.0
1141
+	 * @return void
1142
+	 * @throws EE_Error
1143
+	 */
1144
+	public static function register_message_types()
1145
+	{
1146
+		foreach (self::$_settings as $settings) {
1147
+			if (! empty($settings['message_types'])) {
1148
+				foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1149
+					EE_Register_Message_Type::register($message_type, $message_type_settings);
1150
+				}
1151
+			}
1152
+		}
1153
+	}
1154
+
1155
+
1156
+	/**
1157
+	 * This deregisters an addon that was previously registered with a specific addon_name.
1158
+	 *
1159
+	 * @param string $addon_name the name for the addon that was previously registered
1160
+	 * @throws DomainException
1161
+	 * @throws InvalidArgumentException
1162
+	 * @throws InvalidDataTypeException
1163
+	 * @throws InvalidInterfaceException
1164
+	 *@since    4.3.0
1165
+	 */
1166
+	public static function deregister($addon_name = '')
1167
+	{
1168
+		if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1169
+			try {
1170
+				do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1171
+				$class_name = self::$_settings[ $addon_name ]['class_name'];
1172
+				if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1173
+					// setup DMS
1174
+					EE_Register_Data_Migration_Scripts::deregister($addon_name);
1175
+				}
1176
+				if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1177
+					// register admin page
1178
+					EE_Register_Admin_Page::deregister($addon_name);
1179
+				}
1180
+				if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1181
+					// add to list of modules to be registered
1182
+					EE_Register_Module::deregister($addon_name);
1183
+				}
1184
+				if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1185
+					|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1186
+				) {
1187
+					// add to list of shortcodes to be registered
1188
+					EE_Register_Shortcode::deregister($addon_name);
1189
+				}
1190
+				if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1191
+					// if config_class present let's register config.
1192
+					EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1193
+				}
1194
+				if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1195
+					// add to list of widgets to be registered
1196
+					EE_Register_Widget::deregister($addon_name);
1197
+				}
1198
+				if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1199
+					|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
1200
+				) {
1201
+					// add to list of shortcodes to be registered
1202
+					EE_Register_Model::deregister($addon_name);
1203
+				}
1204
+				if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1205
+					|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1206
+				) {
1207
+					// add to list of shortcodes to be registered
1208
+					EE_Register_Model_Extensions::deregister($addon_name);
1209
+				}
1210
+				if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1211
+					foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1212
+						EE_Register_Message_Type::deregister($message_type);
1213
+					}
1214
+				}
1215
+				// deregister capabilities for addon
1216
+				if (! empty(self::$_settings[ $addon_name ]['capabilities'])
1217
+					|| ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1218
+				) {
1219
+					EE_Register_Capabilities::deregister($addon_name);
1220
+				}
1221
+				// deregister custom_post_types for addon
1222
+				if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1223
+					EE_Register_CPT::deregister($addon_name);
1224
+				}
1225
+				if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1226
+					EE_Register_Payment_Method::deregister($addon_name);
1227
+				}
1228
+				$addon = EE_Registry::instance()->getAddon($class_name);
1229
+				if ($addon instanceof EE_Addon) {
1230
+					remove_action(
1231
+						'deactivate_' . $addon->get_main_plugin_file_basename(),
1232
+						array($addon, 'deactivation')
1233
+					);
1234
+					remove_action(
1235
+						'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1236
+						array($addon, 'initialize_db_if_no_migrations_required')
1237
+					);
1238
+					// remove `after_registration` call
1239
+					remove_action(
1240
+						'AHEE__EE_System__load_espresso_addons__complete',
1241
+						array($addon, 'after_registration'),
1242
+						999
1243
+					);
1244
+				}
1245
+				EE_Registry::instance()->removeAddon($class_name);
1246
+			} catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1247
+				// the add-on was not yet registered in the registry,
1248
+				// so RegistryContainer::__get() throws this exception.
1249
+				// also no need to worry about this or log it,
1250
+				// it's ok to deregister an add-on before its registered in the registry
1251
+			} catch (Exception $e) {
1252
+				new ExceptionLogger($e);
1253
+			}
1254
+			unset(self::$_settings[ $addon_name ]);
1255
+			do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1256
+		}
1257
+	}
1258 1258
 }
Please login to merge, or discard this patch.
Spacing   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -69,15 +69,15 @@  discard block
 block discarded – undo
69 69
         // offsets:    0 . 1 . 2 . 3 . 4
70 70
         $version_parts = explode('.', $min_core_version);
71 71
         // check they specified the micro version (after 2nd period)
72
-        if (! isset($version_parts[2])) {
72
+        if ( ! isset($version_parts[2])) {
73 73
             $version_parts[2] = '0';
74 74
         }
75 75
         // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
76 76
         // soon we can assume that's 'rc', but this current version is 'alpha'
77
-        if (! isset($version_parts[3])) {
77
+        if ( ! isset($version_parts[3])) {
78 78
             $version_parts[3] = 'dev';
79 79
         }
80
-        if (! isset($version_parts[4])) {
80
+        if ( ! isset($version_parts[4])) {
81 81
             $version_parts[4] = '000';
82 82
         }
83 83
         return implode('.', $version_parts);
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
         EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
265 265
         // does this addon work with this version of core or WordPress ?
266 266
         // does this addon work with this version of core or WordPress ?
267
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
267
+        if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
268 268
             return;
269 269
         }
270 270
         // register namespaces
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
                 )
329 329
             );
330 330
         }
331
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
331
+        if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
332 332
             throw new EE_Error(
333 333
                 sprintf(
334 334
                     __(
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
             );
341 341
         }
342 342
         // check that addon has not already been registered with that name
343
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
343
+        if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
344 344
             throw new EE_Error(
345 345
                 sprintf(
346 346
                     __(
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
         // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
373 373
         return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
374 374
             ? $class_name
375
-            : 'EE_' . $class_name;
375
+            : 'EE_'.$class_name;
376 376
     }
377 377
 
378 378
 
@@ -537,9 +537,9 @@  discard block
 block discarded – undo
537 537
         global $wp_version;
538 538
         $incompatibility_message = '';
539 539
         // check whether this addon version is compatible with EE core
540
-        if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
540
+        if (isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
541 541
             && ! self::_meets_min_core_version_requirement(
542
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
542
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
543 543
                 $addon_settings['version']
544 544
             )
545 545
         ) {
@@ -550,11 +550,11 @@  discard block
 block discarded – undo
550 550
                 ),
551 551
                 $addon_name,
552 552
                 '<br />',
553
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
553
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
554 554
                 '<span style="font-weight: bold; color: #D54E21;">',
555 555
                 '</span><br />'
556 556
             );
557
-        } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
557
+        } elseif ( ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
558 558
         ) {
559 559
             $incompatibility_message = sprintf(
560 560
                 __(
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
                 '</span><br />'
582 582
             );
583 583
         }
584
-        if (! empty($incompatibility_message)) {
584
+        if ( ! empty($incompatibility_message)) {
585 585
             // remove 'activate' from the REQUEST
586 586
             // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
587 587
             unset($_GET['activate'], $_REQUEST['activate']);
@@ -609,11 +609,11 @@  discard block
 block discarded – undo
609 609
      */
610 610
     private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
611 611
     {
612
-        if (! empty($setup_args['pue_options'])) {
613
-            self::$_settings[ $addon_name ]['pue_options'] = array(
612
+        if ( ! empty($setup_args['pue_options'])) {
613
+            self::$_settings[$addon_name]['pue_options'] = array(
614 614
                 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
615 615
                     ? (string) $setup_args['pue_options']['pue_plugin_slug']
616
-                    : 'espresso_' . strtolower($class_name),
616
+                    : 'espresso_'.strtolower($class_name),
617 617
                 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
618 618
                     ? (string) $setup_args['pue_options']['plugin_basename']
619 619
                     : plugin_basename($setup_args['main_file_path']),
@@ -669,12 +669,12 @@  discard block
 block discarded – undo
669 669
             // (as the newly-activated addon wasn't around the first time addons were registered).
670 670
             // Note: the presence of pue_options in the addon registration options will initialize the $_settings
671 671
             // property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
672
-            if (! isset(self::$_settings[ $addon_name ])
673
-                || (isset(self::$_settings[ $addon_name ])
674
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
672
+            if ( ! isset(self::$_settings[$addon_name])
673
+                || (isset(self::$_settings[$addon_name])
674
+                    && ! isset(self::$_settings[$addon_name]['class_name'])
675 675
                 )
676 676
             ) {
677
-                self::$_settings[ $addon_name ] = $addon_settings;
677
+                self::$_settings[$addon_name] = $addon_settings;
678 678
                 $addon = self::_load_and_init_addon_class($addon_name);
679 679
                 $addon->set_activation_indicator_option();
680 680
                 // dont bother setting up the rest of the addon.
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
             return true;
684 684
         }
685 685
         // make sure this was called in the right place!
686
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
686
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons')
687 687
             || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
688 688
         ) {
689 689
             EE_Error::doing_it_wrong(
@@ -699,10 +699,10 @@  discard block
 block discarded – undo
699 699
             );
700 700
         }
701 701
         // make sure addon settings are set correctly without overwriting anything existing
702
-        if (isset(self::$_settings[ $addon_name ])) {
703
-            self::$_settings[ $addon_name ] += $addon_settings;
702
+        if (isset(self::$_settings[$addon_name])) {
703
+            self::$_settings[$addon_name] += $addon_settings;
704 704
         } else {
705
-            self::$_settings[ $addon_name ] = $addon_settings;
705
+            self::$_settings[$addon_name] = $addon_settings;
706 706
         }
707 707
         return false;
708 708
     }
@@ -715,13 +715,13 @@  discard block
 block discarded – undo
715 715
      */
716 716
     private static function _setup_autoloaders($addon_name)
717 717
     {
718
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
718
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
719 719
             // setup autoloader for single file
720
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
720
+            EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
721 721
         }
722 722
         // setup autoloaders for folders
723
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
724
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
723
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
724
+            foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
725 725
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
726 726
             }
727 727
         }
@@ -738,26 +738,26 @@  discard block
 block discarded – undo
738 738
     private static function _register_models_and_extensions($addon_name)
739 739
     {
740 740
         // register new models
741
-        if (! empty(self::$_settings[ $addon_name ]['model_paths'])
742
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
741
+        if ( ! empty(self::$_settings[$addon_name]['model_paths'])
742
+            || ! empty(self::$_settings[$addon_name]['class_paths'])
743 743
         ) {
744 744
             EE_Register_Model::register(
745 745
                 $addon_name,
746 746
                 array(
747
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
748
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
747
+                    'model_paths' => self::$_settings[$addon_name]['model_paths'],
748
+                    'class_paths' => self::$_settings[$addon_name]['class_paths'],
749 749
                 )
750 750
             );
751 751
         }
752 752
         // register model extensions
753
-        if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
754
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
753
+        if ( ! empty(self::$_settings[$addon_name]['model_extension_paths'])
754
+            || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
755 755
         ) {
756 756
             EE_Register_Model_Extensions::register(
757 757
                 $addon_name,
758 758
                 array(
759
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
760
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
759
+                    'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
760
+                    'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
761 761
                 )
762 762
             );
763 763
         }
@@ -772,10 +772,10 @@  discard block
 block discarded – undo
772 772
     private static function _register_data_migration_scripts($addon_name)
773 773
     {
774 774
         // setup DMS
775
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
775
+        if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
776 776
             EE_Register_Data_Migration_Scripts::register(
777 777
                 $addon_name,
778
-                array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths'])
778
+                array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
779 779
             );
780 780
         }
781 781
     }
@@ -789,12 +789,12 @@  discard block
 block discarded – undo
789 789
     private static function _register_config($addon_name)
790 790
     {
791 791
         // if config_class is present let's register config.
792
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
792
+        if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
793 793
             EE_Register_Config::register(
794
-                self::$_settings[ $addon_name ]['config_class'],
794
+                self::$_settings[$addon_name]['config_class'],
795 795
                 array(
796
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
797
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
796
+                    'config_section' => self::$_settings[$addon_name]['config_section'],
797
+                    'config_name'    => self::$_settings[$addon_name]['config_name'],
798 798
                 )
799 799
             );
800 800
         }
@@ -808,10 +808,10 @@  discard block
 block discarded – undo
808 808
      */
809 809
     private static function _register_admin_pages($addon_name)
810 810
     {
811
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
811
+        if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
812 812
             EE_Register_Admin_Page::register(
813 813
                 $addon_name,
814
-                array('page_path' => self::$_settings[ $addon_name ]['admin_path'])
814
+                array('page_path' => self::$_settings[$addon_name]['admin_path'])
815 815
             );
816 816
         }
817 817
     }
@@ -824,10 +824,10 @@  discard block
 block discarded – undo
824 824
      */
825 825
     private static function _register_modules($addon_name)
826 826
     {
827
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
827
+        if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
828 828
             EE_Register_Module::register(
829 829
                 $addon_name,
830
-                array('module_paths' => self::$_settings[ $addon_name ]['module_paths'])
830
+                array('module_paths' => self::$_settings[$addon_name]['module_paths'])
831 831
             );
832 832
         }
833 833
     }
@@ -840,16 +840,16 @@  discard block
 block discarded – undo
840 840
      */
841 841
     private static function _register_shortcodes($addon_name)
842 842
     {
843
-        if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
844
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
843
+        if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
844
+            || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
845 845
         ) {
846 846
             EE_Register_Shortcode::register(
847 847
                 $addon_name,
848 848
                 array(
849
-                    'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths'])
850
-                        ? self::$_settings[ $addon_name ]['shortcode_paths'] : array(),
851
-                    'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns'])
852
-                        ? self::$_settings[ $addon_name ]['shortcode_fqcns'] : array(),
849
+                    'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths'])
850
+                        ? self::$_settings[$addon_name]['shortcode_paths'] : array(),
851
+                    'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns'])
852
+                        ? self::$_settings[$addon_name]['shortcode_fqcns'] : array(),
853 853
                 )
854 854
             );
855 855
         }
@@ -863,10 +863,10 @@  discard block
 block discarded – undo
863 863
      */
864 864
     private static function _register_widgets($addon_name)
865 865
     {
866
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
866
+        if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
867 867
             EE_Register_Widget::register(
868 868
                 $addon_name,
869
-                array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths'])
869
+                array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
870 870
             );
871 871
         }
872 872
     }
@@ -879,12 +879,12 @@  discard block
 block discarded – undo
879 879
      */
880 880
     private static function _register_capabilities($addon_name)
881 881
     {
882
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
882
+        if ( ! empty(self::$_settings[$addon_name]['capabilities'])) {
883 883
             EE_Register_Capabilities::register(
884 884
                 $addon_name,
885 885
                 array(
886
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
887
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
886
+                    'capabilities'    => self::$_settings[$addon_name]['capabilities'],
887
+                    'capability_maps' => self::$_settings[$addon_name]['capability_maps'],
888 888
                 )
889 889
             );
890 890
         }
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
      */
898 898
     private static function _register_message_types($addon_name)
899 899
     {
900
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
900
+        if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
901 901
             add_action(
902 902
                 'EE_Brewing_Regular___messages_caf',
903 903
                 array('EE_Register_Addon', 'register_message_types')
@@ -913,15 +913,15 @@  discard block
 block discarded – undo
913 913
      */
914 914
     private static function _register_custom_post_types($addon_name)
915 915
     {
916
-        if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])
917
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
916
+        if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])
917
+            || ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
918 918
         ) {
919 919
             EE_Register_CPT::register(
920 920
                 $addon_name,
921 921
                 array(
922
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
923
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
924
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
922
+                    'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
923
+                    'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
924
+                    'default_terms' => self::$_settings[$addon_name]['default_terms'],
925 925
                 )
926 926
             );
927 927
         }
@@ -939,10 +939,10 @@  discard block
 block discarded – undo
939 939
      */
940 940
     private static function _register_payment_methods($addon_name)
941 941
     {
942
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
942
+        if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
943 943
             EE_Register_Payment_Method::register(
944 944
                 $addon_name,
945
-                array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths'])
945
+                array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
946 946
             );
947 947
         }
948 948
     }
@@ -958,10 +958,10 @@  discard block
 block discarded – undo
958 958
      */
959 959
     private static function registerPrivacyPolicies($addon_name)
960 960
     {
961
-        if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
961
+        if ( ! empty(self::$_settings[$addon_name]['privacy_policies'])) {
962 962
             EE_Register_Privacy_Policy::register(
963 963
                 $addon_name,
964
-                self::$_settings[ $addon_name ]['privacy_policies']
964
+                self::$_settings[$addon_name]['privacy_policies']
965 965
             );
966 966
         }
967 967
     }
@@ -973,10 +973,10 @@  discard block
 block discarded – undo
973 973
      */
974 974
     private static function registerPersonalDataExporters($addon_name)
975 975
     {
976
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
976
+        if ( ! empty(self::$_settings[$addon_name]['personal_data_exporters'])) {
977 977
             EE_Register_Personal_Data_Eraser::register(
978 978
                 $addon_name,
979
-                self::$_settings[ $addon_name ]['personal_data_exporters']
979
+                self::$_settings[$addon_name]['personal_data_exporters']
980 980
             );
981 981
         }
982 982
     }
@@ -988,10 +988,10 @@  discard block
 block discarded – undo
988 988
      */
989 989
     private static function registerPersonalDataErasers($addon_name)
990 990
     {
991
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
991
+        if ( ! empty(self::$_settings[$addon_name]['personal_data_erasers'])) {
992 992
             EE_Register_Personal_Data_Eraser::register(
993 993
                 $addon_name,
994
-                self::$_settings[ $addon_name ]['personal_data_erasers']
994
+                self::$_settings[$addon_name]['personal_data_erasers']
995 995
             );
996 996
         }
997 997
     }
@@ -1009,10 +1009,10 @@  discard block
 block discarded – undo
1009 1009
     private static function _load_and_init_addon_class($addon_name)
1010 1010
     {
1011 1011
         $addon = LoaderFactory::getLoader()->getShared(
1012
-            self::$_settings[ $addon_name ]['class_name'],
1012
+            self::$_settings[$addon_name]['class_name'],
1013 1013
             array('EE_Registry::create(addon)' => true)
1014 1014
         );
1015
-        if (! $addon instanceof EE_Addon) {
1015
+        if ( ! $addon instanceof EE_Addon) {
1016 1016
             throw new DomainException(
1017 1017
                 sprintf(
1018 1018
                     esc_html__(
@@ -1031,28 +1031,28 @@  discard block
 block discarded – undo
1031 1031
         EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1032 1032
 
1033 1033
         $addon->set_name($addon_name);
1034
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1035
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1036
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1037
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1038
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1039
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
1040
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1041
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1042
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1043
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1034
+        $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
1035
+        $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
1036
+        $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
1037
+        $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
1038
+        $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
1039
+        $addon->set_version(self::$_settings[$addon_name]['version']);
1040
+        $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
1041
+        $addon->set_config_section(self::$_settings[$addon_name]['config_section']);
1042
+        $addon->set_config_class(self::$_settings[$addon_name]['config_class']);
1043
+        $addon->set_config_name(self::$_settings[$addon_name]['config_name']);
1044 1044
         // setup the add-on's pue_slug if we have one.
1045
-        if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) {
1046
-            $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']);
1045
+        if ( ! empty(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug'])) {
1046
+            $addon->setPueSlug(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug']);
1047 1047
         }
1048 1048
         // unfortunately this can't be hooked in upon construction,
1049 1049
         // because we don't have the plugin's mainfile path upon construction.
1050 1050
         register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
1051 1051
         // call any additional admin_callback functions during load_admin_controller hook
1052
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1052
+        if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) {
1053 1053
             add_action(
1054 1054
                 'AHEE__EE_System__load_controllers__load_admin_controllers',
1055
-                array($addon, self::$_settings[ $addon_name ]['admin_callback'])
1055
+                array($addon, self::$_settings[$addon_name]['admin_callback'])
1056 1056
             );
1057 1057
         }
1058 1058
         return $addon;
@@ -1068,19 +1068,19 @@  discard block
 block discarded – undo
1068 1068
     {
1069 1069
         if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1070 1070
             // using supplied Domain object
1071
-            $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1072
-                ? self::$_settings[ $addon_name ]['domain']
1071
+            $domain = self::$_settings[$addon_name]['domain'] instanceof DomainInterface
1072
+                ? self::$_settings[$addon_name]['domain']
1073 1073
                 : null;
1074 1074
             // or construct one using Domain FQCN
1075
-            if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1075
+            if ($domain === null && self::$_settings[$addon_name]['domain_fqcn'] !== '') {
1076 1076
                 $domain = LoaderFactory::getLoader()->getShared(
1077
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
1077
+                    self::$_settings[$addon_name]['domain_fqcn'],
1078 1078
                     [
1079 1079
                         new EventEspresso\core\domain\values\FilePath(
1080
-                            self::$_settings[ $addon_name ]['main_file_path']
1080
+                            self::$_settings[$addon_name]['main_file_path']
1081 1081
                         ),
1082 1082
                         EventEspresso\core\domain\values\Version::fromString(
1083
-                            self::$_settings[ $addon_name ]['version']
1083
+                            self::$_settings[$addon_name]['version']
1084 1084
                         ),
1085 1085
                     ]
1086 1086
                 );
@@ -1103,11 +1103,11 @@  discard block
 block discarded – undo
1103 1103
     public static function load_pue_update()
1104 1104
     {
1105 1105
         // load PUE client
1106
-        require_once EE_THIRD_PARTY . 'pue/pue-client.php';
1106
+        require_once EE_THIRD_PARTY.'pue/pue-client.php';
1107 1107
         $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
1108 1108
         // cycle thru settings
1109 1109
         foreach (self::$_settings as $settings) {
1110
-            if (! empty($settings['pue_options'])) {
1110
+            if ( ! empty($settings['pue_options'])) {
1111 1111
                 // initiate the class and start the plugin update engine!
1112 1112
                 new PluginUpdateEngineChecker(
1113 1113
                     // host file URL
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
                     // plugin slug(s)
1116 1116
                     array(
1117 1117
                         'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
1118
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
1118
+                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'),
1119 1119
                     ),
1120 1120
                     // options
1121 1121
                     array(
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
     public static function register_message_types()
1145 1145
     {
1146 1146
         foreach (self::$_settings as $settings) {
1147
-            if (! empty($settings['message_types'])) {
1147
+            if ( ! empty($settings['message_types'])) {
1148 1148
                 foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1149 1149
                     EE_Register_Message_Type::register($message_type, $message_type_settings);
1150 1150
                 }
@@ -1165,70 +1165,70 @@  discard block
 block discarded – undo
1165 1165
      */
1166 1166
     public static function deregister($addon_name = '')
1167 1167
     {
1168
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1168
+        if (isset(self::$_settings[$addon_name]['class_name'])) {
1169 1169
             try {
1170 1170
                 do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1171
-                $class_name = self::$_settings[ $addon_name ]['class_name'];
1172
-                if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1171
+                $class_name = self::$_settings[$addon_name]['class_name'];
1172
+                if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
1173 1173
                     // setup DMS
1174 1174
                     EE_Register_Data_Migration_Scripts::deregister($addon_name);
1175 1175
                 }
1176
-                if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1176
+                if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
1177 1177
                     // register admin page
1178 1178
                     EE_Register_Admin_Page::deregister($addon_name);
1179 1179
                 }
1180
-                if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1180
+                if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
1181 1181
                     // add to list of modules to be registered
1182 1182
                     EE_Register_Module::deregister($addon_name);
1183 1183
                 }
1184
-                if (! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1185
-                    || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1184
+                if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])
1185
+                    || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
1186 1186
                 ) {
1187 1187
                     // add to list of shortcodes to be registered
1188 1188
                     EE_Register_Shortcode::deregister($addon_name);
1189 1189
                 }
1190
-                if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1190
+                if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
1191 1191
                     // if config_class present let's register config.
1192
-                    EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1192
+                    EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1193 1193
                 }
1194
-                if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1194
+                if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
1195 1195
                     // add to list of widgets to be registered
1196 1196
                     EE_Register_Widget::deregister($addon_name);
1197 1197
                 }
1198
-                if (! empty(self::$_settings[ $addon_name ]['model_paths'])
1199
-                    || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1198
+                if ( ! empty(self::$_settings[$addon_name]['model_paths'])
1199
+                    || ! empty(self::$_settings[$addon_name]['class_paths'])
1200 1200
                 ) {
1201 1201
                     // add to list of shortcodes to be registered
1202 1202
                     EE_Register_Model::deregister($addon_name);
1203 1203
                 }
1204
-                if (! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1205
-                    || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1204
+                if ( ! empty(self::$_settings[$addon_name]['model_extension_paths'])
1205
+                    || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1206 1206
                 ) {
1207 1207
                     // add to list of shortcodes to be registered
1208 1208
                     EE_Register_Model_Extensions::deregister($addon_name);
1209 1209
                 }
1210
-                if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1211
-                    foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1210
+                if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
1211
+                    foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1212 1212
                         EE_Register_Message_Type::deregister($message_type);
1213 1213
                     }
1214 1214
                 }
1215 1215
                 // deregister capabilities for addon
1216
-                if (! empty(self::$_settings[ $addon_name ]['capabilities'])
1217
-                    || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1216
+                if ( ! empty(self::$_settings[$addon_name]['capabilities'])
1217
+                    || ! empty(self::$_settings[$addon_name]['capability_maps'])
1218 1218
                 ) {
1219 1219
                     EE_Register_Capabilities::deregister($addon_name);
1220 1220
                 }
1221 1221
                 // deregister custom_post_types for addon
1222
-                if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1222
+                if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1223 1223
                     EE_Register_CPT::deregister($addon_name);
1224 1224
                 }
1225
-                if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1225
+                if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1226 1226
                     EE_Register_Payment_Method::deregister($addon_name);
1227 1227
                 }
1228 1228
                 $addon = EE_Registry::instance()->getAddon($class_name);
1229 1229
                 if ($addon instanceof EE_Addon) {
1230 1230
                     remove_action(
1231
-                        'deactivate_' . $addon->get_main_plugin_file_basename(),
1231
+                        'deactivate_'.$addon->get_main_plugin_file_basename(),
1232 1232
                         array($addon, 'deactivation')
1233 1233
                     );
1234 1234
                     remove_action(
@@ -1251,7 +1251,7 @@  discard block
 block discarded – undo
1251 1251
             } catch (Exception $e) {
1252 1252
                 new ExceptionLogger($e);
1253 1253
             }
1254
-            unset(self::$_settings[ $addon_name ]);
1254
+            unset(self::$_settings[$addon_name]);
1255 1255
             do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1256 1256
         }
1257 1257
     }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Model.lib.php 2 patches
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -11,183 +11,183 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Register_Model implements EEI_Plugin_API
13 13
 {
14
-    /**
15
-     *
16
-     * @var array keys are the model_id used to register with, values are the array provided to register them, exactly
17
-     *      like EE_Register_Model::register()'s 2nd arg
18
-     */
19
-    protected static $_model_registry;
14
+	/**
15
+	 *
16
+	 * @var array keys are the model_id used to register with, values are the array provided to register them, exactly
17
+	 *      like EE_Register_Model::register()'s 2nd arg
18
+	 */
19
+	protected static $_model_registry;
20 20
 
21
-    /**
22
-     *
23
-     * @var array keys are model names, values are their class names. Stored on registration and used
24
-     * on a hook
25
-     */
26
-    protected static $_model_name_to_classname_map;
21
+	/**
22
+	 *
23
+	 * @var array keys are model names, values are their class names. Stored on registration and used
24
+	 * on a hook
25
+	 */
26
+	protected static $_model_name_to_classname_map;
27 27
 
28 28
 
29
-    /**
30
-     * @param string $identifier  unique id for it
31
-     * @param array  $setup_args  {
32
-     * @type array   $model_paths array of folders containing DB models, where each file follows the models naming
33
-     *                            convention, which is: EEM_{model_name}.model.php which contains a single class called
34
-     *                            EEM_{model_name}. Eg. you could pass
35
-     *                            "public_html/wp-content/plugins/my_addon/db_models" (with or without trailing slash)
36
-     *                            and in that folder put each of your model files, like "EEM_Food.model.php" which
37
-     *                            contains the class "EEM_Food" and
38
-     *                            "EEM_Monkey.model.php" which contains the class "EEM_Monkey". These will be
39
-     *                            autoloaded and added to the EE registry so they can be used like ordinary models. The
40
-     *                            class contained in each file should extend EEM_Base.
41
-     * @type array   $class_paths array of folders containing DB classes, where each file follows the model class
42
-     *                            naming convention, which is EE_{model_name}.class.php. The class contained in each
43
-     *                            file should extend EE_Base_Class
44
-     *
45
-     * }
46
-     * @throws EE_Error
47
-     */
48
-    public static function register($identifier = '', array $setup_args = [])
49
-    {
50
-        // required fields MUST be present, so let's make sure they are.
51
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['model_paths'])) {
52
-            throw new EE_Error(
53
-                __(
54
-                    'In order to register Models with EE_Register_Model::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_paths" (an array of full server paths to folders that contain models)',
55
-                    'event_espresso'
56
-                )
57
-            );
58
-        }
29
+	/**
30
+	 * @param string $identifier  unique id for it
31
+	 * @param array  $setup_args  {
32
+	 * @type array   $model_paths array of folders containing DB models, where each file follows the models naming
33
+	 *                            convention, which is: EEM_{model_name}.model.php which contains a single class called
34
+	 *                            EEM_{model_name}. Eg. you could pass
35
+	 *                            "public_html/wp-content/plugins/my_addon/db_models" (with or without trailing slash)
36
+	 *                            and in that folder put each of your model files, like "EEM_Food.model.php" which
37
+	 *                            contains the class "EEM_Food" and
38
+	 *                            "EEM_Monkey.model.php" which contains the class "EEM_Monkey". These will be
39
+	 *                            autoloaded and added to the EE registry so they can be used like ordinary models. The
40
+	 *                            class contained in each file should extend EEM_Base.
41
+	 * @type array   $class_paths array of folders containing DB classes, where each file follows the model class
42
+	 *                            naming convention, which is EE_{model_name}.class.php. The class contained in each
43
+	 *                            file should extend EE_Base_Class
44
+	 *
45
+	 * }
46
+	 * @throws EE_Error
47
+	 */
48
+	public static function register($identifier = '', array $setup_args = [])
49
+	{
50
+		// required fields MUST be present, so let's make sure they are.
51
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['model_paths'])) {
52
+			throw new EE_Error(
53
+				__(
54
+					'In order to register Models with EE_Register_Model::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_paths" (an array of full server paths to folders that contain models)',
55
+					'event_espresso'
56
+				)
57
+			);
58
+		}
59 59
 
60
-        // make sure we don't register twice
61
-        if (isset(self::$_model_registry[ $identifier ])) {
62
-            return;
63
-        }
60
+		// make sure we don't register twice
61
+		if (isset(self::$_model_registry[ $identifier ])) {
62
+			return;
63
+		}
64 64
 
65
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
66
-            || did_action('FHEE__EE_System__parse_model_names')
67
-            || did_action('FHEE__EE_System__parse_implemented_model_names')) {
68
-            EE_Error::doing_it_wrong(
69
-                __METHOD__,
70
-                sprintf(
71
-                    __(
72
-                        'An attempt was made to register "%s" as a group models has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.',
73
-                        'event_espresso'
74
-                    ),
75
-                    $identifier
76
-                ),
77
-                '4.5'
78
-            );
79
-        }
80
-        self::$_model_registry[ $identifier ] = $setup_args;
65
+		if (! did_action('AHEE__EE_System__load_espresso_addons')
66
+			|| did_action('FHEE__EE_System__parse_model_names')
67
+			|| did_action('FHEE__EE_System__parse_implemented_model_names')) {
68
+			EE_Error::doing_it_wrong(
69
+				__METHOD__,
70
+				sprintf(
71
+					__(
72
+						'An attempt was made to register "%s" as a group models has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.',
73
+						'event_espresso'
74
+					),
75
+					$identifier
76
+				),
77
+				'4.5'
78
+			);
79
+		}
80
+		self::$_model_registry[ $identifier ] = $setup_args;
81 81
 
82
-        if ((isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
83
-            || (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))) {
84
-            throw new EE_Error(
85
-                sprintf(
86
-                    __(
87
-                        'You must register both "model_paths" AND "class_paths", not just one or the other You provided %s',
88
-                        'event_espresso'
89
-                    ),
90
-                    implode(", ", array_keys($setup_args))
91
-                )
92
-            );
93
-        }
94
-        if (isset($setup_args['model_paths'])) {
95
-            // make sure they passed in an array
96
-            if (! is_array($setup_args['model_paths'])) {
97
-                $setup_args['model_paths'] = [$setup_args['model_paths']];
98
-            }
99
-            // we want to add this as a model folder
100
-            // and autoload them all
101
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_paths']);
102
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
103
-            $model_name_to_classname_map = [];
104
-            foreach (array_keys($class_to_filepath_map) as $classname) {
105
-                $model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
106
-            }
107
-            self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
108
-            add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
109
-            add_filter(
110
-                'FHEE__EE_System__parse_implemented_model_names',
111
-                ['EE_Register_Model', 'add_addon_models']
112
-            );
113
-            add_filter('FHEE__EE_Registry__load_model__paths', ['EE_Register_Model', 'add_model_folders']);
114
-            unset($setup_args['model_paths']);
115
-        }
116
-        if (isset($setup_args['class_paths'])) {
117
-            // make sure they passed in an array
118
-            if (! is_array($setup_args['class_paths'])) {
119
-                $setup_args['class_paths'] = [$setup_args['class_paths']];
120
-            }
121
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
122
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
123
-            add_filter('FHEE__EE_Registry__load_class__paths', ['EE_Register_Model', 'add_class_folders']);
124
-            unset($setup_args['class_paths']);
125
-        }
126
-        foreach ($setup_args as $unknown_key => $unknown_config) {
127
-            self::deregister($identifier);
128
-            throw new EE_Error(
129
-                sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
130
-            );
131
-        }
132
-    }
82
+		if ((isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
83
+			|| (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))) {
84
+			throw new EE_Error(
85
+				sprintf(
86
+					__(
87
+						'You must register both "model_paths" AND "class_paths", not just one or the other You provided %s',
88
+						'event_espresso'
89
+					),
90
+					implode(", ", array_keys($setup_args))
91
+				)
92
+			);
93
+		}
94
+		if (isset($setup_args['model_paths'])) {
95
+			// make sure they passed in an array
96
+			if (! is_array($setup_args['model_paths'])) {
97
+				$setup_args['model_paths'] = [$setup_args['model_paths']];
98
+			}
99
+			// we want to add this as a model folder
100
+			// and autoload them all
101
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_paths']);
102
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
103
+			$model_name_to_classname_map = [];
104
+			foreach (array_keys($class_to_filepath_map) as $classname) {
105
+				$model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
106
+			}
107
+			self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
108
+			add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
109
+			add_filter(
110
+				'FHEE__EE_System__parse_implemented_model_names',
111
+				['EE_Register_Model', 'add_addon_models']
112
+			);
113
+			add_filter('FHEE__EE_Registry__load_model__paths', ['EE_Register_Model', 'add_model_folders']);
114
+			unset($setup_args['model_paths']);
115
+		}
116
+		if (isset($setup_args['class_paths'])) {
117
+			// make sure they passed in an array
118
+			if (! is_array($setup_args['class_paths'])) {
119
+				$setup_args['class_paths'] = [$setup_args['class_paths']];
120
+			}
121
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
122
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
123
+			add_filter('FHEE__EE_Registry__load_class__paths', ['EE_Register_Model', 'add_class_folders']);
124
+			unset($setup_args['class_paths']);
125
+		}
126
+		foreach ($setup_args as $unknown_key => $unknown_config) {
127
+			self::deregister($identifier);
128
+			throw new EE_Error(
129
+				sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
130
+			);
131
+		}
132
+	}
133 133
 
134 134
 
135
-    /**
136
-     * Filters the core list of models
137
-     *
138
-     * @param array $core_models
139
-     * @return array keys are model names (eg 'Event') and values are their classes (eg 'EE_Event')
140
-     */
141
-    public static function add_addon_models(array $core_models = [])
142
-    {
143
-        foreach (self::$_model_name_to_classname_map as $model_name_to_class_map) {
144
-            $core_models = array_merge($core_models, $model_name_to_class_map);
145
-        }
146
-        return $core_models;
147
-    }
135
+	/**
136
+	 * Filters the core list of models
137
+	 *
138
+	 * @param array $core_models
139
+	 * @return array keys are model names (eg 'Event') and values are their classes (eg 'EE_Event')
140
+	 */
141
+	public static function add_addon_models(array $core_models = [])
142
+	{
143
+		foreach (self::$_model_name_to_classname_map as $model_name_to_class_map) {
144
+			$core_models = array_merge($core_models, $model_name_to_class_map);
145
+		}
146
+		return $core_models;
147
+	}
148 148
 
149 149
 
150
-    /**
151
-     * Filters the list of model folders
152
-     *
153
-     * @param array $folders
154
-     * @return array of folder paths
155
-     */
156
-    public static function add_model_folders(array $folders = [])
157
-    {
158
-        foreach (self::$_model_registry as $setup_args) {
159
-            if (isset($setup_args['model_paths'])) {
160
-                $folders = array_merge($folders, $setup_args['model_paths']);
161
-            }
162
-        }
163
-        return $folders;
164
-    }
150
+	/**
151
+	 * Filters the list of model folders
152
+	 *
153
+	 * @param array $folders
154
+	 * @return array of folder paths
155
+	 */
156
+	public static function add_model_folders(array $folders = [])
157
+	{
158
+		foreach (self::$_model_registry as $setup_args) {
159
+			if (isset($setup_args['model_paths'])) {
160
+				$folders = array_merge($folders, $setup_args['model_paths']);
161
+			}
162
+		}
163
+		return $folders;
164
+	}
165 165
 
166 166
 
167
-    /**
168
-     * Filters the array of model class paths
169
-     *
170
-     * @param array $folders
171
-     * @return array of folder paths
172
-     */
173
-    public static function add_class_folders(array $folders = [])
174
-    {
175
-        foreach (self::$_model_registry as $setup_args) {
176
-            if (isset($setup_args['class_paths'])) {
177
-                $folders = array_merge($folders, $setup_args['class_paths']);
178
-            }
179
-        }
180
-        return $folders;
181
-    }
167
+	/**
168
+	 * Filters the array of model class paths
169
+	 *
170
+	 * @param array $folders
171
+	 * @return array of folder paths
172
+	 */
173
+	public static function add_class_folders(array $folders = [])
174
+	{
175
+		foreach (self::$_model_registry as $setup_args) {
176
+			if (isset($setup_args['class_paths'])) {
177
+				$folders = array_merge($folders, $setup_args['class_paths']);
178
+			}
179
+		}
180
+		return $folders;
181
+	}
182 182
 
183 183
 
184
-    /**
185
-     * deregister
186
-     *
187
-     * @param string $identifier
188
-     */
189
-    public static function deregister($identifier = '')
190
-    {
191
-        unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
192
-    }
184
+	/**
185
+	 * deregister
186
+	 *
187
+	 * @param string $identifier
188
+	 */
189
+	public static function deregister($identifier = '')
190
+	{
191
+		unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
192
+	}
193 193
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -58,11 +58,11 @@  discard block
 block discarded – undo
58 58
         }
59 59
 
60 60
         // make sure we don't register twice
61
-        if (isset(self::$_model_registry[ $identifier ])) {
61
+        if (isset(self::$_model_registry[$identifier])) {
62 62
             return;
63 63
         }
64 64
 
65
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
65
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons')
66 66
             || did_action('FHEE__EE_System__parse_model_names')
67 67
             || did_action('FHEE__EE_System__parse_implemented_model_names')) {
68 68
             EE_Error::doing_it_wrong(
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
                 '4.5'
78 78
             );
79 79
         }
80
-        self::$_model_registry[ $identifier ] = $setup_args;
80
+        self::$_model_registry[$identifier] = $setup_args;
81 81
 
82 82
         if ((isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
83
-            || (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))) {
83
+            || ( ! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))) {
84 84
             throw new EE_Error(
85 85
                 sprintf(
86 86
                     __(
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
         }
94 94
         if (isset($setup_args['model_paths'])) {
95 95
             // make sure they passed in an array
96
-            if (! is_array($setup_args['model_paths'])) {
96
+            if ( ! is_array($setup_args['model_paths'])) {
97 97
                 $setup_args['model_paths'] = [$setup_args['model_paths']];
98 98
             }
99 99
             // we want to add this as a model folder
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
103 103
             $model_name_to_classname_map = [];
104 104
             foreach (array_keys($class_to_filepath_map) as $classname) {
105
-                $model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
105
+                $model_name_to_classname_map[str_replace("EEM_", "", $classname)] = $classname;
106 106
             }
107
-            self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
107
+            self::$_model_name_to_classname_map[$identifier] = $model_name_to_classname_map;
108 108
             add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
109 109
             add_filter(
110 110
                 'FHEE__EE_System__parse_implemented_model_names',
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         }
116 116
         if (isset($setup_args['class_paths'])) {
117 117
             // make sure they passed in an array
118
-            if (! is_array($setup_args['class_paths'])) {
118
+            if ( ! is_array($setup_args['class_paths'])) {
119 119
                 $setup_args['class_paths'] = [$setup_args['class_paths']];
120 120
             }
121 121
             $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
@@ -188,6 +188,6 @@  discard block
 block discarded – undo
188 188
      */
189 189
     public static function deregister($identifier = '')
190 190
     {
191
-        unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
191
+        unset(self::$_model_registry[$identifier], self::$_model_name_to_classname_map[$identifier]);
192 192
     }
193 193
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Module.lib.php 2 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -15,95 +15,95 @@
 block discarded – undo
15 15
 class EE_Register_Module implements EEI_Plugin_API
16 16
 {
17 17
 
18
-    /**
19
-     * Holds values for registered modules
20
-     *
21
-     * @var array
22
-     */
23
-    protected static $_settings = [];
18
+	/**
19
+	 * Holds values for registered modules
20
+	 *
21
+	 * @var array
22
+	 */
23
+	protected static $_settings = [];
24 24
 
25 25
 
26
-    /**
27
-     *    Method for registering new EED_Modules
28
-     *
29
-     * @param string $identifier a unique identifier for this set of modules Required.
30
-     * @param array  $setup_args an array of full server paths to folders containing any EED_Modules, or to the
31
-     *                           EED_Module files themselves Required.
32
-     * @type    array module_paths    an array of full server paths to folders containing any EED_Modules, or to the
33
-     *                           EED_Module files themselves
34
-     * @return void
35
-     * @throws EE_Error
36
-     * @since    4.3.0
37
-     */
38
-    public static function register($identifier = '', array $setup_args = [])
39
-    {
40
-        // required fields MUST be present, so let's make sure they are.
41
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['module_paths'])) {
42
-            throw new EE_Error(
43
-                __(
44
-                    'In order to register Modules with EE_Register_Module::register(), you must include a "module_id" (a unique identifier for this set of modules), and an array containing the following keys: "module_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
45
-                    'event_espresso'
46
-                )
47
-            );
48
-        }
26
+	/**
27
+	 *    Method for registering new EED_Modules
28
+	 *
29
+	 * @param string $identifier a unique identifier for this set of modules Required.
30
+	 * @param array  $setup_args an array of full server paths to folders containing any EED_Modules, or to the
31
+	 *                           EED_Module files themselves Required.
32
+	 * @type    array module_paths    an array of full server paths to folders containing any EED_Modules, or to the
33
+	 *                           EED_Module files themselves
34
+	 * @return void
35
+	 * @throws EE_Error
36
+	 * @since    4.3.0
37
+	 */
38
+	public static function register($identifier = '', array $setup_args = [])
39
+	{
40
+		// required fields MUST be present, so let's make sure they are.
41
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['module_paths'])) {
42
+			throw new EE_Error(
43
+				__(
44
+					'In order to register Modules with EE_Register_Module::register(), you must include a "module_id" (a unique identifier for this set of modules), and an array containing the following keys: "module_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
45
+					'event_espresso'
46
+				)
47
+			);
48
+		}
49 49
 
50
-        // make sure we don't register twice
51
-        if (isset(self::$_settings[ $identifier ])) {
52
-            return;
53
-        }
50
+		// make sure we don't register twice
51
+		if (isset(self::$_settings[ $identifier ])) {
52
+			return;
53
+		}
54 54
 
55
-        // make sure this was called in the right place!
56
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
57
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
58
-        ) {
59
-            EE_Error::doing_it_wrong(
60
-                __METHOD__,
61
-                __(
62
-                    'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
63
-                    'event_espresso'
64
-                ),
65
-                '4.3.0'
66
-            );
67
-        }
68
-        // setup $_settings array from incoming values.
69
-        self::$_settings[ $identifier ] = [
70
-            // array of full server paths to any EED_Modules used by the module
71
-            'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
72
-        ];
73
-        // add to list of modules to be registered
74
-        add_filter(
75
-            'FHEE__EE_Config__register_modules__modules_to_register',
76
-            ['EE_Register_Module', 'add_modules']
77
-        );
78
-    }
55
+		// make sure this was called in the right place!
56
+		if (! did_action('AHEE__EE_System__load_espresso_addons')
57
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
58
+		) {
59
+			EE_Error::doing_it_wrong(
60
+				__METHOD__,
61
+				__(
62
+					'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
63
+					'event_espresso'
64
+				),
65
+				'4.3.0'
66
+			);
67
+		}
68
+		// setup $_settings array from incoming values.
69
+		self::$_settings[ $identifier ] = [
70
+			// array of full server paths to any EED_Modules used by the module
71
+			'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
72
+		];
73
+		// add to list of modules to be registered
74
+		add_filter(
75
+			'FHEE__EE_Config__register_modules__modules_to_register',
76
+			['EE_Register_Module', 'add_modules']
77
+		);
78
+	}
79 79
 
80 80
 
81
-    /**
82
-     * Filters the list of modules to add ours.
83
-     * and they're just full filepaths to FOLDERS containing a module class file. Eg.
84
-     * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
85
-     *
86
-     * @param array $modules_to_register array of paths to all modules that require registering
87
-     * @return array
88
-     */
89
-    public static function add_modules(array $modules_to_register)
90
-    {
91
-        foreach (self::$_settings as $settings) {
92
-            $modules_to_register = array_merge($modules_to_register, $settings['module_paths']);
93
-        }
94
-        return $modules_to_register;
95
-    }
81
+	/**
82
+	 * Filters the list of modules to add ours.
83
+	 * and they're just full filepaths to FOLDERS containing a module class file. Eg.
84
+	 * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
85
+	 *
86
+	 * @param array $modules_to_register array of paths to all modules that require registering
87
+	 * @return array
88
+	 */
89
+	public static function add_modules(array $modules_to_register)
90
+	{
91
+		foreach (self::$_settings as $settings) {
92
+			$modules_to_register = array_merge($modules_to_register, $settings['module_paths']);
93
+		}
94
+		return $modules_to_register;
95
+	}
96 96
 
97 97
 
98
-    /**
99
-     * This deregisters a module that was previously registered with a specific $identifier.
100
-     *
101
-     * @param string $identifier the name for the module that was previously registered
102
-     * @return void
103
-     * @since    4.3.0
104
-     */
105
-    public static function deregister($identifier = '')
106
-    {
107
-        unset(self::$_settings[ $identifier ]);
108
-    }
98
+	/**
99
+	 * This deregisters a module that was previously registered with a specific $identifier.
100
+	 *
101
+	 * @param string $identifier the name for the module that was previously registered
102
+	 * @return void
103
+	 * @since    4.3.0
104
+	 */
105
+	public static function deregister($identifier = '')
106
+	{
107
+		unset(self::$_settings[ $identifier ]);
108
+	}
109 109
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -48,12 +48,12 @@  discard block
 block discarded – undo
48 48
         }
49 49
 
50 50
         // make sure we don't register twice
51
-        if (isset(self::$_settings[ $identifier ])) {
51
+        if (isset(self::$_settings[$identifier])) {
52 52
             return;
53 53
         }
54 54
 
55 55
         // make sure this was called in the right place!
56
-        if (! did_action('AHEE__EE_System__load_espresso_addons')
56
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons')
57 57
             || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
58 58
         ) {
59 59
             EE_Error::doing_it_wrong(
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
             );
67 67
         }
68 68
         // setup $_settings array from incoming values.
69
-        self::$_settings[ $identifier ] = [
69
+        self::$_settings[$identifier] = [
70 70
             // array of full server paths to any EED_Modules used by the module
71 71
             'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
72 72
         ];
@@ -104,6 +104,6 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public static function deregister($identifier = '')
106 106
     {
107
-        unset(self::$_settings[ $identifier ]);
107
+        unset(self::$_settings[$identifier]);
108 108
     }
109 109
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Message_Type.lib.php 2 patches
Indentation   +447 added lines, -447 removed lines patch added patch discarded remove patch
@@ -12,477 +12,477 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * Holds values for registered message types
17
-     *
18
-     * @var array
19
-     */
20
-    protected static $_ee_message_type_registry = [];
15
+	/**
16
+	 * Holds values for registered message types
17
+	 *
18
+	 * @var array
19
+	 */
20
+	protected static $_ee_message_type_registry = [];
21 21
 
22 22
 
23
-    /**
24
-     * Method for registering new message types in the EE_messages system.
25
-     * Note:  All message types must have the following files in order to work:
26
-     * Template files for default templates getting setup.
27
-     * See /core/libraries/messages/defaults/default/ for examples
28
-     * (note that template files match a specific naming schema).
29
-     * These templates will need to be registered with the default template pack.
30
-     * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
31
-     *      for examples.  Note for any new message types, there will need to be a validator for each
32
-     *      messenger combo this message type can activate with.
33
-     * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
34
-     *      message type and its properties.
35
-     *
36
-     * @param string $identifier    Whatever is defined for the $name property of
37
-     *                              the message type you are registering (eg.
38
-     *                              declined_registration). Required.
39
-     * @param array  $setup_args    An array of arguments provided for registering the message type.
40
-     * @throws EE_Error
41
-     *                              }
42
-     * @see      inline docs in the register method for what can be passed in as arguments.
43
-     * @since    4.3.0
44
-     */
45
-    public static function register($identifier = '', array $setup_args = [])
46
-    {
47
-        // required fields MUST be present, so let's make sure they are.
48
-        if (! isset($identifier)
49
-            || ! is_array($setup_args)
50
-            || empty($setup_args['mtfilename'])
51
-            || empty($setup_args['autoloadpaths'])
52
-        ) {
53
-            throw new EE_Error(
54
-                __(
55
-                    'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
56
-                    'event_espresso'
57
-                )
58
-            );
59
-        }
23
+	/**
24
+	 * Method for registering new message types in the EE_messages system.
25
+	 * Note:  All message types must have the following files in order to work:
26
+	 * Template files for default templates getting setup.
27
+	 * See /core/libraries/messages/defaults/default/ for examples
28
+	 * (note that template files match a specific naming schema).
29
+	 * These templates will need to be registered with the default template pack.
30
+	 * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
31
+	 *      for examples.  Note for any new message types, there will need to be a validator for each
32
+	 *      messenger combo this message type can activate with.
33
+	 * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
34
+	 *      message type and its properties.
35
+	 *
36
+	 * @param string $identifier    Whatever is defined for the $name property of
37
+	 *                              the message type you are registering (eg.
38
+	 *                              declined_registration). Required.
39
+	 * @param array  $setup_args    An array of arguments provided for registering the message type.
40
+	 * @throws EE_Error
41
+	 *                              }
42
+	 * @see      inline docs in the register method for what can be passed in as arguments.
43
+	 * @since    4.3.0
44
+	 */
45
+	public static function register($identifier = '', array $setup_args = [])
46
+	{
47
+		// required fields MUST be present, so let's make sure they are.
48
+		if (! isset($identifier)
49
+			|| ! is_array($setup_args)
50
+			|| empty($setup_args['mtfilename'])
51
+			|| empty($setup_args['autoloadpaths'])
52
+		) {
53
+			throw new EE_Error(
54
+				__(
55
+					'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
56
+					'event_espresso'
57
+				)
58
+			);
59
+		}
60 60
 
61
-        // make sure we don't register twice
62
-        if (isset(self::$_ee_message_type_registry[ $identifier ])) {
63
-            return;
64
-        }
61
+		// make sure we don't register twice
62
+		if (isset(self::$_ee_message_type_registry[ $identifier ])) {
63
+			return;
64
+		}
65 65
 
66
-        // make sure this was called in the right place!
67
-        if (! did_action('EE_Brewing_Regular___messages_caf')
68
-            || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
69
-        ) {
70
-            EE_Error::doing_it_wrong(
71
-                __METHOD__,
72
-                sprintf(
73
-                    __(
74
-                        'A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
75
-                        'event_espresso'
76
-                    ),
77
-                    $identifier
78
-                ),
79
-                '4.3.0'
80
-            );
81
-        }
82
-        // setup $__ee_message_type_registry array from incoming values.
83
-        self::$_ee_message_type_registry[ $identifier ] = [
84
-            /**
85
-             * The file name for the message type being registered.
86
-             * Required.
87
-             *
88
-             * @type string
89
-             */
90
-            'mtfilename'                                       => (string) $setup_args['mtfilename'],
91
-            /**
92
-             * Autoload paths for classes used by the message type.
93
-             * Required.
94
-             *
95
-             * @type array
96
-             */
97
-            'autoloadpaths'                                    => (array) $setup_args['autoloadpaths'],
98
-            /**
99
-             * Messengers that the message type should be able to activate with.
100
-             * Use messenger slugs.
101
-             *
102
-             * @type array
103
-             */
104
-            'messengers_to_activate_with'                      => ! empty($setup_args['messengers_to_activate_with'])
105
-                ? (array) $setup_args['messengers_to_activate_with']
106
-                : [],
107
-            /**
108
-             * Messengers that the message type should validate with.
109
-             * Use messenger slugs.
110
-             *
111
-             * @type array
112
-             */
113
-            'messengers_to_validate_with'                      => ! empty($setup_args['messengers_to_validate_with'])
114
-                ? (array) $setup_args['messengers_to_validate_with']
115
-                : [],
116
-            /**
117
-             * Whether to force activate this message type the first time it is registered.
118
-             *
119
-             * @type bool   False means its not activated by default and left up to the end user to activate.
120
-             */
121
-            'force_activation'                                 => ! empty($setup_args['force_activation'])
122
-                                                                  && $setup_args['force_activation'],
123
-            /**
124
-             * What messengers this message type supports the default template pack for.
125
-             * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
126
-             * then it is expected that the message type being registered is doing its own custom default template
127
-             * pack/variation registration.
128
-             *
129
-             * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
130
-             * $setup_arguments array as well:
131
-             * - 'base_path_for_default_templates'
132
-             *
133
-             * @type array   Expect an array of messengers this supports default template packs for.
134
-             */
135
-            'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
136
-                ? (array) $setup_args['messengers_supporting_default_template_pack_with']
137
-                : [],
138
-            /**
139
-             * The base path where the default templates for this message type can be found.
140
-             *
141
-             * @type string
142
-             */
143
-            'base_path_for_default_templates'                  => isset($setup_args['base_path_for_default_templates'])
144
-                ? $setup_args['base_path_for_default_templates'] : '',
145
-            /**
146
-             * The base path where the default variations for this message type can be found.
147
-             *
148
-             * @type string
149
-             */
150
-            'base_path_for_default_variation'                  => isset($setup_args['base_path_for_default_variation'])
151
-                ? $setup_args['base_path_for_default_variation'] : '',
152
-            /**
153
-             * The base url for the default variations for this message type.
154
-             *
155
-             * @type string
156
-             */
157
-            'base_url_for_default_variation'                   => isset($setup_args['base_url_for_default_variation'])
158
-                ? $setup_args['base_url_for_default_variation'] : '',
159
-        ];
160
-        // add filters but only if they haven't already been set (these filters only need to be registered ONCE because
161
-        // the callback handles all registered message types.
162
-        if (false === has_filter(
163
-            'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
164
-            ['EE_Register_Message_Type', 'register_msgs_autoload_paths']
165
-        )) {
166
-            add_filter(
167
-                'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
168
-                ['EE_Register_Message_Type', 'register_msgs_autoload_paths'],
169
-                10
170
-            );
171
-            add_filter(
172
-                'FHEE__EE_messages__get_installed__messagetype_files',
173
-                ['EE_Register_Message_Type', 'register_messagetype_files'],
174
-                10,
175
-                1
176
-            );
177
-            add_filter(
178
-                'FHEE__EE_messenger__get_default_message_types__default_types',
179
-                ['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'],
180
-                10,
181
-                2
182
-            );
183
-            add_filter(
184
-                'FHEE__EE_messenger__get_valid_message_types__valid_types',
185
-                ['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'],
186
-                10,
187
-                2
188
-            );
189
-            // actions
190
-            add_action(
191
-                'AHEE__EE_Addon__initialize_default_data__begin',
192
-                ['EE_Register_Message_Type', 'set_defaults']
193
-            );
66
+		// make sure this was called in the right place!
67
+		if (! did_action('EE_Brewing_Regular___messages_caf')
68
+			|| did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
69
+		) {
70
+			EE_Error::doing_it_wrong(
71
+				__METHOD__,
72
+				sprintf(
73
+					__(
74
+						'A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
75
+						'event_espresso'
76
+					),
77
+					$identifier
78
+				),
79
+				'4.3.0'
80
+			);
81
+		}
82
+		// setup $__ee_message_type_registry array from incoming values.
83
+		self::$_ee_message_type_registry[ $identifier ] = [
84
+			/**
85
+			 * The file name for the message type being registered.
86
+			 * Required.
87
+			 *
88
+			 * @type string
89
+			 */
90
+			'mtfilename'                                       => (string) $setup_args['mtfilename'],
91
+			/**
92
+			 * Autoload paths for classes used by the message type.
93
+			 * Required.
94
+			 *
95
+			 * @type array
96
+			 */
97
+			'autoloadpaths'                                    => (array) $setup_args['autoloadpaths'],
98
+			/**
99
+			 * Messengers that the message type should be able to activate with.
100
+			 * Use messenger slugs.
101
+			 *
102
+			 * @type array
103
+			 */
104
+			'messengers_to_activate_with'                      => ! empty($setup_args['messengers_to_activate_with'])
105
+				? (array) $setup_args['messengers_to_activate_with']
106
+				: [],
107
+			/**
108
+			 * Messengers that the message type should validate with.
109
+			 * Use messenger slugs.
110
+			 *
111
+			 * @type array
112
+			 */
113
+			'messengers_to_validate_with'                      => ! empty($setup_args['messengers_to_validate_with'])
114
+				? (array) $setup_args['messengers_to_validate_with']
115
+				: [],
116
+			/**
117
+			 * Whether to force activate this message type the first time it is registered.
118
+			 *
119
+			 * @type bool   False means its not activated by default and left up to the end user to activate.
120
+			 */
121
+			'force_activation'                                 => ! empty($setup_args['force_activation'])
122
+																  && $setup_args['force_activation'],
123
+			/**
124
+			 * What messengers this message type supports the default template pack for.
125
+			 * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
126
+			 * then it is expected that the message type being registered is doing its own custom default template
127
+			 * pack/variation registration.
128
+			 *
129
+			 * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
130
+			 * $setup_arguments array as well:
131
+			 * - 'base_path_for_default_templates'
132
+			 *
133
+			 * @type array   Expect an array of messengers this supports default template packs for.
134
+			 */
135
+			'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
136
+				? (array) $setup_args['messengers_supporting_default_template_pack_with']
137
+				: [],
138
+			/**
139
+			 * The base path where the default templates for this message type can be found.
140
+			 *
141
+			 * @type string
142
+			 */
143
+			'base_path_for_default_templates'                  => isset($setup_args['base_path_for_default_templates'])
144
+				? $setup_args['base_path_for_default_templates'] : '',
145
+			/**
146
+			 * The base path where the default variations for this message type can be found.
147
+			 *
148
+			 * @type string
149
+			 */
150
+			'base_path_for_default_variation'                  => isset($setup_args['base_path_for_default_variation'])
151
+				? $setup_args['base_path_for_default_variation'] : '',
152
+			/**
153
+			 * The base url for the default variations for this message type.
154
+			 *
155
+			 * @type string
156
+			 */
157
+			'base_url_for_default_variation'                   => isset($setup_args['base_url_for_default_variation'])
158
+				? $setup_args['base_url_for_default_variation'] : '',
159
+		];
160
+		// add filters but only if they haven't already been set (these filters only need to be registered ONCE because
161
+		// the callback handles all registered message types.
162
+		if (false === has_filter(
163
+			'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
164
+			['EE_Register_Message_Type', 'register_msgs_autoload_paths']
165
+		)) {
166
+			add_filter(
167
+				'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
168
+				['EE_Register_Message_Type', 'register_msgs_autoload_paths'],
169
+				10
170
+			);
171
+			add_filter(
172
+				'FHEE__EE_messages__get_installed__messagetype_files',
173
+				['EE_Register_Message_Type', 'register_messagetype_files'],
174
+				10,
175
+				1
176
+			);
177
+			add_filter(
178
+				'FHEE__EE_messenger__get_default_message_types__default_types',
179
+				['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'],
180
+				10,
181
+				2
182
+			);
183
+			add_filter(
184
+				'FHEE__EE_messenger__get_valid_message_types__valid_types',
185
+				['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'],
186
+				10,
187
+				2
188
+			);
189
+			// actions
190
+			add_action(
191
+				'AHEE__EE_Addon__initialize_default_data__begin',
192
+				['EE_Register_Message_Type', 'set_defaults']
193
+			);
194 194
 
195
-            // default template packs and variations related
196
-            add_filter(
197
-                'FHEE__EE_Messages_Template_Pack_Default__get_supports',
198
-                ['EE_Register_Message_Type', 'register_default_template_pack_supports']
199
-            );
200
-            add_filter(
201
-                'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
202
-                ['EE_Register_Message_Type', 'register_base_template_path'],
203
-                10,
204
-                6
205
-            );
206
-            add_filter(
207
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
208
-                ['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
209
-                10,
210
-                8
211
-            );
212
-            add_filter(
213
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
214
-                ['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
215
-                10,
216
-                8
217
-            );
218
-        }
219
-    }
195
+			// default template packs and variations related
196
+			add_filter(
197
+				'FHEE__EE_Messages_Template_Pack_Default__get_supports',
198
+				['EE_Register_Message_Type', 'register_default_template_pack_supports']
199
+			);
200
+			add_filter(
201
+				'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
202
+				['EE_Register_Message_Type', 'register_base_template_path'],
203
+				10,
204
+				6
205
+			);
206
+			add_filter(
207
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
208
+				['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
209
+				10,
210
+				8
211
+			);
212
+			add_filter(
213
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
214
+				['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
215
+				10,
216
+				8
217
+			);
218
+		}
219
+	}
220 220
 
221 221
 
222
-    /**
223
-     * This just ensures that when an addon registers a message type that on initial activation/reactivation the
224
-     * defaults the addon sets are taken care of.
225
-     *
226
-     * @throws EE_Error
227
-     * @throws ReflectionException
228
-     */
229
-    public static function set_defaults()
230
-    {
231
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
232
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
222
+	/**
223
+	 * This just ensures that when an addon registers a message type that on initial activation/reactivation the
224
+	 * defaults the addon sets are taken care of.
225
+	 *
226
+	 * @throws EE_Error
227
+	 * @throws ReflectionException
228
+	 */
229
+	public static function set_defaults()
230
+	{
231
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
232
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
233 233
 
234
-        // for any message types with force activation, let's ensure they are activated
235
-        foreach (self::$_ee_message_type_registry as $identifier => $settings) {
236
-            if ($settings['force_activation']) {
237
-                foreach ($settings['messengers_to_activate_with'] as $messenger) {
238
-                    // DO not force activation if this message type has already been activated in the system
239
-                    if (! $message_resource_manager->has_message_type_been_activated_for_messenger(
240
-                        $identifier,
241
-                        $messenger
242
-                    )
243
-                    ) {
244
-                        $message_resource_manager->ensure_message_type_is_active($identifier, $messenger);
245
-                    }
246
-                }
247
-            }
248
-        }
249
-    }
234
+		// for any message types with force activation, let's ensure they are activated
235
+		foreach (self::$_ee_message_type_registry as $identifier => $settings) {
236
+			if ($settings['force_activation']) {
237
+				foreach ($settings['messengers_to_activate_with'] as $messenger) {
238
+					// DO not force activation if this message type has already been activated in the system
239
+					if (! $message_resource_manager->has_message_type_been_activated_for_messenger(
240
+						$identifier,
241
+						$messenger
242
+					)
243
+					) {
244
+						$message_resource_manager->ensure_message_type_is_active($identifier, $messenger);
245
+					}
246
+				}
247
+			}
248
+		}
249
+	}
250 250
 
251 251
 
252
-    /**
253
-     * This deregisters a message type that was previously registered with a specific message_type_name.
254
-     *
255
-     * @param string $identifier the name for the message type that was previously registered
256
-     * @return void
257
-     * @throws EE_Error
258
-     * @throws ReflectionException
259
-     * @since    4.3.0
260
-     */
261
-    public static function deregister($identifier = '')
262
-    {
263
-        if (! empty(self::$_ee_message_type_registry[ $identifier ])) {
264
-            // let's make sure that we remove any place this message type was made active
265
-            /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
266
-            $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
267
-            // ensures that if this message type is registered again that it retains its previous active state vs
268
-            // remaining inactive.
269
-            $Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
270
-                $identifier,
271
-                true
272
-            );
273
-            $Message_Resource_Manager->deactivate_message_type($identifier, false);
274
-        }
275
-        unset(self::$_ee_message_type_registry[ $identifier ]);
276
-    }
252
+	/**
253
+	 * This deregisters a message type that was previously registered with a specific message_type_name.
254
+	 *
255
+	 * @param string $identifier the name for the message type that was previously registered
256
+	 * @return void
257
+	 * @throws EE_Error
258
+	 * @throws ReflectionException
259
+	 * @since    4.3.0
260
+	 */
261
+	public static function deregister($identifier = '')
262
+	{
263
+		if (! empty(self::$_ee_message_type_registry[ $identifier ])) {
264
+			// let's make sure that we remove any place this message type was made active
265
+			/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
266
+			$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
267
+			// ensures that if this message type is registered again that it retains its previous active state vs
268
+			// remaining inactive.
269
+			$Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
270
+				$identifier,
271
+				true
272
+			);
273
+			$Message_Resource_Manager->deactivate_message_type($identifier, false);
274
+		}
275
+		unset(self::$_ee_message_type_registry[ $identifier ]);
276
+	}
277 277
 
278 278
 
279
-    /**
280
-     * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
281
-     *
282
-     * @param array $messagetype_files The current array of message type file names
283
-     * @return  array                                 Array of message type file names
284
-     * @since   4.3.0
285
-     */
286
-    public static function register_messagetype_files(array $messagetype_files)
287
-    {
288
-        if (empty(self::$_ee_message_type_registry)) {
289
-            return $messagetype_files;
290
-        }
291
-        foreach (self::$_ee_message_type_registry as $mt_reg) {
292
-            if (empty($mt_reg['mtfilename'])) {
293
-                continue;
294
-            }
295
-            $messagetype_files[] = $mt_reg['mtfilename'];
296
-        }
297
-        return $messagetype_files;
298
-    }
279
+	/**
280
+	 * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
281
+	 *
282
+	 * @param array $messagetype_files The current array of message type file names
283
+	 * @return  array                                 Array of message type file names
284
+	 * @since   4.3.0
285
+	 */
286
+	public static function register_messagetype_files(array $messagetype_files)
287
+	{
288
+		if (empty(self::$_ee_message_type_registry)) {
289
+			return $messagetype_files;
290
+		}
291
+		foreach (self::$_ee_message_type_registry as $mt_reg) {
292
+			if (empty($mt_reg['mtfilename'])) {
293
+				continue;
294
+			}
295
+			$messagetype_files[] = $mt_reg['mtfilename'];
296
+		}
297
+		return $messagetype_files;
298
+	}
299 299
 
300 300
 
301
-    /**
302
-     * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
303
-     *
304
-     * @param array $paths array of paths to be checked by EE_messages autoloader.
305
-     * @return array
306
-     * @since    4.3.0
307
-     */
308
-    public static function register_msgs_autoload_paths(array $paths)
309
-    {
310
-        if (! empty(self::$_ee_message_type_registry)) {
311
-            foreach (self::$_ee_message_type_registry as $mt_reg) {
312
-                if (empty($mt_reg['autoloadpaths'])) {
313
-                    continue;
314
-                }
315
-                $paths = array_merge($paths, $mt_reg['autoloadpaths']);
316
-            }
317
-        }
318
-        return $paths;
319
-    }
301
+	/**
302
+	 * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
303
+	 *
304
+	 * @param array $paths array of paths to be checked by EE_messages autoloader.
305
+	 * @return array
306
+	 * @since    4.3.0
307
+	 */
308
+	public static function register_msgs_autoload_paths(array $paths)
309
+	{
310
+		if (! empty(self::$_ee_message_type_registry)) {
311
+			foreach (self::$_ee_message_type_registry as $mt_reg) {
312
+				if (empty($mt_reg['autoloadpaths'])) {
313
+					continue;
314
+				}
315
+				$paths = array_merge($paths, $mt_reg['autoloadpaths']);
316
+			}
317
+		}
318
+		return $paths;
319
+	}
320 320
 
321 321
 
322
-    /**
323
-     * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
324
-     *
325
-     * @param array        $default_types   array of message types activated with messenger (
326
-     *                                      corresponds to the $name property of message type)
327
-     * @param EE_messenger $messenger       The EE_messenger the filter is called from.
328
-     * @return array
329
-     * @since  4.3.0
330
-     */
331
-    public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger)
332
-    {
333
-        if (empty(self::$_ee_message_type_registry)) {
334
-            return $default_types;
335
-        }
336
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
337
-            if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
338
-                continue;
339
-            }
340
-            // loop through each of the messengers and if it matches the loaded class
341
-            // then we add this message type to the
342
-            foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
343
-                if ($messenger->name == $msgr) {
344
-                    $default_types[] = $identifier;
345
-                }
346
-            }
347
-        }
322
+	/**
323
+	 * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
324
+	 *
325
+	 * @param array        $default_types   array of message types activated with messenger (
326
+	 *                                      corresponds to the $name property of message type)
327
+	 * @param EE_messenger $messenger       The EE_messenger the filter is called from.
328
+	 * @return array
329
+	 * @since  4.3.0
330
+	 */
331
+	public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger)
332
+	{
333
+		if (empty(self::$_ee_message_type_registry)) {
334
+			return $default_types;
335
+		}
336
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
337
+			if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
338
+				continue;
339
+			}
340
+			// loop through each of the messengers and if it matches the loaded class
341
+			// then we add this message type to the
342
+			foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
343
+				if ($messenger->name == $msgr) {
344
+					$default_types[] = $identifier;
345
+				}
346
+			}
347
+		}
348 348
 
349
-        return $default_types;
350
-    }
349
+		return $default_types;
350
+	}
351 351
 
352 352
 
353
-    /**
354
-     * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
355
-     *
356
-     * @param array        $valid_types     array of message types valid with messenger (
357
-     *                                      corresponds to the $name property of message type)
358
-     * @param EE_messenger $messenger       The EE_messenger the filter is called from.
359
-     * @return  array
360
-     * @since   4.3.0
361
-     */
362
-    public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger)
363
-    {
364
-        if (empty(self::$_ee_message_type_registry)) {
365
-            return $valid_types;
366
-        }
367
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
368
-            if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
369
-                continue;
370
-            }
371
-            // loop through each of the messengers and if it matches the loaded class
372
-            // then we add this message type to the
373
-            foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
374
-                if ($messenger->name == $msgr) {
375
-                    $valid_types[] = $identifier;
376
-                }
377
-            }
378
-        }
353
+	/**
354
+	 * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
355
+	 *
356
+	 * @param array        $valid_types     array of message types valid with messenger (
357
+	 *                                      corresponds to the $name property of message type)
358
+	 * @param EE_messenger $messenger       The EE_messenger the filter is called from.
359
+	 * @return  array
360
+	 * @since   4.3.0
361
+	 */
362
+	public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger)
363
+	{
364
+		if (empty(self::$_ee_message_type_registry)) {
365
+			return $valid_types;
366
+		}
367
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
368
+			if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
369
+				continue;
370
+			}
371
+			// loop through each of the messengers and if it matches the loaded class
372
+			// then we add this message type to the
373
+			foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
374
+				if ($messenger->name == $msgr) {
375
+					$valid_types[] = $identifier;
376
+				}
377
+			}
378
+		}
379 379
 
380
-        return $valid_types;
381
-    }
380
+		return $valid_types;
381
+	}
382 382
 
383 383
 
384
-    /**
385
-     * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
386
-     * supporting the default template pack
387
-     *
388
-     * @param array $supports
389
-     *
390
-     * @return array
391
-     */
392
-    public static function register_default_template_pack_supports(array $supports)
393
-    {
394
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
395
-            if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
396
-                continue;
397
-            }
398
-            foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
399
-                $supports[ $messenger_slug ][] = $identifier;
400
-            }
401
-        }
402
-        return $supports;
403
-    }
384
+	/**
385
+	 * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
386
+	 * supporting the default template pack
387
+	 *
388
+	 * @param array $supports
389
+	 *
390
+	 * @return array
391
+	 */
392
+	public static function register_default_template_pack_supports(array $supports)
393
+	{
394
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
395
+			if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
396
+				continue;
397
+			}
398
+			foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
399
+				$supports[ $messenger_slug ][] = $identifier;
400
+			}
401
+		}
402
+		return $supports;
403
+	}
404 404
 
405 405
 
406
-    /**
407
-     * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
408
-     *
409
-     * @param string                    $base_path The original base path for message templates
410
-     * @param EE_messenger              $messenger
411
-     * @param EE_message_type           $message_type
412
-     * @param string                    $field     The field requesting a template
413
-     * @param string                    $context   The context requesting a template
414
-     * @param EE_Messages_Template_Pack $template_pack
415
-     *
416
-     * @return string
417
-     */
418
-    public static function register_base_template_path(
419
-        $base_path,
420
-        EE_messenger $messenger,
421
-        EE_message_type $message_type,
422
-        $field,
423
-        $context,
424
-        EE_Messages_Template_Pack $template_pack
425
-    ) {
426
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default
427
-            || ! $message_type instanceof EE_message_type
428
-        ) {
429
-            return $base_path;
430
-        }
431
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
432
-            if ($message_type->name === $identifier
433
-                && ! empty($mt_reg['base_path_for_default_templates'])
434
-            ) {
435
-                return $mt_reg['base_path_for_default_templates'];
436
-            }
437
-        }
438
-        return $base_path;
439
-    }
406
+	/**
407
+	 * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
408
+	 *
409
+	 * @param string                    $base_path The original base path for message templates
410
+	 * @param EE_messenger              $messenger
411
+	 * @param EE_message_type           $message_type
412
+	 * @param string                    $field     The field requesting a template
413
+	 * @param string                    $context   The context requesting a template
414
+	 * @param EE_Messages_Template_Pack $template_pack
415
+	 *
416
+	 * @return string
417
+	 */
418
+	public static function register_base_template_path(
419
+		$base_path,
420
+		EE_messenger $messenger,
421
+		EE_message_type $message_type,
422
+		$field,
423
+		$context,
424
+		EE_Messages_Template_Pack $template_pack
425
+	) {
426
+		if (! $template_pack instanceof EE_Messages_Template_Pack_Default
427
+			|| ! $message_type instanceof EE_message_type
428
+		) {
429
+			return $base_path;
430
+		}
431
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
432
+			if ($message_type->name === $identifier
433
+				&& ! empty($mt_reg['base_path_for_default_templates'])
434
+			) {
435
+				return $mt_reg['base_path_for_default_templates'];
436
+			}
437
+		}
438
+		return $base_path;
439
+	}
440 440
 
441 441
 
442
-    /**
443
-     * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
444
-     * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
445
-     *
446
-     * @param string                    $base_path_or_url  The original incoming base url or path
447
-     * @param string                    $messenger_slug    The slug of the messenger the template is being generated
448
-     *                                                     for.
449
-     * @param string                    $message_type_slug The slug of the message type the template is being generated
450
-     *                                                     for.
451
-     * @param string                    $type              The "type" of css being requested.
452
-     * @param string                    $variation         The variation being requested.
453
-     * @param bool                      $url               whether a url or path is being requested.
454
-     * @param string                    $file_extension    What file extension is expected for the variation file.
455
-     * @param EE_Messages_Template_Pack $template_pack
456
-     *
457
-     * @return string
458
-     */
459
-    public static function register_variation_base_path_or_url(
460
-        $base_path_or_url,
461
-        $messenger_slug,
462
-        $message_type_slug,
463
-        $type,
464
-        $variation,
465
-        $url,
466
-        $file_extension,
467
-        EE_Messages_Template_Pack $template_pack
468
-    ) {
469
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
470
-            return $base_path_or_url;
471
-        }
472
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
473
-            if ($identifier === $message_type_slug
474
-            ) {
475
-                if ($url
476
-                    && ! empty($mt_reg['base_url_for_default_variation'])
477
-                ) {
478
-                    return $mt_reg['base_url_for_default_variation'];
479
-                } elseif (! $url
480
-                          && ! empty($mt_reg['base_path_for_default_variation'])
481
-                ) {
482
-                    return $mt_reg['base_path_for_default_variation'];
483
-                }
484
-            }
485
-        }
486
-        return $base_path_or_url;
487
-    }
442
+	/**
443
+	 * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
444
+	 * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
445
+	 *
446
+	 * @param string                    $base_path_or_url  The original incoming base url or path
447
+	 * @param string                    $messenger_slug    The slug of the messenger the template is being generated
448
+	 *                                                     for.
449
+	 * @param string                    $message_type_slug The slug of the message type the template is being generated
450
+	 *                                                     for.
451
+	 * @param string                    $type              The "type" of css being requested.
452
+	 * @param string                    $variation         The variation being requested.
453
+	 * @param bool                      $url               whether a url or path is being requested.
454
+	 * @param string                    $file_extension    What file extension is expected for the variation file.
455
+	 * @param EE_Messages_Template_Pack $template_pack
456
+	 *
457
+	 * @return string
458
+	 */
459
+	public static function register_variation_base_path_or_url(
460
+		$base_path_or_url,
461
+		$messenger_slug,
462
+		$message_type_slug,
463
+		$type,
464
+		$variation,
465
+		$url,
466
+		$file_extension,
467
+		EE_Messages_Template_Pack $template_pack
468
+	) {
469
+		if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
470
+			return $base_path_or_url;
471
+		}
472
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
473
+			if ($identifier === $message_type_slug
474
+			) {
475
+				if ($url
476
+					&& ! empty($mt_reg['base_url_for_default_variation'])
477
+				) {
478
+					return $mt_reg['base_url_for_default_variation'];
479
+				} elseif (! $url
480
+						  && ! empty($mt_reg['base_path_for_default_variation'])
481
+				) {
482
+					return $mt_reg['base_path_for_default_variation'];
483
+				}
484
+			}
485
+		}
486
+		return $base_path_or_url;
487
+	}
488 488
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     public static function register($identifier = '', array $setup_args = [])
46 46
     {
47 47
         // required fields MUST be present, so let's make sure they are.
48
-        if (! isset($identifier)
48
+        if ( ! isset($identifier)
49 49
             || ! is_array($setup_args)
50 50
             || empty($setup_args['mtfilename'])
51 51
             || empty($setup_args['autoloadpaths'])
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
         }
60 60
 
61 61
         // make sure we don't register twice
62
-        if (isset(self::$_ee_message_type_registry[ $identifier ])) {
62
+        if (isset(self::$_ee_message_type_registry[$identifier])) {
63 63
             return;
64 64
         }
65 65
 
66 66
         // make sure this was called in the right place!
67
-        if (! did_action('EE_Brewing_Regular___messages_caf')
67
+        if ( ! did_action('EE_Brewing_Regular___messages_caf')
68 68
             || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
69 69
         ) {
70 70
             EE_Error::doing_it_wrong(
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
             );
81 81
         }
82 82
         // setup $__ee_message_type_registry array from incoming values.
83
-        self::$_ee_message_type_registry[ $identifier ] = [
83
+        self::$_ee_message_type_registry[$identifier] = [
84 84
             /**
85 85
              * The file name for the message type being registered.
86 86
              * Required.
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
             if ($settings['force_activation']) {
237 237
                 foreach ($settings['messengers_to_activate_with'] as $messenger) {
238 238
                     // DO not force activation if this message type has already been activated in the system
239
-                    if (! $message_resource_manager->has_message_type_been_activated_for_messenger(
239
+                    if ( ! $message_resource_manager->has_message_type_been_activated_for_messenger(
240 240
                         $identifier,
241 241
                         $messenger
242 242
                     )
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
      */
261 261
     public static function deregister($identifier = '')
262 262
     {
263
-        if (! empty(self::$_ee_message_type_registry[ $identifier ])) {
263
+        if ( ! empty(self::$_ee_message_type_registry[$identifier])) {
264 264
             // let's make sure that we remove any place this message type was made active
265 265
             /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
266 266
             $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
             );
273 273
             $Message_Resource_Manager->deactivate_message_type($identifier, false);
274 274
         }
275
-        unset(self::$_ee_message_type_registry[ $identifier ]);
275
+        unset(self::$_ee_message_type_registry[$identifier]);
276 276
     }
277 277
 
278 278
 
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
      */
308 308
     public static function register_msgs_autoload_paths(array $paths)
309 309
     {
310
-        if (! empty(self::$_ee_message_type_registry)) {
310
+        if ( ! empty(self::$_ee_message_type_registry)) {
311 311
             foreach (self::$_ee_message_type_registry as $mt_reg) {
312 312
                 if (empty($mt_reg['autoloadpaths'])) {
313 313
                     continue;
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
                 continue;
397 397
             }
398 398
             foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
399
-                $supports[ $messenger_slug ][] = $identifier;
399
+                $supports[$messenger_slug][] = $identifier;
400 400
             }
401 401
         }
402 402
         return $supports;
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
         $context,
424 424
         EE_Messages_Template_Pack $template_pack
425 425
     ) {
426
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default
426
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default
427 427
             || ! $message_type instanceof EE_message_type
428 428
         ) {
429 429
             return $base_path;
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
         $file_extension,
467 467
         EE_Messages_Template_Pack $template_pack
468 468
     ) {
469
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
469
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) {
470 470
             return $base_path_or_url;
471 471
         }
472 472
         foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
                     && ! empty($mt_reg['base_url_for_default_variation'])
477 477
                 ) {
478 478
                     return $mt_reg['base_url_for_default_variation'];
479
-                } elseif (! $url
479
+                } elseif ( ! $url
480 480
                           && ! empty($mt_reg['base_path_for_default_variation'])
481 481
                 ) {
482 482
                     return $mt_reg['base_path_for_default_variation'];
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.13.rc.005');
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.13.rc.005');
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.
core/libraries/messages/EE_messenger.lib.php 2 patches
Indentation   +735 added lines, -735 removed lines patch added patch discarded remove patch
@@ -18,182 +18,182 @@  discard block
 block discarded – undo
18 18
 
19 19
 
20 20
 
21
-    /**
22
-     * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.
23
-     * This property gets set by the _set_default_message_types() method.
24
-     *
25
-     * @var array
26
-     */
27
-    protected $_default_message_types = array();
21
+	/**
22
+	 * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.
23
+	 * This property gets set by the _set_default_message_types() method.
24
+	 *
25
+	 * @var array
26
+	 */
27
+	protected $_default_message_types = array();
28 28
 
29 29
 
30 30
 
31 31
 
32
-    /**
33
-     * This property holds the message types that are valid for use with this messenger.
34
-     * It gets set by the _set_valid_message_types() method.
35
-     *
36
-     * @var array
37
-     */
38
-    protected $_valid_message_types = array();
32
+	/**
33
+	 * This property holds the message types that are valid for use with this messenger.
34
+	 * It gets set by the _set_valid_message_types() method.
35
+	 *
36
+	 * @var array
37
+	 */
38
+	protected $_valid_message_types = array();
39 39
 
40 40
 
41 41
 
42
-    /**
43
-     * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context.  So message types don't need to set a $_validator_config property.
44
-     *
45
-     * Remember, ALL fields must be declared in this array.  However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).
46
-     *
47
-     * Array should be in this format:
48
-     *
49
-     * array(
50
-     *  'field_name(i.e.to)' => array(
51
-     *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match).
52
-     *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => __('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label.
53
-     *      'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types).  If not required you can just leave empty.,
54
-     *      'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation.  Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.
55
-     *  )
56
-     * )
57
-     *
58
-     * @var array
59
-     */
60
-    protected $_validator_config = array();
42
+	/**
43
+	 * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context.  So message types don't need to set a $_validator_config property.
44
+	 *
45
+	 * Remember, ALL fields must be declared in this array.  However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).
46
+	 *
47
+	 * Array should be in this format:
48
+	 *
49
+	 * array(
50
+	 *  'field_name(i.e.to)' => array(
51
+	 *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match).
52
+	 *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => __('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label.
53
+	 *      'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types).  If not required you can just leave empty.,
54
+	 *      'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation.  Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.
55
+	 *  )
56
+	 * )
57
+	 *
58
+	 * @var array
59
+	 */
60
+	protected $_validator_config = array();
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
66
-     * @var object
67
-     */
68
-    protected $_EEM_data;
64
+	/**
65
+	 * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger
66
+	 * @var object
67
+	 */
68
+	protected $_EEM_data;
69 69
 
70 70
 
71 71
 
72
-    /**
73
-     * this property just holds an array of the various template refs.
74
-     * @var array
75
-     */
76
-    protected $_template_fields = array();
72
+	/**
73
+	 * this property just holds an array of the various template refs.
74
+	 * @var array
75
+	 */
76
+	protected $_template_fields = array();
77 77
 
78 78
 
79 79
 
80 80
 
81
-    /**
82
-     * This holds an array of the arguments used in parsing a template for the sender.
83
-     * @var array
84
-     */
85
-    protected $_template_args = array();
81
+	/**
82
+	 * This holds an array of the arguments used in parsing a template for the sender.
83
+	 * @var array
84
+	 */
85
+	protected $_template_args = array();
86 86
 
87 87
 
88 88
 
89 89
 
90 90
 
91 91
 
92
-    /**
93
-     * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger
94
-     *
95
-     * @protected
96
-     * @var array
97
-     */
98
-    protected $_test_settings_fields = array();
92
+	/**
93
+	 * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger
94
+	 *
95
+	 * @protected
96
+	 * @var array
97
+	 */
98
+	protected $_test_settings_fields = array();
99 99
 
100 100
 
101 101
 
102 102
 
103 103
 
104 104
 
105
-    /**
106
-     * This will hold the EE_Messages_Template_Pack object when set on the messenger.  This is set via the validate and setup method which grabs the template pack from the incoming messages object.
107
-     *
108
-     * @since 4.5.0
109
-     *
110
-     * @var EE_Messages_Template_Pack
111
-     */
112
-    protected $_tmp_pack;
105
+	/**
106
+	 * This will hold the EE_Messages_Template_Pack object when set on the messenger.  This is set via the validate and setup method which grabs the template pack from the incoming messages object.
107
+	 *
108
+	 * @since 4.5.0
109
+	 *
110
+	 * @var EE_Messages_Template_Pack
111
+	 */
112
+	protected $_tmp_pack;
113 113
 
114 114
 
115 115
 
116 116
 
117
-    /**
118
-     * This will hold the variation to use when performing a send.  It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.
119
-     *
120
-     * @since 4.5.0
121
-     *
122
-     * @var string
123
-     */
124
-    protected $_variation;
117
+	/**
118
+	 * This will hold the variation to use when performing a send.  It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.
119
+	 *
120
+	 * @since 4.5.0
121
+	 *
122
+	 * @var string
123
+	 */
124
+	protected $_variation;
125 125
 
126 126
 
127 127
 
128 128
 
129 129
 
130
-    /**
131
-     * This property is a stdClass that holds labels for all the various supporting properties for this messenger.  These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:
132
-     *
133
-     *  - template pack
134
-     *  - template variation
135
-     *
136
-     * @since 4.5.0
137
-     *
138
-     * @var stdClass
139
-     */
140
-    protected $_supports_labels;
130
+	/**
131
+	 * This property is a stdClass that holds labels for all the various supporting properties for this messenger.  These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:
132
+	 *
133
+	 *  - template pack
134
+	 *  - template variation
135
+	 *
136
+	 * @since 4.5.0
137
+	 *
138
+	 * @var stdClass
139
+	 */
140
+	protected $_supports_labels;
141 141
 
142 142
 
143 143
 
144 144
 
145 145
 
146
-    /**
147
-     * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.
148
-     *
149
-     * @var EE_message_type
150
-     */
151
-    protected $_incoming_message_type;
146
+	/**
147
+	 * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.
148
+	 *
149
+	 * @var EE_message_type
150
+	 */
151
+	protected $_incoming_message_type;
152 152
 
153 153
 
154 154
 
155
-    /**
156
-     * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
157
-     *
158
-     * @var bool
159
-     */
160
-    public $activate_on_install = false;
155
+	/**
156
+	 * This flag sets whether a messenger is activated by default  on installation (or reactivation) of EE core or not.
157
+	 *
158
+	 * @var bool
159
+	 */
160
+	public $activate_on_install = false;
161 161
 
162 162
 
163 163
 
164 164
 
165 165
 
166
-    public function __construct()
167
-    {
168
-        $this->_EEM_data = EEM_Message_Template_Group::instance();
169
-        $this->_messages_item_type = 'messenger';
166
+	public function __construct()
167
+	{
168
+		$this->_EEM_data = EEM_Message_Template_Group::instance();
169
+		$this->_messages_item_type = 'messenger';
170 170
 
171
-        parent::__construct();
171
+		parent::__construct();
172 172
 
173
-        $this->_set_test_settings_fields();
174
-        $this->_set_template_fields();
175
-        $this->_set_default_message_types();
176
-        $this->_set_valid_message_types();
177
-        $this->_set_validator_config();
173
+		$this->_set_test_settings_fields();
174
+		$this->_set_template_fields();
175
+		$this->_set_default_message_types();
176
+		$this->_set_valid_message_types();
177
+		$this->_set_validator_config();
178 178
 
179 179
 
180
-        $this->_supports_labels = new stdClass();
181
-        $this->_set_supports_labels();
182
-    }
180
+		$this->_supports_labels = new stdClass();
181
+		$this->_set_supports_labels();
182
+	}
183 183
 
184 184
 
185 185
 
186 186
 
187 187
 
188
-    /**
189
-     * _set_template_fields
190
-     * This sets up the fields that a messenger requires for the message to go out.
191
-     *
192
-     * @abstract
193
-     * @access  protected
194
-     * @return void
195
-     */
196
-    abstract protected function _set_template_fields();
188
+	/**
189
+	 * _set_template_fields
190
+	 * This sets up the fields that a messenger requires for the message to go out.
191
+	 *
192
+	 * @abstract
193
+	 * @access  protected
194
+	 * @return void
195
+	 */
196
+	abstract protected function _set_template_fields();
197 197
 
198 198
 
199 199
 
@@ -203,14 +203,14 @@  discard block
 block discarded – undo
203 203
 
204 204
 
205 205
 
206
-    /**
207
-     * This method sets the _default_message_type property (see definition in docs attached to property)
208
-     *
209
-     * @abstract
210
-     * @access protected
211
-     * @return void
212
-     */
213
-    abstract protected function _set_default_message_types();
206
+	/**
207
+	 * This method sets the _default_message_type property (see definition in docs attached to property)
208
+	 *
209
+	 * @abstract
210
+	 * @access protected
211
+	 * @return void
212
+	 */
213
+	abstract protected function _set_default_message_types();
214 214
 
215 215
 
216 216
 
@@ -218,15 +218,15 @@  discard block
 block discarded – undo
218 218
 
219 219
 
220 220
 
221
-    /**
222
-     * Sets the _valid_message_types property (see definition in cods attached to property)
223
-     *
224
-     * @since 4.5.0
225
-     *
226
-     * @abstract
227
-     * @return void
228
-     */
229
-    abstract protected function _set_valid_message_types();
221
+	/**
222
+	 * Sets the _valid_message_types property (see definition in cods attached to property)
223
+	 *
224
+	 * @since 4.5.0
225
+	 *
226
+	 * @abstract
227
+	 * @return void
228
+	 */
229
+	abstract protected function _set_valid_message_types();
230 230
 
231 231
 
232 232
 
@@ -234,171 +234,171 @@  discard block
 block discarded – undo
234 234
 
235 235
 
236 236
 
237
-    /**
238
-     * Child classes must declare the $_validator_config property using this method.
239
-     * See comments for $_validator_config for details on what it is used for.
240
-     *
241
-     * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes.
242
-     *
243
-     * @access protected
244
-     * @return void
245
-     */
246
-    abstract protected function _set_validator_config();
237
+	/**
238
+	 * Child classes must declare the $_validator_config property using this method.
239
+	 * See comments for $_validator_config for details on what it is used for.
240
+	 *
241
+	 * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes.
242
+	 *
243
+	 * @access protected
244
+	 * @return void
245
+	 */
246
+	abstract protected function _set_validator_config();
247 247
 
248 248
 
249 249
 
250 250
 
251 251
 
252 252
 
253
-    /**
254
-     * We just deliver the messages don't kill us!!  This method will need to be modified by child classes for whatever action is taken to actually send a message.
255
-     *
256
-     * @return bool|WP_Error
257
-     * @throw \Exception
258
-     */
259
-    abstract protected function _send_message();
253
+	/**
254
+	 * We just deliver the messages don't kill us!!  This method will need to be modified by child classes for whatever action is taken to actually send a message.
255
+	 *
256
+	 * @return bool|WP_Error
257
+	 * @throw \Exception
258
+	 */
259
+	abstract protected function _send_message();
260 260
 
261 261
 
262 262
 
263 263
 
264
-    /**
265
-     * We give you pretty previews of the messages!
266
-     * @return string html body for message content.
267
-     */
268
-    abstract protected function _preview();
264
+	/**
265
+	 * We give you pretty previews of the messages!
266
+	 * @return string html body for message content.
267
+	 */
268
+	abstract protected function _preview();
269 269
 
270 270
 
271 271
 
272 272
 
273
-    /**
274
-     * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
275
-     *
276
-     * @since 4.5.0
277
-     *
278
-     * @return void
279
-     */
280
-    public function enqueue_scripts_styles()
281
-    {
282
-        do_action('AHEE__EE_messenger__enqueue_scripts_styles');
283
-    }
273
+	/**
274
+	 * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.
275
+	 *
276
+	 * @since 4.5.0
277
+	 *
278
+	 * @return void
279
+	 */
280
+	public function enqueue_scripts_styles()
281
+	{
282
+		do_action('AHEE__EE_messenger__enqueue_scripts_styles');
283
+	}
284 284
 
285 285
 
286 286
 
287 287
 
288 288
 
289
-    /**
290
-     * This is used to indicate whether a messenger must be sent immediately or not.
291
-     * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
292
-     * away.  The PDF messenger is similar.
293
-     *
294
-     * This flag thus overrides any priorities that may be set on the message type used to generate the message.
295
-     *
296
-     * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
297
-     *
298
-     * @since  4.9.0
299
-     * @return bool
300
-     */
301
-    public function send_now()
302
-    {
303
-        return false;
304
-    }
289
+	/**
290
+	 * This is used to indicate whether a messenger must be sent immediately or not.
291
+	 * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right
292
+	 * away.  The PDF messenger is similar.
293
+	 *
294
+	 * This flag thus overrides any priorities that may be set on the message type used to generate the message.
295
+	 *
296
+	 * Default for this is false.  So children classes must override this if they want a message to be executed immediately.
297
+	 *
298
+	 * @since  4.9.0
299
+	 * @return bool
300
+	 */
301
+	public function send_now()
302
+	{
303
+		return false;
304
+	}
305 305
 
306 306
 
307 307
 
308 308
 
309 309
 
310
-    /**
311
-     * This is a way for a messenger to indicate whether it allows an empty to field or not.
312
-     * Note: If the generated message is a for a preview, this value is ignored.
313
-     * @since 4.9.0
314
-     * @return bool
315
-     */
316
-    public function allow_empty_to_field()
317
-    {
318
-        return false;
319
-    }
310
+	/**
311
+	 * This is a way for a messenger to indicate whether it allows an empty to field or not.
312
+	 * Note: If the generated message is a for a preview, this value is ignored.
313
+	 * @since 4.9.0
314
+	 * @return bool
315
+	 */
316
+	public function allow_empty_to_field()
317
+	{
318
+		return false;
319
+	}
320 320
 
321 321
 
322 322
 
323 323
 
324 324
 
325
-    /**
326
-     * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
327
-     * @see property definition for info on how its formatted.
328
-     *
329
-     * @since 4.5.0;
330
-     * @return void
331
-     */
332
-    protected function _set_supports_labels()
333
-    {
334
-        $this->_set_supports_labels_defaults();
335
-    }
325
+	/**
326
+	 * Sets the defaults for the _supports_labels property.  Can be overridden by child classes.
327
+	 * @see property definition for info on how its formatted.
328
+	 *
329
+	 * @since 4.5.0;
330
+	 * @return void
331
+	 */
332
+	protected function _set_supports_labels()
333
+	{
334
+		$this->_set_supports_labels_defaults();
335
+	}
336 336
 
337 337
 
338 338
 
339 339
 
340 340
 
341
-    /**
342
-     * Sets the defaults for the _supports_labels property.
343
-     *
344
-     * @since 4.5.0
345
-     *
346
-     * @return void
347
-     */
348
-    private function _set_supports_labels_defaults()
349
-    {
350
-        $this->_supports_labels->template_pack = __('Template Structure', 'event_espresso');
351
-        $this->_supports_labels->template_variation = __('Template Style', 'event_espresso');
352
-        $this->_supports_labels->template_pack_description = __('Template Structure options are bundled structural changes for templates.', 'event_espresso');
341
+	/**
342
+	 * Sets the defaults for the _supports_labels property.
343
+	 *
344
+	 * @since 4.5.0
345
+	 *
346
+	 * @return void
347
+	 */
348
+	private function _set_supports_labels_defaults()
349
+	{
350
+		$this->_supports_labels->template_pack = __('Template Structure', 'event_espresso');
351
+		$this->_supports_labels->template_variation = __('Template Style', 'event_espresso');
352
+		$this->_supports_labels->template_pack_description = __('Template Structure options are bundled structural changes for templates.', 'event_espresso');
353 353
 
354
-        $this->_supports_labels->template_variation_description = __('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso');
354
+		$this->_supports_labels->template_variation_description = __('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso');
355 355
 
356
-        $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
357
-    }
356
+		$this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
357
+	}
358 358
 
359 359
 
360 360
 
361 361
 
362 362
 
363
-    /**
364
-     * This returns the _supports_labels property.
365
-     *
366
-     * @since 4.5.0
367
-     *
368
-     * @return stdClass
369
-     */
370
-    public function get_supports_labels()
371
-    {
372
-        if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
373
-            $this->_set_supports_labels_defaults();
374
-        }
375
-        return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
376
-    }
363
+	/**
364
+	 * This returns the _supports_labels property.
365
+	 *
366
+	 * @since 4.5.0
367
+	 *
368
+	 * @return stdClass
369
+	 */
370
+	public function get_supports_labels()
371
+	{
372
+		if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
373
+			$this->_set_supports_labels_defaults();
374
+		}
375
+		return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
376
+	}
377 377
 
378 378
 
379 379
 
380 380
 
381
-    /**
382
-     * Used to retrieve a variation (typically the path/url to a css file)
383
-     *
384
-     * @since 4.5.0
385
-     *
386
-     * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
387
-     * @param string                    $message_type_name The name property of the message type that we need the variation for.
388
-     * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
389
-     * @param string                    $type What variation type to return. Default is 'main'.
390
-     * @param string               $variation What variation for the template pack
391
-     * @param bool             $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.
392
-     *
393
-     * @return string                    path or url for the requested variation.
394
-     */
395
-    public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
396
-    {
397
-        $this->_tmp_pack = $pack;
398
-        $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
399
-        $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
400
-        return $variation_path;
401
-    }
381
+	/**
382
+	 * Used to retrieve a variation (typically the path/url to a css file)
383
+	 *
384
+	 * @since 4.5.0
385
+	 *
386
+	 * @param EE_Messages_Template_Pack $pack   The template pack used for retrieving the variation.
387
+	 * @param string                    $message_type_name The name property of the message type that we need the variation for.
388
+	 * @param bool                      $url   Whether to return url (true) or path (false). Default is false.
389
+	 * @param string                    $type What variation type to return. Default is 'main'.
390
+	 * @param string               $variation What variation for the template pack
391
+	 * @param bool             $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.
392
+	 *
393
+	 * @return string                    path or url for the requested variation.
394
+	 */
395
+	public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)
396
+	{
397
+		$this->_tmp_pack = $pack;
398
+		$variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
399
+		$variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
400
+		return $variation_path;
401
+	}
402 402
 
403 403
 
404 404
 
@@ -406,492 +406,492 @@  discard block
 block discarded – undo
406 406
 
407 407
 
408 408
 
409
-    /**
410
-     * This just returns the default message types associated with this messenger when it is first activated.
411
-     *
412
-     * @access public
413
-     * @return array
414
-     */
415
-    public function get_default_message_types()
416
-    {
417
-        $class = get_class($this);
409
+	/**
410
+	 * This just returns the default message types associated with this messenger when it is first activated.
411
+	 *
412
+	 * @access public
413
+	 * @return array
414
+	 */
415
+	public function get_default_message_types()
416
+	{
417
+		$class = get_class($this);
418 418
 
419
-        // messenger specific filter
420
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
419
+		// messenger specific filter
420
+		$default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
421 421
 
422
-        // all messengers filter
423
-        $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
424
-        return $default_types;
425
-    }
422
+		// all messengers filter
423
+		$default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
424
+		return $default_types;
425
+	}
426 426
 
427 427
 
428 428
 
429 429
 
430
-    /**
431
-     * Returns the valid message types associated with this messenger.
432
-     *
433
-     * @since 4.5.0
434
-     *
435
-     * @return array
436
-     */
437
-    public function get_valid_message_types()
438
-    {
439
-        $class = get_class($this);
440
-
441
-        // messenger specific filter
442
-        // messenger specific filter
443
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444
-
445
-        // all messengers filter
446
-        $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
447
-        return $valid_types;
448
-    }
449
-
450
-
451
-
452
-
453
-
454
-    /**
455
-     * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.
456
-     *
457
-     * @access public
458
-     * @param array $new_config Whatever is put in here will reset the _validator_config property
459
-     */
460
-    public function set_validator_config($new_config)
461
-    {
462
-        $this->_validator_config = $new_config;
463
-    }
464
-
465
-
466
-
467
-
468
-    /**
469
-     * This returns the _validator_config property
470
-     *
471
-     * @access public
472
-     * @return array
473
-     */
474
-    public function get_validator_config()
475
-    {
476
-        $class = get_class($this);
477
-
478
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
479
-        $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480
-        return $config;
481
-    }
482
-
483
-
484
-
485
-
486
-    /**
487
-     * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.
488
-     *
489
-     * @param string $page the slug of the EE admin page
490
-     * @param array $message_types an array of active message type objects
491
-     * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
492
-     * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
493
-     * @access public
494
-     * @return string content for page
495
-     */
496
-    public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
497
-    {
498
-        return $this->_get_admin_page_content($page, $action, $extra, $message_types);
499
-    }
500
-
501
-
502
-
503
-    /**
504
-     * @param $message_types
505
-     * @param array $extra
506
-     * @return mixed|string
507
-     */
508
-    protected function _get_admin_content_events_edit($message_types, $extra)
509
-    {
510
-        // defaults
511
-        $template_args = array();
512
-        $selector_rows = '';
513
-
514
-        // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
515
-        $event_id = isset($extra['event']) ? $extra['event'] : null;
516
-
517
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
519
-
520
-        // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521
-        $global_templates = EEM_Message_Template_Group::instance()->get_all(
522
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
523
-        );
524
-        $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525
-            $event_id,
526
-            array(
527
-                'MTP_messenger' => $this->name,
528
-                'MTP_is_active' => true
529
-            )
530
-        );
531
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
532
-
533
-        // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534
-        foreach ($global_templates as $mtpgID => $mtpg) {
535
-            if ($mtpg instanceof EE_Message_Template_Group) {
536
-                // verify this message type is supposed to show on this page
537
-                $mtp_obj = $mtpg->message_type_obj();
538
-                if (! $mtp_obj instanceof EE_message_type) {
539
-                    continue;
540
-                }
541
-                $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543
-                    continue;
544
-                }
545
-                $select_values = array();
546
-                $select_values[ $mtpgID ] = __('Global', 'event_espresso');
547
-                $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548
-                // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
549
-                if (! $mtpg->get('MTP_is_override')) {
550
-                    // any custom templates for this message type?
551
-                    $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552
-                    foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
554
-                        $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555
-                    }
556
-                }
557
-                // if there is no $default_value then we set it as the global
558
-                $default_value = empty($default_value) ? $mtpgID : $default_value;
559
-                $edit_url_query_args = [
560
-                    'page' => 'espresso_messages',
561
-                    'action' => 'edit_message_template',
562
-                    'id' => $default_value,
563
-                    'evt_id' => $event_id
564
-                ];
565
-                $edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
566
-                $create_url_query_args = [
567
-                    'page' => 'espresso_messages',
568
-                    'action' => 'add_new_message_template',
569
-                    'GRP_ID' => $default_value
570
-                ];
571
-                $create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
572
-                $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
573
-                $st_args['mt_slug'] = $mtpg->message_type();
574
-                $st_args['messenger_slug'] = $this->name;
575
-                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
576
-                // note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
577
-                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __('Create New Custom', 'event_espresso') . '</a>';
578
-                $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
579
-                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __('Edit', 'event_espresso') . '</a>' : '';
580
-                $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
581
-            }
582
-        }
583
-
584
-        // if no selectors present then get out.
585
-        if (empty($selector_rows)) {
586
-            return '';
587
-        }
588
-
589
-        $template_args['selector_rows'] = $selector_rows;
590
-        return EEH_Template::display_template($template_wrapper_path, $template_args, true);
591
-    }
592
-
593
-
594
-
595
-
596
-
597
-
598
-    /**
599
-     * get_template_fields
600
-     *
601
-     * @access public
602
-     * @return array $this->_template_fields
603
-     */
604
-    public function get_template_fields()
605
-    {
606
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
607
-        $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
608
-        return $template_fields;
609
-    }
610
-
611
-
612
-
613
-
614
-    /** SETUP METHODS **/
615
-    /**
616
-     * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
617
-     * @param string $item
618
-     * @param mixed $value
619
-     */
620
-    protected function _set_template_value($item, $value)
621
-    {
622
-        if (array_key_exists($item, $this->_template_fields)) {
623
-            $prop = '_' . $item;
624
-            $this->{$prop}= $value;
625
-        }
626
-    }
627
-
628
-    /**
629
-     * Sets up the message for sending.
630
-     *
631
-     * @param  EE_message $message the message object that contains details about the message.
632
-     * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
633
-     *
634
-     * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
635
-     *              added to EE_Error.
636
-     *              true = message sent successfully
637
-     *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
638
-     *              Throwing a SendMessageException means the message failed sending and cannot be retried.
639
-     *
640
-     * @throws SendMessageException
641
-     */
642
-    final public function send_message($message, EE_message_type $message_type)
643
-    {
644
-        try {
645
-            $this->_validate_and_setup($message);
646
-            $this->_incoming_message_type = $message_type;
647
-            $response = $this->_send_message();
648
-            if ($response instanceof WP_Error) {
649
-                EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
650
-                $response = false;
651
-            }
652
-        } catch (\Exception $e) {
653
-            // convert to an instance of SendMessageException
654
-            throw new SendMessageException($e->getMessage());
655
-        }
656
-        return $response;
657
-    }
658
-
659
-
660
-
661
-    /**
662
-     * Sets up and returns message preview
663
-     * @param  EE_Message $message incoming message object
664
-     * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
665
-     * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
666
-     * @return string          return the message html content
667
-     */
668
-    public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
669
-    {
670
-        $this->_validate_and_setup($message);
671
-
672
-        $this->_incoming_message_type = $message_type;
673
-
674
-        if ($send) {
675
-            // are we overriding any existing template fields?
676
-            $settings = apply_filters(
677
-                'FHEE__EE_messenger__get_preview__messenger_test_settings',
678
-                $this->get_existing_test_settings(),
679
-                $this,
680
-                $send,
681
-                $message,
682
-                $message_type
683
-            );
684
-            if (! empty($settings)) {
685
-                foreach ($settings as $field => $value) {
686
-                    $this->_set_template_value($field, $value);
687
-                }
688
-            }
689
-        }
690
-
691
-        // enqueue preview js so that any links/buttons on the page are disabled.
692
-        if (! $send) {
693
-            // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
694
-            // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
695
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
696
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
697
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
698
-        }
699
-
700
-        return $send ? $this->_send_message() : $this->_preview();
701
-    }
702
-
703
-
704
-
705
-
706
-    /**
707
-     * Callback for enqueue_scripts so that we setup the preview script for all previews.
708
-     *
709
-     * @since 4.5.0
710
-     *
711
-     * @return void
712
-     */
713
-    public function add_preview_script()
714
-    {
715
-        // error message
716
-        EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
717
-            __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso')
718
-        );
719
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
720
-        wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
721
-        wp_enqueue_script('ee-messages-preview-js');
722
-    }
723
-
724
-
725
-
726
-
727
-    /**
728
-     * simply validates the incoming message object and then sets up the properties for the messenger
729
-     * @param  EE_Message $message
730
-     * @throws EE_Error
731
-     */
732
-    protected function _validate_and_setup(EE_Message $message)
733
-    {
734
-        $template_pack = $message->get_template_pack();
735
-        $variation = $message->get_template_pack_variation();
736
-
737
-        // verify we have the required template pack value on the $message object.
738
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
739
-            throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
740
-        }
741
-
742
-        $this->_tmp_pack = $template_pack;
743
-
744
-        $this->_variation = $variation ? $variation : 'default';
745
-
746
-        $template_fields = $this->get_template_fields();
747
-
748
-        foreach ($template_fields as $template => $value) {
749
-            if ($template !== 'extra') {
750
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
751
-                $message_template_value = $column_value ? $column_value : null;
752
-                $this->_set_template_value($template, $message_template_value);
753
-            }
754
-        }
755
-    }
756
-
757
-
758
-
759
-    /**
760
-     * Utility method for child classes to get the contents of a template file and return
761
-     *
762
-     * We're assuming the child messenger class has already setup template args!
763
-     * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
764
-     * @return string
765
-     * @throws \EE_Error
766
-     */
767
-    protected function _get_main_template($preview = false)
768
-    {
769
-        $type = $preview ? 'preview' : 'main';
770
-
771
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
772
-
773
-        // check file exists and is readable
774
-        if (!is_readable($wrapper_template)) {
775
-            throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
776
-        }
777
-
778
-        // add message type to template args
779
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
780
-
781
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
782
-    }
783
-
784
-
785
-
786
-    /**
787
-     * set the _test_settings_fields property
788
-     *
789
-     * @access protected
790
-     * @return void
791
-     */
792
-    protected function _set_test_settings_fields()
793
-    {
794
-        $this->_test_settings_fields = array();
795
-    }
796
-
797
-
798
-
799
-    /**
800
-     * return the _test_settings_fields property
801
-     * @return array
802
-     */
803
-    public function get_test_settings_fields()
804
-    {
805
-        return $this->_test_settings_fields;
806
-    }
807
-
808
-
809
-
810
-
811
-    /**
812
-     * This just returns any existing test settings that might be saved in the database
813
-     *
814
-     * @access public
815
-     * @return array
816
-     */
817
-    public function get_existing_test_settings()
818
-    {
819
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
820
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
821
-        $settings = $Message_Resource_Manager->get_active_messengers_option();
822
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
823
-    }
824
-
825
-
826
-
827
-    /**
828
-     * All this does is set the existing test settings (in the db) for the messenger
829
-     *
830
-     * @access public
831
-     * @param $settings
832
-     * @return bool success/fail
833
-     */
834
-    public function set_existing_test_settings($settings)
835
-    {
836
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
837
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
838
-        $existing = $Message_Resource_Manager->get_active_messengers_option();
839
-        $existing[ $this->name ]['test_settings'] = $settings;
840
-        return $Message_Resource_Manager->update_active_messengers_option($existing);
841
-    }
842
-
843
-
844
-
845
-    /**
846
-     * This just returns the field label for a given field setup in the _template_fields property.
847
-     *
848
-     * @since   4.3.0
849
-     *
850
-     * @param string $field The field to retrieve the label for
851
-     * @return string             The label
852
-     */
853
-    public function get_field_label($field)
854
-    {
855
-        // first let's see if the field requests is in the top level array.
856
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
857
-            return $this->_template[ $field ]['label'];
858
-        }
859
-
860
-        // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
861
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
862
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
863
-        }
864
-
865
-        // now it's possible this field may just be existing in any of the extra array items.
866
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
867
-            foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
868
-                if (!is_array($subfields)) {
869
-                    continue;
870
-                }
871
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
872
-                    return $subfields[ $field ]['label'];
873
-                }
874
-            }
875
-        }
876
-
877
-        // if we made it here then there's no label set so let's just return the $field.
878
-        return $field;
879
-    }
880
-
881
-
882
-
883
-
884
-    /**
885
-     * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).
886
-     *
887
-     * @since 4.5.0
888
-     *
889
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
890
-     *
891
-     * @return void
892
-     */
893
-    public function do_secondary_messenger_hooks($sending_messenger_name)
894
-    {
895
-        return;
896
-    }
430
+	/**
431
+	 * Returns the valid message types associated with this messenger.
432
+	 *
433
+	 * @since 4.5.0
434
+	 *
435
+	 * @return array
436
+	 */
437
+	public function get_valid_message_types()
438
+	{
439
+		$class = get_class($this);
440
+
441
+		// messenger specific filter
442
+		// messenger specific filter
443
+		$valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444
+
445
+		// all messengers filter
446
+		$valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
447
+		return $valid_types;
448
+	}
449
+
450
+
451
+
452
+
453
+
454
+	/**
455
+	 * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.
456
+	 *
457
+	 * @access public
458
+	 * @param array $new_config Whatever is put in here will reset the _validator_config property
459
+	 */
460
+	public function set_validator_config($new_config)
461
+	{
462
+		$this->_validator_config = $new_config;
463
+	}
464
+
465
+
466
+
467
+
468
+	/**
469
+	 * This returns the _validator_config property
470
+	 *
471
+	 * @access public
472
+	 * @return array
473
+	 */
474
+	public function get_validator_config()
475
+	{
476
+		$class = get_class($this);
477
+
478
+		$config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
479
+		$config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480
+		return $config;
481
+	}
482
+
483
+
484
+
485
+
486
+	/**
487
+	 * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.
488
+	 *
489
+	 * @param string $page the slug of the EE admin page
490
+	 * @param array $message_types an array of active message type objects
491
+	 * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)
492
+	 * @param array $extra  This is just an extra argument that can be used to pass additional data for setting up page content.
493
+	 * @access public
494
+	 * @return string content for page
495
+	 */
496
+	public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())
497
+	{
498
+		return $this->_get_admin_page_content($page, $action, $extra, $message_types);
499
+	}
500
+
501
+
502
+
503
+	/**
504
+	 * @param $message_types
505
+	 * @param array $extra
506
+	 * @return mixed|string
507
+	 */
508
+	protected function _get_admin_content_events_edit($message_types, $extra)
509
+	{
510
+		// defaults
511
+		$template_args = array();
512
+		$selector_rows = '';
513
+
514
+		// we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
515
+		$event_id = isset($extra['event']) ? $extra['event'] : null;
516
+
517
+		$template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
+		$template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
519
+
520
+		// array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521
+		$global_templates = EEM_Message_Template_Group::instance()->get_all(
522
+			array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
523
+		);
524
+		$templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525
+			$event_id,
526
+			array(
527
+				'MTP_messenger' => $this->name,
528
+				'MTP_is_active' => true
529
+			)
530
+		);
531
+		$templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
532
+
533
+		// so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534
+		foreach ($global_templates as $mtpgID => $mtpg) {
535
+			if ($mtpg instanceof EE_Message_Template_Group) {
536
+				// verify this message type is supposed to show on this page
537
+				$mtp_obj = $mtpg->message_type_obj();
538
+				if (! $mtp_obj instanceof EE_message_type) {
539
+					continue;
540
+				}
541
+				$mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
+				if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543
+					continue;
544
+				}
545
+				$select_values = array();
546
+				$select_values[ $mtpgID ] = __('Global', 'event_espresso');
547
+				$default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548
+				// if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
549
+				if (! $mtpg->get('MTP_is_override')) {
550
+					// any custom templates for this message type?
551
+					$custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552
+					foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
+						$select_values[ $cmtpgID ] = $cmtpg->name();
554
+						$default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555
+					}
556
+				}
557
+				// if there is no $default_value then we set it as the global
558
+				$default_value = empty($default_value) ? $mtpgID : $default_value;
559
+				$edit_url_query_args = [
560
+					'page' => 'espresso_messages',
561
+					'action' => 'edit_message_template',
562
+					'id' => $default_value,
563
+					'evt_id' => $event_id
564
+				];
565
+				$edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php'));
566
+				$create_url_query_args = [
567
+					'page' => 'espresso_messages',
568
+					'action' => 'add_new_message_template',
569
+					'GRP_ID' => $default_value
570
+				];
571
+				$create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php'));
572
+				$st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
573
+				$st_args['mt_slug'] = $mtpg->message_type();
574
+				$st_args['messenger_slug'] = $this->name;
575
+				$st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
576
+				// note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
577
+				$st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __('Create New Custom', 'event_espresso') . '</a>';
578
+				$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
579
+				$st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __('Edit', 'event_espresso') . '</a>' : '';
580
+				$selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
581
+			}
582
+		}
583
+
584
+		// if no selectors present then get out.
585
+		if (empty($selector_rows)) {
586
+			return '';
587
+		}
588
+
589
+		$template_args['selector_rows'] = $selector_rows;
590
+		return EEH_Template::display_template($template_wrapper_path, $template_args, true);
591
+	}
592
+
593
+
594
+
595
+
596
+
597
+
598
+	/**
599
+	 * get_template_fields
600
+	 *
601
+	 * @access public
602
+	 * @return array $this->_template_fields
603
+	 */
604
+	public function get_template_fields()
605
+	{
606
+		$template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
607
+		$template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
608
+		return $template_fields;
609
+	}
610
+
611
+
612
+
613
+
614
+	/** SETUP METHODS **/
615
+	/**
616
+	 * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
617
+	 * @param string $item
618
+	 * @param mixed $value
619
+	 */
620
+	protected function _set_template_value($item, $value)
621
+	{
622
+		if (array_key_exists($item, $this->_template_fields)) {
623
+			$prop = '_' . $item;
624
+			$this->{$prop}= $value;
625
+		}
626
+	}
627
+
628
+	/**
629
+	 * Sets up the message for sending.
630
+	 *
631
+	 * @param  EE_message $message the message object that contains details about the message.
632
+	 * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
633
+	 *
634
+	 * @return bool Very important that all messengers return bool for successful send or not.  Error messages can be
635
+	 *              added to EE_Error.
636
+	 *              true = message sent successfully
637
+	 *              false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).
638
+	 *              Throwing a SendMessageException means the message failed sending and cannot be retried.
639
+	 *
640
+	 * @throws SendMessageException
641
+	 */
642
+	final public function send_message($message, EE_message_type $message_type)
643
+	{
644
+		try {
645
+			$this->_validate_and_setup($message);
646
+			$this->_incoming_message_type = $message_type;
647
+			$response = $this->_send_message();
648
+			if ($response instanceof WP_Error) {
649
+				EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);
650
+				$response = false;
651
+			}
652
+		} catch (\Exception $e) {
653
+			// convert to an instance of SendMessageException
654
+			throw new SendMessageException($e->getMessage());
655
+		}
656
+		return $response;
657
+	}
658
+
659
+
660
+
661
+	/**
662
+	 * Sets up and returns message preview
663
+	 * @param  EE_Message $message incoming message object
664
+	 * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.
665
+	 * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
666
+	 * @return string          return the message html content
667
+	 */
668
+	public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)
669
+	{
670
+		$this->_validate_and_setup($message);
671
+
672
+		$this->_incoming_message_type = $message_type;
673
+
674
+		if ($send) {
675
+			// are we overriding any existing template fields?
676
+			$settings = apply_filters(
677
+				'FHEE__EE_messenger__get_preview__messenger_test_settings',
678
+				$this->get_existing_test_settings(),
679
+				$this,
680
+				$send,
681
+				$message,
682
+				$message_type
683
+			);
684
+			if (! empty($settings)) {
685
+				foreach ($settings as $field => $value) {
686
+					$this->_set_template_value($field, $value);
687
+				}
688
+			}
689
+		}
690
+
691
+		// enqueue preview js so that any links/buttons on the page are disabled.
692
+		if (! $send) {
693
+			// the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
694
+			// it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
695
+			add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
696
+			add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
697
+			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
698
+		}
699
+
700
+		return $send ? $this->_send_message() : $this->_preview();
701
+	}
702
+
703
+
704
+
705
+
706
+	/**
707
+	 * Callback for enqueue_scripts so that we setup the preview script for all previews.
708
+	 *
709
+	 * @since 4.5.0
710
+	 *
711
+	 * @return void
712
+	 */
713
+	public function add_preview_script()
714
+	{
715
+		// error message
716
+		EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
717
+			__('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso')
718
+		);
719
+		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
720
+		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
721
+		wp_enqueue_script('ee-messages-preview-js');
722
+	}
723
+
724
+
725
+
726
+
727
+	/**
728
+	 * simply validates the incoming message object and then sets up the properties for the messenger
729
+	 * @param  EE_Message $message
730
+	 * @throws EE_Error
731
+	 */
732
+	protected function _validate_and_setup(EE_Message $message)
733
+	{
734
+		$template_pack = $message->get_template_pack();
735
+		$variation = $message->get_template_pack_variation();
736
+
737
+		// verify we have the required template pack value on the $message object.
738
+		if (! $template_pack instanceof EE_Messages_Template_Pack) {
739
+			throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
740
+		}
741
+
742
+		$this->_tmp_pack = $template_pack;
743
+
744
+		$this->_variation = $variation ? $variation : 'default';
745
+
746
+		$template_fields = $this->get_template_fields();
747
+
748
+		foreach ($template_fields as $template => $value) {
749
+			if ($template !== 'extra') {
750
+				$column_value = $message->get_field_or_extra_meta('MSG_' . $template);
751
+				$message_template_value = $column_value ? $column_value : null;
752
+				$this->_set_template_value($template, $message_template_value);
753
+			}
754
+		}
755
+	}
756
+
757
+
758
+
759
+	/**
760
+	 * Utility method for child classes to get the contents of a template file and return
761
+	 *
762
+	 * We're assuming the child messenger class has already setup template args!
763
+	 * @param  bool $preview if true we use the preview wrapper otherwise we use main wrapper.
764
+	 * @return string
765
+	 * @throws \EE_Error
766
+	 */
767
+	protected function _get_main_template($preview = false)
768
+	{
769
+		$type = $preview ? 'preview' : 'main';
770
+
771
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
772
+
773
+		// check file exists and is readable
774
+		if (!is_readable($wrapper_template)) {
775
+			throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
776
+		}
777
+
778
+		// add message type to template args
779
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
780
+
781
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
782
+	}
783
+
784
+
785
+
786
+	/**
787
+	 * set the _test_settings_fields property
788
+	 *
789
+	 * @access protected
790
+	 * @return void
791
+	 */
792
+	protected function _set_test_settings_fields()
793
+	{
794
+		$this->_test_settings_fields = array();
795
+	}
796
+
797
+
798
+
799
+	/**
800
+	 * return the _test_settings_fields property
801
+	 * @return array
802
+	 */
803
+	public function get_test_settings_fields()
804
+	{
805
+		return $this->_test_settings_fields;
806
+	}
807
+
808
+
809
+
810
+
811
+	/**
812
+	 * This just returns any existing test settings that might be saved in the database
813
+	 *
814
+	 * @access public
815
+	 * @return array
816
+	 */
817
+	public function get_existing_test_settings()
818
+	{
819
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
820
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
821
+		$settings = $Message_Resource_Manager->get_active_messengers_option();
822
+		return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
823
+	}
824
+
825
+
826
+
827
+	/**
828
+	 * All this does is set the existing test settings (in the db) for the messenger
829
+	 *
830
+	 * @access public
831
+	 * @param $settings
832
+	 * @return bool success/fail
833
+	 */
834
+	public function set_existing_test_settings($settings)
835
+	{
836
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
837
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
838
+		$existing = $Message_Resource_Manager->get_active_messengers_option();
839
+		$existing[ $this->name ]['test_settings'] = $settings;
840
+		return $Message_Resource_Manager->update_active_messengers_option($existing);
841
+	}
842
+
843
+
844
+
845
+	/**
846
+	 * This just returns the field label for a given field setup in the _template_fields property.
847
+	 *
848
+	 * @since   4.3.0
849
+	 *
850
+	 * @param string $field The field to retrieve the label for
851
+	 * @return string             The label
852
+	 */
853
+	public function get_field_label($field)
854
+	{
855
+		// first let's see if the field requests is in the top level array.
856
+		if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
857
+			return $this->_template[ $field ]['label'];
858
+		}
859
+
860
+		// nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
861
+		if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
862
+			return $this->_template_fields['extra'][ $field ]['main']['label'];
863
+		}
864
+
865
+		// now it's possible this field may just be existing in any of the extra array items.
866
+		if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
867
+			foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
868
+				if (!is_array($subfields)) {
869
+					continue;
870
+				}
871
+				if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
872
+					return $subfields[ $field ]['label'];
873
+				}
874
+			}
875
+		}
876
+
877
+		// if we made it here then there's no label set so let's just return the $field.
878
+		return $field;
879
+	}
880
+
881
+
882
+
883
+
884
+	/**
885
+	 * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).
886
+	 *
887
+	 * @since 4.5.0
888
+	 *
889
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
890
+	 *
891
+	 * @return void
892
+	 */
893
+	public function do_secondary_messenger_hooks($sending_messenger_name)
894
+	{
895
+		return;
896
+	}
897 897
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
         $class = get_class($this);
418 418
 
419 419
         // messenger specific filter
420
-        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this);
420
+        $default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this);
421 421
 
422 422
         // all messengers filter
423 423
         $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 
441 441
         // messenger specific filter
442 442
         // messenger specific filter
443
-        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
443
+        $valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
444 444
 
445 445
         // all messengers filter
446 446
         $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
     {
476 476
         $class = get_class($this);
477 477
 
478
-        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this);
478
+        $config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this);
479 479
         $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
480 480
         return $config;
481 481
     }
@@ -514,12 +514,12 @@  discard block
 block discarded – undo
514 514
         // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
515 515
         $event_id = isset($extra['event']) ? $extra['event'] : null;
516 516
 
517
-        $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
-        $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
517
+        $template_wrapper_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
518
+        $template_row_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_row.template.php';
519 519
 
520 520
         // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
521 521
         $global_templates = EEM_Message_Template_Group::instance()->get_all(
522
-            array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )
522
+            array(array('MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true))
523 523
         );
524 524
         $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(
525 525
             $event_id,
@@ -528,29 +528,29 @@  discard block
 block discarded – undo
528 528
                 'MTP_is_active' => true
529 529
             )
530 530
         );
531
-        $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();
531
+        $templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array();
532 532
 
533 533
         // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
534 534
         foreach ($global_templates as $mtpgID => $mtpg) {
535 535
             if ($mtpg instanceof EE_Message_Template_Group) {
536 536
                 // verify this message type is supposed to show on this page
537 537
                 $mtp_obj = $mtpg->message_type_obj();
538
-                if (! $mtp_obj instanceof EE_message_type) {
538
+                if ( ! $mtp_obj instanceof EE_message_type) {
539 539
                     continue;
540 540
                 }
541 541
                 $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
542
-                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
542
+                if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) {
543 543
                     continue;
544 544
                 }
545 545
                 $select_values = array();
546
-                $select_values[ $mtpgID ] = __('Global', 'event_espresso');
546
+                $select_values[$mtpgID] = __('Global', 'event_espresso');
547 547
                 $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null;
548 548
                 // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
549
-                if (! $mtpg->get('MTP_is_override')) {
549
+                if ( ! $mtpg->get('MTP_is_override')) {
550 550
                     // any custom templates for this message type?
551 551
                     $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
552 552
                     foreach ($custom_templates as $cmtpgID => $cmtpg) {
553
-                        $select_values[ $cmtpgID ] = $cmtpg->name();
553
+                        $select_values[$cmtpgID] = $cmtpg->name();
554 554
                         $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
555 555
                     }
556 556
                 }
@@ -572,11 +572,11 @@  discard block
 block discarded – undo
572 572
                 $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
573 573
                 $st_args['mt_slug'] = $mtpg->message_type();
574 574
                 $st_args['messenger_slug'] = $this->name;
575
-                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector');
575
+                $st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation['.$mtpgID.']', $select_values, $default_value, 'data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'"', 'message-template-selector');
576 576
                 // note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
577
-                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __('Create New Custom', 'event_espresso') . '</a>';
577
+                $st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$create_url.'" class="button button-small create-mtpg-button">'.__('Create New Custom', 'event_espresso').'</a>';
578 578
                 $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messages_add_new_message_template') ? $st_args['create_button'] : '';
579
-                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __('Edit', 'event_espresso') . '</a>' : '';
579
+                $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$edit_url.'" class="button button-small edit-mtpg-button">'.__('Edit', 'event_espresso').'</a>' : '';
580 580
                 $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);
581 581
             }
582 582
         }
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
      */
604 604
     public function get_template_fields()
605 605
     {
606
-        $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this);
606
+        $template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this);
607 607
         $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
608 608
         return $template_fields;
609 609
     }
@@ -620,8 +620,8 @@  discard block
 block discarded – undo
620 620
     protected function _set_template_value($item, $value)
621 621
     {
622 622
         if (array_key_exists($item, $this->_template_fields)) {
623
-            $prop = '_' . $item;
624
-            $this->{$prop}= $value;
623
+            $prop = '_'.$item;
624
+            $this->{$prop} = $value;
625 625
         }
626 626
     }
627 627
 
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
                 $message,
682 682
                 $message_type
683 683
             );
684
-            if (! empty($settings)) {
684
+            if ( ! empty($settings)) {
685 685
                 foreach ($settings as $field => $value) {
686 686
                     $this->_set_template_value($field, $value);
687 687
                 }
@@ -689,12 +689,12 @@  discard block
 block discarded – undo
689 689
         }
690 690
 
691 691
         // enqueue preview js so that any links/buttons on the page are disabled.
692
-        if (! $send) {
692
+        if ( ! $send) {
693 693
             // the below may seem like duplication.  However, typically if a messenger enqueues scripts/styles,
694 694
             // it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
695
-            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
696
-            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10);
697
-            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10);
695
+            add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10);
696
+            add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10);
697
+            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10);
698 698
         }
699 699
 
700 700
         return $send ? $this->_send_message() : $this->_preview();
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
         EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(
717 717
             __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso')
718 718
         );
719
-        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true);
719
+        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
720 720
         wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
721 721
         wp_enqueue_script('ee-messages-preview-js');
722 722
     }
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
         $variation = $message->get_template_pack_variation();
736 736
 
737 737
         // verify we have the required template pack value on the $message object.
738
-        if (! $template_pack instanceof EE_Messages_Template_Pack) {
738
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack) {
739 739
             throw new EE_Error(__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso'));
740 740
         }
741 741
 
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
 
748 748
         foreach ($template_fields as $template => $value) {
749 749
             if ($template !== 'extra') {
750
-                $column_value = $message->get_field_or_extra_meta('MSG_' . $template);
750
+                $column_value = $message->get_field_or_extra_meta('MSG_'.$template);
751 751
                 $message_template_value = $column_value ? $column_value : null;
752 752
                 $this->_set_template_value($template, $message_template_value);
753 753
             }
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
         $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
772 772
 
773 773
         // check file exists and is readable
774
-        if (!is_readable($wrapper_template)) {
774
+        if ( ! is_readable($wrapper_template)) {
775 775
             throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
776 776
         }
777 777
 
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
820 820
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
821 821
         $settings = $Message_Resource_Manager->get_active_messengers_option();
822
-        return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();
822
+        return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array();
823 823
     }
824 824
 
825 825
 
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
         /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
837 837
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
838 838
         $existing = $Message_Resource_Manager->get_active_messengers_option();
839
-        $existing[ $this->name ]['test_settings'] = $settings;
839
+        $existing[$this->name]['test_settings'] = $settings;
840 840
         return $Message_Resource_Manager->update_active_messengers_option($existing);
841 841
     }
842 842
 
@@ -853,23 +853,23 @@  discard block
 block discarded – undo
853 853
     public function get_field_label($field)
854 854
     {
855 855
         // first let's see if the field requests is in the top level array.
856
-        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) {
857
-            return $this->_template[ $field ]['label'];
856
+        if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) {
857
+            return $this->_template[$field]['label'];
858 858
         }
859 859
 
860 860
         // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
861
-        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) {
862
-            return $this->_template_fields['extra'][ $field ]['main']['label'];
861
+        if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) {
862
+            return $this->_template_fields['extra'][$field]['main']['label'];
863 863
         }
864 864
 
865 865
         // now it's possible this field may just be existing in any of the extra array items.
866
-        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
866
+        if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
867 867
             foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
868
-                if (!is_array($subfields)) {
868
+                if ( ! is_array($subfields)) {
869 869
                     continue;
870 870
                 }
871
-                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) {
872
-                    return $subfields[ $field ]['label'];
871
+                if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) {
872
+                    return $subfields[$field]['label'];
873 873
                 }
874 874
             }
875 875
         }
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Proper.form.php 1 patch
Indentation   +1524 added lines, -1524 removed lines patch added patch discarded remove patch
@@ -14,1528 +14,1528 @@
 block discarded – undo
14 14
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
15 15
 {
16 16
 
17
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
-
19
-    /**
20
-     * Subsections
21
-     *
22
-     * @var EE_Form_Section_Validatable[]
23
-     */
24
-    protected $_subsections = array();
25
-
26
-    /**
27
-     * Strategy for laying out the form
28
-     *
29
-     * @var EE_Form_Section_Layout_Base
30
-     */
31
-    protected $_layout_strategy;
32
-
33
-    /**
34
-     * Whether or not this form has received and validated a form submission yet
35
-     *
36
-     * @var boolean
37
-     */
38
-    protected $_received_submission = false;
39
-
40
-    /**
41
-     * message displayed to users upon successful form submission
42
-     *
43
-     * @var string
44
-     */
45
-    protected $_form_submission_success_message = '';
46
-
47
-    /**
48
-     * message displayed to users upon unsuccessful form submission
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_form_submission_error_message = '';
53
-
54
-    /**
55
-     * @var array like $_REQUEST
56
-     */
57
-    protected $cached_request_data;
58
-
59
-    /**
60
-     * Stores whether this form (and its sub-sections) were found to be valid or not.
61
-     * Starts off as null, but once the form is validated, it set to either true or false
62
-     * @var boolean|null
63
-     */
64
-    protected $is_valid;
65
-
66
-    /**
67
-     * Stores all the data that will localized for form validation
68
-     *
69
-     * @var array
70
-     */
71
-    static protected $_js_localization = array();
72
-
73
-    /**
74
-     * whether or not the form's localized validation JS vars have been set
75
-     *
76
-     * @type boolean
77
-     */
78
-    static protected $_scripts_localized = false;
79
-
80
-
81
-    /**
82
-     * when constructing a proper form section, calls _construct_finalize on children
83
-     * so that they know who their parent is, and what name they've been given.
84
-     *
85
-     * @param array[] $options_array   {
86
-     * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
-     * @type          $include         string[] numerically-indexed where values are section names to be included,
88
-     *                                 and in that order. This is handy if you want
89
-     *                                 the subsections to be ordered differently than the default, and if you override
90
-     *                                 which fields are shown
91
-     * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
-     *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
-     *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
-     *                                 items from that list of inclusions)
95
-     * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
-     *                                 } @see EE_Form_Section_Validatable::__construct()
97
-     * @throws EE_Error
98
-     */
99
-    public function __construct($options_array = array())
100
-    {
101
-        $options_array = (array) apply_filters(
102
-            'FHEE__EE_Form_Section_Proper___construct__options_array',
103
-            $options_array,
104
-            $this
105
-        );
106
-        // call parent first, as it may be setting the name
107
-        parent::__construct($options_array);
108
-        // if they've included subsections in the constructor, add them now
109
-        if (isset($options_array['include'])) {
110
-            // we are going to make sure we ONLY have those subsections to include
111
-            // AND we are going to make sure they're in that specified order
112
-            $reordered_subsections = array();
113
-            foreach ($options_array['include'] as $input_name) {
114
-                if (isset($this->_subsections[ $input_name ])) {
115
-                    $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
-                }
117
-            }
118
-            $this->_subsections = $reordered_subsections;
119
-        }
120
-        if (isset($options_array['exclude'])) {
121
-            $exclude            = $options_array['exclude'];
122
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
-        }
124
-        if (isset($options_array['layout_strategy'])) {
125
-            $this->_layout_strategy = $options_array['layout_strategy'];
126
-        }
127
-        if (! $this->_layout_strategy) {
128
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
-        }
130
-        $this->_layout_strategy->_construct_finalize($this);
131
-        // ok so we are definitely going to want the forms JS,
132
-        // so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
-            // ok so they've constructed this object after when they should have.
135
-            // just enqueue the generic form scripts and initialize the form immediately in the JS
136
-            EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
-        } else {
138
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
-        }
141
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
-        /**
143
-         * Gives other plugins a chance to hook in before construct finalize is called.
144
-         * The form probably doesn't yet have a parent form section.
145
-         * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
-         * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
-         * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
-         *
149
-         * @since 4.9.32
150
-         * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
-         *                                              except maybe calling _construct_finalize has been done
152
-         * @param array                  $options_array options passed into the constructor
153
-         */
154
-        do_action(
155
-            'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
-            $this,
157
-            $options_array
158
-        );
159
-        if (isset($options_array['name'])) {
160
-            $this->_construct_finalize(null, $options_array['name']);
161
-        }
162
-    }
163
-
164
-
165
-    /**
166
-     * Finishes construction given the parent form section and this form section's name
167
-     *
168
-     * @param EE_Form_Section_Proper $parent_form_section
169
-     * @param string                 $name
170
-     * @throws EE_Error
171
-     */
172
-    public function _construct_finalize($parent_form_section, $name)
173
-    {
174
-        parent::_construct_finalize($parent_form_section, $name);
175
-        $this->_set_default_name_if_empty();
176
-        $this->_set_default_html_id_if_empty();
177
-        foreach ($this->_subsections as $subsection_name => $subsection) {
178
-            if ($subsection instanceof EE_Form_Section_Base) {
179
-                $subsection->_construct_finalize($this, $subsection_name);
180
-            } else {
181
-                throw new EE_Error(
182
-                    sprintf(
183
-                        esc_html__(
184
-                            'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
-                            'event_espresso'
186
-                        ),
187
-                        $subsection_name,
188
-                        get_class($this),
189
-                        $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
-                    )
191
-                );
192
-            }
193
-        }
194
-        /**
195
-         * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
-         * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
-         * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
-         * This might only happen just before displaying the form, or just before it receives form submission data.
199
-         * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
-         * ensured it has a name, HTML IDs, etc
201
-         *
202
-         * @param EE_Form_Section_Proper      $this
203
-         * @param EE_Form_Section_Proper|null $parent_form_section
204
-         * @param string                      $name
205
-         */
206
-        do_action(
207
-            'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
-            $this,
209
-            $parent_form_section,
210
-            $name
211
-        );
212
-    }
213
-
214
-
215
-    /**
216
-     * Gets the layout strategy for this form section
217
-     *
218
-     * @return EE_Form_Section_Layout_Base
219
-     */
220
-    public function get_layout_strategy()
221
-    {
222
-        return $this->_layout_strategy;
223
-    }
224
-
225
-
226
-    /**
227
-     * Gets the HTML for a single input for this form section according
228
-     * to the layout strategy
229
-     *
230
-     * @param EE_Form_Input_Base $input
231
-     * @return string
232
-     */
233
-    public function get_html_for_input($input)
234
-    {
235
-        return $this->_layout_strategy->layout_input($input);
236
-    }
237
-
238
-
239
-    /**
240
-     * was_submitted - checks if form inputs are present in request data
241
-     * Basically an alias for form_data_present_in() (which is used by both
242
-     * proper form sections and form inputs)
243
-     *
244
-     * @param null $form_data
245
-     * @return boolean
246
-     * @throws EE_Error
247
-     */
248
-    public function was_submitted($form_data = null)
249
-    {
250
-        return $this->form_data_present_in($form_data);
251
-    }
252
-
253
-    /**
254
-     * Gets the cached request data; but if there is none, or $req_data was set with
255
-     * something different, refresh the cache, and then return it
256
-     * @param null $req_data
257
-     * @return array
258
-     */
259
-    protected function getCachedRequest($req_data = null)
260
-    {
261
-        if ($this->cached_request_data === null
262
-            || (
263
-                $req_data !== null &&
264
-                $req_data !== $this->cached_request_data
265
-            )
266
-        ) {
267
-            $req_data = apply_filters(
268
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
-                $req_data,
270
-                $this
271
-            );
272
-            if ($req_data === null) {
273
-                $req_data = array_merge($_GET, $_POST);
274
-            }
275
-            $req_data = apply_filters(
276
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
-                $req_data,
278
-                $this
279
-            );
280
-            $this->cached_request_data = (array) $req_data;
281
-        }
282
-        return $this->cached_request_data;
283
-    }
284
-
285
-
286
-    /**
287
-     * After the form section is initially created, call this to sanitize the data in the submission
288
-     * which relates to this form section, validate it, and set it as properties on the form.
289
-     *
290
-     * @param array|null $req_data should usually be $_POST (the default).
291
-     *                             However, you CAN supply a different array.
292
-     *                             Consider using set_defaults() instead however.
293
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
294
-     *                             the inputs will have the correct name in the request data for this function
295
-     *                             to find them and populate the form with them.
296
-     *                             If you have a flat form (with only input subsections),
297
-     *                             you can supply a flat array where keys
298
-     *                             are the form input names and values are their values)
299
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
-     *                             of course, to validate that data, and set errors on the invalid values.
301
-     *                             But if the data has already been validated
302
-     *                             (eg you validated the data then stored it in the DB)
303
-     *                             you may want to skip this step.
304
-     * @throws InvalidArgumentException
305
-     * @throws InvalidInterfaceException
306
-     * @throws InvalidDataTypeException
307
-     * @throws EE_Error
308
-     */
309
-    public function receive_form_submission($req_data = null, $validate = true)
310
-    {
311
-        $req_data = $this->getCachedRequest($req_data);
312
-        $this->_normalize($req_data);
313
-        if ($validate) {
314
-            $this->_validate();
315
-            // if it's invalid, we're going to want to re-display so remember what they submitted
316
-            if (! $this->is_valid()) {
317
-                $this->store_submitted_form_data_in_session();
318
-            }
319
-        }
320
-        if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
-            $this->set_submission_error_message();
322
-        }
323
-        do_action(
324
-            'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
-            $req_data,
326
-            $this,
327
-            $validate
328
-        );
329
-    }
330
-
331
-
332
-    /**
333
-     * caches the originally submitted input values in the session
334
-     * so that they can be used to repopulate the form if it failed validation
335
-     *
336
-     * @return boolean whether or not the data was successfully stored in the session
337
-     * @throws InvalidArgumentException
338
-     * @throws InvalidInterfaceException
339
-     * @throws InvalidDataTypeException
340
-     * @throws EE_Error
341
-     */
342
-    protected function store_submitted_form_data_in_session()
343
-    {
344
-        return EE_Registry::instance()->SSN->set_session_data(
345
-            array(
346
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
-            )
348
-        );
349
-    }
350
-
351
-
352
-    /**
353
-     * retrieves the originally submitted input values in the session
354
-     * so that they can be used to repopulate the form if it failed validation
355
-     *
356
-     * @return array
357
-     * @throws InvalidArgumentException
358
-     * @throws InvalidInterfaceException
359
-     * @throws InvalidDataTypeException
360
-     */
361
-    protected function get_submitted_form_data_from_session()
362
-    {
363
-        $session = EE_Registry::instance()->SSN;
364
-        if ($session instanceof EE_Session) {
365
-            return $session->get_session_data(
366
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
-            );
368
-        }
369
-        return array();
370
-    }
371
-
372
-
373
-    /**
374
-     * flushed the originally submitted input values from the session
375
-     *
376
-     * @return boolean whether or not the data was successfully removed from the session
377
-     * @throws InvalidArgumentException
378
-     * @throws InvalidInterfaceException
379
-     * @throws InvalidDataTypeException
380
-     */
381
-    public static function flush_submitted_form_data_from_session()
382
-    {
383
-        return EE_Registry::instance()->SSN->reset_data(
384
-            array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
-        );
386
-    }
387
-
388
-
389
-    /**
390
-     * Populates this form and its subsections with data from the session.
391
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
-     * validation errors when displaying too)
393
-     * Returns true if the form was populated from the session, false otherwise
394
-     *
395
-     * @return boolean
396
-     * @throws InvalidArgumentException
397
-     * @throws InvalidInterfaceException
398
-     * @throws InvalidDataTypeException
399
-     * @throws EE_Error
400
-     */
401
-    public function populate_from_session()
402
-    {
403
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
404
-        if (empty($form_data_in_session)) {
405
-            return false;
406
-        }
407
-        $this->receive_form_submission($form_data_in_session);
408
-        add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session'));
409
-        if ($this->form_data_present_in($form_data_in_session)) {
410
-            return true;
411
-        }
412
-        return false;
413
-    }
414
-
415
-
416
-    /**
417
-     * Populates the default data for the form, given an array where keys are
418
-     * the input names, and values are their values (preferably normalized to be their
419
-     * proper PHP types, not all strings... although that should be ok too).
420
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
421
-     * the value being an array formatted in teh same way
422
-     *
423
-     * @param array $default_data
424
-     * @throws EE_Error
425
-     */
426
-    public function populate_defaults($default_data)
427
-    {
428
-        foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
-            if (isset($default_data[ $subsection_name ])) {
430
-                if ($subsection instanceof EE_Form_Input_Base) {
431
-                    $subsection->set_default($default_data[ $subsection_name ]);
432
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
433
-                    $subsection->populate_defaults($default_data[ $subsection_name ]);
434
-                }
435
-            }
436
-        }
437
-    }
438
-
439
-
440
-    /**
441
-     * returns true if subsection exists
442
-     *
443
-     * @param string $name
444
-     * @return boolean
445
-     */
446
-    public function subsection_exists($name)
447
-    {
448
-        return isset($this->_subsections[ $name ]) ? true : false;
449
-    }
450
-
451
-
452
-    /**
453
-     * Gets the subsection specified by its name
454
-     *
455
-     * @param string  $name
456
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
-     *                                                      so that the inputs will be properly configured.
458
-     *                                                      However, some client code may be ok
459
-     *                                                      with construction finalize being called later
460
-     *                                                      (realizing that the subsections' html names
461
-     *                                                      might not be set yet, etc.)
462
-     * @return EE_Form_Section_Base
463
-     * @throws EE_Error
464
-     */
465
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
466
-    {
467
-        if ($require_construction_to_be_finalized) {
468
-            $this->ensure_construct_finalized_called();
469
-        }
470
-        return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
-    }
472
-
473
-
474
-    /**
475
-     * Gets all the validatable subsections of this form section
476
-     *
477
-     * @return EE_Form_Section_Validatable[]
478
-     * @throws EE_Error
479
-     */
480
-    public function get_validatable_subsections()
481
-    {
482
-        $validatable_subsections = array();
483
-        foreach ($this->subsections() as $name => $obj) {
484
-            if ($obj instanceof EE_Form_Section_Validatable) {
485
-                $validatable_subsections[ $name ] = $obj;
486
-            }
487
-        }
488
-        return $validatable_subsections;
489
-    }
490
-
491
-
492
-    /**
493
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
-     * throw an EE_Error.
495
-     *
496
-     * @param string  $name
497
-     * @param boolean $require_construction_to_be_finalized most client code should
498
-     *                                                      leave this as TRUE so that the inputs will be properly
499
-     *                                                      configured. However, some client code may be ok with
500
-     *                                                      construction finalize being called later
501
-     *                                                      (realizing that the subsections' html names might not be
502
-     *                                                      set yet, etc.)
503
-     * @return EE_Form_Input_Base
504
-     * @throws EE_Error
505
-     */
506
-    public function get_input($name, $require_construction_to_be_finalized = true)
507
-    {
508
-        $subsection = $this->get_subsection(
509
-            $name,
510
-            $require_construction_to_be_finalized
511
-        );
512
-        if (! $subsection instanceof EE_Form_Input_Base) {
513
-            throw new EE_Error(
514
-                sprintf(
515
-                    esc_html__(
516
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
-                        'event_espresso'
518
-                    ),
519
-                    $name,
520
-                    get_class($this),
521
-                    $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
-                )
523
-            );
524
-        }
525
-        return $subsection;
526
-    }
527
-
528
-
529
-    /**
530
-     * Like get_input(), gets the proper subsection of the form given the name,
531
-     * otherwise throws an EE_Error
532
-     *
533
-     * @param string  $name
534
-     * @param boolean $require_construction_to_be_finalized most client code should
535
-     *                                                      leave this as TRUE so that the inputs will be properly
536
-     *                                                      configured. However, some client code may be ok with
537
-     *                                                      construction finalize being called later
538
-     *                                                      (realizing that the subsections' html names might not be
539
-     *                                                      set yet, etc.)
540
-     * @return EE_Form_Section_Proper
541
-     * @throws EE_Error
542
-     */
543
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
-    {
545
-        $subsection = $this->get_subsection(
546
-            $name,
547
-            $require_construction_to_be_finalized
548
-        );
549
-        if (! $subsection instanceof EE_Form_Section_Proper) {
550
-            throw new EE_Error(
551
-                sprintf(
552
-                    esc_html__(
553
-                        "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
-                        'event_espresso'
555
-                    ),
556
-                    $name,
557
-                    get_class($this)
558
-                )
559
-            );
560
-        }
561
-        return $subsection;
562
-    }
563
-
564
-
565
-    /**
566
-     * Gets the value of the specified input. Should be called after receive_form_submission()
567
-     * or populate_defaults() on the form, where the normalized value on the input is set.
568
-     *
569
-     * @param string $name
570
-     * @return mixed depending on the input's type and its normalization strategy
571
-     * @throws EE_Error
572
-     */
573
-    public function get_input_value($name)
574
-    {
575
-        $input = $this->get_input($name);
576
-        return $input->normalized_value();
577
-    }
578
-
579
-
580
-    /**
581
-     * Checks if this form section itself is valid, and then checks its subsections
582
-     *
583
-     * @throws EE_Error
584
-     * @return boolean
585
-     */
586
-    public function is_valid()
587
-    {
588
-        if ($this->is_valid === null) {
589
-            if (! $this->has_received_submission()) {
590
-                throw new EE_Error(
591
-                    sprintf(
592
-                        esc_html__(
593
-                            'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
-                            'event_espresso'
595
-                        )
596
-                    )
597
-                );
598
-            }
599
-            if (! parent::is_valid()) {
600
-                $this->is_valid = false;
601
-            } else {
602
-                // ok so no general errors to this entire form section.
603
-                // so let's check the subsections, but only set errors if that hasn't been done yet
604
-                $this->is_valid = true;
605
-                foreach ($this->get_validatable_subsections() as $subsection) {
606
-                    if (! $subsection->is_valid()) {
607
-                        $this->is_valid = false;
608
-                    }
609
-                }
610
-            }
611
-        }
612
-        return $this->is_valid;
613
-    }
614
-
615
-
616
-    /**
617
-     * gets the default name of this form section if none is specified
618
-     *
619
-     * @return void
620
-     */
621
-    protected function _set_default_name_if_empty()
622
-    {
623
-        if (! $this->_name) {
624
-            $classname    = get_class($this);
625
-            $default_name = str_replace('EE_', '', $classname);
626
-            $this->_name  = $default_name;
627
-        }
628
-    }
629
-
630
-
631
-    /**
632
-     * Returns the HTML for the form, except for the form opening and closing tags
633
-     * (as the form section doesn't know where you necessarily want to send the information to),
634
-     * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
-     * Not doing_it_wrong because theoretically this CAN be used properly,
637
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
-     * any CSS.
639
-     *
640
-     * @throws InvalidArgumentException
641
-     * @throws InvalidInterfaceException
642
-     * @throws InvalidDataTypeException
643
-     * @throws EE_Error
644
-     */
645
-    public function get_html_and_js()
646
-    {
647
-        $this->enqueue_js();
648
-        return $this->get_html();
649
-    }
650
-
651
-
652
-    /**
653
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
-     *
655
-     * @param bool $display_previously_submitted_data
656
-     * @return string
657
-     * @throws InvalidArgumentException
658
-     * @throws InvalidInterfaceException
659
-     * @throws InvalidDataTypeException
660
-     * @throws EE_Error
661
-     * @throws EE_Error
662
-     * @throws EE_Error
663
-     */
664
-    public function get_html($display_previously_submitted_data = true)
665
-    {
666
-        $this->ensure_construct_finalized_called();
667
-        if ($display_previously_submitted_data) {
668
-            $this->populate_from_session();
669
-        }
670
-        return $this->_form_html_filter
671
-            ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
-            : $this->_layout_strategy->layout_form();
673
-    }
674
-
675
-
676
-    /**
677
-     * enqueues JS and CSS for the form.
678
-     * It is preferred to call this before wp_enqueue_scripts so the
679
-     * scripts and styles can be put in the header, but if called later
680
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
-     * only be in the header; but in HTML5 its ok in the body.
682
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
-     *
685
-     * @return void
686
-     * @throws EE_Error
687
-     */
688
-    public function enqueue_js()
689
-    {
690
-        $this->_enqueue_and_localize_form_js();
691
-        foreach ($this->subsections() as $subsection) {
692
-            $subsection->enqueue_js();
693
-        }
694
-    }
695
-
696
-
697
-    /**
698
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
-     * the wp_enqueue_scripts hook.
701
-     * However, registering the form js and localizing it can happen when we
702
-     * actually output the form (which is preferred, seeing how teh form's fields
703
-     * could change until it's actually outputted)
704
-     *
705
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
-     *                                                    to be triggered automatically or not
707
-     * @return void
708
-     */
709
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
-    {
711
-        wp_register_script(
712
-            'ee_form_section_validation',
713
-            EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js',
714
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
-            EVENT_ESPRESSO_VERSION,
716
-            true
717
-        );
718
-        wp_localize_script(
719
-            'ee_form_section_validation',
720
-            'ee_form_section_validation_init',
721
-            array('init' => $init_form_validation_automatically ? '1' : '0')
722
-        );
723
-    }
724
-
725
-
726
-    /**
727
-     * gets the variables used by form_section_validation.js.
728
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
-     * but before the wordpress hook wp_loaded
730
-     *
731
-     * @throws EE_Error
732
-     */
733
-    public function _enqueue_and_localize_form_js()
734
-    {
735
-        $this->ensure_construct_finalized_called();
736
-        // actually, we don't want to localize just yet. There may be other forms on the page.
737
-        // so we need to add our form section data to a static variable accessible by all form sections
738
-        // and localize it just before the footer
739
-        $this->localize_validation_rules();
740
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
-    }
743
-
744
-
745
-    /**
746
-     * add our form section data to a static variable accessible by all form sections
747
-     *
748
-     * @param bool $return_for_subsection
749
-     * @return void
750
-     * @throws EE_Error
751
-     */
752
-    public function localize_validation_rules($return_for_subsection = false)
753
-    {
754
-        // we only want to localize vars ONCE for the entire form,
755
-        // so if the form section doesn't have a parent, then it must be the top dog
756
-        if ($return_for_subsection || ! $this->parent_section()) {
757
-            EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
-                'form_section_id'  => $this->html_id(true),
759
-                'validation_rules' => $this->get_jquery_validation_rules(),
760
-                'other_data'       => $this->get_other_js_data(),
761
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
762
-            );
763
-            EE_Form_Section_Proper::$_scripts_localized                                = true;
764
-        }
765
-    }
766
-
767
-
768
-    /**
769
-     * Gets an array of extra data that will be useful for client-side javascript.
770
-     * This is primarily data added by inputs and forms in addition to any
771
-     * scripts they might enqueue
772
-     *
773
-     * @param array $form_other_js_data
774
-     * @return array
775
-     * @throws EE_Error
776
-     */
777
-    public function get_other_js_data($form_other_js_data = array())
778
-    {
779
-        foreach ($this->subsections() as $subsection) {
780
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
-        }
782
-        return $form_other_js_data;
783
-    }
784
-
785
-
786
-    /**
787
-     * Gets a flat array of inputs for this form section and its subsections.
788
-     * Keys are their form names, and values are the inputs themselves
789
-     *
790
-     * @return EE_Form_Input_Base
791
-     * @throws EE_Error
792
-     */
793
-    public function inputs_in_subsections()
794
-    {
795
-        $inputs = array();
796
-        foreach ($this->subsections() as $subsection) {
797
-            if ($subsection instanceof EE_Form_Input_Base) {
798
-                $inputs[ $subsection->html_name() ] = $subsection;
799
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
800
-                $inputs += $subsection->inputs_in_subsections();
801
-            }
802
-        }
803
-        return $inputs;
804
-    }
805
-
806
-
807
-    /**
808
-     * Gets a flat array of all the validation errors.
809
-     * Keys are html names (because those should be unique)
810
-     * and values are a string of all their validation errors
811
-     *
812
-     * @return string[]
813
-     * @throws EE_Error
814
-     */
815
-    public function subsection_validation_errors_by_html_name()
816
-    {
817
-        $inputs = $this->inputs();
818
-        $errors = array();
819
-        foreach ($inputs as $form_input) {
820
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
-                $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
-            }
823
-        }
824
-        return $errors;
825
-    }
826
-
827
-
828
-    /**
829
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
-     * Should be setup by each form during the _enqueues_and_localize_form_js
831
-     *
832
-     * @throws InvalidArgumentException
833
-     * @throws InvalidInterfaceException
834
-     * @throws InvalidDataTypeException
835
-     */
836
-    public static function localize_script_for_all_forms()
837
-    {
838
-        // allow inputs and stuff to hook in their JS and stuff here
839
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
843
-            : 'wp_default';
844
-        EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
-        wp_enqueue_script('ee_form_section_validation');
846
-        wp_localize_script(
847
-            'ee_form_section_validation',
848
-            'ee_form_section_vars',
849
-            EE_Form_Section_Proper::$_js_localization
850
-        );
851
-    }
852
-
853
-
854
-    /**
855
-     * ensure_scripts_localized
856
-     *
857
-     * @throws EE_Error
858
-     */
859
-    public function ensure_scripts_localized()
860
-    {
861
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
862
-            $this->_enqueue_and_localize_form_js();
863
-        }
864
-    }
865
-
866
-
867
-    /**
868
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
869
-     * is that the key here should be the same as the custom validation rule put in the JS file
870
-     *
871
-     * @return array keys are custom validation rules, and values are internationalized strings
872
-     */
873
-    private static function _get_localized_error_messages()
874
-    {
875
-        return array(
876
-            'validUrl' => wp_strip_all_tags(__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso')),
877
-            'regex'    => wp_strip_all_tags(__('Please check your input', 'event_espresso'))
878
-        );
879
-    }
880
-
881
-
882
-    /**
883
-     * @return array
884
-     */
885
-    public static function js_localization()
886
-    {
887
-        return self::$_js_localization;
888
-    }
889
-
890
-
891
-    /**
892
-     * @return void
893
-     */
894
-    public static function reset_js_localization()
895
-    {
896
-        self::$_js_localization = array();
897
-    }
898
-
899
-
900
-    /**
901
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
-     * See parent function for more...
903
-     *
904
-     * @return array
905
-     * @throws EE_Error
906
-     */
907
-    public function get_jquery_validation_rules()
908
-    {
909
-        $jquery_validation_rules = array();
910
-        foreach ($this->get_validatable_subsections() as $subsection) {
911
-            $jquery_validation_rules = array_merge(
912
-                $jquery_validation_rules,
913
-                $subsection->get_jquery_validation_rules()
914
-            );
915
-        }
916
-        return $jquery_validation_rules;
917
-    }
918
-
919
-
920
-    /**
921
-     * Sanitizes all the data and sets the sanitized value of each field
922
-     *
923
-     * @param array $req_data like $_POST
924
-     * @return void
925
-     * @throws EE_Error
926
-     */
927
-    protected function _normalize($req_data)
928
-    {
929
-        $this->_received_submission = true;
930
-        $this->_validation_errors   = array();
931
-        foreach ($this->get_validatable_subsections() as $subsection) {
932
-            try {
933
-                $subsection->_normalize($req_data);
934
-            } catch (EE_Validation_Error $e) {
935
-                $subsection->add_validation_error($e);
936
-            }
937
-        }
938
-    }
939
-
940
-
941
-    /**
942
-     * Performs validation on this form section and its subsections.
943
-     * For each subsection,
944
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
945
-     * and passes it the subsection, then calls _validate on that subsection.
946
-     * If you need to perform validation on the form as a whole (considering multiple)
947
-     * you would be best to override this _validate method,
948
-     * calling parent::_validate() first.
949
-     *
950
-     * @throws EE_Error
951
-     */
952
-    protected function _validate()
953
-    {
954
-        // reset the cache of whether this form is valid or not- we're re-validating it now
955
-        $this->is_valid = null;
956
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
-            if (method_exists($this, '_validate_' . $subsection_name)) {
958
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
-            }
960
-            $subsection->_validate();
961
-        }
962
-    }
963
-
964
-
965
-    /**
966
-     * Gets all the validated inputs for the form section
967
-     *
968
-     * @return array
969
-     * @throws EE_Error
970
-     */
971
-    public function valid_data()
972
-    {
973
-        $inputs = array();
974
-        foreach ($this->subsections() as $subsection_name => $subsection) {
975
-            if ($subsection instanceof EE_Form_Section_Proper) {
976
-                $inputs[ $subsection_name ] = $subsection->valid_data();
977
-            } elseif ($subsection instanceof EE_Form_Input_Base) {
978
-                $inputs[ $subsection_name ] = $subsection->normalized_value();
979
-            }
980
-        }
981
-        return $inputs;
982
-    }
983
-
984
-
985
-    /**
986
-     * Gets all the inputs on this form section
987
-     *
988
-     * @return EE_Form_Input_Base[]
989
-     * @throws EE_Error
990
-     */
991
-    public function inputs()
992
-    {
993
-        $inputs = array();
994
-        foreach ($this->subsections() as $subsection_name => $subsection) {
995
-            if ($subsection instanceof EE_Form_Input_Base) {
996
-                $inputs[ $subsection_name ] = $subsection;
997
-            }
998
-        }
999
-        return $inputs;
1000
-    }
1001
-
1002
-
1003
-    /**
1004
-     * Gets all the subsections which are a proper form
1005
-     *
1006
-     * @return EE_Form_Section_Proper[]
1007
-     * @throws EE_Error
1008
-     */
1009
-    public function subforms()
1010
-    {
1011
-        $form_sections = array();
1012
-        foreach ($this->subsections() as $name => $obj) {
1013
-            if ($obj instanceof EE_Form_Section_Proper) {
1014
-                $form_sections[ $name ] = $obj;
1015
-            }
1016
-        }
1017
-        return $form_sections;
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
-     * Consider using inputs() or subforms()
1024
-     * if you only want form inputs or proper form sections.
1025
-     *
1026
-     * @param boolean $require_construction_to_be_finalized most client code should
1027
-     *                                                      leave this as TRUE so that the inputs will be properly
1028
-     *                                                      configured. However, some client code may be ok with
1029
-     *                                                      construction finalize being called later
1030
-     *                                                      (realizing that the subsections' html names might not be
1031
-     *                                                      set yet, etc.)
1032
-     * @return EE_Form_Section_Proper[]
1033
-     * @throws EE_Error
1034
-     */
1035
-    public function subsections($require_construction_to_be_finalized = true)
1036
-    {
1037
-        if ($require_construction_to_be_finalized) {
1038
-            $this->ensure_construct_finalized_called();
1039
-        }
1040
-        return $this->_subsections;
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     * Returns whether this form has any subforms or inputs
1046
-     * @return bool
1047
-     */
1048
-    public function hasSubsections()
1049
-    {
1050
-        return ! empty($this->_subsections);
1051
-    }
1052
-
1053
-
1054
-    /**
1055
-     * Returns a simple array where keys are input names, and values are their normalized
1056
-     * values. (Similar to calling get_input_value on inputs)
1057
-     *
1058
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
-     *                                        or just this forms' direct children inputs
1060
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
-     *                                        or allow multidimensional array
1062
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
-     *                                        with array keys being input names
1064
-     *                                        (regardless of whether they are from a subsection or not),
1065
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1066
-     *                                        where keys are always subsection names and values are either
1067
-     *                                        the input's normalized value, or an array like the top-level array
1068
-     * @throws EE_Error
1069
-     */
1070
-    public function input_values($include_subform_inputs = false, $flatten = false)
1071
-    {
1072
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
-    }
1074
-
1075
-
1076
-    /**
1077
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
-     * is not necessarily the value we want to display to users. This creates an array
1080
-     * where keys are the input names, and values are their display values
1081
-     *
1082
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
-     *                                        or just this forms' direct children inputs
1084
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
-     *                                        or allow multidimensional array
1086
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
-     *                                        with array keys being input names
1088
-     *                                        (regardless of whether they are from a subsection or not),
1089
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1090
-     *                                        where keys are always subsection names and values are either
1091
-     *                                        the input's normalized value, or an array like the top-level array
1092
-     * @throws EE_Error
1093
-     */
1094
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
-    {
1096
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
-    }
1098
-
1099
-
1100
-    /**
1101
-     * Gets the input values from the form
1102
-     *
1103
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
-     *                                        or just the normalized value
1105
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
-     *                                        or just this forms' direct children inputs
1107
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
-     *                                        or allow multidimensional array
1109
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
-     *                                        input names (regardless of whether they are from a subsection or not),
1111
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1112
-     *                                        where keys are always subsection names and values are either
1113
-     *                                        the input's normalized value, or an array like the top-level array
1114
-     * @throws EE_Error
1115
-     */
1116
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
-    {
1118
-        $input_values = array();
1119
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1120
-            if ($subsection instanceof EE_Form_Input_Base) {
1121
-                $input_values[ $subsection_name ] = $pretty
1122
-                    ? $subsection->pretty_value()
1123
-                    : $subsection->normalized_value();
1124
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
-                $subform_input_values = $subsection->_input_values(
1126
-                    $pretty,
1127
-                    $include_subform_inputs,
1128
-                    $flatten
1129
-                );
1130
-                if ($flatten) {
1131
-                    $input_values = array_merge($input_values, $subform_input_values);
1132
-                } else {
1133
-                    $input_values[ $subsection_name ] = $subform_input_values;
1134
-                }
1135
-            }
1136
-        }
1137
-        return $input_values;
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * Gets the originally submitted input values from the form
1143
-     *
1144
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
-     *                                   or just this forms' direct children inputs
1146
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
-     *                                   with array keys being input names
1148
-     *                                   (regardless of whether they are from a subsection or not),
1149
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1150
-     *                                   where keys are always subsection names and values are either
1151
-     *                                   the input's normalized value, or an array like the top-level array
1152
-     * @throws EE_Error
1153
-     */
1154
-    public function submitted_values($include_subforms = false)
1155
-    {
1156
-        $submitted_values = array();
1157
-        foreach ($this->subsections() as $subsection) {
1158
-            if ($subsection instanceof EE_Form_Input_Base) {
1159
-                // is this input part of an array of inputs?
1160
-                if (strpos($subsection->html_name(), '[') !== false) {
1161
-                    $full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
-                        explode(
1163
-                            '[',
1164
-                            str_replace(']', '', $subsection->html_name())
1165
-                        ),
1166
-                        $subsection->raw_value()
1167
-                    );
1168
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
-                } else {
1170
-                    $submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
-                }
1172
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1174
-                $submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
-            }
1176
-        }
1177
-        return $submitted_values;
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * Indicates whether or not this form has received a submission yet
1183
-     * (ie, had receive_form_submission called on it yet)
1184
-     *
1185
-     * @return boolean
1186
-     * @throws EE_Error
1187
-     */
1188
-    public function has_received_submission()
1189
-    {
1190
-        $this->ensure_construct_finalized_called();
1191
-        return $this->_received_submission;
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * Equivalent to passing 'exclude' in the constructor's options array.
1197
-     * Removes the listed inputs from the form
1198
-     *
1199
-     * @param array $inputs_to_exclude values are the input names
1200
-     * @return void
1201
-     */
1202
-    public function exclude(array $inputs_to_exclude = array())
1203
-    {
1204
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
-            unset($this->_subsections[ $input_to_exclude_name ]);
1206
-        }
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1212
-     * @param array $inputs_to_hide
1213
-     * @throws EE_Error
1214
-     */
1215
-    public function hide(array $inputs_to_hide = array())
1216
-    {
1217
-        foreach ($inputs_to_hide as $input_to_hide) {
1218
-            $input = $this->get_input($input_to_hide);
1219
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1220
-        }
1221
-    }
1222
-
1223
-
1224
-    /**
1225
-     * add_subsections
1226
-     * Adds the listed subsections to the form section.
1227
-     * If $subsection_name_to_target is provided,
1228
-     * then new subsections are added before or after that subsection,
1229
-     * otherwise to the start or end of the entire subsections array.
1230
-     *
1231
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1232
-     *                                                          where keys are their names
1233
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1234
-     *                                                          should be added before or after
1235
-     *                                                          IF $subsection_name_to_target is null,
1236
-     *                                                          then $new_subsections will be added to
1237
-     *                                                          the beginning or end of the entire subsections array
1238
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1239
-     *                                                          $subsection_name_to_target,
1240
-     *                                                          or if $subsection_name_to_target is null,
1241
-     *                                                          before or after entire subsections array
1242
-     * @return void
1243
-     * @throws EE_Error
1244
-     */
1245
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1246
-    {
1247
-        foreach ($new_subsections as $subsection_name => $subsection) {
1248
-            if (! $subsection instanceof EE_Form_Section_Base) {
1249
-                EE_Error::add_error(
1250
-                    sprintf(
1251
-                        esc_html__(
1252
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1253
-                            'event_espresso'
1254
-                        ),
1255
-                        get_class($subsection),
1256
-                        $subsection_name,
1257
-                        $this->name()
1258
-                    )
1259
-                );
1260
-                unset($new_subsections[ $subsection_name ]);
1261
-            }
1262
-        }
1263
-        $this->_subsections = EEH_Array::insert_into_array(
1264
-            $this->_subsections,
1265
-            $new_subsections,
1266
-            $subsection_name_to_target,
1267
-            $add_before
1268
-        );
1269
-        if ($this->_construction_finalized) {
1270
-            foreach ($this->_subsections as $name => $subsection) {
1271
-                $subsection->_construct_finalize($this, $name);
1272
-            }
1273
-        }
1274
-    }
1275
-
1276
-
1277
-    /**
1278
-     * @param string $subsection_name
1279
-     * @param bool   $recursive
1280
-     * @return bool
1281
-     */
1282
-    public function has_subsection($subsection_name, $recursive = false)
1283
-    {
1284
-        foreach ($this->_subsections as $name => $subsection) {
1285
-            if ($name === $subsection_name
1286
-                || (
1287
-                    $recursive
1288
-                    && $subsection instanceof EE_Form_Section_Proper
1289
-                    && $subsection->has_subsection($subsection_name, $recursive)
1290
-                )
1291
-            ) {
1292
-                return true;
1293
-            }
1294
-        }
1295
-        return false;
1296
-    }
1297
-
1298
-
1299
-
1300
-    /**
1301
-     * Just gets all validatable subsections to clean their sensitive data
1302
-     *
1303
-     * @throws EE_Error
1304
-     */
1305
-    public function clean_sensitive_data()
1306
-    {
1307
-        foreach ($this->get_validatable_subsections() as $subsection) {
1308
-            $subsection->clean_sensitive_data();
1309
-        }
1310
-    }
1311
-
1312
-
1313
-    /**
1314
-     * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1315
-     * @param string                           $form_submission_error_message
1316
-     * @param EE_Form_Section_Validatable $form_section unused
1317
-     * @throws EE_Error
1318
-     */
1319
-    public function set_submission_error_message(
1320
-        $form_submission_error_message = ''
1321
-    ) {
1322
-        $this->_form_submission_error_message = ! empty($form_submission_error_message)
1323
-            ? $form_submission_error_message
1324
-            : $this->getAllValidationErrorsString();
1325
-    }
1326
-
1327
-
1328
-    /**
1329
-     * Returns the cached error message. A default value is set for this during _validate(),
1330
-     * (called during receive_form_submission) but it can be explicitly set using
1331
-     * set_submission_error_message
1332
-     *
1333
-     * @return string
1334
-     */
1335
-    public function submission_error_message()
1336
-    {
1337
-        return $this->_form_submission_error_message;
1338
-    }
1339
-
1340
-
1341
-    /**
1342
-     * Sets a message to display if the data submitted to the form was valid.
1343
-     * @param string $form_submission_success_message
1344
-     */
1345
-    public function set_submission_success_message($form_submission_success_message = '')
1346
-    {
1347
-        $this->_form_submission_success_message = ! empty($form_submission_success_message)
1348
-            ? $form_submission_success_message
1349
-            : esc_html__('Form submitted successfully', 'event_espresso');
1350
-    }
1351
-
1352
-
1353
-    /**
1354
-     * Gets a message appropriate for display when the form is correctly submitted
1355
-     * @return string
1356
-     */
1357
-    public function submission_success_message()
1358
-    {
1359
-        return $this->_form_submission_success_message;
1360
-    }
1361
-
1362
-
1363
-    /**
1364
-     * Returns the prefix that should be used on child of this form section for
1365
-     * their html names. If this form section itself has a parent, prepends ITS
1366
-     * prefix onto this form section's prefix. Used primarily by
1367
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1368
-     *
1369
-     * @return string
1370
-     * @throws EE_Error
1371
-     */
1372
-    public function html_name_prefix()
1373
-    {
1374
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1375
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1376
-        }
1377
-        return $this->name();
1378
-    }
1379
-
1380
-
1381
-    /**
1382
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1383
-     * calls it (assumes there is no parent and that we want the name to be whatever
1384
-     * was set, which is probably nothing, or the classname)
1385
-     *
1386
-     * @return string
1387
-     * @throws EE_Error
1388
-     */
1389
-    public function name()
1390
-    {
1391
-        $this->ensure_construct_finalized_called();
1392
-        return parent::name();
1393
-    }
1394
-
1395
-
1396
-    /**
1397
-     * @return EE_Form_Section_Proper
1398
-     * @throws EE_Error
1399
-     */
1400
-    public function parent_section()
1401
-    {
1402
-        $this->ensure_construct_finalized_called();
1403
-        return parent::parent_section();
1404
-    }
1405
-
1406
-
1407
-    /**
1408
-     * make sure construction finalized was called, otherwise children might not be ready
1409
-     *
1410
-     * @return void
1411
-     * @throws EE_Error
1412
-     */
1413
-    public function ensure_construct_finalized_called()
1414
-    {
1415
-        if (! $this->_construction_finalized) {
1416
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1417
-        }
1418
-    }
1419
-
1420
-
1421
-    /**
1422
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1423
-     * are in teh form data. If any are found, returns true. Else false
1424
-     *
1425
-     * @param array $req_data
1426
-     * @return boolean
1427
-     * @throws EE_Error
1428
-     */
1429
-    public function form_data_present_in($req_data = null)
1430
-    {
1431
-        $req_data = $this->getCachedRequest($req_data);
1432
-        foreach ($this->subsections() as $subsection) {
1433
-            if ($subsection instanceof EE_Form_Input_Base) {
1434
-                if ($subsection->form_data_present_in($req_data)) {
1435
-                    return true;
1436
-                }
1437
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1438
-                if ($subsection->form_data_present_in($req_data)) {
1439
-                    return true;
1440
-                }
1441
-            }
1442
-        }
1443
-        return false;
1444
-    }
1445
-
1446
-
1447
-    /**
1448
-     * Gets validation errors for this form section and subsections
1449
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1450
-     * gets the validation errors for ALL subsection
1451
-     *
1452
-     * @return EE_Validation_Error[]
1453
-     * @throws EE_Error
1454
-     */
1455
-    public function get_validation_errors_accumulated()
1456
-    {
1457
-        $validation_errors = $this->get_validation_errors();
1458
-        foreach ($this->get_validatable_subsections() as $subsection) {
1459
-            if ($subsection instanceof EE_Form_Section_Proper) {
1460
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1461
-            } else {
1462
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1463
-            }
1464
-            if ($validation_errors_on_this_subsection) {
1465
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1466
-            }
1467
-        }
1468
-        return $validation_errors;
1469
-    }
1470
-
1471
-    /**
1472
-     * Fetch validation errors from children and grandchildren and puts them in a single string.
1473
-     * This traverses the form section tree to generate this, but you probably want to instead use
1474
-     * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1475
-     *
1476
-     * @return string
1477
-     * @since 4.9.59.p
1478
-     */
1479
-    protected function getAllValidationErrorsString()
1480
-    {
1481
-        $submission_error_messages = array();
1482
-        // bad, bad, bad registrant
1483
-        foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1484
-            if ($validation_error instanceof EE_Validation_Error) {
1485
-                $form_section = $validation_error->get_form_section();
1486
-                if ($form_section instanceof EE_Form_Input_Base) {
1487
-                    $label = $validation_error->get_form_section()->html_label_text();
1488
-                } elseif ($form_section instanceof EE_Form_Section_Validatable) {
1489
-                    $label = $validation_error->get_form_section()->name();
1490
-                } else {
1491
-                    $label = esc_html__('Unknown', 'event_espresso');
1492
-                }
1493
-                $submission_error_messages[] = sprintf(
1494
-                    __('%s : %s', 'event_espresso'),
1495
-                    $label,
1496
-                    $validation_error->getMessage()
1497
-                );
1498
-            }
1499
-        }
1500
-        return implode('<br>', $submission_error_messages);
1501
-    }
1502
-
1503
-
1504
-    /**
1505
-     * This isn't just the name of an input, it's a path pointing to an input. The
1506
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1507
-     * dot-dot-slash (../) means to ascend into the parent section.
1508
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1509
-     * which will be returned.
1510
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1511
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1512
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1513
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1514
-     * Etc
1515
-     *
1516
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1517
-     * @return EE_Form_Section_Base
1518
-     * @throws EE_Error
1519
-     */
1520
-    public function find_section_from_path($form_section_path)
1521
-    {
1522
-        // check if we can find the input from purely going straight up the tree
1523
-        $input = parent::find_section_from_path($form_section_path);
1524
-        if ($input instanceof EE_Form_Section_Base) {
1525
-            return $input;
1526
-        }
1527
-        $next_slash_pos = strpos($form_section_path, '/');
1528
-        if ($next_slash_pos !== false) {
1529
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1530
-            $subpath            = substr($form_section_path, $next_slash_pos + 1);
1531
-        } else {
1532
-            $child_section_name = $form_section_path;
1533
-            $subpath            = '';
1534
-        }
1535
-        $child_section = $this->get_subsection($child_section_name);
1536
-        if ($child_section instanceof EE_Form_Section_Base) {
1537
-            return $child_section->find_section_from_path($subpath);
1538
-        }
1539
-        return null;
1540
-    }
17
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
+
19
+	/**
20
+	 * Subsections
21
+	 *
22
+	 * @var EE_Form_Section_Validatable[]
23
+	 */
24
+	protected $_subsections = array();
25
+
26
+	/**
27
+	 * Strategy for laying out the form
28
+	 *
29
+	 * @var EE_Form_Section_Layout_Base
30
+	 */
31
+	protected $_layout_strategy;
32
+
33
+	/**
34
+	 * Whether or not this form has received and validated a form submission yet
35
+	 *
36
+	 * @var boolean
37
+	 */
38
+	protected $_received_submission = false;
39
+
40
+	/**
41
+	 * message displayed to users upon successful form submission
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $_form_submission_success_message = '';
46
+
47
+	/**
48
+	 * message displayed to users upon unsuccessful form submission
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_form_submission_error_message = '';
53
+
54
+	/**
55
+	 * @var array like $_REQUEST
56
+	 */
57
+	protected $cached_request_data;
58
+
59
+	/**
60
+	 * Stores whether this form (and its sub-sections) were found to be valid or not.
61
+	 * Starts off as null, but once the form is validated, it set to either true or false
62
+	 * @var boolean|null
63
+	 */
64
+	protected $is_valid;
65
+
66
+	/**
67
+	 * Stores all the data that will localized for form validation
68
+	 *
69
+	 * @var array
70
+	 */
71
+	static protected $_js_localization = array();
72
+
73
+	/**
74
+	 * whether or not the form's localized validation JS vars have been set
75
+	 *
76
+	 * @type boolean
77
+	 */
78
+	static protected $_scripts_localized = false;
79
+
80
+
81
+	/**
82
+	 * when constructing a proper form section, calls _construct_finalize on children
83
+	 * so that they know who their parent is, and what name they've been given.
84
+	 *
85
+	 * @param array[] $options_array   {
86
+	 * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
+	 * @type          $include         string[] numerically-indexed where values are section names to be included,
88
+	 *                                 and in that order. This is handy if you want
89
+	 *                                 the subsections to be ordered differently than the default, and if you override
90
+	 *                                 which fields are shown
91
+	 * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
+	 *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
+	 *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
+	 *                                 items from that list of inclusions)
95
+	 * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
+	 *                                 } @see EE_Form_Section_Validatable::__construct()
97
+	 * @throws EE_Error
98
+	 */
99
+	public function __construct($options_array = array())
100
+	{
101
+		$options_array = (array) apply_filters(
102
+			'FHEE__EE_Form_Section_Proper___construct__options_array',
103
+			$options_array,
104
+			$this
105
+		);
106
+		// call parent first, as it may be setting the name
107
+		parent::__construct($options_array);
108
+		// if they've included subsections in the constructor, add them now
109
+		if (isset($options_array['include'])) {
110
+			// we are going to make sure we ONLY have those subsections to include
111
+			// AND we are going to make sure they're in that specified order
112
+			$reordered_subsections = array();
113
+			foreach ($options_array['include'] as $input_name) {
114
+				if (isset($this->_subsections[ $input_name ])) {
115
+					$reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
+				}
117
+			}
118
+			$this->_subsections = $reordered_subsections;
119
+		}
120
+		if (isset($options_array['exclude'])) {
121
+			$exclude            = $options_array['exclude'];
122
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
+		}
124
+		if (isset($options_array['layout_strategy'])) {
125
+			$this->_layout_strategy = $options_array['layout_strategy'];
126
+		}
127
+		if (! $this->_layout_strategy) {
128
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
+		}
130
+		$this->_layout_strategy->_construct_finalize($this);
131
+		// ok so we are definitely going to want the forms JS,
132
+		// so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
+			// ok so they've constructed this object after when they should have.
135
+			// just enqueue the generic form scripts and initialize the form immediately in the JS
136
+			EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
+		} else {
138
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
+		}
141
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
+		/**
143
+		 * Gives other plugins a chance to hook in before construct finalize is called.
144
+		 * The form probably doesn't yet have a parent form section.
145
+		 * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
+		 * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
+		 * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
+		 *
149
+		 * @since 4.9.32
150
+		 * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
+		 *                                              except maybe calling _construct_finalize has been done
152
+		 * @param array                  $options_array options passed into the constructor
153
+		 */
154
+		do_action(
155
+			'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
+			$this,
157
+			$options_array
158
+		);
159
+		if (isset($options_array['name'])) {
160
+			$this->_construct_finalize(null, $options_array['name']);
161
+		}
162
+	}
163
+
164
+
165
+	/**
166
+	 * Finishes construction given the parent form section and this form section's name
167
+	 *
168
+	 * @param EE_Form_Section_Proper $parent_form_section
169
+	 * @param string                 $name
170
+	 * @throws EE_Error
171
+	 */
172
+	public function _construct_finalize($parent_form_section, $name)
173
+	{
174
+		parent::_construct_finalize($parent_form_section, $name);
175
+		$this->_set_default_name_if_empty();
176
+		$this->_set_default_html_id_if_empty();
177
+		foreach ($this->_subsections as $subsection_name => $subsection) {
178
+			if ($subsection instanceof EE_Form_Section_Base) {
179
+				$subsection->_construct_finalize($this, $subsection_name);
180
+			} else {
181
+				throw new EE_Error(
182
+					sprintf(
183
+						esc_html__(
184
+							'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
+							'event_espresso'
186
+						),
187
+						$subsection_name,
188
+						get_class($this),
189
+						$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
+					)
191
+				);
192
+			}
193
+		}
194
+		/**
195
+		 * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
+		 * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
+		 * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
+		 * This might only happen just before displaying the form, or just before it receives form submission data.
199
+		 * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
+		 * ensured it has a name, HTML IDs, etc
201
+		 *
202
+		 * @param EE_Form_Section_Proper      $this
203
+		 * @param EE_Form_Section_Proper|null $parent_form_section
204
+		 * @param string                      $name
205
+		 */
206
+		do_action(
207
+			'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
+			$this,
209
+			$parent_form_section,
210
+			$name
211
+		);
212
+	}
213
+
214
+
215
+	/**
216
+	 * Gets the layout strategy for this form section
217
+	 *
218
+	 * @return EE_Form_Section_Layout_Base
219
+	 */
220
+	public function get_layout_strategy()
221
+	{
222
+		return $this->_layout_strategy;
223
+	}
224
+
225
+
226
+	/**
227
+	 * Gets the HTML for a single input for this form section according
228
+	 * to the layout strategy
229
+	 *
230
+	 * @param EE_Form_Input_Base $input
231
+	 * @return string
232
+	 */
233
+	public function get_html_for_input($input)
234
+	{
235
+		return $this->_layout_strategy->layout_input($input);
236
+	}
237
+
238
+
239
+	/**
240
+	 * was_submitted - checks if form inputs are present in request data
241
+	 * Basically an alias for form_data_present_in() (which is used by both
242
+	 * proper form sections and form inputs)
243
+	 *
244
+	 * @param null $form_data
245
+	 * @return boolean
246
+	 * @throws EE_Error
247
+	 */
248
+	public function was_submitted($form_data = null)
249
+	{
250
+		return $this->form_data_present_in($form_data);
251
+	}
252
+
253
+	/**
254
+	 * Gets the cached request data; but if there is none, or $req_data was set with
255
+	 * something different, refresh the cache, and then return it
256
+	 * @param null $req_data
257
+	 * @return array
258
+	 */
259
+	protected function getCachedRequest($req_data = null)
260
+	{
261
+		if ($this->cached_request_data === null
262
+			|| (
263
+				$req_data !== null &&
264
+				$req_data !== $this->cached_request_data
265
+			)
266
+		) {
267
+			$req_data = apply_filters(
268
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
+				$req_data,
270
+				$this
271
+			);
272
+			if ($req_data === null) {
273
+				$req_data = array_merge($_GET, $_POST);
274
+			}
275
+			$req_data = apply_filters(
276
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
+				$req_data,
278
+				$this
279
+			);
280
+			$this->cached_request_data = (array) $req_data;
281
+		}
282
+		return $this->cached_request_data;
283
+	}
284
+
285
+
286
+	/**
287
+	 * After the form section is initially created, call this to sanitize the data in the submission
288
+	 * which relates to this form section, validate it, and set it as properties on the form.
289
+	 *
290
+	 * @param array|null $req_data should usually be $_POST (the default).
291
+	 *                             However, you CAN supply a different array.
292
+	 *                             Consider using set_defaults() instead however.
293
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
294
+	 *                             the inputs will have the correct name in the request data for this function
295
+	 *                             to find them and populate the form with them.
296
+	 *                             If you have a flat form (with only input subsections),
297
+	 *                             you can supply a flat array where keys
298
+	 *                             are the form input names and values are their values)
299
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
+	 *                             of course, to validate that data, and set errors on the invalid values.
301
+	 *                             But if the data has already been validated
302
+	 *                             (eg you validated the data then stored it in the DB)
303
+	 *                             you may want to skip this step.
304
+	 * @throws InvalidArgumentException
305
+	 * @throws InvalidInterfaceException
306
+	 * @throws InvalidDataTypeException
307
+	 * @throws EE_Error
308
+	 */
309
+	public function receive_form_submission($req_data = null, $validate = true)
310
+	{
311
+		$req_data = $this->getCachedRequest($req_data);
312
+		$this->_normalize($req_data);
313
+		if ($validate) {
314
+			$this->_validate();
315
+			// if it's invalid, we're going to want to re-display so remember what they submitted
316
+			if (! $this->is_valid()) {
317
+				$this->store_submitted_form_data_in_session();
318
+			}
319
+		}
320
+		if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
+			$this->set_submission_error_message();
322
+		}
323
+		do_action(
324
+			'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
+			$req_data,
326
+			$this,
327
+			$validate
328
+		);
329
+	}
330
+
331
+
332
+	/**
333
+	 * caches the originally submitted input values in the session
334
+	 * so that they can be used to repopulate the form if it failed validation
335
+	 *
336
+	 * @return boolean whether or not the data was successfully stored in the session
337
+	 * @throws InvalidArgumentException
338
+	 * @throws InvalidInterfaceException
339
+	 * @throws InvalidDataTypeException
340
+	 * @throws EE_Error
341
+	 */
342
+	protected function store_submitted_form_data_in_session()
343
+	{
344
+		return EE_Registry::instance()->SSN->set_session_data(
345
+			array(
346
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
+			)
348
+		);
349
+	}
350
+
351
+
352
+	/**
353
+	 * retrieves the originally submitted input values in the session
354
+	 * so that they can be used to repopulate the form if it failed validation
355
+	 *
356
+	 * @return array
357
+	 * @throws InvalidArgumentException
358
+	 * @throws InvalidInterfaceException
359
+	 * @throws InvalidDataTypeException
360
+	 */
361
+	protected function get_submitted_form_data_from_session()
362
+	{
363
+		$session = EE_Registry::instance()->SSN;
364
+		if ($session instanceof EE_Session) {
365
+			return $session->get_session_data(
366
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
+			);
368
+		}
369
+		return array();
370
+	}
371
+
372
+
373
+	/**
374
+	 * flushed the originally submitted input values from the session
375
+	 *
376
+	 * @return boolean whether or not the data was successfully removed from the session
377
+	 * @throws InvalidArgumentException
378
+	 * @throws InvalidInterfaceException
379
+	 * @throws InvalidDataTypeException
380
+	 */
381
+	public static function flush_submitted_form_data_from_session()
382
+	{
383
+		return EE_Registry::instance()->SSN->reset_data(
384
+			array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
+		);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Populates this form and its subsections with data from the session.
391
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
+	 * validation errors when displaying too)
393
+	 * Returns true if the form was populated from the session, false otherwise
394
+	 *
395
+	 * @return boolean
396
+	 * @throws InvalidArgumentException
397
+	 * @throws InvalidInterfaceException
398
+	 * @throws InvalidDataTypeException
399
+	 * @throws EE_Error
400
+	 */
401
+	public function populate_from_session()
402
+	{
403
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
404
+		if (empty($form_data_in_session)) {
405
+			return false;
406
+		}
407
+		$this->receive_form_submission($form_data_in_session);
408
+		add_action('shutdown', array('EE_Form_Section_Proper', 'flush_submitted_form_data_from_session'));
409
+		if ($this->form_data_present_in($form_data_in_session)) {
410
+			return true;
411
+		}
412
+		return false;
413
+	}
414
+
415
+
416
+	/**
417
+	 * Populates the default data for the form, given an array where keys are
418
+	 * the input names, and values are their values (preferably normalized to be their
419
+	 * proper PHP types, not all strings... although that should be ok too).
420
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
421
+	 * the value being an array formatted in teh same way
422
+	 *
423
+	 * @param array $default_data
424
+	 * @throws EE_Error
425
+	 */
426
+	public function populate_defaults($default_data)
427
+	{
428
+		foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
+			if (isset($default_data[ $subsection_name ])) {
430
+				if ($subsection instanceof EE_Form_Input_Base) {
431
+					$subsection->set_default($default_data[ $subsection_name ]);
432
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
433
+					$subsection->populate_defaults($default_data[ $subsection_name ]);
434
+				}
435
+			}
436
+		}
437
+	}
438
+
439
+
440
+	/**
441
+	 * returns true if subsection exists
442
+	 *
443
+	 * @param string $name
444
+	 * @return boolean
445
+	 */
446
+	public function subsection_exists($name)
447
+	{
448
+		return isset($this->_subsections[ $name ]) ? true : false;
449
+	}
450
+
451
+
452
+	/**
453
+	 * Gets the subsection specified by its name
454
+	 *
455
+	 * @param string  $name
456
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
+	 *                                                      so that the inputs will be properly configured.
458
+	 *                                                      However, some client code may be ok
459
+	 *                                                      with construction finalize being called later
460
+	 *                                                      (realizing that the subsections' html names
461
+	 *                                                      might not be set yet, etc.)
462
+	 * @return EE_Form_Section_Base
463
+	 * @throws EE_Error
464
+	 */
465
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
466
+	{
467
+		if ($require_construction_to_be_finalized) {
468
+			$this->ensure_construct_finalized_called();
469
+		}
470
+		return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
+	}
472
+
473
+
474
+	/**
475
+	 * Gets all the validatable subsections of this form section
476
+	 *
477
+	 * @return EE_Form_Section_Validatable[]
478
+	 * @throws EE_Error
479
+	 */
480
+	public function get_validatable_subsections()
481
+	{
482
+		$validatable_subsections = array();
483
+		foreach ($this->subsections() as $name => $obj) {
484
+			if ($obj instanceof EE_Form_Section_Validatable) {
485
+				$validatable_subsections[ $name ] = $obj;
486
+			}
487
+		}
488
+		return $validatable_subsections;
489
+	}
490
+
491
+
492
+	/**
493
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
+	 * throw an EE_Error.
495
+	 *
496
+	 * @param string  $name
497
+	 * @param boolean $require_construction_to_be_finalized most client code should
498
+	 *                                                      leave this as TRUE so that the inputs will be properly
499
+	 *                                                      configured. However, some client code may be ok with
500
+	 *                                                      construction finalize being called later
501
+	 *                                                      (realizing that the subsections' html names might not be
502
+	 *                                                      set yet, etc.)
503
+	 * @return EE_Form_Input_Base
504
+	 * @throws EE_Error
505
+	 */
506
+	public function get_input($name, $require_construction_to_be_finalized = true)
507
+	{
508
+		$subsection = $this->get_subsection(
509
+			$name,
510
+			$require_construction_to_be_finalized
511
+		);
512
+		if (! $subsection instanceof EE_Form_Input_Base) {
513
+			throw new EE_Error(
514
+				sprintf(
515
+					esc_html__(
516
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
+						'event_espresso'
518
+					),
519
+					$name,
520
+					get_class($this),
521
+					$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
+				)
523
+			);
524
+		}
525
+		return $subsection;
526
+	}
527
+
528
+
529
+	/**
530
+	 * Like get_input(), gets the proper subsection of the form given the name,
531
+	 * otherwise throws an EE_Error
532
+	 *
533
+	 * @param string  $name
534
+	 * @param boolean $require_construction_to_be_finalized most client code should
535
+	 *                                                      leave this as TRUE so that the inputs will be properly
536
+	 *                                                      configured. However, some client code may be ok with
537
+	 *                                                      construction finalize being called later
538
+	 *                                                      (realizing that the subsections' html names might not be
539
+	 *                                                      set yet, etc.)
540
+	 * @return EE_Form_Section_Proper
541
+	 * @throws EE_Error
542
+	 */
543
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
+	{
545
+		$subsection = $this->get_subsection(
546
+			$name,
547
+			$require_construction_to_be_finalized
548
+		);
549
+		if (! $subsection instanceof EE_Form_Section_Proper) {
550
+			throw new EE_Error(
551
+				sprintf(
552
+					esc_html__(
553
+						"Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
+						'event_espresso'
555
+					),
556
+					$name,
557
+					get_class($this)
558
+				)
559
+			);
560
+		}
561
+		return $subsection;
562
+	}
563
+
564
+
565
+	/**
566
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
567
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
568
+	 *
569
+	 * @param string $name
570
+	 * @return mixed depending on the input's type and its normalization strategy
571
+	 * @throws EE_Error
572
+	 */
573
+	public function get_input_value($name)
574
+	{
575
+		$input = $this->get_input($name);
576
+		return $input->normalized_value();
577
+	}
578
+
579
+
580
+	/**
581
+	 * Checks if this form section itself is valid, and then checks its subsections
582
+	 *
583
+	 * @throws EE_Error
584
+	 * @return boolean
585
+	 */
586
+	public function is_valid()
587
+	{
588
+		if ($this->is_valid === null) {
589
+			if (! $this->has_received_submission()) {
590
+				throw new EE_Error(
591
+					sprintf(
592
+						esc_html__(
593
+							'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
+							'event_espresso'
595
+						)
596
+					)
597
+				);
598
+			}
599
+			if (! parent::is_valid()) {
600
+				$this->is_valid = false;
601
+			} else {
602
+				// ok so no general errors to this entire form section.
603
+				// so let's check the subsections, but only set errors if that hasn't been done yet
604
+				$this->is_valid = true;
605
+				foreach ($this->get_validatable_subsections() as $subsection) {
606
+					if (! $subsection->is_valid()) {
607
+						$this->is_valid = false;
608
+					}
609
+				}
610
+			}
611
+		}
612
+		return $this->is_valid;
613
+	}
614
+
615
+
616
+	/**
617
+	 * gets the default name of this form section if none is specified
618
+	 *
619
+	 * @return void
620
+	 */
621
+	protected function _set_default_name_if_empty()
622
+	{
623
+		if (! $this->_name) {
624
+			$classname    = get_class($this);
625
+			$default_name = str_replace('EE_', '', $classname);
626
+			$this->_name  = $default_name;
627
+		}
628
+	}
629
+
630
+
631
+	/**
632
+	 * Returns the HTML for the form, except for the form opening and closing tags
633
+	 * (as the form section doesn't know where you necessarily want to send the information to),
634
+	 * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
637
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
+	 * any CSS.
639
+	 *
640
+	 * @throws InvalidArgumentException
641
+	 * @throws InvalidInterfaceException
642
+	 * @throws InvalidDataTypeException
643
+	 * @throws EE_Error
644
+	 */
645
+	public function get_html_and_js()
646
+	{
647
+		$this->enqueue_js();
648
+		return $this->get_html();
649
+	}
650
+
651
+
652
+	/**
653
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
+	 *
655
+	 * @param bool $display_previously_submitted_data
656
+	 * @return string
657
+	 * @throws InvalidArgumentException
658
+	 * @throws InvalidInterfaceException
659
+	 * @throws InvalidDataTypeException
660
+	 * @throws EE_Error
661
+	 * @throws EE_Error
662
+	 * @throws EE_Error
663
+	 */
664
+	public function get_html($display_previously_submitted_data = true)
665
+	{
666
+		$this->ensure_construct_finalized_called();
667
+		if ($display_previously_submitted_data) {
668
+			$this->populate_from_session();
669
+		}
670
+		return $this->_form_html_filter
671
+			? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
+			: $this->_layout_strategy->layout_form();
673
+	}
674
+
675
+
676
+	/**
677
+	 * enqueues JS and CSS for the form.
678
+	 * It is preferred to call this before wp_enqueue_scripts so the
679
+	 * scripts and styles can be put in the header, but if called later
680
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
+	 * only be in the header; but in HTML5 its ok in the body.
682
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
+	 *
685
+	 * @return void
686
+	 * @throws EE_Error
687
+	 */
688
+	public function enqueue_js()
689
+	{
690
+		$this->_enqueue_and_localize_form_js();
691
+		foreach ($this->subsections() as $subsection) {
692
+			$subsection->enqueue_js();
693
+		}
694
+	}
695
+
696
+
697
+	/**
698
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
+	 * the wp_enqueue_scripts hook.
701
+	 * However, registering the form js and localizing it can happen when we
702
+	 * actually output the form (which is preferred, seeing how teh form's fields
703
+	 * could change until it's actually outputted)
704
+	 *
705
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
+	 *                                                    to be triggered automatically or not
707
+	 * @return void
708
+	 */
709
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
+	{
711
+		wp_register_script(
712
+			'ee_form_section_validation',
713
+			EE_GLOBAL_ASSETS_URL . 'scripts' . '/form_section_validation.js',
714
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
+			EVENT_ESPRESSO_VERSION,
716
+			true
717
+		);
718
+		wp_localize_script(
719
+			'ee_form_section_validation',
720
+			'ee_form_section_validation_init',
721
+			array('init' => $init_form_validation_automatically ? '1' : '0')
722
+		);
723
+	}
724
+
725
+
726
+	/**
727
+	 * gets the variables used by form_section_validation.js.
728
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
+	 * but before the wordpress hook wp_loaded
730
+	 *
731
+	 * @throws EE_Error
732
+	 */
733
+	public function _enqueue_and_localize_form_js()
734
+	{
735
+		$this->ensure_construct_finalized_called();
736
+		// actually, we don't want to localize just yet. There may be other forms on the page.
737
+		// so we need to add our form section data to a static variable accessible by all form sections
738
+		// and localize it just before the footer
739
+		$this->localize_validation_rules();
740
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
+	}
743
+
744
+
745
+	/**
746
+	 * add our form section data to a static variable accessible by all form sections
747
+	 *
748
+	 * @param bool $return_for_subsection
749
+	 * @return void
750
+	 * @throws EE_Error
751
+	 */
752
+	public function localize_validation_rules($return_for_subsection = false)
753
+	{
754
+		// we only want to localize vars ONCE for the entire form,
755
+		// so if the form section doesn't have a parent, then it must be the top dog
756
+		if ($return_for_subsection || ! $this->parent_section()) {
757
+			EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
+				'form_section_id'  => $this->html_id(true),
759
+				'validation_rules' => $this->get_jquery_validation_rules(),
760
+				'other_data'       => $this->get_other_js_data(),
761
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
762
+			);
763
+			EE_Form_Section_Proper::$_scripts_localized                                = true;
764
+		}
765
+	}
766
+
767
+
768
+	/**
769
+	 * Gets an array of extra data that will be useful for client-side javascript.
770
+	 * This is primarily data added by inputs and forms in addition to any
771
+	 * scripts they might enqueue
772
+	 *
773
+	 * @param array $form_other_js_data
774
+	 * @return array
775
+	 * @throws EE_Error
776
+	 */
777
+	public function get_other_js_data($form_other_js_data = array())
778
+	{
779
+		foreach ($this->subsections() as $subsection) {
780
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
+		}
782
+		return $form_other_js_data;
783
+	}
784
+
785
+
786
+	/**
787
+	 * Gets a flat array of inputs for this form section and its subsections.
788
+	 * Keys are their form names, and values are the inputs themselves
789
+	 *
790
+	 * @return EE_Form_Input_Base
791
+	 * @throws EE_Error
792
+	 */
793
+	public function inputs_in_subsections()
794
+	{
795
+		$inputs = array();
796
+		foreach ($this->subsections() as $subsection) {
797
+			if ($subsection instanceof EE_Form_Input_Base) {
798
+				$inputs[ $subsection->html_name() ] = $subsection;
799
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
800
+				$inputs += $subsection->inputs_in_subsections();
801
+			}
802
+		}
803
+		return $inputs;
804
+	}
805
+
806
+
807
+	/**
808
+	 * Gets a flat array of all the validation errors.
809
+	 * Keys are html names (because those should be unique)
810
+	 * and values are a string of all their validation errors
811
+	 *
812
+	 * @return string[]
813
+	 * @throws EE_Error
814
+	 */
815
+	public function subsection_validation_errors_by_html_name()
816
+	{
817
+		$inputs = $this->inputs();
818
+		$errors = array();
819
+		foreach ($inputs as $form_input) {
820
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
+				$errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
+			}
823
+		}
824
+		return $errors;
825
+	}
826
+
827
+
828
+	/**
829
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
831
+	 *
832
+	 * @throws InvalidArgumentException
833
+	 * @throws InvalidInterfaceException
834
+	 * @throws InvalidDataTypeException
835
+	 */
836
+	public static function localize_script_for_all_forms()
837
+	{
838
+		// allow inputs and stuff to hook in their JS and stuff here
839
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
+			? EE_Registry::instance()->CFG->registration->email_validation_level
843
+			: 'wp_default';
844
+		EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
+		wp_enqueue_script('ee_form_section_validation');
846
+		wp_localize_script(
847
+			'ee_form_section_validation',
848
+			'ee_form_section_vars',
849
+			EE_Form_Section_Proper::$_js_localization
850
+		);
851
+	}
852
+
853
+
854
+	/**
855
+	 * ensure_scripts_localized
856
+	 *
857
+	 * @throws EE_Error
858
+	 */
859
+	public function ensure_scripts_localized()
860
+	{
861
+		if (! EE_Form_Section_Proper::$_scripts_localized) {
862
+			$this->_enqueue_and_localize_form_js();
863
+		}
864
+	}
865
+
866
+
867
+	/**
868
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
869
+	 * is that the key here should be the same as the custom validation rule put in the JS file
870
+	 *
871
+	 * @return array keys are custom validation rules, and values are internationalized strings
872
+	 */
873
+	private static function _get_localized_error_messages()
874
+	{
875
+		return array(
876
+			'validUrl' => wp_strip_all_tags(__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso')),
877
+			'regex'    => wp_strip_all_tags(__('Please check your input', 'event_espresso'))
878
+		);
879
+	}
880
+
881
+
882
+	/**
883
+	 * @return array
884
+	 */
885
+	public static function js_localization()
886
+	{
887
+		return self::$_js_localization;
888
+	}
889
+
890
+
891
+	/**
892
+	 * @return void
893
+	 */
894
+	public static function reset_js_localization()
895
+	{
896
+		self::$_js_localization = array();
897
+	}
898
+
899
+
900
+	/**
901
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
+	 * See parent function for more...
903
+	 *
904
+	 * @return array
905
+	 * @throws EE_Error
906
+	 */
907
+	public function get_jquery_validation_rules()
908
+	{
909
+		$jquery_validation_rules = array();
910
+		foreach ($this->get_validatable_subsections() as $subsection) {
911
+			$jquery_validation_rules = array_merge(
912
+				$jquery_validation_rules,
913
+				$subsection->get_jquery_validation_rules()
914
+			);
915
+		}
916
+		return $jquery_validation_rules;
917
+	}
918
+
919
+
920
+	/**
921
+	 * Sanitizes all the data and sets the sanitized value of each field
922
+	 *
923
+	 * @param array $req_data like $_POST
924
+	 * @return void
925
+	 * @throws EE_Error
926
+	 */
927
+	protected function _normalize($req_data)
928
+	{
929
+		$this->_received_submission = true;
930
+		$this->_validation_errors   = array();
931
+		foreach ($this->get_validatable_subsections() as $subsection) {
932
+			try {
933
+				$subsection->_normalize($req_data);
934
+			} catch (EE_Validation_Error $e) {
935
+				$subsection->add_validation_error($e);
936
+			}
937
+		}
938
+	}
939
+
940
+
941
+	/**
942
+	 * Performs validation on this form section and its subsections.
943
+	 * For each subsection,
944
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
945
+	 * and passes it the subsection, then calls _validate on that subsection.
946
+	 * If you need to perform validation on the form as a whole (considering multiple)
947
+	 * you would be best to override this _validate method,
948
+	 * calling parent::_validate() first.
949
+	 *
950
+	 * @throws EE_Error
951
+	 */
952
+	protected function _validate()
953
+	{
954
+		// reset the cache of whether this form is valid or not- we're re-validating it now
955
+		$this->is_valid = null;
956
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
+			if (method_exists($this, '_validate_' . $subsection_name)) {
958
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
+			}
960
+			$subsection->_validate();
961
+		}
962
+	}
963
+
964
+
965
+	/**
966
+	 * Gets all the validated inputs for the form section
967
+	 *
968
+	 * @return array
969
+	 * @throws EE_Error
970
+	 */
971
+	public function valid_data()
972
+	{
973
+		$inputs = array();
974
+		foreach ($this->subsections() as $subsection_name => $subsection) {
975
+			if ($subsection instanceof EE_Form_Section_Proper) {
976
+				$inputs[ $subsection_name ] = $subsection->valid_data();
977
+			} elseif ($subsection instanceof EE_Form_Input_Base) {
978
+				$inputs[ $subsection_name ] = $subsection->normalized_value();
979
+			}
980
+		}
981
+		return $inputs;
982
+	}
983
+
984
+
985
+	/**
986
+	 * Gets all the inputs on this form section
987
+	 *
988
+	 * @return EE_Form_Input_Base[]
989
+	 * @throws EE_Error
990
+	 */
991
+	public function inputs()
992
+	{
993
+		$inputs = array();
994
+		foreach ($this->subsections() as $subsection_name => $subsection) {
995
+			if ($subsection instanceof EE_Form_Input_Base) {
996
+				$inputs[ $subsection_name ] = $subsection;
997
+			}
998
+		}
999
+		return $inputs;
1000
+	}
1001
+
1002
+
1003
+	/**
1004
+	 * Gets all the subsections which are a proper form
1005
+	 *
1006
+	 * @return EE_Form_Section_Proper[]
1007
+	 * @throws EE_Error
1008
+	 */
1009
+	public function subforms()
1010
+	{
1011
+		$form_sections = array();
1012
+		foreach ($this->subsections() as $name => $obj) {
1013
+			if ($obj instanceof EE_Form_Section_Proper) {
1014
+				$form_sections[ $name ] = $obj;
1015
+			}
1016
+		}
1017
+		return $form_sections;
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
+	 * Consider using inputs() or subforms()
1024
+	 * if you only want form inputs or proper form sections.
1025
+	 *
1026
+	 * @param boolean $require_construction_to_be_finalized most client code should
1027
+	 *                                                      leave this as TRUE so that the inputs will be properly
1028
+	 *                                                      configured. However, some client code may be ok with
1029
+	 *                                                      construction finalize being called later
1030
+	 *                                                      (realizing that the subsections' html names might not be
1031
+	 *                                                      set yet, etc.)
1032
+	 * @return EE_Form_Section_Proper[]
1033
+	 * @throws EE_Error
1034
+	 */
1035
+	public function subsections($require_construction_to_be_finalized = true)
1036
+	{
1037
+		if ($require_construction_to_be_finalized) {
1038
+			$this->ensure_construct_finalized_called();
1039
+		}
1040
+		return $this->_subsections;
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 * Returns whether this form has any subforms or inputs
1046
+	 * @return bool
1047
+	 */
1048
+	public function hasSubsections()
1049
+	{
1050
+		return ! empty($this->_subsections);
1051
+	}
1052
+
1053
+
1054
+	/**
1055
+	 * Returns a simple array where keys are input names, and values are their normalized
1056
+	 * values. (Similar to calling get_input_value on inputs)
1057
+	 *
1058
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
+	 *                                        or just this forms' direct children inputs
1060
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
+	 *                                        or allow multidimensional array
1062
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
+	 *                                        with array keys being input names
1064
+	 *                                        (regardless of whether they are from a subsection or not),
1065
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1066
+	 *                                        where keys are always subsection names and values are either
1067
+	 *                                        the input's normalized value, or an array like the top-level array
1068
+	 * @throws EE_Error
1069
+	 */
1070
+	public function input_values($include_subform_inputs = false, $flatten = false)
1071
+	{
1072
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
+	}
1074
+
1075
+
1076
+	/**
1077
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
+	 * is not necessarily the value we want to display to users. This creates an array
1080
+	 * where keys are the input names, and values are their display values
1081
+	 *
1082
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
+	 *                                        or just this forms' direct children inputs
1084
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
+	 *                                        or allow multidimensional array
1086
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
+	 *                                        with array keys being input names
1088
+	 *                                        (regardless of whether they are from a subsection or not),
1089
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1090
+	 *                                        where keys are always subsection names and values are either
1091
+	 *                                        the input's normalized value, or an array like the top-level array
1092
+	 * @throws EE_Error
1093
+	 */
1094
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
+	{
1096
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
+	}
1098
+
1099
+
1100
+	/**
1101
+	 * Gets the input values from the form
1102
+	 *
1103
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
+	 *                                        or just the normalized value
1105
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
+	 *                                        or just this forms' direct children inputs
1107
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
+	 *                                        or allow multidimensional array
1109
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
+	 *                                        input names (regardless of whether they are from a subsection or not),
1111
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1112
+	 *                                        where keys are always subsection names and values are either
1113
+	 *                                        the input's normalized value, or an array like the top-level array
1114
+	 * @throws EE_Error
1115
+	 */
1116
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
+	{
1118
+		$input_values = array();
1119
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1120
+			if ($subsection instanceof EE_Form_Input_Base) {
1121
+				$input_values[ $subsection_name ] = $pretty
1122
+					? $subsection->pretty_value()
1123
+					: $subsection->normalized_value();
1124
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
+				$subform_input_values = $subsection->_input_values(
1126
+					$pretty,
1127
+					$include_subform_inputs,
1128
+					$flatten
1129
+				);
1130
+				if ($flatten) {
1131
+					$input_values = array_merge($input_values, $subform_input_values);
1132
+				} else {
1133
+					$input_values[ $subsection_name ] = $subform_input_values;
1134
+				}
1135
+			}
1136
+		}
1137
+		return $input_values;
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * Gets the originally submitted input values from the form
1143
+	 *
1144
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
+	 *                                   or just this forms' direct children inputs
1146
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
+	 *                                   with array keys being input names
1148
+	 *                                   (regardless of whether they are from a subsection or not),
1149
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1150
+	 *                                   where keys are always subsection names and values are either
1151
+	 *                                   the input's normalized value, or an array like the top-level array
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	public function submitted_values($include_subforms = false)
1155
+	{
1156
+		$submitted_values = array();
1157
+		foreach ($this->subsections() as $subsection) {
1158
+			if ($subsection instanceof EE_Form_Input_Base) {
1159
+				// is this input part of an array of inputs?
1160
+				if (strpos($subsection->html_name(), '[') !== false) {
1161
+					$full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
+						explode(
1163
+							'[',
1164
+							str_replace(']', '', $subsection->html_name())
1165
+						),
1166
+						$subsection->raw_value()
1167
+					);
1168
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
+				} else {
1170
+					$submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
+				}
1172
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1174
+				$submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
+			}
1176
+		}
1177
+		return $submitted_values;
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * Indicates whether or not this form has received a submission yet
1183
+	 * (ie, had receive_form_submission called on it yet)
1184
+	 *
1185
+	 * @return boolean
1186
+	 * @throws EE_Error
1187
+	 */
1188
+	public function has_received_submission()
1189
+	{
1190
+		$this->ensure_construct_finalized_called();
1191
+		return $this->_received_submission;
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1197
+	 * Removes the listed inputs from the form
1198
+	 *
1199
+	 * @param array $inputs_to_exclude values are the input names
1200
+	 * @return void
1201
+	 */
1202
+	public function exclude(array $inputs_to_exclude = array())
1203
+	{
1204
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
+			unset($this->_subsections[ $input_to_exclude_name ]);
1206
+		}
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1212
+	 * @param array $inputs_to_hide
1213
+	 * @throws EE_Error
1214
+	 */
1215
+	public function hide(array $inputs_to_hide = array())
1216
+	{
1217
+		foreach ($inputs_to_hide as $input_to_hide) {
1218
+			$input = $this->get_input($input_to_hide);
1219
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1220
+		}
1221
+	}
1222
+
1223
+
1224
+	/**
1225
+	 * add_subsections
1226
+	 * Adds the listed subsections to the form section.
1227
+	 * If $subsection_name_to_target is provided,
1228
+	 * then new subsections are added before or after that subsection,
1229
+	 * otherwise to the start or end of the entire subsections array.
1230
+	 *
1231
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1232
+	 *                                                          where keys are their names
1233
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1234
+	 *                                                          should be added before or after
1235
+	 *                                                          IF $subsection_name_to_target is null,
1236
+	 *                                                          then $new_subsections will be added to
1237
+	 *                                                          the beginning or end of the entire subsections array
1238
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1239
+	 *                                                          $subsection_name_to_target,
1240
+	 *                                                          or if $subsection_name_to_target is null,
1241
+	 *                                                          before or after entire subsections array
1242
+	 * @return void
1243
+	 * @throws EE_Error
1244
+	 */
1245
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1246
+	{
1247
+		foreach ($new_subsections as $subsection_name => $subsection) {
1248
+			if (! $subsection instanceof EE_Form_Section_Base) {
1249
+				EE_Error::add_error(
1250
+					sprintf(
1251
+						esc_html__(
1252
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1253
+							'event_espresso'
1254
+						),
1255
+						get_class($subsection),
1256
+						$subsection_name,
1257
+						$this->name()
1258
+					)
1259
+				);
1260
+				unset($new_subsections[ $subsection_name ]);
1261
+			}
1262
+		}
1263
+		$this->_subsections = EEH_Array::insert_into_array(
1264
+			$this->_subsections,
1265
+			$new_subsections,
1266
+			$subsection_name_to_target,
1267
+			$add_before
1268
+		);
1269
+		if ($this->_construction_finalized) {
1270
+			foreach ($this->_subsections as $name => $subsection) {
1271
+				$subsection->_construct_finalize($this, $name);
1272
+			}
1273
+		}
1274
+	}
1275
+
1276
+
1277
+	/**
1278
+	 * @param string $subsection_name
1279
+	 * @param bool   $recursive
1280
+	 * @return bool
1281
+	 */
1282
+	public function has_subsection($subsection_name, $recursive = false)
1283
+	{
1284
+		foreach ($this->_subsections as $name => $subsection) {
1285
+			if ($name === $subsection_name
1286
+				|| (
1287
+					$recursive
1288
+					&& $subsection instanceof EE_Form_Section_Proper
1289
+					&& $subsection->has_subsection($subsection_name, $recursive)
1290
+				)
1291
+			) {
1292
+				return true;
1293
+			}
1294
+		}
1295
+		return false;
1296
+	}
1297
+
1298
+
1299
+
1300
+	/**
1301
+	 * Just gets all validatable subsections to clean their sensitive data
1302
+	 *
1303
+	 * @throws EE_Error
1304
+	 */
1305
+	public function clean_sensitive_data()
1306
+	{
1307
+		foreach ($this->get_validatable_subsections() as $subsection) {
1308
+			$subsection->clean_sensitive_data();
1309
+		}
1310
+	}
1311
+
1312
+
1313
+	/**
1314
+	 * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1315
+	 * @param string                           $form_submission_error_message
1316
+	 * @param EE_Form_Section_Validatable $form_section unused
1317
+	 * @throws EE_Error
1318
+	 */
1319
+	public function set_submission_error_message(
1320
+		$form_submission_error_message = ''
1321
+	) {
1322
+		$this->_form_submission_error_message = ! empty($form_submission_error_message)
1323
+			? $form_submission_error_message
1324
+			: $this->getAllValidationErrorsString();
1325
+	}
1326
+
1327
+
1328
+	/**
1329
+	 * Returns the cached error message. A default value is set for this during _validate(),
1330
+	 * (called during receive_form_submission) but it can be explicitly set using
1331
+	 * set_submission_error_message
1332
+	 *
1333
+	 * @return string
1334
+	 */
1335
+	public function submission_error_message()
1336
+	{
1337
+		return $this->_form_submission_error_message;
1338
+	}
1339
+
1340
+
1341
+	/**
1342
+	 * Sets a message to display if the data submitted to the form was valid.
1343
+	 * @param string $form_submission_success_message
1344
+	 */
1345
+	public function set_submission_success_message($form_submission_success_message = '')
1346
+	{
1347
+		$this->_form_submission_success_message = ! empty($form_submission_success_message)
1348
+			? $form_submission_success_message
1349
+			: esc_html__('Form submitted successfully', 'event_espresso');
1350
+	}
1351
+
1352
+
1353
+	/**
1354
+	 * Gets a message appropriate for display when the form is correctly submitted
1355
+	 * @return string
1356
+	 */
1357
+	public function submission_success_message()
1358
+	{
1359
+		return $this->_form_submission_success_message;
1360
+	}
1361
+
1362
+
1363
+	/**
1364
+	 * Returns the prefix that should be used on child of this form section for
1365
+	 * their html names. If this form section itself has a parent, prepends ITS
1366
+	 * prefix onto this form section's prefix. Used primarily by
1367
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1368
+	 *
1369
+	 * @return string
1370
+	 * @throws EE_Error
1371
+	 */
1372
+	public function html_name_prefix()
1373
+	{
1374
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1375
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1376
+		}
1377
+		return $this->name();
1378
+	}
1379
+
1380
+
1381
+	/**
1382
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1383
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1384
+	 * was set, which is probably nothing, or the classname)
1385
+	 *
1386
+	 * @return string
1387
+	 * @throws EE_Error
1388
+	 */
1389
+	public function name()
1390
+	{
1391
+		$this->ensure_construct_finalized_called();
1392
+		return parent::name();
1393
+	}
1394
+
1395
+
1396
+	/**
1397
+	 * @return EE_Form_Section_Proper
1398
+	 * @throws EE_Error
1399
+	 */
1400
+	public function parent_section()
1401
+	{
1402
+		$this->ensure_construct_finalized_called();
1403
+		return parent::parent_section();
1404
+	}
1405
+
1406
+
1407
+	/**
1408
+	 * make sure construction finalized was called, otherwise children might not be ready
1409
+	 *
1410
+	 * @return void
1411
+	 * @throws EE_Error
1412
+	 */
1413
+	public function ensure_construct_finalized_called()
1414
+	{
1415
+		if (! $this->_construction_finalized) {
1416
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1417
+		}
1418
+	}
1419
+
1420
+
1421
+	/**
1422
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1423
+	 * are in teh form data. If any are found, returns true. Else false
1424
+	 *
1425
+	 * @param array $req_data
1426
+	 * @return boolean
1427
+	 * @throws EE_Error
1428
+	 */
1429
+	public function form_data_present_in($req_data = null)
1430
+	{
1431
+		$req_data = $this->getCachedRequest($req_data);
1432
+		foreach ($this->subsections() as $subsection) {
1433
+			if ($subsection instanceof EE_Form_Input_Base) {
1434
+				if ($subsection->form_data_present_in($req_data)) {
1435
+					return true;
1436
+				}
1437
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1438
+				if ($subsection->form_data_present_in($req_data)) {
1439
+					return true;
1440
+				}
1441
+			}
1442
+		}
1443
+		return false;
1444
+	}
1445
+
1446
+
1447
+	/**
1448
+	 * Gets validation errors for this form section and subsections
1449
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1450
+	 * gets the validation errors for ALL subsection
1451
+	 *
1452
+	 * @return EE_Validation_Error[]
1453
+	 * @throws EE_Error
1454
+	 */
1455
+	public function get_validation_errors_accumulated()
1456
+	{
1457
+		$validation_errors = $this->get_validation_errors();
1458
+		foreach ($this->get_validatable_subsections() as $subsection) {
1459
+			if ($subsection instanceof EE_Form_Section_Proper) {
1460
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1461
+			} else {
1462
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1463
+			}
1464
+			if ($validation_errors_on_this_subsection) {
1465
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1466
+			}
1467
+		}
1468
+		return $validation_errors;
1469
+	}
1470
+
1471
+	/**
1472
+	 * Fetch validation errors from children and grandchildren and puts them in a single string.
1473
+	 * This traverses the form section tree to generate this, but you probably want to instead use
1474
+	 * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1475
+	 *
1476
+	 * @return string
1477
+	 * @since 4.9.59.p
1478
+	 */
1479
+	protected function getAllValidationErrorsString()
1480
+	{
1481
+		$submission_error_messages = array();
1482
+		// bad, bad, bad registrant
1483
+		foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1484
+			if ($validation_error instanceof EE_Validation_Error) {
1485
+				$form_section = $validation_error->get_form_section();
1486
+				if ($form_section instanceof EE_Form_Input_Base) {
1487
+					$label = $validation_error->get_form_section()->html_label_text();
1488
+				} elseif ($form_section instanceof EE_Form_Section_Validatable) {
1489
+					$label = $validation_error->get_form_section()->name();
1490
+				} else {
1491
+					$label = esc_html__('Unknown', 'event_espresso');
1492
+				}
1493
+				$submission_error_messages[] = sprintf(
1494
+					__('%s : %s', 'event_espresso'),
1495
+					$label,
1496
+					$validation_error->getMessage()
1497
+				);
1498
+			}
1499
+		}
1500
+		return implode('<br>', $submission_error_messages);
1501
+	}
1502
+
1503
+
1504
+	/**
1505
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1506
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1507
+	 * dot-dot-slash (../) means to ascend into the parent section.
1508
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1509
+	 * which will be returned.
1510
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1511
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1512
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1513
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1514
+	 * Etc
1515
+	 *
1516
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1517
+	 * @return EE_Form_Section_Base
1518
+	 * @throws EE_Error
1519
+	 */
1520
+	public function find_section_from_path($form_section_path)
1521
+	{
1522
+		// check if we can find the input from purely going straight up the tree
1523
+		$input = parent::find_section_from_path($form_section_path);
1524
+		if ($input instanceof EE_Form_Section_Base) {
1525
+			return $input;
1526
+		}
1527
+		$next_slash_pos = strpos($form_section_path, '/');
1528
+		if ($next_slash_pos !== false) {
1529
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1530
+			$subpath            = substr($form_section_path, $next_slash_pos + 1);
1531
+		} else {
1532
+			$child_section_name = $form_section_path;
1533
+			$subpath            = '';
1534
+		}
1535
+		$child_section = $this->get_subsection($child_section_name);
1536
+		if ($child_section instanceof EE_Form_Section_Base) {
1537
+			return $child_section->find_section_from_path($subpath);
1538
+		}
1539
+		return null;
1540
+	}
1541 1541
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +4061 added lines, -4061 removed lines patch added patch discarded remove patch
@@ -17,4128 +17,4128 @@
 block discarded – undo
17 17
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @var LoaderInterface $loader
22
-     */
23
-    protected $loader;
20
+	/**
21
+	 * @var LoaderInterface $loader
22
+	 */
23
+	protected $loader;
24 24
 
25
-    // set in _init_page_props()
26
-    public $page_slug;
25
+	// set in _init_page_props()
26
+	public $page_slug;
27 27
 
28
-    public $page_label;
28
+	public $page_label;
29 29
 
30
-    public $page_folder;
30
+	public $page_folder;
31 31
 
32
-    // set in define_page_props()
33
-    protected $_admin_base_url;
32
+	// set in define_page_props()
33
+	protected $_admin_base_url;
34 34
 
35
-    protected $_admin_base_path;
35
+	protected $_admin_base_path;
36 36
 
37
-    protected $_admin_page_title;
37
+	protected $_admin_page_title;
38 38
 
39
-    protected $_labels;
39
+	protected $_labels;
40 40
 
41 41
 
42
-    // set early within EE_Admin_Init
43
-    protected $_wp_page_slug;
42
+	// set early within EE_Admin_Init
43
+	protected $_wp_page_slug;
44 44
 
45
-    // navtabs
46
-    protected $_nav_tabs;
45
+	// navtabs
46
+	protected $_nav_tabs;
47 47
 
48
-    protected $_default_nav_tab_name;
48
+	protected $_default_nav_tab_name;
49 49
 
50
-    /**
51
-     * @var array $_help_tour
52
-     */
53
-    protected $_help_tour = array();
50
+	/**
51
+	 * @var array $_help_tour
52
+	 */
53
+	protected $_help_tour = array();
54 54
 
55 55
 
56
-    // template variables (used by templates)
57
-    protected $_template_path;
56
+	// template variables (used by templates)
57
+	protected $_template_path;
58 58
 
59
-    protected $_column_template_path;
59
+	protected $_column_template_path;
60 60
 
61
-    /**
62
-     * @var array $_template_args
63
-     */
64
-    protected $_template_args = array();
61
+	/**
62
+	 * @var array $_template_args
63
+	 */
64
+	protected $_template_args = array();
65 65
 
66
-    /**
67
-     * this will hold the list table object for a given view.
68
-     *
69
-     * @var EE_Admin_List_Table $_list_table_object
70
-     */
71
-    protected $_list_table_object;
66
+	/**
67
+	 * this will hold the list table object for a given view.
68
+	 *
69
+	 * @var EE_Admin_List_Table $_list_table_object
70
+	 */
71
+	protected $_list_table_object;
72 72
 
73
-    // bools
74
-    protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
73
+	// bools
74
+	protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
75 75
 
76
-    protected $_routing;
76
+	protected $_routing;
77 77
 
78
-    // list table args
79
-    protected $_view;
78
+	// list table args
79
+	protected $_view;
80 80
 
81
-    protected $_views;
81
+	protected $_views;
82 82
 
83 83
 
84
-    // action => method pairs used for routing incoming requests
85
-    protected $_page_routes;
84
+	// action => method pairs used for routing incoming requests
85
+	protected $_page_routes;
86 86
 
87
-    /**
88
-     * @var array $_page_config
89
-     */
90
-    protected $_page_config;
87
+	/**
88
+	 * @var array $_page_config
89
+	 */
90
+	protected $_page_config;
91 91
 
92
-    /**
93
-     * the current page route and route config
94
-     *
95
-     * @var string $_route
96
-     */
97
-    protected $_route;
92
+	/**
93
+	 * the current page route and route config
94
+	 *
95
+	 * @var string $_route
96
+	 */
97
+	protected $_route;
98 98
 
99
-    /**
100
-     * @var string $_cpt_route
101
-     */
102
-    protected $_cpt_route;
99
+	/**
100
+	 * @var string $_cpt_route
101
+	 */
102
+	protected $_cpt_route;
103 103
 
104
-    /**
105
-     * @var array $_route_config
106
-     */
107
-    protected $_route_config;
108
-
109
-    /**
110
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
111
-     * actions.
112
-     *
113
-     * @since 4.6.x
114
-     * @var array.
115
-     */
116
-    protected $_default_route_query_args;
117
-
118
-    // set via request page and action args.
119
-    protected $_current_page;
120
-
121
-    protected $_current_view;
122
-
123
-    protected $_current_page_view_url;
124
-
125
-    // sanitized request action (and nonce)
126
-
127
-    /**
128
-     * @var string $_req_action
129
-     */
130
-    protected $_req_action;
131
-
132
-    /**
133
-     * @var string $_req_nonce
134
-     */
135
-    protected $_req_nonce;
136
-
137
-    // search related
138
-    protected $_search_btn_label;
139
-
140
-    protected $_search_box_callback;
141
-
142
-    /**
143
-     * WP Current Screen object
144
-     *
145
-     * @var WP_Screen
146
-     */
147
-    protected $_current_screen;
148
-
149
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
150
-    protected $_hook_obj;
151
-
152
-    // for holding incoming request data
153
-    protected $_req_data = [];
154
-
155
-    // yes / no array for admin form fields
156
-    protected $_yes_no_values = array();
157
-
158
-    // some default things shared by all child classes
159
-    protected $_default_espresso_metaboxes;
160
-
161
-    /**
162
-     *    EE_Registry Object
163
-     *
164
-     * @var    EE_Registry
165
-     */
166
-    protected $EE = null;
167
-
168
-
169
-    /**
170
-     * This is just a property that flags whether the given route is a caffeinated route or not.
171
-     *
172
-     * @var boolean
173
-     */
174
-    protected $_is_caf = false;
175
-
176
-
177
-    /**
178
-     * @Constructor
179
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
180
-     * @throws EE_Error
181
-     * @throws InvalidArgumentException
182
-     * @throws ReflectionException
183
-     * @throws InvalidDataTypeException
184
-     * @throws InvalidInterfaceException
185
-     */
186
-    public function __construct($routing = true)
187
-    {
188
-        $this->loader = LoaderFactory::getLoader();
189
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
190
-            $this->_is_caf = true;
191
-        }
192
-        $this->_yes_no_values = array(
193
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
194
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
195
-        );
196
-        // set the _req_data property.
197
-        $this->_req_data = array_merge($_GET, $_POST);
198
-        // routing enabled?
199
-        $this->_routing = $routing;
200
-        // set initial page props (child method)
201
-        $this->_init_page_props();
202
-        // set global defaults
203
-        $this->_set_defaults();
204
-        // set early because incoming requests could be ajax related and we need to register those hooks.
205
-        $this->_global_ajax_hooks();
206
-        $this->_ajax_hooks();
207
-        // other_page_hooks have to be early too.
208
-        $this->_do_other_page_hooks();
209
-        // This just allows us to have extending classes do something specific
210
-        // before the parent constructor runs _page_setup().
211
-        if (method_exists($this, '_before_page_setup')) {
212
-            $this->_before_page_setup();
213
-        }
214
-        // set up page dependencies
215
-        $this->_page_setup();
216
-    }
217
-
218
-
219
-    /**
220
-     * _init_page_props
221
-     * Child classes use to set at least the following properties:
222
-     * $page_slug.
223
-     * $page_label.
224
-     *
225
-     * @abstract
226
-     * @return void
227
-     */
228
-    abstract protected function _init_page_props();
229
-
230
-
231
-    /**
232
-     * _ajax_hooks
233
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
234
-     * Note: within the ajax callback methods.
235
-     *
236
-     * @abstract
237
-     * @return void
238
-     */
239
-    abstract protected function _ajax_hooks();
240
-
241
-
242
-    /**
243
-     * _define_page_props
244
-     * child classes define page properties in here.  Must include at least:
245
-     * $_admin_base_url = base_url for all admin pages
246
-     * $_admin_page_title = default admin_page_title for admin pages
247
-     * $_labels = array of default labels for various automatically generated elements:
248
-     *    array(
249
-     *        'buttons' => array(
250
-     *            'add' => esc_html__('label for add new button'),
251
-     *            'edit' => esc_html__('label for edit button'),
252
-     *            'delete' => esc_html__('label for delete button')
253
-     *            )
254
-     *        )
255
-     *
256
-     * @abstract
257
-     * @return void
258
-     */
259
-    abstract protected function _define_page_props();
260
-
261
-
262
-    /**
263
-     * _set_page_routes
264
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
265
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
266
-     * have a 'default' route. Here's the format
267
-     * $this->_page_routes = array(
268
-     *        'default' => array(
269
-     *            'func' => '_default_method_handling_route',
270
-     *            'args' => array('array','of','args'),
271
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
272
-     *            ajax request, backend processing)
273
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
274
-     *            headers route after.  The string you enter here should match the defined route reference for a
275
-     *            headers sent route.
276
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
277
-     *            this route.
278
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
279
-     *            checks).
280
-     *        ),
281
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
282
-     *        handling method.
283
-     *        )
284
-     * )
285
-     *
286
-     * @abstract
287
-     * @return void
288
-     */
289
-    abstract protected function _set_page_routes();
290
-
291
-
292
-    /**
293
-     * _set_page_config
294
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
295
-     * array corresponds to the page_route for the loaded page. Format:
296
-     * $this->_page_config = array(
297
-     *        'default' => array(
298
-     *            'labels' => array(
299
-     *                'buttons' => array(
300
-     *                    'add' => esc_html__('label for adding item'),
301
-     *                    'edit' => esc_html__('label for editing item'),
302
-     *                    'delete' => esc_html__('label for deleting item')
303
-     *                ),
304
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
305
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
306
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
307
-     *            _define_page_props() method
308
-     *            'nav' => array(
309
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
310
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
311
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
312
-     *                'order' => 10, //required to indicate tab position.
313
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
314
-     *                displayed then add this parameter.
315
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
316
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
317
-     *            metaboxes set for eventespresso admin pages.
318
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
319
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
320
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
321
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
322
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
323
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
324
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
325
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
326
-     *            want to display.
327
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
328
-     *                'tab_id' => array(
329
-     *                    'title' => 'tab_title',
330
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
331
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
332
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
333
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
334
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
335
-     *                    attempt to use the callback which should match the name of a method in the class
336
-     *                    ),
337
-     *                'tab2_id' => array(
338
-     *                    'title' => 'tab2 title',
339
-     *                    'filename' => 'file_name_2'
340
-     *                    'callback' => 'callback_method_for_content',
341
-     *                 ),
342
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
343
-     *            help tab area on an admin page. @link
344
-     *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
345
-     *            'help_tour' => array(
346
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
347
-     *                in a folder for this admin page named "help_tours", a file name matching the key given here
348
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
349
-     *            ),
350
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
351
-     *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
352
-     *            just set
353
-     *            'require_nonce' to FALSE
354
-     *            )
355
-     * )
356
-     *
357
-     * @abstract
358
-     * @return void
359
-     */
360
-    abstract protected function _set_page_config();
361
-
362
-
363
-
364
-
365
-
366
-    /** end sample help_tour methods **/
367
-    /**
368
-     * _add_screen_options
369
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
370
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
371
-     * to a particular view.
372
-     *
373
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
374
-     *         see also WP_Screen object documents...
375
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
376
-     * @abstract
377
-     * @return void
378
-     */
379
-    abstract protected function _add_screen_options();
380
-
381
-
382
-    /**
383
-     * _add_feature_pointers
384
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
385
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
386
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
387
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
388
-     * extended) also see:
389
-     *
390
-     * @link   http://eamann.com/tech/wordpress-portland/
391
-     * @abstract
392
-     * @return void
393
-     */
394
-    abstract protected function _add_feature_pointers();
395
-
396
-
397
-    /**
398
-     * load_scripts_styles
399
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
400
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
401
-     * scripts/styles per view by putting them in a dynamic function in this format
402
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
403
-     *
404
-     * @abstract
405
-     * @return void
406
-     */
407
-    abstract public function load_scripts_styles();
408
-
409
-
410
-    /**
411
-     * admin_init
412
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
413
-     * all pages/views loaded by child class.
414
-     *
415
-     * @abstract
416
-     * @return void
417
-     */
418
-    abstract public function admin_init();
419
-
420
-
421
-    /**
422
-     * admin_notices
423
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
424
-     * all pages/views loaded by child class.
425
-     *
426
-     * @abstract
427
-     * @return void
428
-     */
429
-    abstract public function admin_notices();
430
-
431
-
432
-    /**
433
-     * admin_footer_scripts
434
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
435
-     * will apply to all pages/views loaded by child class.
436
-     *
437
-     * @return void
438
-     */
439
-    abstract public function admin_footer_scripts();
440
-
441
-
442
-    /**
443
-     * admin_footer
444
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
445
-     * apply to all pages/views loaded by child class.
446
-     *
447
-     * @return void
448
-     */
449
-    public function admin_footer()
450
-    {
451
-    }
452
-
453
-
454
-    /**
455
-     * _global_ajax_hooks
456
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
457
-     * Note: within the ajax callback methods.
458
-     *
459
-     * @abstract
460
-     * @return void
461
-     */
462
-    protected function _global_ajax_hooks()
463
-    {
464
-        // for lazy loading of metabox content
465
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
466
-    }
467
-
468
-
469
-    public function ajax_metabox_content()
470
-    {
471
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
472
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
473
-        self::cached_rss_display($contentid, $url);
474
-        wp_die();
475
-    }
476
-
477
-
478
-    /**
479
-     * _page_setup
480
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
481
-     * doesn't match the object.
482
-     *
483
-     * @final
484
-     * @return void
485
-     * @throws EE_Error
486
-     * @throws InvalidArgumentException
487
-     * @throws ReflectionException
488
-     * @throws InvalidDataTypeException
489
-     * @throws InvalidInterfaceException
490
-     */
491
-    final protected function _page_setup()
492
-    {
493
-        // requires?
494
-        // admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
495
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
496
-        // next verify if we need to load anything...
497
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
498
-        $this->page_folder = strtolower(
499
-            str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
500
-        );
501
-        global $ee_menu_slugs;
502
-        $ee_menu_slugs = (array) $ee_menu_slugs;
503
-        if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) {
504
-            return;
505
-        }
506
-        // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
507
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
508
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
509
-                ? $this->_req_data['action2']
510
-                : $this->_req_data['action'];
511
-        }
512
-        // then set blank or -1 action values to 'default'
513
-        $this->_req_action = isset($this->_req_data['action'])
514
-                             && ! empty($this->_req_data['action'])
515
-                             && $this->_req_data['action'] !== '-1'
516
-            ? sanitize_key($this->_req_data['action'])
517
-            : 'default';
518
-        // if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
519
-        //  This covers cases where we're coming in from a list table that isn't on the default route.
520
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
521
-            ? $this->_req_data['route'] : $this->_req_action;
522
-        // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
523
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route'])
524
-            ? $this->_req_data['route']
525
-            : $this->_req_action;
526
-        $this->_current_view = $this->_req_action;
527
-        $this->_req_nonce = $this->_req_action . '_nonce';
528
-        $this->_define_page_props();
529
-        $this->_current_page_view_url = add_query_arg(
530
-            array('page' => $this->_current_page, 'action' => $this->_current_view),
531
-            $this->_admin_base_url
532
-        );
533
-        // default things
534
-        $this->_default_espresso_metaboxes = array(
535
-            '_espresso_news_post_box',
536
-            '_espresso_links_post_box',
537
-            '_espresso_ratings_request',
538
-            '_espresso_sponsors_post_box',
539
-        );
540
-        // set page configs
541
-        $this->_set_page_routes();
542
-        $this->_set_page_config();
543
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
544
-        if (isset($this->_req_data['wp_referer'])) {
545
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
546
-        }
547
-        // for caffeinated and other extended functionality.
548
-        //  If there is a _extend_page_config method
549
-        // then let's run that to modify the all the various page configuration arrays
550
-        if (method_exists($this, '_extend_page_config')) {
551
-            $this->_extend_page_config();
552
-        }
553
-        // for CPT and other extended functionality.
554
-        // If there is an _extend_page_config_for_cpt
555
-        // then let's run that to modify all the various page configuration arrays.
556
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
557
-            $this->_extend_page_config_for_cpt();
558
-        }
559
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
560
-        $this->_page_routes = apply_filters(
561
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
562
-            $this->_page_routes,
563
-            $this
564
-        );
565
-        $this->_page_config = apply_filters(
566
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
567
-            $this->_page_config,
568
-            $this
569
-        );
570
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
571
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
572
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
573
-            add_action(
574
-                'AHEE__EE_Admin_Page__route_admin_request',
575
-                array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
576
-                10,
577
-                2
578
-            );
579
-        }
580
-        // next route only if routing enabled
581
-        if ($this->_routing && ! defined('DOING_AJAX')) {
582
-            $this->_verify_routes();
583
-            // next let's just check user_access and kill if no access
584
-            $this->check_user_access();
585
-            if ($this->_is_UI_request) {
586
-                // admin_init stuff - global, all views for this page class, specific view
587
-                add_action('admin_init', array($this, 'admin_init'), 10);
588
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
589
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
590
-                }
591
-            } else {
592
-                // hijack regular WP loading and route admin request immediately
593
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
594
-                $this->route_admin_request();
595
-            }
596
-        }
597
-    }
598
-
599
-
600
-    /**
601
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
602
-     *
603
-     * @return void
604
-     * @throws ReflectionException
605
-     * @throws EE_Error
606
-     */
607
-    private function _do_other_page_hooks()
608
-    {
609
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
610
-        foreach ($registered_pages as $page) {
611
-            // now let's setup the file name and class that should be present
612
-            $classname = str_replace('.class.php', '', $page);
613
-            // autoloaders should take care of loading file
614
-            if (! class_exists($classname)) {
615
-                $error_msg[] = sprintf(
616
-                    esc_html__(
617
-                        'Something went wrong with loading the %s admin hooks page.',
618
-                        'event_espresso'
619
-                    ),
620
-                    $page
621
-                );
622
-                $error_msg[] = $error_msg[0]
623
-                               . "\r\n"
624
-                               . sprintf(
625
-                                   esc_html__(
626
-                                       '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',
627
-                                       'event_espresso'
628
-                                   ),
629
-                                   $page,
630
-                                   '<br />',
631
-                                   '<strong>' . $classname . '</strong>'
632
-                               );
633
-                throw new EE_Error(implode('||', $error_msg));
634
-            }
635
-            $a = new ReflectionClass($classname);
636
-            // notice we are passing the instance of this class to the hook object.
637
-            $hookobj[] = $a->newInstance($this);
638
-        }
639
-    }
640
-
641
-
642
-    public function load_page_dependencies()
643
-    {
644
-        try {
645
-            $this->_load_page_dependencies();
646
-        } catch (EE_Error $e) {
647
-            $e->get_error();
648
-        }
649
-    }
650
-
651
-
652
-    /**
653
-     * load_page_dependencies
654
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
655
-     *
656
-     * @return void
657
-     * @throws DomainException
658
-     * @throws EE_Error
659
-     * @throws InvalidArgumentException
660
-     * @throws InvalidDataTypeException
661
-     * @throws InvalidInterfaceException
662
-     * @throws ReflectionException
663
-     */
664
-    protected function _load_page_dependencies()
665
-    {
666
-        // let's set the current_screen and screen options to override what WP set
667
-        $this->_current_screen = get_current_screen();
668
-        // load admin_notices - global, page class, and view specific
669
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
670
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
671
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
672
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
673
-        }
674
-        // load network admin_notices - global, page class, and view specific
675
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
676
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
677
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
678
-        }
679
-        // this will save any per_page screen options if they are present
680
-        $this->_set_per_page_screen_options();
681
-        // setup list table properties
682
-        $this->_set_list_table();
683
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
684
-        // However in some cases the metaboxes will need to be added within a route handling callback.
685
-        $this->_add_registered_meta_boxes();
686
-        $this->_add_screen_columns();
687
-        // add screen options - global, page child class, and view specific
688
-        $this->_add_global_screen_options();
689
-        $this->_add_screen_options();
690
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
691
-        if (method_exists($this, $add_screen_options)) {
692
-            $this->{$add_screen_options}();
693
-        }
694
-        // add help tab(s) and tours- set via page_config and qtips.
695
-        // $this->_add_help_tour();
696
-        $this->_add_help_tabs();
697
-        $this->_add_qtips();
698
-        // add feature_pointers - global, page child class, and view specific
699
-        $this->_add_feature_pointers();
700
-        $this->_add_global_feature_pointers();
701
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
702
-        if (method_exists($this, $add_feature_pointer)) {
703
-            $this->{$add_feature_pointer}();
704
-        }
705
-        // enqueue scripts/styles - global, page class, and view specific
706
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
707
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
708
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
709
-            add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
710
-        }
711
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
712
-        // admin_print_footer_scripts - global, page child class, and view specific.
713
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
714
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
715
-        // is a good use case. Notice the late priority we're giving these
716
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
717
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
718
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
719
-            add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
720
-        }
721
-        // admin footer scripts
722
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
723
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
724
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
725
-            add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
726
-        }
727
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
728
-        // targeted hook
729
-        do_action(
730
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
731
-        );
732
-    }
733
-
734
-
735
-    /**
736
-     * _set_defaults
737
-     * This sets some global defaults for class properties.
738
-     */
739
-    private function _set_defaults()
740
-    {
741
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
742
-        $this->_event = $this->_template_path = $this->_column_template_path = null;
743
-        $this->_nav_tabs = $this->_views = $this->_page_routes = array();
744
-        $this->_page_config = $this->_default_route_query_args = array();
745
-        $this->_default_nav_tab_name = 'overview';
746
-        // init template args
747
-        $this->_template_args = array(
748
-            'admin_page_header'  => '',
749
-            'admin_page_content' => '',
750
-            'post_body_content'  => '',
751
-            'before_list_table'  => '',
752
-            'after_list_table'   => '',
753
-        );
754
-    }
755
-
756
-
757
-    /**
758
-     * route_admin_request
759
-     *
760
-     * @see    _route_admin_request()
761
-     * @return exception|void error
762
-     * @throws InvalidArgumentException
763
-     * @throws InvalidInterfaceException
764
-     * @throws InvalidDataTypeException
765
-     * @throws EE_Error
766
-     * @throws ReflectionException
767
-     */
768
-    public function route_admin_request()
769
-    {
770
-        try {
771
-            $this->_route_admin_request();
772
-        } catch (EE_Error $e) {
773
-            $e->get_error();
774
-        }
775
-    }
776
-
777
-
778
-    public function set_wp_page_slug($wp_page_slug)
779
-    {
780
-        $this->_wp_page_slug = $wp_page_slug;
781
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
782
-        if (is_network_admin()) {
783
-            $this->_wp_page_slug .= '-network';
784
-        }
785
-    }
786
-
787
-
788
-    /**
789
-     * _verify_routes
790
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
791
-     * we know if we need to drop out.
792
-     *
793
-     * @return bool
794
-     * @throws EE_Error
795
-     */
796
-    protected function _verify_routes()
797
-    {
798
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
799
-        if (! $this->_current_page && ! defined('DOING_AJAX')) {
800
-            return false;
801
-        }
802
-        $this->_route = false;
803
-        // check that the page_routes array is not empty
804
-        if (empty($this->_page_routes)) {
805
-            // user error msg
806
-            $error_msg = sprintf(
807
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
808
-                $this->_admin_page_title
809
-            );
810
-            // developer error msg
811
-            $error_msg .= '||' . $error_msg
812
-                          . esc_html__(
813
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
814
-                              'event_espresso'
815
-                          );
816
-            throw new EE_Error($error_msg);
817
-        }
818
-        // and that the requested page route exists
819
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
820
-            $this->_route = $this->_page_routes[ $this->_req_action ];
821
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
822
-                ? $this->_page_config[ $this->_req_action ] : array();
823
-        } else {
824
-            // user error msg
825
-            $error_msg = sprintf(
826
-                esc_html__(
827
-                    'The requested page route does not exist for the %s admin page.',
828
-                    'event_espresso'
829
-                ),
830
-                $this->_admin_page_title
831
-            );
832
-            // developer error msg
833
-            $error_msg .= '||' . $error_msg
834
-                          . sprintf(
835
-                              esc_html__(
836
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
837
-                                  'event_espresso'
838
-                              ),
839
-                              $this->_req_action
840
-                          );
841
-            throw new EE_Error($error_msg);
842
-        }
843
-        // and that a default route exists
844
-        if (! array_key_exists('default', $this->_page_routes)) {
845
-            // user error msg
846
-            $error_msg = sprintf(
847
-                esc_html__(
848
-                    'A default page route has not been set for the % admin page.',
849
-                    'event_espresso'
850
-                ),
851
-                $this->_admin_page_title
852
-            );
853
-            // developer error msg
854
-            $error_msg .= '||' . $error_msg
855
-                          . esc_html__(
856
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
857
-                              'event_espresso'
858
-                          );
859
-            throw new EE_Error($error_msg);
860
-        }
861
-        // first lets' catch if the UI request has EVER been set.
862
-        if ($this->_is_UI_request === null) {
863
-            // lets set if this is a UI request or not.
864
-            $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
865
-            // wait a minute... we might have a noheader in the route array
866
-            $this->_is_UI_request = is_array($this->_route)
867
-                                    && isset($this->_route['noheader'])
868
-                                    && $this->_route['noheader'] ? false : $this->_is_UI_request;
869
-        }
870
-        $this->_set_current_labels();
871
-        return true;
872
-    }
873
-
874
-
875
-    /**
876
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
877
-     *
878
-     * @param  string $route the route name we're verifying
879
-     * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
880
-     * @throws EE_Error
881
-     */
882
-    protected function _verify_route($route)
883
-    {
884
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
885
-            return true;
886
-        }
887
-        // user error msg
888
-        $error_msg = sprintf(
889
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
890
-            $this->_admin_page_title
891
-        );
892
-        // developer error msg
893
-        $error_msg .= '||' . $error_msg
894
-                      . sprintf(
895
-                          esc_html__(
896
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
897
-                              'event_espresso'
898
-                          ),
899
-                          $route
900
-                      );
901
-        throw new EE_Error($error_msg);
902
-    }
903
-
904
-
905
-    /**
906
-     * perform nonce verification
907
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
908
-     * using this method (and save retyping!)
909
-     *
910
-     * @param  string $nonce     The nonce sent
911
-     * @param  string $nonce_ref The nonce reference string (name0)
912
-     * @return void
913
-     * @throws EE_Error
914
-     */
915
-    protected function _verify_nonce($nonce, $nonce_ref)
916
-    {
917
-        // verify nonce against expected value
918
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
919
-            // these are not the droids you are looking for !!!
920
-            $msg = sprintf(
921
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
922
-                '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
923
-                '</a>'
924
-            );
925
-            if (WP_DEBUG) {
926
-                $msg .= "\n  "
927
-                        . sprintf(
928
-                            esc_html__(
929
-                                'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
930
-                                'event_espresso'
931
-                            ),
932
-                            __CLASS__
933
-                        );
934
-            }
935
-            if (! defined('DOING_AJAX')) {
936
-                wp_die($msg);
937
-            } else {
938
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
939
-                $this->_return_json();
940
-            }
941
-        }
942
-    }
943
-
944
-
945
-    /**
946
-     * _route_admin_request()
947
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
948
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
949
-     * in the page routes and then will try to load the corresponding method.
950
-     *
951
-     * @return void
952
-     * @throws EE_Error
953
-     * @throws InvalidArgumentException
954
-     * @throws InvalidDataTypeException
955
-     * @throws InvalidInterfaceException
956
-     * @throws ReflectionException
957
-     */
958
-    protected function _route_admin_request()
959
-    {
960
-        if (! $this->_is_UI_request) {
961
-            $this->_verify_routes();
962
-        }
963
-        $nonce_check = isset($this->_route_config['require_nonce'])
964
-            ? $this->_route_config['require_nonce']
965
-            : true;
966
-        if ($this->_req_action !== 'default' && $nonce_check) {
967
-            // set nonce from post data
968
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
969
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ])
970
-                : '';
971
-            $this->_verify_nonce($nonce, $this->_req_nonce);
972
-        }
973
-        // set the nav_tabs array but ONLY if this is  UI_request
974
-        if ($this->_is_UI_request) {
975
-            $this->_set_nav_tabs();
976
-        }
977
-        // grab callback function
978
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
979
-        // check if callback has args
980
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
981
-        $error_msg = '';
982
-        // action right before calling route
983
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
984
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
985
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
986
-        }
987
-        // right before calling the route, let's remove _wp_http_referer from the
988
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
989
-        $_SERVER['REQUEST_URI'] = remove_query_arg(
990
-            '_wp_http_referer',
991
-            wp_unslash($_SERVER['REQUEST_URI'])
992
-        );
993
-        if (! empty($func)) {
994
-            if (is_array($func)) {
995
-                list($class, $method) = $func;
996
-            } elseif (strpos($func, '::') !== false) {
997
-                list($class, $method) = explode('::', $func);
998
-            } else {
999
-                $class = $this;
1000
-                $method = $func;
1001
-            }
1002
-            if (! (is_object($class) && $class === $this)) {
1003
-                // send along this admin page object for access by addons.
1004
-                $args['admin_page_object'] = $this;
1005
-            }
1006
-            if (// is it a method on a class that doesn't work?
1007
-                (
1008
-                    (
1009
-                        method_exists($class, $method)
1010
-                        && call_user_func_array(array($class, $method), $args) === false
1011
-                    )
1012
-                    && (
1013
-                        // is it a standalone function that doesn't work?
1014
-                        function_exists($method)
1015
-                        && call_user_func_array(
1016
-                            $func,
1017
-                            array_merge(array('admin_page_object' => $this), $args)
1018
-                        ) === false
1019
-                    )
1020
-                )
1021
-                || (
1022
-                    // is it neither a class method NOR a standalone function?
1023
-                    ! method_exists($class, $method)
1024
-                    && ! function_exists($method)
1025
-                )
1026
-            ) {
1027
-                // user error msg
1028
-                $error_msg = esc_html__(
1029
-                    'An error occurred. The  requested page route could not be found.',
1030
-                    'event_espresso'
1031
-                );
1032
-                // developer error msg
1033
-                $error_msg .= '||';
1034
-                $error_msg .= sprintf(
1035
-                    esc_html__(
1036
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1037
-                        'event_espresso'
1038
-                    ),
1039
-                    $method
1040
-                );
1041
-            }
1042
-            if (! empty($error_msg)) {
1043
-                throw new EE_Error($error_msg);
1044
-            }
1045
-        }
1046
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1047
-        // then we need to reset the routing properties to the new route.
1048
-        // 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.
1049
-        if ($this->_is_UI_request === false
1050
-            && is_array($this->_route)
1051
-            && ! empty($this->_route['headers_sent_route'])
1052
-        ) {
1053
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1054
-        }
1055
-    }
1056
-
1057
-
1058
-    /**
1059
-     * This method just allows the resetting of page properties in the case where a no headers
1060
-     * route redirects to a headers route in its route config.
1061
-     *
1062
-     * @since   4.3.0
1063
-     * @param  string $new_route New (non header) route to redirect to.
1064
-     * @return   void
1065
-     * @throws ReflectionException
1066
-     * @throws InvalidArgumentException
1067
-     * @throws InvalidInterfaceException
1068
-     * @throws InvalidDataTypeException
1069
-     * @throws EE_Error
1070
-     */
1071
-    protected function _reset_routing_properties($new_route)
1072
-    {
1073
-        $this->_is_UI_request = true;
1074
-        // now we set the current route to whatever the headers_sent_route is set at
1075
-        $this->_req_data['action'] = $new_route;
1076
-        // rerun page setup
1077
-        $this->_page_setup();
1078
-    }
1079
-
1080
-
1081
-    /**
1082
-     * _add_query_arg
1083
-     * adds nonce to array of arguments then calls WP add_query_arg function
1084
-     *(internally just uses EEH_URL's function with the same name)
1085
-     *
1086
-     * @param array  $args
1087
-     * @param string $url
1088
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1089
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1090
-     *                                        Example usage: If the current page is:
1091
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1092
-     *                                        &action=default&event_id=20&month_range=March%202015
1093
-     *                                        &_wpnonce=5467821
1094
-     *                                        and you call:
1095
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1096
-     *                                        array(
1097
-     *                                        'action' => 'resend_something',
1098
-     *                                        'page=>espresso_registrations'
1099
-     *                                        ),
1100
-     *                                        $some_url,
1101
-     *                                        true
1102
-     *                                        );
1103
-     *                                        It will produce a url in this structure:
1104
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1105
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1106
-     *                                        month_range]=March%202015
1107
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1108
-     * @return string
1109
-     */
1110
-    public static function add_query_args_and_nonce(
1111
-        $args = array(),
1112
-        $url = false,
1113
-        $sticky = false,
1114
-        $exclude_nonce = false
1115
-    ) {
1116
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1117
-        if ($sticky) {
1118
-            $request = $_REQUEST;
1119
-            unset($request['_wp_http_referer']);
1120
-            unset($request['wp_referer']);
1121
-            foreach ($request as $key => $value) {
1122
-                // do not add nonces
1123
-                if (strpos($key, 'nonce') !== false) {
1124
-                    continue;
1125
-                }
1126
-                $args[ 'wp_referer[' . $key . ']' ] = $value;
1127
-            }
1128
-        }
1129
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1130
-    }
1131
-
1132
-
1133
-    /**
1134
-     * This returns a generated link that will load the related help tab.
1135
-     *
1136
-     * @param  string $help_tab_id the id for the connected help tab
1137
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1138
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1139
-     * @uses EEH_Template::get_help_tab_link()
1140
-     * @return string              generated link
1141
-     */
1142
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1143
-    {
1144
-        return EEH_Template::get_help_tab_link(
1145
-            $help_tab_id,
1146
-            $this->page_slug,
1147
-            $this->_req_action,
1148
-            $icon_style,
1149
-            $help_text
1150
-        );
1151
-    }
1152
-
1153
-
1154
-    /**
1155
-     * _add_help_tabs
1156
-     * Note child classes define their help tabs within the page_config array.
1157
-     *
1158
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1159
-     * @return void
1160
-     * @throws DomainException
1161
-     * @throws EE_Error
1162
-     */
1163
-    protected function _add_help_tabs()
1164
-    {
1165
-        $tour_buttons = '';
1166
-        if (isset($this->_page_config[ $this->_req_action ])) {
1167
-            $config = $this->_page_config[ $this->_req_action ];
1168
-            // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1169
-            // is there a help tour for the current route?  if there is let's setup the tour buttons
1170
-            // if (isset($this->_help_tour[ $this->_req_action ])) {
1171
-            //     $tb = array();
1172
-            //     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1173
-            //     foreach ($this->_help_tour['tours'] as $tour) {
1174
-            //         // if this is the end tour then we don't need to setup a button
1175
-            //         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1176
-            //             continue;
1177
-            //         }
1178
-            //         $tb[] = '<button id="trigger-tour-'
1179
-            //                 . $tour->get_slug()
1180
-            //                 . '" class="button-primary trigger-ee-help-tour">'
1181
-            //                 . $tour->get_label()
1182
-            //                 . '</button>';
1183
-            //     }
1184
-            //     $tour_buttons .= implode('<br />', $tb);
1185
-            //     $tour_buttons .= '</div></div>';
1186
-            // }
1187
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1188
-            if (is_array($config) && isset($config['help_sidebar'])) {
1189
-                // check that the callback given is valid
1190
-                if (! method_exists($this, $config['help_sidebar'])) {
1191
-                    throw new EE_Error(
1192
-                        sprintf(
1193
-                            esc_html__(
1194
-                                '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',
1195
-                                'event_espresso'
1196
-                            ),
1197
-                            $config['help_sidebar'],
1198
-                            get_class($this)
1199
-                        )
1200
-                    );
1201
-                }
1202
-                $content = apply_filters(
1203
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1204
-                    $this->{$config['help_sidebar']}()
1205
-                );
1206
-                $content .= $tour_buttons; // add help tour buttons.
1207
-                // do we have any help tours setup?  Cause if we do we want to add the buttons
1208
-                $this->_current_screen->set_help_sidebar($content);
1209
-            }
1210
-            // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar.
1211
-            if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1212
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1213
-            }
1214
-            // handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1215
-            if (! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1216
-                $_ht['id'] = $this->page_slug;
1217
-                $_ht['title'] = esc_html__('Help Tours', 'event_espresso');
1218
-                $_ht['content'] = '<p>'
1219
-                                  . esc_html__(
1220
-                                      'The buttons to the right allow you to start/restart any help tours available for this page',
1221
-                                      'event_espresso'
1222
-                                  ) . '</p>';
1223
-                $this->_current_screen->add_help_tab($_ht);
1224
-            }
1225
-            if (! isset($config['help_tabs'])) {
1226
-                return;
1227
-            } //no help tabs for this route
1228
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1229
-                // we're here so there ARE help tabs!
1230
-                // make sure we've got what we need
1231
-                if (! isset($cfg['title'])) {
1232
-                    throw new EE_Error(
1233
-                        esc_html__(
1234
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1235
-                            'event_espresso'
1236
-                        )
1237
-                    );
1238
-                }
1239
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1240
-                    throw new EE_Error(
1241
-                        esc_html__(
1242
-                            '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',
1243
-                            'event_espresso'
1244
-                        )
1245
-                    );
1246
-                }
1247
-                // first priority goes to content.
1248
-                if (! empty($cfg['content'])) {
1249
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1250
-                    // second priority goes to filename
1251
-                } elseif (! empty($cfg['filename'])) {
1252
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1253
-                    // 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)
1254
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1255
-                                                             . basename($this->_get_dir())
1256
-                                                             . '/help_tabs/'
1257
-                                                             . $cfg['filename']
1258
-                                                             . '.help_tab.php' : $file_path;
1259
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1260
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1261
-                        EE_Error::add_error(
1262
-                            sprintf(
1263
-                                esc_html__(
1264
-                                    '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',
1265
-                                    'event_espresso'
1266
-                                ),
1267
-                                $tab_id,
1268
-                                key($config),
1269
-                                $file_path
1270
-                            ),
1271
-                            __FILE__,
1272
-                            __FUNCTION__,
1273
-                            __LINE__
1274
-                        );
1275
-                        return;
1276
-                    }
1277
-                    $template_args['admin_page_obj'] = $this;
1278
-                    $content = EEH_Template::display_template(
1279
-                        $file_path,
1280
-                        $template_args,
1281
-                        true
1282
-                    );
1283
-                } else {
1284
-                    $content = '';
1285
-                }
1286
-                // check if callback is valid
1287
-                if (empty($content) && (
1288
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1289
-                    )
1290
-                ) {
1291
-                    EE_Error::add_error(
1292
-                        sprintf(
1293
-                            esc_html__(
1294
-                                '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.',
1295
-                                'event_espresso'
1296
-                            ),
1297
-                            $cfg['title']
1298
-                        ),
1299
-                        __FILE__,
1300
-                        __FUNCTION__,
1301
-                        __LINE__
1302
-                    );
1303
-                    return;
1304
-                }
1305
-                // setup config array for help tab method
1306
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1307
-                $_ht = array(
1308
-                    'id'       => $id,
1309
-                    'title'    => $cfg['title'],
1310
-                    'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1311
-                    'content'  => $content,
1312
-                );
1313
-                $this->_current_screen->add_help_tab($_ht);
1314
-            }
1315
-        }
1316
-    }
1317
-
1318
-
1319
-    /**
1320
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1321
-     * an array with properties for setting up usage of the joyride plugin
1322
-     *
1323
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1324
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1325
-     *         _set_page_config() comments
1326
-     * @return void
1327
-     * @throws EE_Error
1328
-     * @throws InvalidArgumentException
1329
-     * @throws InvalidDataTypeException
1330
-     * @throws InvalidInterfaceException
1331
-     */
1332
-    protected function _add_help_tour()
1333
-    {
1334
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1335
-        // $tours = array();
1336
-        // $this->_help_tour = array();
1337
-        // // exit early if help tours are turned off globally
1338
-        // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1339
-        //     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1340
-        // ) {
1341
-        //     return;
1342
-        // }
1343
-        // // loop through _page_config to find any help_tour defined
1344
-        // foreach ($this->_page_config as $route => $config) {
1345
-        //     // we're only going to set things up for this route
1346
-        //     if ($route !== $this->_req_action) {
1347
-        //         continue;
1348
-        //     }
1349
-        //     if (isset($config['help_tour'])) {
1350
-        //         foreach ($config['help_tour'] as $tour) {
1351
-        //             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1352
-        //             // let's see if we can get that file...
1353
-        //             // if not its possible this is a decaf route not set in caffeinated
1354
-        //             // so lets try and get the caffeinated equivalent
1355
-        //             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1356
-        //                                                      . basename($this->_get_dir())
1357
-        //                                                      . '/help_tours/'
1358
-        //                                                      . $tour
1359
-        //                                                      . '.class.php' : $file_path;
1360
-        //             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1361
-        //             if (! is_readable($file_path)) {
1362
-        //                 EE_Error::add_error(
1363
-        //                     sprintf(
1364
-        //                         esc_html__(
1365
-        //                             'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1366
-        //                             'event_espresso'
1367
-        //                         ),
1368
-        //                         $file_path,
1369
-        //                         $tour
1370
-        //                     ),
1371
-        //                     __FILE__,
1372
-        //                     __FUNCTION__,
1373
-        //                     __LINE__
1374
-        //                 );
1375
-        //                 return;
1376
-        //             }
1377
-        //             require_once $file_path;
1378
-        //             if (! class_exists($tour)) {
1379
-        //                 $error_msg[] = sprintf(
1380
-        //                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1381
-        //                     $tour
1382
-        //                 );
1383
-        //                 $error_msg[] = $error_msg[0] . "\r\n"
1384
-        //                                . sprintf(
1385
-        //                                    esc_html__(
1386
-        //                                        'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1387
-        //                                        'event_espresso'
1388
-        //                                    ),
1389
-        //                                    $tour,
1390
-        //                                    '<br />',
1391
-        //                                    $tour,
1392
-        //                                    $this->_req_action,
1393
-        //                                    get_class($this)
1394
-        //                                );
1395
-        //                 throw new EE_Error(implode('||', $error_msg));
1396
-        //             }
1397
-        //             $tour_obj = new $tour($this->_is_caf);
1398
-        //             $tours[] = $tour_obj;
1399
-        //             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1400
-        //         }
1401
-        //         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1402
-        //         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1403
-        //         $tours[] = $end_stop_tour;
1404
-        //         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1405
-        //     }
1406
-        // }
1407
-        //
1408
-        // if (! empty($tours)) {
1409
-        //     $this->_help_tour['tours'] = $tours;
1410
-        // }
1411
-        // // that's it!  Now that the $_help_tours property is set (or not)
1412
-        // // the scripts and html should be taken care of automatically.
1413
-        //
1414
-        // /**
1415
-        //  * Allow extending the help tours variable.
1416
-        //  *
1417
-        //  * @param Array $_help_tour The array containing all help tour information to be displayed.
1418
-        //  */
1419
-        // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1420
-    }
1421
-
1422
-
1423
-    /**
1424
-     * This simply sets up any qtips that have been defined in the page config
1425
-     *
1426
-     * @return void
1427
-     */
1428
-    protected function _add_qtips()
1429
-    {
1430
-        if (isset($this->_route_config['qtips'])) {
1431
-            $qtips = (array) $this->_route_config['qtips'];
1432
-            // load qtip loader
1433
-            $path = array(
1434
-                $this->_get_dir() . '/qtips/',
1435
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1436
-            );
1437
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1438
-        }
1439
-    }
1440
-
1441
-
1442
-    /**
1443
-     * _set_nav_tabs
1444
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1445
-     * wish to add additional tabs or modify accordingly.
1446
-     *
1447
-     * @return void
1448
-     * @throws InvalidArgumentException
1449
-     * @throws InvalidInterfaceException
1450
-     * @throws InvalidDataTypeException
1451
-     */
1452
-    protected function _set_nav_tabs()
1453
-    {
1454
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1455
-        $i = 0;
1456
-        foreach ($this->_page_config as $slug => $config) {
1457
-            if (! is_array($config)
1458
-                || (
1459
-                    is_array($config)
1460
-                    && (
1461
-                        (isset($config['nav']) && ! $config['nav'])
1462
-                        || ! isset($config['nav'])
1463
-                    )
1464
-                )
1465
-            ) {
1466
-                continue;
1467
-            }
1468
-            // no nav tab for this config
1469
-            // check for persistent flag
1470
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1471
-                // nav tab is only to appear when route requested.
1472
-                continue;
1473
-            }
1474
-            if (! $this->check_user_access($slug, true)) {
1475
-                // no nav tab because current user does not have access.
1476
-                continue;
1477
-            }
1478
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1479
-            $this->_nav_tabs[ $slug ] = array(
1480
-                'url'       => isset($config['nav']['url'])
1481
-                    ? $config['nav']['url']
1482
-                    : self::add_query_args_and_nonce(
1483
-                        array('action' => $slug),
1484
-                        $this->_admin_base_url
1485
-                    ),
1486
-                'link_text' => isset($config['nav']['label'])
1487
-                    ? $config['nav']['label']
1488
-                    : ucwords(
1489
-                        str_replace('_', ' ', $slug)
1490
-                    ),
1491
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1492
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1493
-            );
1494
-            $i++;
1495
-        }
1496
-        // if $this->_nav_tabs is empty then lets set the default
1497
-        if (empty($this->_nav_tabs)) {
1498
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = array(
1499
-                'url'       => $this->_admin_base_url,
1500
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1501
-                'css_class' => 'nav-tab-active',
1502
-                'order'     => 10,
1503
-            );
1504
-        }
1505
-        // now let's sort the tabs according to order
1506
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1507
-    }
1508
-
1509
-
1510
-    /**
1511
-     * _set_current_labels
1512
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1513
-     * property array
1514
-     *
1515
-     * @return void
1516
-     */
1517
-    private function _set_current_labels()
1518
-    {
1519
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1520
-            foreach ($this->_route_config['labels'] as $label => $text) {
1521
-                if (is_array($text)) {
1522
-                    foreach ($text as $sublabel => $subtext) {
1523
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1524
-                    }
1525
-                } else {
1526
-                    $this->_labels[ $label ] = $text;
1527
-                }
1528
-            }
1529
-        }
1530
-    }
1531
-
1532
-
1533
-    /**
1534
-     *        verifies user access for this admin page
1535
-     *
1536
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1537
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1538
-     *                               return false if verify fail.
1539
-     * @return bool
1540
-     * @throws InvalidArgumentException
1541
-     * @throws InvalidDataTypeException
1542
-     * @throws InvalidInterfaceException
1543
-     */
1544
-    public function check_user_access($route_to_check = '', $verify_only = false)
1545
-    {
1546
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1547
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1548
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1549
-                      && is_array(
1550
-                          $this->_page_routes[ $route_to_check ]
1551
-                      )
1552
-                      && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1553
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1554
-        if (empty($capability) && empty($route_to_check)) {
1555
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1556
-                : $this->_route['capability'];
1557
-        } else {
1558
-            $capability = empty($capability) ? 'manage_options' : $capability;
1559
-        }
1560
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1561
-        if (! defined('DOING_AJAX')
1562
-            && (
1563
-                ! function_exists('is_admin')
1564
-                || ! EE_Registry::instance()->CAP->current_user_can(
1565
-                    $capability,
1566
-                    $this->page_slug
1567
-                    . '_'
1568
-                    . $route_to_check,
1569
-                    $id
1570
-                )
1571
-            )
1572
-        ) {
1573
-            if ($verify_only) {
1574
-                return false;
1575
-            }
1576
-            if (is_user_logged_in()) {
1577
-                wp_die(__('You do not have access to this route.', 'event_espresso'));
1578
-            } else {
1579
-                return false;
1580
-            }
1581
-        }
1582
-        return true;
1583
-    }
1584
-
1585
-
1586
-    /**
1587
-     * admin_init_global
1588
-     * This runs all the code that we want executed within the WP admin_init hook.
1589
-     * This method executes for ALL EE Admin pages.
1590
-     *
1591
-     * @return void
1592
-     */
1593
-    public function admin_init_global()
1594
-    {
1595
-    }
1596
-
1597
-
1598
-    /**
1599
-     * wp_loaded_global
1600
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1601
-     * EE_Admin page and will execute on every EE Admin Page load
1602
-     *
1603
-     * @return void
1604
-     */
1605
-    public function wp_loaded()
1606
-    {
1607
-    }
1608
-
1609
-
1610
-    /**
1611
-     * admin_notices
1612
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1613
-     * ALL EE_Admin pages.
1614
-     *
1615
-     * @return void
1616
-     */
1617
-    public function admin_notices_global()
1618
-    {
1619
-        $this->_display_no_javascript_warning();
1620
-        $this->_display_espresso_notices();
1621
-    }
1622
-
1623
-
1624
-    public function network_admin_notices_global()
1625
-    {
1626
-        $this->_display_no_javascript_warning();
1627
-        $this->_display_espresso_notices();
1628
-    }
1629
-
1630
-
1631
-    /**
1632
-     * admin_footer_scripts_global
1633
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1634
-     * will apply on ALL EE_Admin pages.
1635
-     *
1636
-     * @return void
1637
-     */
1638
-    public function admin_footer_scripts_global()
1639
-    {
1640
-        $this->_add_admin_page_ajax_loading_img();
1641
-        $this->_add_admin_page_overlay();
1642
-        // if metaboxes are present we need to add the nonce field
1643
-        if (isset($this->_route_config['metaboxes'])
1644
-            || isset($this->_route_config['list_table'])
1645
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1646
-        ) {
1647
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1648
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1649
-        }
1650
-    }
1651
-
1652
-
1653
-    /**
1654
-     * admin_footer_global
1655
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1656
-     * ALL EE_Admin Pages.
1657
-     *
1658
-     * @return void
1659
-     * @throws EE_Error
1660
-     */
1661
-    public function admin_footer_global()
1662
-    {
1663
-        // dialog container for dialog helper
1664
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1665
-        $d_cont .= '<div class="ee-notices"></div>';
1666
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1667
-        $d_cont .= '</div>';
1668
-        echo $d_cont;
1669
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1670
-        // help tour stuff?
1671
-        // if (isset($this->_help_tour[ $this->_req_action ])) {
1672
-        //     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1673
-        // }
1674
-        // current set timezone for timezone js
1675
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1676
-    }
1677
-
1678
-
1679
-    /**
1680
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1681
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1682
-     * help popups then in your templates or your content you set "triggers" for the content using the
1683
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1684
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1685
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1686
-     * for the
1687
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1688
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1689
-     *    'help_trigger_id' => array(
1690
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1691
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1692
-     *    )
1693
-     * );
1694
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1695
-     *
1696
-     * @param array $help_array
1697
-     * @param bool  $display
1698
-     * @return string content
1699
-     * @throws DomainException
1700
-     * @throws EE_Error
1701
-     */
1702
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1703
-    {
1704
-        $content = '';
1705
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1706
-        // loop through the array and setup content
1707
-        foreach ($help_array as $trigger => $help) {
1708
-            // make sure the array is setup properly
1709
-            if (! isset($help['title']) || ! isset($help['content'])) {
1710
-                throw new EE_Error(
1711
-                    esc_html__(
1712
-                        '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',
1713
-                        'event_espresso'
1714
-                    )
1715
-                );
1716
-            }
1717
-            // we're good so let'd setup the template vars and then assign parsed template content to our content.
1718
-            $template_args = array(
1719
-                'help_popup_id'      => $trigger,
1720
-                'help_popup_title'   => $help['title'],
1721
-                'help_popup_content' => $help['content'],
1722
-            );
1723
-            $content .= EEH_Template::display_template(
1724
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1725
-                $template_args,
1726
-                true
1727
-            );
1728
-        }
1729
-        if ($display) {
1730
-            echo $content;
1731
-            return '';
1732
-        }
1733
-        return $content;
1734
-    }
1735
-
1736
-
1737
-    /**
1738
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1739
-     *
1740
-     * @return array properly formatted array for help popup content
1741
-     * @throws EE_Error
1742
-     */
1743
-    private function _get_help_content()
1744
-    {
1745
-        // what is the method we're looking for?
1746
-        $method_name = '_help_popup_content_' . $this->_req_action;
1747
-        // if method doesn't exist let's get out.
1748
-        if (! method_exists($this, $method_name)) {
1749
-            return array();
1750
-        }
1751
-        // k we're good to go let's retrieve the help array
1752
-        $help_array = call_user_func(array($this, $method_name));
1753
-        // make sure we've got an array!
1754
-        if (! is_array($help_array)) {
1755
-            throw new EE_Error(
1756
-                esc_html__(
1757
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1758
-                    'event_espresso'
1759
-                )
1760
-            );
1761
-        }
1762
-        return $help_array;
1763
-    }
1764
-
1765
-
1766
-    /**
1767
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1768
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1769
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1770
-     *
1771
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1772
-     * @param boolean $display    if false then we return the trigger string
1773
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1774
-     * @return string
1775
-     * @throws DomainException
1776
-     * @throws EE_Error
1777
-     */
1778
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1779
-    {
1780
-        if (defined('DOING_AJAX')) {
1781
-            return '';
1782
-        }
1783
-        // 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
1784
-        $help_array = $this->_get_help_content();
1785
-        $help_content = '';
1786
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1787
-            $help_array[ $trigger_id ] = array(
1788
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1789
-                'content' => esc_html__(
1790
-                    '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.)',
1791
-                    'event_espresso'
1792
-                ),
1793
-            );
1794
-            $help_content = $this->_set_help_popup_content($help_array, false);
1795
-        }
1796
-        // let's setup the trigger
1797
-        $content = '<a class="ee-dialog" href="?height='
1798
-                   . $dimensions[0]
1799
-                   . '&width='
1800
-                   . $dimensions[1]
1801
-                   . '&inlineId='
1802
-                   . $trigger_id
1803
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1804
-        $content .= $help_content;
1805
-        if ($display) {
1806
-            echo $content;
1807
-            return '';
1808
-        }
1809
-        return $content;
1810
-    }
1811
-
1812
-
1813
-    /**
1814
-     * _add_global_screen_options
1815
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1816
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1817
-     *
1818
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1819
-     *         see also WP_Screen object documents...
1820
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1821
-     * @abstract
1822
-     * @return void
1823
-     */
1824
-    private function _add_global_screen_options()
1825
-    {
1826
-    }
1827
-
1828
-
1829
-    /**
1830
-     * _add_global_feature_pointers
1831
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1832
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1833
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1834
-     *
1835
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1836
-     *         extended) also see:
1837
-     * @link   http://eamann.com/tech/wordpress-portland/
1838
-     * @abstract
1839
-     * @return void
1840
-     */
1841
-    private function _add_global_feature_pointers()
1842
-    {
1843
-    }
1844
-
1845
-
1846
-    /**
1847
-     * load_global_scripts_styles
1848
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1849
-     *
1850
-     * @return void
1851
-     * @throws EE_Error
1852
-     */
1853
-    public function load_global_scripts_styles()
1854
-    {
1855
-        /** STYLES **/
1856
-        // add debugging styles
1857
-        if (WP_DEBUG) {
1858
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1859
-        }
1860
-        // register all styles
1861
-        wp_register_style(
1862
-            'espresso-ui-theme',
1863
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1864
-            array(),
1865
-            EVENT_ESPRESSO_VERSION
1866
-        );
1867
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1868
-        // helpers styles
1869
-        wp_register_style(
1870
-            'ee-text-links',
1871
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1872
-            array(),
1873
-            EVENT_ESPRESSO_VERSION
1874
-        );
1875
-        /** SCRIPTS **/
1876
-        // register all scripts
1877
-        wp_register_script(
1878
-            'ee-dialog',
1879
-            EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1880
-            array('jquery', 'jquery-ui-draggable'),
1881
-            EVENT_ESPRESSO_VERSION,
1882
-            true
1883
-        );
1884
-        wp_register_script(
1885
-            'ee_admin_js',
1886
-            EE_ADMIN_URL . 'assets/ee-admin-page.js',
1887
-            array('espresso_core', 'ee-parse-uri', 'ee-dialog'),
1888
-            EVENT_ESPRESSO_VERSION,
1889
-            true
1890
-        );
1891
-        wp_register_script(
1892
-            'jquery-ui-timepicker-addon',
1893
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1894
-            array('jquery-ui-datepicker', 'jquery-ui-slider'),
1895
-            EVENT_ESPRESSO_VERSION,
1896
-            true
1897
-        );
1898
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1899
-        // if (EE_Registry::instance()->CFG->admin->help_tour_activation) {
1900
-        //     add_filter('FHEE_load_joyride', '__return_true');
1901
-        // }
1902
-        // script for sorting tables
1903
-        wp_register_script(
1904
-            'espresso_ajax_table_sorting',
1905
-            EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1906
-            array('ee_admin_js', 'jquery-ui-sortable'),
1907
-            EVENT_ESPRESSO_VERSION,
1908
-            true
1909
-        );
1910
-        // script for parsing uri's
1911
-        wp_register_script(
1912
-            'ee-parse-uri',
1913
-            EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1914
-            array(),
1915
-            EVENT_ESPRESSO_VERSION,
1916
-            true
1917
-        );
1918
-        // and parsing associative serialized form elements
1919
-        wp_register_script(
1920
-            'ee-serialize-full-array',
1921
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1922
-            array('jquery'),
1923
-            EVENT_ESPRESSO_VERSION,
1924
-            true
1925
-        );
1926
-        // helpers scripts
1927
-        wp_register_script(
1928
-            'ee-text-links',
1929
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1930
-            array('jquery'),
1931
-            EVENT_ESPRESSO_VERSION,
1932
-            true
1933
-        );
1934
-        wp_register_script(
1935
-            'ee-moment-core',
1936
-            EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1937
-            array(),
1938
-            EVENT_ESPRESSO_VERSION,
1939
-            true
1940
-        );
1941
-        wp_register_script(
1942
-            'ee-moment',
1943
-            EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1944
-            array('ee-moment-core'),
1945
-            EVENT_ESPRESSO_VERSION,
1946
-            true
1947
-        );
1948
-        wp_register_script(
1949
-            'ee-datepicker',
1950
-            EE_ADMIN_URL . 'assets/ee-datepicker.js',
1951
-            array('jquery-ui-timepicker-addon', 'ee-moment'),
1952
-            EVENT_ESPRESSO_VERSION,
1953
-            true
1954
-        );
1955
-        // google charts
1956
-        wp_register_script(
1957
-            'google-charts',
1958
-            'https://www.gstatic.com/charts/loader.js',
1959
-            array(),
1960
-            EVENT_ESPRESSO_VERSION,
1961
-            false
1962
-        );
1963
-        // ENQUEUE ALL BASICS BY DEFAULT
1964
-        wp_enqueue_style('ee-admin-css');
1965
-        wp_enqueue_script('ee_admin_js');
1966
-        wp_enqueue_script('ee-accounting');
1967
-        wp_enqueue_script('jquery-validate');
1968
-        // taking care of metaboxes
1969
-        if (empty($this->_cpt_route)
1970
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1971
-        ) {
1972
-            wp_enqueue_script('dashboard');
1973
-        }
1974
-        // LOCALIZED DATA
1975
-        // localize script for ajax lazy loading
1976
-        $lazy_loader_container_ids = apply_filters(
1977
-            'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1978
-            array('espresso_news_post_box_content')
1979
-        );
1980
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1981
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1982
-        // /**
1983
-        //  * help tour stuff
1984
-        //  */
1985
-        // if (! empty($this->_help_tour)) {
1986
-        //     // register the js for kicking things off
1987
-        //     wp_enqueue_script(
1988
-        //         'ee-help-tour',
1989
-        //         EE_ADMIN_URL . 'assets/ee-help-tour.js',
1990
-        //         array('jquery-joyride'),
1991
-        //         EVENT_ESPRESSO_VERSION,
1992
-        //         true
1993
-        //     );
1994
-        //     $tours = array();
1995
-        //     // setup tours for the js tour object
1996
-        //     foreach ($this->_help_tour['tours'] as $tour) {
1997
-        //         if ($tour instanceof EE_Help_Tour) {
1998
-        //             $tours[] = array(
1999
-        //                 'id'      => $tour->get_slug(),
2000
-        //                 'options' => $tour->get_options(),
2001
-        //             );
2002
-        //         }
2003
-        //     }
2004
-        //     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
2005
-        //     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
2006
-        // }
2007
-    }
2008
-
2009
-
2010
-    /**
2011
-     *        admin_footer_scripts_eei18n_js_strings
2012
-     *
2013
-     * @return        void
2014
-     */
2015
-    public function admin_footer_scripts_eei18n_js_strings()
2016
-    {
2017
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
2018
-        EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
2019
-            __(
2020
-                '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!!!',
2021
-                'event_espresso'
2022
-            )
2023
-        );
2024
-        EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso'));
2025
-        EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso'));
2026
-        EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso'));
2027
-        EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso'));
2028
-        EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso'));
2029
-        EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso'));
2030
-        EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso'));
2031
-        EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso'));
2032
-        EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso'));
2033
-        EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso'));
2034
-        EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso'));
2035
-        EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso'));
2036
-        EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso'));
2037
-        EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso'));
2038
-        EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso'));
2039
-        EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso'));
2040
-        EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso'));
2041
-        EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso'));
2042
-        EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso'));
2043
-        EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso'));
2044
-        EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso'));
2045
-        EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso'));
2046
-        EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso'));
2047
-        EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso'));
2048
-        EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso'));
2049
-        EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso'));
2050
-        EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
2051
-        EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
2052
-        EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso'));
2053
-        EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso'));
2054
-        EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso'));
2055
-        EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso'));
2056
-        EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso'));
2057
-        EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso'));
2058
-        EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso'));
2059
-        EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso'));
2060
-        EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso'));
2061
-        EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso'));
2062
-    }
2063
-
2064
-
2065
-    /**
2066
-     *        load enhanced xdebug styles for ppl with failing eyesight
2067
-     *
2068
-     * @return        void
2069
-     */
2070
-    public function add_xdebug_style()
2071
-    {
2072
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2073
-    }
2074
-
2075
-
2076
-    /************************/
2077
-    /** LIST TABLE METHODS **/
2078
-    /************************/
2079
-    /**
2080
-     * this sets up the list table if the current view requires it.
2081
-     *
2082
-     * @return void
2083
-     * @throws EE_Error
2084
-     */
2085
-    protected function _set_list_table()
2086
-    {
2087
-        // first is this a list_table view?
2088
-        if (! isset($this->_route_config['list_table'])) {
2089
-            return;
2090
-        } //not a list_table view so get out.
2091
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2092
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2093
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2094
-            // user error msg
2095
-            $error_msg = esc_html__(
2096
-                'An error occurred. The requested list table views could not be found.',
2097
-                'event_espresso'
2098
-            );
2099
-            // developer error msg
2100
-            $error_msg .= '||'
2101
-                          . sprintf(
2102
-                              esc_html__(
2103
-                                  '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.',
2104
-                                  'event_espresso'
2105
-                              ),
2106
-                              $this->_req_action,
2107
-                              $list_table_view
2108
-                          );
2109
-            throw new EE_Error($error_msg);
2110
-        }
2111
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2112
-        $this->_views = apply_filters(
2113
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2114
-            $this->_views
2115
-        );
2116
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2117
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2118
-        $this->_set_list_table_view();
2119
-        $this->_set_list_table_object();
2120
-    }
2121
-
2122
-
2123
-    /**
2124
-     * set current view for List Table
2125
-     *
2126
-     * @return void
2127
-     */
2128
-    protected function _set_list_table_view()
2129
-    {
2130
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2131
-        // looking at active items or dumpster diving ?
2132
-        if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2133
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2134
-        } else {
2135
-            $this->_view = sanitize_key($this->_req_data['status']);
2136
-        }
2137
-    }
2138
-
2139
-
2140
-    /**
2141
-     * _set_list_table_object
2142
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2143
-     *
2144
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2145
-     * @throws \InvalidArgumentException
2146
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2147
-     * @throws EE_Error
2148
-     * @throws InvalidInterfaceException
2149
-     */
2150
-    protected function _set_list_table_object()
2151
-    {
2152
-        if (isset($this->_route_config['list_table'])) {
2153
-            if (! class_exists($this->_route_config['list_table'])) {
2154
-                throw new EE_Error(
2155
-                    sprintf(
2156
-                        esc_html__(
2157
-                            '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.',
2158
-                            'event_espresso'
2159
-                        ),
2160
-                        $this->_route_config['list_table'],
2161
-                        get_class($this)
2162
-                    )
2163
-                );
2164
-            }
2165
-            $this->_list_table_object = $this->loader->getShared(
2166
-                $this->_route_config['list_table'],
2167
-                array($this)
2168
-            );
2169
-        }
2170
-    }
2171
-
2172
-
2173
-    /**
2174
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2175
-     *
2176
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2177
-     *                                                    urls.  The array should be indexed by the view it is being
2178
-     *                                                    added to.
2179
-     * @return array
2180
-     */
2181
-    public function get_list_table_view_RLs($extra_query_args = array())
2182
-    {
2183
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2184
-        if (empty($this->_views)) {
2185
-            $this->_views = array();
2186
-        }
2187
-        // cycle thru views
2188
-        foreach ($this->_views as $key => $view) {
2189
-            $query_args = array();
2190
-            // check for current view
2191
-            $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2192
-            $query_args['action'] = $this->_req_action;
2193
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2194
-            $query_args['status'] = $view['slug'];
2195
-            // merge any other arguments sent in.
2196
-            if (isset($extra_query_args[ $view['slug'] ])) {
2197
-                $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2198
-            }
2199
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2200
-        }
2201
-        return $this->_views;
2202
-    }
2203
-
2204
-
2205
-    /**
2206
-     * _entries_per_page_dropdown
2207
-     * generates a drop down box for selecting the number of visible rows in an admin page list table
2208
-     *
2209
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2210
-     *         WP does it.
2211
-     * @param int $max_entries total number of rows in the table
2212
-     * @return string
2213
-     */
2214
-    protected function _entries_per_page_dropdown($max_entries = 0)
2215
-    {
2216
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2217
-        $values = array(10, 25, 50, 100);
2218
-        $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2219
-        if ($max_entries) {
2220
-            $values[] = $max_entries;
2221
-            sort($values);
2222
-        }
2223
-        $entries_per_page_dropdown = '
104
+	/**
105
+	 * @var array $_route_config
106
+	 */
107
+	protected $_route_config;
108
+
109
+	/**
110
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
111
+	 * actions.
112
+	 *
113
+	 * @since 4.6.x
114
+	 * @var array.
115
+	 */
116
+	protected $_default_route_query_args;
117
+
118
+	// set via request page and action args.
119
+	protected $_current_page;
120
+
121
+	protected $_current_view;
122
+
123
+	protected $_current_page_view_url;
124
+
125
+	// sanitized request action (and nonce)
126
+
127
+	/**
128
+	 * @var string $_req_action
129
+	 */
130
+	protected $_req_action;
131
+
132
+	/**
133
+	 * @var string $_req_nonce
134
+	 */
135
+	protected $_req_nonce;
136
+
137
+	// search related
138
+	protected $_search_btn_label;
139
+
140
+	protected $_search_box_callback;
141
+
142
+	/**
143
+	 * WP Current Screen object
144
+	 *
145
+	 * @var WP_Screen
146
+	 */
147
+	protected $_current_screen;
148
+
149
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
150
+	protected $_hook_obj;
151
+
152
+	// for holding incoming request data
153
+	protected $_req_data = [];
154
+
155
+	// yes / no array for admin form fields
156
+	protected $_yes_no_values = array();
157
+
158
+	// some default things shared by all child classes
159
+	protected $_default_espresso_metaboxes;
160
+
161
+	/**
162
+	 *    EE_Registry Object
163
+	 *
164
+	 * @var    EE_Registry
165
+	 */
166
+	protected $EE = null;
167
+
168
+
169
+	/**
170
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
171
+	 *
172
+	 * @var boolean
173
+	 */
174
+	protected $_is_caf = false;
175
+
176
+
177
+	/**
178
+	 * @Constructor
179
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
180
+	 * @throws EE_Error
181
+	 * @throws InvalidArgumentException
182
+	 * @throws ReflectionException
183
+	 * @throws InvalidDataTypeException
184
+	 * @throws InvalidInterfaceException
185
+	 */
186
+	public function __construct($routing = true)
187
+	{
188
+		$this->loader = LoaderFactory::getLoader();
189
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
190
+			$this->_is_caf = true;
191
+		}
192
+		$this->_yes_no_values = array(
193
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
194
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
195
+		);
196
+		// set the _req_data property.
197
+		$this->_req_data = array_merge($_GET, $_POST);
198
+		// routing enabled?
199
+		$this->_routing = $routing;
200
+		// set initial page props (child method)
201
+		$this->_init_page_props();
202
+		// set global defaults
203
+		$this->_set_defaults();
204
+		// set early because incoming requests could be ajax related and we need to register those hooks.
205
+		$this->_global_ajax_hooks();
206
+		$this->_ajax_hooks();
207
+		// other_page_hooks have to be early too.
208
+		$this->_do_other_page_hooks();
209
+		// This just allows us to have extending classes do something specific
210
+		// before the parent constructor runs _page_setup().
211
+		if (method_exists($this, '_before_page_setup')) {
212
+			$this->_before_page_setup();
213
+		}
214
+		// set up page dependencies
215
+		$this->_page_setup();
216
+	}
217
+
218
+
219
+	/**
220
+	 * _init_page_props
221
+	 * Child classes use to set at least the following properties:
222
+	 * $page_slug.
223
+	 * $page_label.
224
+	 *
225
+	 * @abstract
226
+	 * @return void
227
+	 */
228
+	abstract protected function _init_page_props();
229
+
230
+
231
+	/**
232
+	 * _ajax_hooks
233
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
234
+	 * Note: within the ajax callback methods.
235
+	 *
236
+	 * @abstract
237
+	 * @return void
238
+	 */
239
+	abstract protected function _ajax_hooks();
240
+
241
+
242
+	/**
243
+	 * _define_page_props
244
+	 * child classes define page properties in here.  Must include at least:
245
+	 * $_admin_base_url = base_url for all admin pages
246
+	 * $_admin_page_title = default admin_page_title for admin pages
247
+	 * $_labels = array of default labels for various automatically generated elements:
248
+	 *    array(
249
+	 *        'buttons' => array(
250
+	 *            'add' => esc_html__('label for add new button'),
251
+	 *            'edit' => esc_html__('label for edit button'),
252
+	 *            'delete' => esc_html__('label for delete button')
253
+	 *            )
254
+	 *        )
255
+	 *
256
+	 * @abstract
257
+	 * @return void
258
+	 */
259
+	abstract protected function _define_page_props();
260
+
261
+
262
+	/**
263
+	 * _set_page_routes
264
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
265
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
266
+	 * have a 'default' route. Here's the format
267
+	 * $this->_page_routes = array(
268
+	 *        'default' => array(
269
+	 *            'func' => '_default_method_handling_route',
270
+	 *            'args' => array('array','of','args'),
271
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
272
+	 *            ajax request, backend processing)
273
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
274
+	 *            headers route after.  The string you enter here should match the defined route reference for a
275
+	 *            headers sent route.
276
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
277
+	 *            this route.
278
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
279
+	 *            checks).
280
+	 *        ),
281
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
282
+	 *        handling method.
283
+	 *        )
284
+	 * )
285
+	 *
286
+	 * @abstract
287
+	 * @return void
288
+	 */
289
+	abstract protected function _set_page_routes();
290
+
291
+
292
+	/**
293
+	 * _set_page_config
294
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
295
+	 * array corresponds to the page_route for the loaded page. Format:
296
+	 * $this->_page_config = array(
297
+	 *        'default' => array(
298
+	 *            'labels' => array(
299
+	 *                'buttons' => array(
300
+	 *                    'add' => esc_html__('label for adding item'),
301
+	 *                    'edit' => esc_html__('label for editing item'),
302
+	 *                    'delete' => esc_html__('label for deleting item')
303
+	 *                ),
304
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
305
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
306
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
307
+	 *            _define_page_props() method
308
+	 *            'nav' => array(
309
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
310
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
311
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
312
+	 *                'order' => 10, //required to indicate tab position.
313
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
314
+	 *                displayed then add this parameter.
315
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
316
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
317
+	 *            metaboxes set for eventespresso admin pages.
318
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
319
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
320
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
321
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
322
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
323
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
324
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
325
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
326
+	 *            want to display.
327
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
328
+	 *                'tab_id' => array(
329
+	 *                    'title' => 'tab_title',
330
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
331
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
332
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
333
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
334
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
335
+	 *                    attempt to use the callback which should match the name of a method in the class
336
+	 *                    ),
337
+	 *                'tab2_id' => array(
338
+	 *                    'title' => 'tab2 title',
339
+	 *                    'filename' => 'file_name_2'
340
+	 *                    'callback' => 'callback_method_for_content',
341
+	 *                 ),
342
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
343
+	 *            help tab area on an admin page. @link
344
+	 *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
345
+	 *            'help_tour' => array(
346
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
347
+	 *                in a folder for this admin page named "help_tours", a file name matching the key given here
348
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
349
+	 *            ),
350
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
351
+	 *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
352
+	 *            just set
353
+	 *            'require_nonce' to FALSE
354
+	 *            )
355
+	 * )
356
+	 *
357
+	 * @abstract
358
+	 * @return void
359
+	 */
360
+	abstract protected function _set_page_config();
361
+
362
+
363
+
364
+
365
+
366
+	/** end sample help_tour methods **/
367
+	/**
368
+	 * _add_screen_options
369
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
370
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
371
+	 * to a particular view.
372
+	 *
373
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
374
+	 *         see also WP_Screen object documents...
375
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
376
+	 * @abstract
377
+	 * @return void
378
+	 */
379
+	abstract protected function _add_screen_options();
380
+
381
+
382
+	/**
383
+	 * _add_feature_pointers
384
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
385
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
386
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
387
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
388
+	 * extended) also see:
389
+	 *
390
+	 * @link   http://eamann.com/tech/wordpress-portland/
391
+	 * @abstract
392
+	 * @return void
393
+	 */
394
+	abstract protected function _add_feature_pointers();
395
+
396
+
397
+	/**
398
+	 * load_scripts_styles
399
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
400
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
401
+	 * scripts/styles per view by putting them in a dynamic function in this format
402
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
403
+	 *
404
+	 * @abstract
405
+	 * @return void
406
+	 */
407
+	abstract public function load_scripts_styles();
408
+
409
+
410
+	/**
411
+	 * admin_init
412
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
413
+	 * all pages/views loaded by child class.
414
+	 *
415
+	 * @abstract
416
+	 * @return void
417
+	 */
418
+	abstract public function admin_init();
419
+
420
+
421
+	/**
422
+	 * admin_notices
423
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
424
+	 * all pages/views loaded by child class.
425
+	 *
426
+	 * @abstract
427
+	 * @return void
428
+	 */
429
+	abstract public function admin_notices();
430
+
431
+
432
+	/**
433
+	 * admin_footer_scripts
434
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
435
+	 * will apply to all pages/views loaded by child class.
436
+	 *
437
+	 * @return void
438
+	 */
439
+	abstract public function admin_footer_scripts();
440
+
441
+
442
+	/**
443
+	 * admin_footer
444
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
445
+	 * apply to all pages/views loaded by child class.
446
+	 *
447
+	 * @return void
448
+	 */
449
+	public function admin_footer()
450
+	{
451
+	}
452
+
453
+
454
+	/**
455
+	 * _global_ajax_hooks
456
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
457
+	 * Note: within the ajax callback methods.
458
+	 *
459
+	 * @abstract
460
+	 * @return void
461
+	 */
462
+	protected function _global_ajax_hooks()
463
+	{
464
+		// for lazy loading of metabox content
465
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
466
+	}
467
+
468
+
469
+	public function ajax_metabox_content()
470
+	{
471
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
472
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
473
+		self::cached_rss_display($contentid, $url);
474
+		wp_die();
475
+	}
476
+
477
+
478
+	/**
479
+	 * _page_setup
480
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
481
+	 * doesn't match the object.
482
+	 *
483
+	 * @final
484
+	 * @return void
485
+	 * @throws EE_Error
486
+	 * @throws InvalidArgumentException
487
+	 * @throws ReflectionException
488
+	 * @throws InvalidDataTypeException
489
+	 * @throws InvalidInterfaceException
490
+	 */
491
+	final protected function _page_setup()
492
+	{
493
+		// requires?
494
+		// admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
495
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
496
+		// next verify if we need to load anything...
497
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
498
+		$this->page_folder = strtolower(
499
+			str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
500
+		);
501
+		global $ee_menu_slugs;
502
+		$ee_menu_slugs = (array) $ee_menu_slugs;
503
+		if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) {
504
+			return;
505
+		}
506
+		// becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
507
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
508
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
509
+				? $this->_req_data['action2']
510
+				: $this->_req_data['action'];
511
+		}
512
+		// then set blank or -1 action values to 'default'
513
+		$this->_req_action = isset($this->_req_data['action'])
514
+							 && ! empty($this->_req_data['action'])
515
+							 && $this->_req_data['action'] !== '-1'
516
+			? sanitize_key($this->_req_data['action'])
517
+			: 'default';
518
+		// if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
519
+		//  This covers cases where we're coming in from a list table that isn't on the default route.
520
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
521
+			? $this->_req_data['route'] : $this->_req_action;
522
+		// however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
523
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route'])
524
+			? $this->_req_data['route']
525
+			: $this->_req_action;
526
+		$this->_current_view = $this->_req_action;
527
+		$this->_req_nonce = $this->_req_action . '_nonce';
528
+		$this->_define_page_props();
529
+		$this->_current_page_view_url = add_query_arg(
530
+			array('page' => $this->_current_page, 'action' => $this->_current_view),
531
+			$this->_admin_base_url
532
+		);
533
+		// default things
534
+		$this->_default_espresso_metaboxes = array(
535
+			'_espresso_news_post_box',
536
+			'_espresso_links_post_box',
537
+			'_espresso_ratings_request',
538
+			'_espresso_sponsors_post_box',
539
+		);
540
+		// set page configs
541
+		$this->_set_page_routes();
542
+		$this->_set_page_config();
543
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
544
+		if (isset($this->_req_data['wp_referer'])) {
545
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
546
+		}
547
+		// for caffeinated and other extended functionality.
548
+		//  If there is a _extend_page_config method
549
+		// then let's run that to modify the all the various page configuration arrays
550
+		if (method_exists($this, '_extend_page_config')) {
551
+			$this->_extend_page_config();
552
+		}
553
+		// for CPT and other extended functionality.
554
+		// If there is an _extend_page_config_for_cpt
555
+		// then let's run that to modify all the various page configuration arrays.
556
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
557
+			$this->_extend_page_config_for_cpt();
558
+		}
559
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
560
+		$this->_page_routes = apply_filters(
561
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
562
+			$this->_page_routes,
563
+			$this
564
+		);
565
+		$this->_page_config = apply_filters(
566
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
567
+			$this->_page_config,
568
+			$this
569
+		);
570
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
571
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
572
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
573
+			add_action(
574
+				'AHEE__EE_Admin_Page__route_admin_request',
575
+				array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
576
+				10,
577
+				2
578
+			);
579
+		}
580
+		// next route only if routing enabled
581
+		if ($this->_routing && ! defined('DOING_AJAX')) {
582
+			$this->_verify_routes();
583
+			// next let's just check user_access and kill if no access
584
+			$this->check_user_access();
585
+			if ($this->_is_UI_request) {
586
+				// admin_init stuff - global, all views for this page class, specific view
587
+				add_action('admin_init', array($this, 'admin_init'), 10);
588
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
589
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
590
+				}
591
+			} else {
592
+				// hijack regular WP loading and route admin request immediately
593
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
594
+				$this->route_admin_request();
595
+			}
596
+		}
597
+	}
598
+
599
+
600
+	/**
601
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
602
+	 *
603
+	 * @return void
604
+	 * @throws ReflectionException
605
+	 * @throws EE_Error
606
+	 */
607
+	private function _do_other_page_hooks()
608
+	{
609
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
610
+		foreach ($registered_pages as $page) {
611
+			// now let's setup the file name and class that should be present
612
+			$classname = str_replace('.class.php', '', $page);
613
+			// autoloaders should take care of loading file
614
+			if (! class_exists($classname)) {
615
+				$error_msg[] = sprintf(
616
+					esc_html__(
617
+						'Something went wrong with loading the %s admin hooks page.',
618
+						'event_espresso'
619
+					),
620
+					$page
621
+				);
622
+				$error_msg[] = $error_msg[0]
623
+							   . "\r\n"
624
+							   . sprintf(
625
+								   esc_html__(
626
+									   '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',
627
+									   'event_espresso'
628
+								   ),
629
+								   $page,
630
+								   '<br />',
631
+								   '<strong>' . $classname . '</strong>'
632
+							   );
633
+				throw new EE_Error(implode('||', $error_msg));
634
+			}
635
+			$a = new ReflectionClass($classname);
636
+			// notice we are passing the instance of this class to the hook object.
637
+			$hookobj[] = $a->newInstance($this);
638
+		}
639
+	}
640
+
641
+
642
+	public function load_page_dependencies()
643
+	{
644
+		try {
645
+			$this->_load_page_dependencies();
646
+		} catch (EE_Error $e) {
647
+			$e->get_error();
648
+		}
649
+	}
650
+
651
+
652
+	/**
653
+	 * load_page_dependencies
654
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
655
+	 *
656
+	 * @return void
657
+	 * @throws DomainException
658
+	 * @throws EE_Error
659
+	 * @throws InvalidArgumentException
660
+	 * @throws InvalidDataTypeException
661
+	 * @throws InvalidInterfaceException
662
+	 * @throws ReflectionException
663
+	 */
664
+	protected function _load_page_dependencies()
665
+	{
666
+		// let's set the current_screen and screen options to override what WP set
667
+		$this->_current_screen = get_current_screen();
668
+		// load admin_notices - global, page class, and view specific
669
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
670
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
671
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
672
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
673
+		}
674
+		// load network admin_notices - global, page class, and view specific
675
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
676
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
677
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
678
+		}
679
+		// this will save any per_page screen options if they are present
680
+		$this->_set_per_page_screen_options();
681
+		// setup list table properties
682
+		$this->_set_list_table();
683
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
684
+		// However in some cases the metaboxes will need to be added within a route handling callback.
685
+		$this->_add_registered_meta_boxes();
686
+		$this->_add_screen_columns();
687
+		// add screen options - global, page child class, and view specific
688
+		$this->_add_global_screen_options();
689
+		$this->_add_screen_options();
690
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
691
+		if (method_exists($this, $add_screen_options)) {
692
+			$this->{$add_screen_options}();
693
+		}
694
+		// add help tab(s) and tours- set via page_config and qtips.
695
+		// $this->_add_help_tour();
696
+		$this->_add_help_tabs();
697
+		$this->_add_qtips();
698
+		// add feature_pointers - global, page child class, and view specific
699
+		$this->_add_feature_pointers();
700
+		$this->_add_global_feature_pointers();
701
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
702
+		if (method_exists($this, $add_feature_pointer)) {
703
+			$this->{$add_feature_pointer}();
704
+		}
705
+		// enqueue scripts/styles - global, page class, and view specific
706
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
707
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
708
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
709
+			add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
710
+		}
711
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
712
+		// admin_print_footer_scripts - global, page child class, and view specific.
713
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
714
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
715
+		// is a good use case. Notice the late priority we're giving these
716
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
717
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
718
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
719
+			add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
720
+		}
721
+		// admin footer scripts
722
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
723
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
724
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
725
+			add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
726
+		}
727
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
728
+		// targeted hook
729
+		do_action(
730
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
731
+		);
732
+	}
733
+
734
+
735
+	/**
736
+	 * _set_defaults
737
+	 * This sets some global defaults for class properties.
738
+	 */
739
+	private function _set_defaults()
740
+	{
741
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
742
+		$this->_event = $this->_template_path = $this->_column_template_path = null;
743
+		$this->_nav_tabs = $this->_views = $this->_page_routes = array();
744
+		$this->_page_config = $this->_default_route_query_args = array();
745
+		$this->_default_nav_tab_name = 'overview';
746
+		// init template args
747
+		$this->_template_args = array(
748
+			'admin_page_header'  => '',
749
+			'admin_page_content' => '',
750
+			'post_body_content'  => '',
751
+			'before_list_table'  => '',
752
+			'after_list_table'   => '',
753
+		);
754
+	}
755
+
756
+
757
+	/**
758
+	 * route_admin_request
759
+	 *
760
+	 * @see    _route_admin_request()
761
+	 * @return exception|void error
762
+	 * @throws InvalidArgumentException
763
+	 * @throws InvalidInterfaceException
764
+	 * @throws InvalidDataTypeException
765
+	 * @throws EE_Error
766
+	 * @throws ReflectionException
767
+	 */
768
+	public function route_admin_request()
769
+	{
770
+		try {
771
+			$this->_route_admin_request();
772
+		} catch (EE_Error $e) {
773
+			$e->get_error();
774
+		}
775
+	}
776
+
777
+
778
+	public function set_wp_page_slug($wp_page_slug)
779
+	{
780
+		$this->_wp_page_slug = $wp_page_slug;
781
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
782
+		if (is_network_admin()) {
783
+			$this->_wp_page_slug .= '-network';
784
+		}
785
+	}
786
+
787
+
788
+	/**
789
+	 * _verify_routes
790
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
791
+	 * we know if we need to drop out.
792
+	 *
793
+	 * @return bool
794
+	 * @throws EE_Error
795
+	 */
796
+	protected function _verify_routes()
797
+	{
798
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
799
+		if (! $this->_current_page && ! defined('DOING_AJAX')) {
800
+			return false;
801
+		}
802
+		$this->_route = false;
803
+		// check that the page_routes array is not empty
804
+		if (empty($this->_page_routes)) {
805
+			// user error msg
806
+			$error_msg = sprintf(
807
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
808
+				$this->_admin_page_title
809
+			);
810
+			// developer error msg
811
+			$error_msg .= '||' . $error_msg
812
+						  . esc_html__(
813
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
814
+							  'event_espresso'
815
+						  );
816
+			throw new EE_Error($error_msg);
817
+		}
818
+		// and that the requested page route exists
819
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
820
+			$this->_route = $this->_page_routes[ $this->_req_action ];
821
+			$this->_route_config = isset($this->_page_config[ $this->_req_action ])
822
+				? $this->_page_config[ $this->_req_action ] : array();
823
+		} else {
824
+			// user error msg
825
+			$error_msg = sprintf(
826
+				esc_html__(
827
+					'The requested page route does not exist for the %s admin page.',
828
+					'event_espresso'
829
+				),
830
+				$this->_admin_page_title
831
+			);
832
+			// developer error msg
833
+			$error_msg .= '||' . $error_msg
834
+						  . sprintf(
835
+							  esc_html__(
836
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
837
+								  'event_espresso'
838
+							  ),
839
+							  $this->_req_action
840
+						  );
841
+			throw new EE_Error($error_msg);
842
+		}
843
+		// and that a default route exists
844
+		if (! array_key_exists('default', $this->_page_routes)) {
845
+			// user error msg
846
+			$error_msg = sprintf(
847
+				esc_html__(
848
+					'A default page route has not been set for the % admin page.',
849
+					'event_espresso'
850
+				),
851
+				$this->_admin_page_title
852
+			);
853
+			// developer error msg
854
+			$error_msg .= '||' . $error_msg
855
+						  . esc_html__(
856
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
857
+							  'event_espresso'
858
+						  );
859
+			throw new EE_Error($error_msg);
860
+		}
861
+		// first lets' catch if the UI request has EVER been set.
862
+		if ($this->_is_UI_request === null) {
863
+			// lets set if this is a UI request or not.
864
+			$this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
865
+			// wait a minute... we might have a noheader in the route array
866
+			$this->_is_UI_request = is_array($this->_route)
867
+									&& isset($this->_route['noheader'])
868
+									&& $this->_route['noheader'] ? false : $this->_is_UI_request;
869
+		}
870
+		$this->_set_current_labels();
871
+		return true;
872
+	}
873
+
874
+
875
+	/**
876
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
877
+	 *
878
+	 * @param  string $route the route name we're verifying
879
+	 * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
880
+	 * @throws EE_Error
881
+	 */
882
+	protected function _verify_route($route)
883
+	{
884
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
885
+			return true;
886
+		}
887
+		// user error msg
888
+		$error_msg = sprintf(
889
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
890
+			$this->_admin_page_title
891
+		);
892
+		// developer error msg
893
+		$error_msg .= '||' . $error_msg
894
+					  . sprintf(
895
+						  esc_html__(
896
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
897
+							  'event_espresso'
898
+						  ),
899
+						  $route
900
+					  );
901
+		throw new EE_Error($error_msg);
902
+	}
903
+
904
+
905
+	/**
906
+	 * perform nonce verification
907
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
908
+	 * using this method (and save retyping!)
909
+	 *
910
+	 * @param  string $nonce     The nonce sent
911
+	 * @param  string $nonce_ref The nonce reference string (name0)
912
+	 * @return void
913
+	 * @throws EE_Error
914
+	 */
915
+	protected function _verify_nonce($nonce, $nonce_ref)
916
+	{
917
+		// verify nonce against expected value
918
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
919
+			// these are not the droids you are looking for !!!
920
+			$msg = sprintf(
921
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
922
+				'<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
923
+				'</a>'
924
+			);
925
+			if (WP_DEBUG) {
926
+				$msg .= "\n  "
927
+						. sprintf(
928
+							esc_html__(
929
+								'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
930
+								'event_espresso'
931
+							),
932
+							__CLASS__
933
+						);
934
+			}
935
+			if (! defined('DOING_AJAX')) {
936
+				wp_die($msg);
937
+			} else {
938
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
939
+				$this->_return_json();
940
+			}
941
+		}
942
+	}
943
+
944
+
945
+	/**
946
+	 * _route_admin_request()
947
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
948
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
949
+	 * in the page routes and then will try to load the corresponding method.
950
+	 *
951
+	 * @return void
952
+	 * @throws EE_Error
953
+	 * @throws InvalidArgumentException
954
+	 * @throws InvalidDataTypeException
955
+	 * @throws InvalidInterfaceException
956
+	 * @throws ReflectionException
957
+	 */
958
+	protected function _route_admin_request()
959
+	{
960
+		if (! $this->_is_UI_request) {
961
+			$this->_verify_routes();
962
+		}
963
+		$nonce_check = isset($this->_route_config['require_nonce'])
964
+			? $this->_route_config['require_nonce']
965
+			: true;
966
+		if ($this->_req_action !== 'default' && $nonce_check) {
967
+			// set nonce from post data
968
+			$nonce = isset($this->_req_data[ $this->_req_nonce ])
969
+				? sanitize_text_field($this->_req_data[ $this->_req_nonce ])
970
+				: '';
971
+			$this->_verify_nonce($nonce, $this->_req_nonce);
972
+		}
973
+		// set the nav_tabs array but ONLY if this is  UI_request
974
+		if ($this->_is_UI_request) {
975
+			$this->_set_nav_tabs();
976
+		}
977
+		// grab callback function
978
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
979
+		// check if callback has args
980
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
981
+		$error_msg = '';
982
+		// action right before calling route
983
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
984
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
985
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
986
+		}
987
+		// right before calling the route, let's remove _wp_http_referer from the
988
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
989
+		$_SERVER['REQUEST_URI'] = remove_query_arg(
990
+			'_wp_http_referer',
991
+			wp_unslash($_SERVER['REQUEST_URI'])
992
+		);
993
+		if (! empty($func)) {
994
+			if (is_array($func)) {
995
+				list($class, $method) = $func;
996
+			} elseif (strpos($func, '::') !== false) {
997
+				list($class, $method) = explode('::', $func);
998
+			} else {
999
+				$class = $this;
1000
+				$method = $func;
1001
+			}
1002
+			if (! (is_object($class) && $class === $this)) {
1003
+				// send along this admin page object for access by addons.
1004
+				$args['admin_page_object'] = $this;
1005
+			}
1006
+			if (// is it a method on a class that doesn't work?
1007
+				(
1008
+					(
1009
+						method_exists($class, $method)
1010
+						&& call_user_func_array(array($class, $method), $args) === false
1011
+					)
1012
+					&& (
1013
+						// is it a standalone function that doesn't work?
1014
+						function_exists($method)
1015
+						&& call_user_func_array(
1016
+							$func,
1017
+							array_merge(array('admin_page_object' => $this), $args)
1018
+						) === false
1019
+					)
1020
+				)
1021
+				|| (
1022
+					// is it neither a class method NOR a standalone function?
1023
+					! method_exists($class, $method)
1024
+					&& ! function_exists($method)
1025
+				)
1026
+			) {
1027
+				// user error msg
1028
+				$error_msg = esc_html__(
1029
+					'An error occurred. The  requested page route could not be found.',
1030
+					'event_espresso'
1031
+				);
1032
+				// developer error msg
1033
+				$error_msg .= '||';
1034
+				$error_msg .= sprintf(
1035
+					esc_html__(
1036
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1037
+						'event_espresso'
1038
+					),
1039
+					$method
1040
+				);
1041
+			}
1042
+			if (! empty($error_msg)) {
1043
+				throw new EE_Error($error_msg);
1044
+			}
1045
+		}
1046
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1047
+		// then we need to reset the routing properties to the new route.
1048
+		// 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.
1049
+		if ($this->_is_UI_request === false
1050
+			&& is_array($this->_route)
1051
+			&& ! empty($this->_route['headers_sent_route'])
1052
+		) {
1053
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1054
+		}
1055
+	}
1056
+
1057
+
1058
+	/**
1059
+	 * This method just allows the resetting of page properties in the case where a no headers
1060
+	 * route redirects to a headers route in its route config.
1061
+	 *
1062
+	 * @since   4.3.0
1063
+	 * @param  string $new_route New (non header) route to redirect to.
1064
+	 * @return   void
1065
+	 * @throws ReflectionException
1066
+	 * @throws InvalidArgumentException
1067
+	 * @throws InvalidInterfaceException
1068
+	 * @throws InvalidDataTypeException
1069
+	 * @throws EE_Error
1070
+	 */
1071
+	protected function _reset_routing_properties($new_route)
1072
+	{
1073
+		$this->_is_UI_request = true;
1074
+		// now we set the current route to whatever the headers_sent_route is set at
1075
+		$this->_req_data['action'] = $new_route;
1076
+		// rerun page setup
1077
+		$this->_page_setup();
1078
+	}
1079
+
1080
+
1081
+	/**
1082
+	 * _add_query_arg
1083
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1084
+	 *(internally just uses EEH_URL's function with the same name)
1085
+	 *
1086
+	 * @param array  $args
1087
+	 * @param string $url
1088
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1089
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1090
+	 *                                        Example usage: If the current page is:
1091
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1092
+	 *                                        &action=default&event_id=20&month_range=March%202015
1093
+	 *                                        &_wpnonce=5467821
1094
+	 *                                        and you call:
1095
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1096
+	 *                                        array(
1097
+	 *                                        'action' => 'resend_something',
1098
+	 *                                        'page=>espresso_registrations'
1099
+	 *                                        ),
1100
+	 *                                        $some_url,
1101
+	 *                                        true
1102
+	 *                                        );
1103
+	 *                                        It will produce a url in this structure:
1104
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1105
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1106
+	 *                                        month_range]=March%202015
1107
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1108
+	 * @return string
1109
+	 */
1110
+	public static function add_query_args_and_nonce(
1111
+		$args = array(),
1112
+		$url = false,
1113
+		$sticky = false,
1114
+		$exclude_nonce = false
1115
+	) {
1116
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1117
+		if ($sticky) {
1118
+			$request = $_REQUEST;
1119
+			unset($request['_wp_http_referer']);
1120
+			unset($request['wp_referer']);
1121
+			foreach ($request as $key => $value) {
1122
+				// do not add nonces
1123
+				if (strpos($key, 'nonce') !== false) {
1124
+					continue;
1125
+				}
1126
+				$args[ 'wp_referer[' . $key . ']' ] = $value;
1127
+			}
1128
+		}
1129
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1130
+	}
1131
+
1132
+
1133
+	/**
1134
+	 * This returns a generated link that will load the related help tab.
1135
+	 *
1136
+	 * @param  string $help_tab_id the id for the connected help tab
1137
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1138
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1139
+	 * @uses EEH_Template::get_help_tab_link()
1140
+	 * @return string              generated link
1141
+	 */
1142
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1143
+	{
1144
+		return EEH_Template::get_help_tab_link(
1145
+			$help_tab_id,
1146
+			$this->page_slug,
1147
+			$this->_req_action,
1148
+			$icon_style,
1149
+			$help_text
1150
+		);
1151
+	}
1152
+
1153
+
1154
+	/**
1155
+	 * _add_help_tabs
1156
+	 * Note child classes define their help tabs within the page_config array.
1157
+	 *
1158
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1159
+	 * @return void
1160
+	 * @throws DomainException
1161
+	 * @throws EE_Error
1162
+	 */
1163
+	protected function _add_help_tabs()
1164
+	{
1165
+		$tour_buttons = '';
1166
+		if (isset($this->_page_config[ $this->_req_action ])) {
1167
+			$config = $this->_page_config[ $this->_req_action ];
1168
+			// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1169
+			// is there a help tour for the current route?  if there is let's setup the tour buttons
1170
+			// if (isset($this->_help_tour[ $this->_req_action ])) {
1171
+			//     $tb = array();
1172
+			//     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1173
+			//     foreach ($this->_help_tour['tours'] as $tour) {
1174
+			//         // if this is the end tour then we don't need to setup a button
1175
+			//         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1176
+			//             continue;
1177
+			//         }
1178
+			//         $tb[] = '<button id="trigger-tour-'
1179
+			//                 . $tour->get_slug()
1180
+			//                 . '" class="button-primary trigger-ee-help-tour">'
1181
+			//                 . $tour->get_label()
1182
+			//                 . '</button>';
1183
+			//     }
1184
+			//     $tour_buttons .= implode('<br />', $tb);
1185
+			//     $tour_buttons .= '</div></div>';
1186
+			// }
1187
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1188
+			if (is_array($config) && isset($config['help_sidebar'])) {
1189
+				// check that the callback given is valid
1190
+				if (! method_exists($this, $config['help_sidebar'])) {
1191
+					throw new EE_Error(
1192
+						sprintf(
1193
+							esc_html__(
1194
+								'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',
1195
+								'event_espresso'
1196
+							),
1197
+							$config['help_sidebar'],
1198
+							get_class($this)
1199
+						)
1200
+					);
1201
+				}
1202
+				$content = apply_filters(
1203
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1204
+					$this->{$config['help_sidebar']}()
1205
+				);
1206
+				$content .= $tour_buttons; // add help tour buttons.
1207
+				// do we have any help tours setup?  Cause if we do we want to add the buttons
1208
+				$this->_current_screen->set_help_sidebar($content);
1209
+			}
1210
+			// if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar.
1211
+			if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1212
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1213
+			}
1214
+			// handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1215
+			if (! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1216
+				$_ht['id'] = $this->page_slug;
1217
+				$_ht['title'] = esc_html__('Help Tours', 'event_espresso');
1218
+				$_ht['content'] = '<p>'
1219
+								  . esc_html__(
1220
+									  'The buttons to the right allow you to start/restart any help tours available for this page',
1221
+									  'event_espresso'
1222
+								  ) . '</p>';
1223
+				$this->_current_screen->add_help_tab($_ht);
1224
+			}
1225
+			if (! isset($config['help_tabs'])) {
1226
+				return;
1227
+			} //no help tabs for this route
1228
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1229
+				// we're here so there ARE help tabs!
1230
+				// make sure we've got what we need
1231
+				if (! isset($cfg['title'])) {
1232
+					throw new EE_Error(
1233
+						esc_html__(
1234
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1235
+							'event_espresso'
1236
+						)
1237
+					);
1238
+				}
1239
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1240
+					throw new EE_Error(
1241
+						esc_html__(
1242
+							'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',
1243
+							'event_espresso'
1244
+						)
1245
+					);
1246
+				}
1247
+				// first priority goes to content.
1248
+				if (! empty($cfg['content'])) {
1249
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1250
+					// second priority goes to filename
1251
+				} elseif (! empty($cfg['filename'])) {
1252
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1253
+					// 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)
1254
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1255
+															 . basename($this->_get_dir())
1256
+															 . '/help_tabs/'
1257
+															 . $cfg['filename']
1258
+															 . '.help_tab.php' : $file_path;
1259
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1260
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1261
+						EE_Error::add_error(
1262
+							sprintf(
1263
+								esc_html__(
1264
+									'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',
1265
+									'event_espresso'
1266
+								),
1267
+								$tab_id,
1268
+								key($config),
1269
+								$file_path
1270
+							),
1271
+							__FILE__,
1272
+							__FUNCTION__,
1273
+							__LINE__
1274
+						);
1275
+						return;
1276
+					}
1277
+					$template_args['admin_page_obj'] = $this;
1278
+					$content = EEH_Template::display_template(
1279
+						$file_path,
1280
+						$template_args,
1281
+						true
1282
+					);
1283
+				} else {
1284
+					$content = '';
1285
+				}
1286
+				// check if callback is valid
1287
+				if (empty($content) && (
1288
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1289
+					)
1290
+				) {
1291
+					EE_Error::add_error(
1292
+						sprintf(
1293
+							esc_html__(
1294
+								'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.',
1295
+								'event_espresso'
1296
+							),
1297
+							$cfg['title']
1298
+						),
1299
+						__FILE__,
1300
+						__FUNCTION__,
1301
+						__LINE__
1302
+					);
1303
+					return;
1304
+				}
1305
+				// setup config array for help tab method
1306
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1307
+				$_ht = array(
1308
+					'id'       => $id,
1309
+					'title'    => $cfg['title'],
1310
+					'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1311
+					'content'  => $content,
1312
+				);
1313
+				$this->_current_screen->add_help_tab($_ht);
1314
+			}
1315
+		}
1316
+	}
1317
+
1318
+
1319
+	/**
1320
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1321
+	 * an array with properties for setting up usage of the joyride plugin
1322
+	 *
1323
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1324
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1325
+	 *         _set_page_config() comments
1326
+	 * @return void
1327
+	 * @throws EE_Error
1328
+	 * @throws InvalidArgumentException
1329
+	 * @throws InvalidDataTypeException
1330
+	 * @throws InvalidInterfaceException
1331
+	 */
1332
+	protected function _add_help_tour()
1333
+	{
1334
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1335
+		// $tours = array();
1336
+		// $this->_help_tour = array();
1337
+		// // exit early if help tours are turned off globally
1338
+		// if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1339
+		//     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1340
+		// ) {
1341
+		//     return;
1342
+		// }
1343
+		// // loop through _page_config to find any help_tour defined
1344
+		// foreach ($this->_page_config as $route => $config) {
1345
+		//     // we're only going to set things up for this route
1346
+		//     if ($route !== $this->_req_action) {
1347
+		//         continue;
1348
+		//     }
1349
+		//     if (isset($config['help_tour'])) {
1350
+		//         foreach ($config['help_tour'] as $tour) {
1351
+		//             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1352
+		//             // let's see if we can get that file...
1353
+		//             // if not its possible this is a decaf route not set in caffeinated
1354
+		//             // so lets try and get the caffeinated equivalent
1355
+		//             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1356
+		//                                                      . basename($this->_get_dir())
1357
+		//                                                      . '/help_tours/'
1358
+		//                                                      . $tour
1359
+		//                                                      . '.class.php' : $file_path;
1360
+		//             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1361
+		//             if (! is_readable($file_path)) {
1362
+		//                 EE_Error::add_error(
1363
+		//                     sprintf(
1364
+		//                         esc_html__(
1365
+		//                             'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1366
+		//                             'event_espresso'
1367
+		//                         ),
1368
+		//                         $file_path,
1369
+		//                         $tour
1370
+		//                     ),
1371
+		//                     __FILE__,
1372
+		//                     __FUNCTION__,
1373
+		//                     __LINE__
1374
+		//                 );
1375
+		//                 return;
1376
+		//             }
1377
+		//             require_once $file_path;
1378
+		//             if (! class_exists($tour)) {
1379
+		//                 $error_msg[] = sprintf(
1380
+		//                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1381
+		//                     $tour
1382
+		//                 );
1383
+		//                 $error_msg[] = $error_msg[0] . "\r\n"
1384
+		//                                . sprintf(
1385
+		//                                    esc_html__(
1386
+		//                                        'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1387
+		//                                        'event_espresso'
1388
+		//                                    ),
1389
+		//                                    $tour,
1390
+		//                                    '<br />',
1391
+		//                                    $tour,
1392
+		//                                    $this->_req_action,
1393
+		//                                    get_class($this)
1394
+		//                                );
1395
+		//                 throw new EE_Error(implode('||', $error_msg));
1396
+		//             }
1397
+		//             $tour_obj = new $tour($this->_is_caf);
1398
+		//             $tours[] = $tour_obj;
1399
+		//             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1400
+		//         }
1401
+		//         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1402
+		//         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1403
+		//         $tours[] = $end_stop_tour;
1404
+		//         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1405
+		//     }
1406
+		// }
1407
+		//
1408
+		// if (! empty($tours)) {
1409
+		//     $this->_help_tour['tours'] = $tours;
1410
+		// }
1411
+		// // that's it!  Now that the $_help_tours property is set (or not)
1412
+		// // the scripts and html should be taken care of automatically.
1413
+		//
1414
+		// /**
1415
+		//  * Allow extending the help tours variable.
1416
+		//  *
1417
+		//  * @param Array $_help_tour The array containing all help tour information to be displayed.
1418
+		//  */
1419
+		// $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1420
+	}
1421
+
1422
+
1423
+	/**
1424
+	 * This simply sets up any qtips that have been defined in the page config
1425
+	 *
1426
+	 * @return void
1427
+	 */
1428
+	protected function _add_qtips()
1429
+	{
1430
+		if (isset($this->_route_config['qtips'])) {
1431
+			$qtips = (array) $this->_route_config['qtips'];
1432
+			// load qtip loader
1433
+			$path = array(
1434
+				$this->_get_dir() . '/qtips/',
1435
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1436
+			);
1437
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1438
+		}
1439
+	}
1440
+
1441
+
1442
+	/**
1443
+	 * _set_nav_tabs
1444
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1445
+	 * wish to add additional tabs or modify accordingly.
1446
+	 *
1447
+	 * @return void
1448
+	 * @throws InvalidArgumentException
1449
+	 * @throws InvalidInterfaceException
1450
+	 * @throws InvalidDataTypeException
1451
+	 */
1452
+	protected function _set_nav_tabs()
1453
+	{
1454
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1455
+		$i = 0;
1456
+		foreach ($this->_page_config as $slug => $config) {
1457
+			if (! is_array($config)
1458
+				|| (
1459
+					is_array($config)
1460
+					&& (
1461
+						(isset($config['nav']) && ! $config['nav'])
1462
+						|| ! isset($config['nav'])
1463
+					)
1464
+				)
1465
+			) {
1466
+				continue;
1467
+			}
1468
+			// no nav tab for this config
1469
+			// check for persistent flag
1470
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1471
+				// nav tab is only to appear when route requested.
1472
+				continue;
1473
+			}
1474
+			if (! $this->check_user_access($slug, true)) {
1475
+				// no nav tab because current user does not have access.
1476
+				continue;
1477
+			}
1478
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1479
+			$this->_nav_tabs[ $slug ] = array(
1480
+				'url'       => isset($config['nav']['url'])
1481
+					? $config['nav']['url']
1482
+					: self::add_query_args_and_nonce(
1483
+						array('action' => $slug),
1484
+						$this->_admin_base_url
1485
+					),
1486
+				'link_text' => isset($config['nav']['label'])
1487
+					? $config['nav']['label']
1488
+					: ucwords(
1489
+						str_replace('_', ' ', $slug)
1490
+					),
1491
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1492
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1493
+			);
1494
+			$i++;
1495
+		}
1496
+		// if $this->_nav_tabs is empty then lets set the default
1497
+		if (empty($this->_nav_tabs)) {
1498
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = array(
1499
+				'url'       => $this->_admin_base_url,
1500
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1501
+				'css_class' => 'nav-tab-active',
1502
+				'order'     => 10,
1503
+			);
1504
+		}
1505
+		// now let's sort the tabs according to order
1506
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1507
+	}
1508
+
1509
+
1510
+	/**
1511
+	 * _set_current_labels
1512
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1513
+	 * property array
1514
+	 *
1515
+	 * @return void
1516
+	 */
1517
+	private function _set_current_labels()
1518
+	{
1519
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1520
+			foreach ($this->_route_config['labels'] as $label => $text) {
1521
+				if (is_array($text)) {
1522
+					foreach ($text as $sublabel => $subtext) {
1523
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1524
+					}
1525
+				} else {
1526
+					$this->_labels[ $label ] = $text;
1527
+				}
1528
+			}
1529
+		}
1530
+	}
1531
+
1532
+
1533
+	/**
1534
+	 *        verifies user access for this admin page
1535
+	 *
1536
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1537
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1538
+	 *                               return false if verify fail.
1539
+	 * @return bool
1540
+	 * @throws InvalidArgumentException
1541
+	 * @throws InvalidDataTypeException
1542
+	 * @throws InvalidInterfaceException
1543
+	 */
1544
+	public function check_user_access($route_to_check = '', $verify_only = false)
1545
+	{
1546
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1547
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1548
+		$capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1549
+					  && is_array(
1550
+						  $this->_page_routes[ $route_to_check ]
1551
+					  )
1552
+					  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1553
+			? $this->_page_routes[ $route_to_check ]['capability'] : null;
1554
+		if (empty($capability) && empty($route_to_check)) {
1555
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1556
+				: $this->_route['capability'];
1557
+		} else {
1558
+			$capability = empty($capability) ? 'manage_options' : $capability;
1559
+		}
1560
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1561
+		if (! defined('DOING_AJAX')
1562
+			&& (
1563
+				! function_exists('is_admin')
1564
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1565
+					$capability,
1566
+					$this->page_slug
1567
+					. '_'
1568
+					. $route_to_check,
1569
+					$id
1570
+				)
1571
+			)
1572
+		) {
1573
+			if ($verify_only) {
1574
+				return false;
1575
+			}
1576
+			if (is_user_logged_in()) {
1577
+				wp_die(__('You do not have access to this route.', 'event_espresso'));
1578
+			} else {
1579
+				return false;
1580
+			}
1581
+		}
1582
+		return true;
1583
+	}
1584
+
1585
+
1586
+	/**
1587
+	 * admin_init_global
1588
+	 * This runs all the code that we want executed within the WP admin_init hook.
1589
+	 * This method executes for ALL EE Admin pages.
1590
+	 *
1591
+	 * @return void
1592
+	 */
1593
+	public function admin_init_global()
1594
+	{
1595
+	}
1596
+
1597
+
1598
+	/**
1599
+	 * wp_loaded_global
1600
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1601
+	 * EE_Admin page and will execute on every EE Admin Page load
1602
+	 *
1603
+	 * @return void
1604
+	 */
1605
+	public function wp_loaded()
1606
+	{
1607
+	}
1608
+
1609
+
1610
+	/**
1611
+	 * admin_notices
1612
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1613
+	 * ALL EE_Admin pages.
1614
+	 *
1615
+	 * @return void
1616
+	 */
1617
+	public function admin_notices_global()
1618
+	{
1619
+		$this->_display_no_javascript_warning();
1620
+		$this->_display_espresso_notices();
1621
+	}
1622
+
1623
+
1624
+	public function network_admin_notices_global()
1625
+	{
1626
+		$this->_display_no_javascript_warning();
1627
+		$this->_display_espresso_notices();
1628
+	}
1629
+
1630
+
1631
+	/**
1632
+	 * admin_footer_scripts_global
1633
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1634
+	 * will apply on ALL EE_Admin pages.
1635
+	 *
1636
+	 * @return void
1637
+	 */
1638
+	public function admin_footer_scripts_global()
1639
+	{
1640
+		$this->_add_admin_page_ajax_loading_img();
1641
+		$this->_add_admin_page_overlay();
1642
+		// if metaboxes are present we need to add the nonce field
1643
+		if (isset($this->_route_config['metaboxes'])
1644
+			|| isset($this->_route_config['list_table'])
1645
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1646
+		) {
1647
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1648
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1649
+		}
1650
+	}
1651
+
1652
+
1653
+	/**
1654
+	 * admin_footer_global
1655
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1656
+	 * ALL EE_Admin Pages.
1657
+	 *
1658
+	 * @return void
1659
+	 * @throws EE_Error
1660
+	 */
1661
+	public function admin_footer_global()
1662
+	{
1663
+		// dialog container for dialog helper
1664
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1665
+		$d_cont .= '<div class="ee-notices"></div>';
1666
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1667
+		$d_cont .= '</div>';
1668
+		echo $d_cont;
1669
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1670
+		// help tour stuff?
1671
+		// if (isset($this->_help_tour[ $this->_req_action ])) {
1672
+		//     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1673
+		// }
1674
+		// current set timezone for timezone js
1675
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1676
+	}
1677
+
1678
+
1679
+	/**
1680
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1681
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1682
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1683
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1684
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1685
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1686
+	 * for the
1687
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1688
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1689
+	 *    'help_trigger_id' => array(
1690
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1691
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1692
+	 *    )
1693
+	 * );
1694
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1695
+	 *
1696
+	 * @param array $help_array
1697
+	 * @param bool  $display
1698
+	 * @return string content
1699
+	 * @throws DomainException
1700
+	 * @throws EE_Error
1701
+	 */
1702
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1703
+	{
1704
+		$content = '';
1705
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1706
+		// loop through the array and setup content
1707
+		foreach ($help_array as $trigger => $help) {
1708
+			// make sure the array is setup properly
1709
+			if (! isset($help['title']) || ! isset($help['content'])) {
1710
+				throw new EE_Error(
1711
+					esc_html__(
1712
+						'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',
1713
+						'event_espresso'
1714
+					)
1715
+				);
1716
+			}
1717
+			// we're good so let'd setup the template vars and then assign parsed template content to our content.
1718
+			$template_args = array(
1719
+				'help_popup_id'      => $trigger,
1720
+				'help_popup_title'   => $help['title'],
1721
+				'help_popup_content' => $help['content'],
1722
+			);
1723
+			$content .= EEH_Template::display_template(
1724
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1725
+				$template_args,
1726
+				true
1727
+			);
1728
+		}
1729
+		if ($display) {
1730
+			echo $content;
1731
+			return '';
1732
+		}
1733
+		return $content;
1734
+	}
1735
+
1736
+
1737
+	/**
1738
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1739
+	 *
1740
+	 * @return array properly formatted array for help popup content
1741
+	 * @throws EE_Error
1742
+	 */
1743
+	private function _get_help_content()
1744
+	{
1745
+		// what is the method we're looking for?
1746
+		$method_name = '_help_popup_content_' . $this->_req_action;
1747
+		// if method doesn't exist let's get out.
1748
+		if (! method_exists($this, $method_name)) {
1749
+			return array();
1750
+		}
1751
+		// k we're good to go let's retrieve the help array
1752
+		$help_array = call_user_func(array($this, $method_name));
1753
+		// make sure we've got an array!
1754
+		if (! is_array($help_array)) {
1755
+			throw new EE_Error(
1756
+				esc_html__(
1757
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1758
+					'event_espresso'
1759
+				)
1760
+			);
1761
+		}
1762
+		return $help_array;
1763
+	}
1764
+
1765
+
1766
+	/**
1767
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1768
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1769
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1770
+	 *
1771
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1772
+	 * @param boolean $display    if false then we return the trigger string
1773
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1774
+	 * @return string
1775
+	 * @throws DomainException
1776
+	 * @throws EE_Error
1777
+	 */
1778
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1779
+	{
1780
+		if (defined('DOING_AJAX')) {
1781
+			return '';
1782
+		}
1783
+		// 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
1784
+		$help_array = $this->_get_help_content();
1785
+		$help_content = '';
1786
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1787
+			$help_array[ $trigger_id ] = array(
1788
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1789
+				'content' => esc_html__(
1790
+					'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.)',
1791
+					'event_espresso'
1792
+				),
1793
+			);
1794
+			$help_content = $this->_set_help_popup_content($help_array, false);
1795
+		}
1796
+		// let's setup the trigger
1797
+		$content = '<a class="ee-dialog" href="?height='
1798
+				   . $dimensions[0]
1799
+				   . '&width='
1800
+				   . $dimensions[1]
1801
+				   . '&inlineId='
1802
+				   . $trigger_id
1803
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1804
+		$content .= $help_content;
1805
+		if ($display) {
1806
+			echo $content;
1807
+			return '';
1808
+		}
1809
+		return $content;
1810
+	}
1811
+
1812
+
1813
+	/**
1814
+	 * _add_global_screen_options
1815
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1816
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1817
+	 *
1818
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1819
+	 *         see also WP_Screen object documents...
1820
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1821
+	 * @abstract
1822
+	 * @return void
1823
+	 */
1824
+	private function _add_global_screen_options()
1825
+	{
1826
+	}
1827
+
1828
+
1829
+	/**
1830
+	 * _add_global_feature_pointers
1831
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1832
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1833
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1834
+	 *
1835
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1836
+	 *         extended) also see:
1837
+	 * @link   http://eamann.com/tech/wordpress-portland/
1838
+	 * @abstract
1839
+	 * @return void
1840
+	 */
1841
+	private function _add_global_feature_pointers()
1842
+	{
1843
+	}
1844
+
1845
+
1846
+	/**
1847
+	 * load_global_scripts_styles
1848
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1849
+	 *
1850
+	 * @return void
1851
+	 * @throws EE_Error
1852
+	 */
1853
+	public function load_global_scripts_styles()
1854
+	{
1855
+		/** STYLES **/
1856
+		// add debugging styles
1857
+		if (WP_DEBUG) {
1858
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1859
+		}
1860
+		// register all styles
1861
+		wp_register_style(
1862
+			'espresso-ui-theme',
1863
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1864
+			array(),
1865
+			EVENT_ESPRESSO_VERSION
1866
+		);
1867
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1868
+		// helpers styles
1869
+		wp_register_style(
1870
+			'ee-text-links',
1871
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1872
+			array(),
1873
+			EVENT_ESPRESSO_VERSION
1874
+		);
1875
+		/** SCRIPTS **/
1876
+		// register all scripts
1877
+		wp_register_script(
1878
+			'ee-dialog',
1879
+			EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1880
+			array('jquery', 'jquery-ui-draggable'),
1881
+			EVENT_ESPRESSO_VERSION,
1882
+			true
1883
+		);
1884
+		wp_register_script(
1885
+			'ee_admin_js',
1886
+			EE_ADMIN_URL . 'assets/ee-admin-page.js',
1887
+			array('espresso_core', 'ee-parse-uri', 'ee-dialog'),
1888
+			EVENT_ESPRESSO_VERSION,
1889
+			true
1890
+		);
1891
+		wp_register_script(
1892
+			'jquery-ui-timepicker-addon',
1893
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1894
+			array('jquery-ui-datepicker', 'jquery-ui-slider'),
1895
+			EVENT_ESPRESSO_VERSION,
1896
+			true
1897
+		);
1898
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1899
+		// if (EE_Registry::instance()->CFG->admin->help_tour_activation) {
1900
+		//     add_filter('FHEE_load_joyride', '__return_true');
1901
+		// }
1902
+		// script for sorting tables
1903
+		wp_register_script(
1904
+			'espresso_ajax_table_sorting',
1905
+			EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1906
+			array('ee_admin_js', 'jquery-ui-sortable'),
1907
+			EVENT_ESPRESSO_VERSION,
1908
+			true
1909
+		);
1910
+		// script for parsing uri's
1911
+		wp_register_script(
1912
+			'ee-parse-uri',
1913
+			EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1914
+			array(),
1915
+			EVENT_ESPRESSO_VERSION,
1916
+			true
1917
+		);
1918
+		// and parsing associative serialized form elements
1919
+		wp_register_script(
1920
+			'ee-serialize-full-array',
1921
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1922
+			array('jquery'),
1923
+			EVENT_ESPRESSO_VERSION,
1924
+			true
1925
+		);
1926
+		// helpers scripts
1927
+		wp_register_script(
1928
+			'ee-text-links',
1929
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1930
+			array('jquery'),
1931
+			EVENT_ESPRESSO_VERSION,
1932
+			true
1933
+		);
1934
+		wp_register_script(
1935
+			'ee-moment-core',
1936
+			EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1937
+			array(),
1938
+			EVENT_ESPRESSO_VERSION,
1939
+			true
1940
+		);
1941
+		wp_register_script(
1942
+			'ee-moment',
1943
+			EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1944
+			array('ee-moment-core'),
1945
+			EVENT_ESPRESSO_VERSION,
1946
+			true
1947
+		);
1948
+		wp_register_script(
1949
+			'ee-datepicker',
1950
+			EE_ADMIN_URL . 'assets/ee-datepicker.js',
1951
+			array('jquery-ui-timepicker-addon', 'ee-moment'),
1952
+			EVENT_ESPRESSO_VERSION,
1953
+			true
1954
+		);
1955
+		// google charts
1956
+		wp_register_script(
1957
+			'google-charts',
1958
+			'https://www.gstatic.com/charts/loader.js',
1959
+			array(),
1960
+			EVENT_ESPRESSO_VERSION,
1961
+			false
1962
+		);
1963
+		// ENQUEUE ALL BASICS BY DEFAULT
1964
+		wp_enqueue_style('ee-admin-css');
1965
+		wp_enqueue_script('ee_admin_js');
1966
+		wp_enqueue_script('ee-accounting');
1967
+		wp_enqueue_script('jquery-validate');
1968
+		// taking care of metaboxes
1969
+		if (empty($this->_cpt_route)
1970
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1971
+		) {
1972
+			wp_enqueue_script('dashboard');
1973
+		}
1974
+		// LOCALIZED DATA
1975
+		// localize script for ajax lazy loading
1976
+		$lazy_loader_container_ids = apply_filters(
1977
+			'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1978
+			array('espresso_news_post_box_content')
1979
+		);
1980
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1981
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1982
+		// /**
1983
+		//  * help tour stuff
1984
+		//  */
1985
+		// if (! empty($this->_help_tour)) {
1986
+		//     // register the js for kicking things off
1987
+		//     wp_enqueue_script(
1988
+		//         'ee-help-tour',
1989
+		//         EE_ADMIN_URL . 'assets/ee-help-tour.js',
1990
+		//         array('jquery-joyride'),
1991
+		//         EVENT_ESPRESSO_VERSION,
1992
+		//         true
1993
+		//     );
1994
+		//     $tours = array();
1995
+		//     // setup tours for the js tour object
1996
+		//     foreach ($this->_help_tour['tours'] as $tour) {
1997
+		//         if ($tour instanceof EE_Help_Tour) {
1998
+		//             $tours[] = array(
1999
+		//                 'id'      => $tour->get_slug(),
2000
+		//                 'options' => $tour->get_options(),
2001
+		//             );
2002
+		//         }
2003
+		//     }
2004
+		//     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
2005
+		//     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
2006
+		// }
2007
+	}
2008
+
2009
+
2010
+	/**
2011
+	 *        admin_footer_scripts_eei18n_js_strings
2012
+	 *
2013
+	 * @return        void
2014
+	 */
2015
+	public function admin_footer_scripts_eei18n_js_strings()
2016
+	{
2017
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
2018
+		EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
2019
+			__(
2020
+				'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!!!',
2021
+				'event_espresso'
2022
+			)
2023
+		);
2024
+		EE_Registry::$i18n_js_strings['January'] = wp_strip_all_tags(__('January', 'event_espresso'));
2025
+		EE_Registry::$i18n_js_strings['February'] = wp_strip_all_tags(__('February', 'event_espresso'));
2026
+		EE_Registry::$i18n_js_strings['March'] = wp_strip_all_tags(__('March', 'event_espresso'));
2027
+		EE_Registry::$i18n_js_strings['April'] = wp_strip_all_tags(__('April', 'event_espresso'));
2028
+		EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso'));
2029
+		EE_Registry::$i18n_js_strings['June'] = wp_strip_all_tags(__('June', 'event_espresso'));
2030
+		EE_Registry::$i18n_js_strings['July'] = wp_strip_all_tags(__('July', 'event_espresso'));
2031
+		EE_Registry::$i18n_js_strings['August'] = wp_strip_all_tags(__('August', 'event_espresso'));
2032
+		EE_Registry::$i18n_js_strings['September'] = wp_strip_all_tags(__('September', 'event_espresso'));
2033
+		EE_Registry::$i18n_js_strings['October'] = wp_strip_all_tags(__('October', 'event_espresso'));
2034
+		EE_Registry::$i18n_js_strings['November'] = wp_strip_all_tags(__('November', 'event_espresso'));
2035
+		EE_Registry::$i18n_js_strings['December'] = wp_strip_all_tags(__('December', 'event_espresso'));
2036
+		EE_Registry::$i18n_js_strings['Jan'] = wp_strip_all_tags(__('Jan', 'event_espresso'));
2037
+		EE_Registry::$i18n_js_strings['Feb'] = wp_strip_all_tags(__('Feb', 'event_espresso'));
2038
+		EE_Registry::$i18n_js_strings['Mar'] = wp_strip_all_tags(__('Mar', 'event_espresso'));
2039
+		EE_Registry::$i18n_js_strings['Apr'] = wp_strip_all_tags(__('Apr', 'event_espresso'));
2040
+		EE_Registry::$i18n_js_strings['May'] = wp_strip_all_tags(__('May', 'event_espresso'));
2041
+		EE_Registry::$i18n_js_strings['Jun'] = wp_strip_all_tags(__('Jun', 'event_espresso'));
2042
+		EE_Registry::$i18n_js_strings['Jul'] = wp_strip_all_tags(__('Jul', 'event_espresso'));
2043
+		EE_Registry::$i18n_js_strings['Aug'] = wp_strip_all_tags(__('Aug', 'event_espresso'));
2044
+		EE_Registry::$i18n_js_strings['Sep'] = wp_strip_all_tags(__('Sep', 'event_espresso'));
2045
+		EE_Registry::$i18n_js_strings['Oct'] = wp_strip_all_tags(__('Oct', 'event_espresso'));
2046
+		EE_Registry::$i18n_js_strings['Nov'] = wp_strip_all_tags(__('Nov', 'event_espresso'));
2047
+		EE_Registry::$i18n_js_strings['Dec'] = wp_strip_all_tags(__('Dec', 'event_espresso'));
2048
+		EE_Registry::$i18n_js_strings['Sunday'] = wp_strip_all_tags(__('Sunday', 'event_espresso'));
2049
+		EE_Registry::$i18n_js_strings['Monday'] = wp_strip_all_tags(__('Monday', 'event_espresso'));
2050
+		EE_Registry::$i18n_js_strings['Tuesday'] = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
2051
+		EE_Registry::$i18n_js_strings['Wednesday'] = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
2052
+		EE_Registry::$i18n_js_strings['Thursday'] = wp_strip_all_tags(__('Thursday', 'event_espresso'));
2053
+		EE_Registry::$i18n_js_strings['Friday'] = wp_strip_all_tags(__('Friday', 'event_espresso'));
2054
+		EE_Registry::$i18n_js_strings['Saturday'] = wp_strip_all_tags(__('Saturday', 'event_espresso'));
2055
+		EE_Registry::$i18n_js_strings['Sun'] = wp_strip_all_tags(__('Sun', 'event_espresso'));
2056
+		EE_Registry::$i18n_js_strings['Mon'] = wp_strip_all_tags(__('Mon', 'event_espresso'));
2057
+		EE_Registry::$i18n_js_strings['Tue'] = wp_strip_all_tags(__('Tue', 'event_espresso'));
2058
+		EE_Registry::$i18n_js_strings['Wed'] = wp_strip_all_tags(__('Wed', 'event_espresso'));
2059
+		EE_Registry::$i18n_js_strings['Thu'] = wp_strip_all_tags(__('Thu', 'event_espresso'));
2060
+		EE_Registry::$i18n_js_strings['Fri'] = wp_strip_all_tags(__('Fri', 'event_espresso'));
2061
+		EE_Registry::$i18n_js_strings['Sat'] = wp_strip_all_tags(__('Sat', 'event_espresso'));
2062
+	}
2063
+
2064
+
2065
+	/**
2066
+	 *        load enhanced xdebug styles for ppl with failing eyesight
2067
+	 *
2068
+	 * @return        void
2069
+	 */
2070
+	public function add_xdebug_style()
2071
+	{
2072
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2073
+	}
2074
+
2075
+
2076
+	/************************/
2077
+	/** LIST TABLE METHODS **/
2078
+	/************************/
2079
+	/**
2080
+	 * this sets up the list table if the current view requires it.
2081
+	 *
2082
+	 * @return void
2083
+	 * @throws EE_Error
2084
+	 */
2085
+	protected function _set_list_table()
2086
+	{
2087
+		// first is this a list_table view?
2088
+		if (! isset($this->_route_config['list_table'])) {
2089
+			return;
2090
+		} //not a list_table view so get out.
2091
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2092
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2093
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2094
+			// user error msg
2095
+			$error_msg = esc_html__(
2096
+				'An error occurred. The requested list table views could not be found.',
2097
+				'event_espresso'
2098
+			);
2099
+			// developer error msg
2100
+			$error_msg .= '||'
2101
+						  . sprintf(
2102
+							  esc_html__(
2103
+								  '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.',
2104
+								  'event_espresso'
2105
+							  ),
2106
+							  $this->_req_action,
2107
+							  $list_table_view
2108
+						  );
2109
+			throw new EE_Error($error_msg);
2110
+		}
2111
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2112
+		$this->_views = apply_filters(
2113
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2114
+			$this->_views
2115
+		);
2116
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2117
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2118
+		$this->_set_list_table_view();
2119
+		$this->_set_list_table_object();
2120
+	}
2121
+
2122
+
2123
+	/**
2124
+	 * set current view for List Table
2125
+	 *
2126
+	 * @return void
2127
+	 */
2128
+	protected function _set_list_table_view()
2129
+	{
2130
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2131
+		// looking at active items or dumpster diving ?
2132
+		if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2133
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2134
+		} else {
2135
+			$this->_view = sanitize_key($this->_req_data['status']);
2136
+		}
2137
+	}
2138
+
2139
+
2140
+	/**
2141
+	 * _set_list_table_object
2142
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2143
+	 *
2144
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2145
+	 * @throws \InvalidArgumentException
2146
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2147
+	 * @throws EE_Error
2148
+	 * @throws InvalidInterfaceException
2149
+	 */
2150
+	protected function _set_list_table_object()
2151
+	{
2152
+		if (isset($this->_route_config['list_table'])) {
2153
+			if (! class_exists($this->_route_config['list_table'])) {
2154
+				throw new EE_Error(
2155
+					sprintf(
2156
+						esc_html__(
2157
+							'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.',
2158
+							'event_espresso'
2159
+						),
2160
+						$this->_route_config['list_table'],
2161
+						get_class($this)
2162
+					)
2163
+				);
2164
+			}
2165
+			$this->_list_table_object = $this->loader->getShared(
2166
+				$this->_route_config['list_table'],
2167
+				array($this)
2168
+			);
2169
+		}
2170
+	}
2171
+
2172
+
2173
+	/**
2174
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2175
+	 *
2176
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2177
+	 *                                                    urls.  The array should be indexed by the view it is being
2178
+	 *                                                    added to.
2179
+	 * @return array
2180
+	 */
2181
+	public function get_list_table_view_RLs($extra_query_args = array())
2182
+	{
2183
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2184
+		if (empty($this->_views)) {
2185
+			$this->_views = array();
2186
+		}
2187
+		// cycle thru views
2188
+		foreach ($this->_views as $key => $view) {
2189
+			$query_args = array();
2190
+			// check for current view
2191
+			$this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2192
+			$query_args['action'] = $this->_req_action;
2193
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2194
+			$query_args['status'] = $view['slug'];
2195
+			// merge any other arguments sent in.
2196
+			if (isset($extra_query_args[ $view['slug'] ])) {
2197
+				$query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2198
+			}
2199
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2200
+		}
2201
+		return $this->_views;
2202
+	}
2203
+
2204
+
2205
+	/**
2206
+	 * _entries_per_page_dropdown
2207
+	 * generates a drop down box for selecting the number of visible rows in an admin page list table
2208
+	 *
2209
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2210
+	 *         WP does it.
2211
+	 * @param int $max_entries total number of rows in the table
2212
+	 * @return string
2213
+	 */
2214
+	protected function _entries_per_page_dropdown($max_entries = 0)
2215
+	{
2216
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2217
+		$values = array(10, 25, 50, 100);
2218
+		$per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2219
+		if ($max_entries) {
2220
+			$values[] = $max_entries;
2221
+			sort($values);
2222
+		}
2223
+		$entries_per_page_dropdown = '
2224 2224
 			<div id="entries-per-page-dv" class="alignleft actions">
2225 2225
 				<label class="hide-if-no-js">
2226 2226
 					Show
2227 2227
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2228
-        foreach ($values as $value) {
2229
-            if ($value < $max_entries) {
2230
-                $selected = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2231
-                $entries_per_page_dropdown .= '
2228
+		foreach ($values as $value) {
2229
+			if ($value < $max_entries) {
2230
+				$selected = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2231
+				$entries_per_page_dropdown .= '
2232 2232
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2233
-            }
2234
-        }
2235
-        $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2236
-        $entries_per_page_dropdown .= '
2233
+			}
2234
+		}
2235
+		$selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2236
+		$entries_per_page_dropdown .= '
2237 2237
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2238
-        $entries_per_page_dropdown .= '
2238
+		$entries_per_page_dropdown .= '
2239 2239
 					</select>
2240 2240
 					entries
2241 2241
 				</label>
2242 2242
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2243 2243
 			</div>
2244 2244
 		';
2245
-        return $entries_per_page_dropdown;
2246
-    }
2247
-
2248
-
2249
-    /**
2250
-     *        _set_search_attributes
2251
-     *
2252
-     * @return        void
2253
-     */
2254
-    public function _set_search_attributes()
2255
-    {
2256
-        $this->_template_args['search']['btn_label'] = sprintf(
2257
-            esc_html__('Search %s', 'event_espresso'),
2258
-            empty($this->_search_btn_label) ? $this->page_label
2259
-                : $this->_search_btn_label
2260
-        );
2261
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
2262
-    }
2263
-
2264
-
2265
-
2266
-    /*** END LIST TABLE METHODS **/
2267
-
2268
-
2269
-    /**
2270
-     * _add_registered_metaboxes
2271
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2272
-     *
2273
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2274
-     * @return void
2275
-     * @throws EE_Error
2276
-     */
2277
-    private function _add_registered_meta_boxes()
2278
-    {
2279
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2280
-        // we only add meta boxes if the page_route calls for it
2281
-        if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2282
-            && is_array(
2283
-                $this->_route_config['metaboxes']
2284
-            )
2285
-        ) {
2286
-            // this simply loops through the callbacks provided
2287
-            // and checks if there is a corresponding callback registered by the child
2288
-            // if there is then we go ahead and process the metabox loader.
2289
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2290
-                // first check for Closures
2291
-                if ($metabox_callback instanceof Closure) {
2292
-                    $result = $metabox_callback();
2293
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2294
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2295
-                } else {
2296
-                    $result = call_user_func(array($this, &$metabox_callback));
2297
-                }
2298
-                if ($result === false) {
2299
-                    // user error msg
2300
-                    $error_msg = esc_html__(
2301
-                        'An error occurred. The  requested metabox could not be found.',
2302
-                        'event_espresso'
2303
-                    );
2304
-                    // developer error msg
2305
-                    $error_msg .= '||'
2306
-                                  . sprintf(
2307
-                                      esc_html__(
2308
-                                          '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.',
2309
-                                          'event_espresso'
2310
-                                      ),
2311
-                                      $metabox_callback
2312
-                                  );
2313
-                    throw new EE_Error($error_msg);
2314
-                }
2315
-            }
2316
-        }
2317
-    }
2318
-
2319
-
2320
-    /**
2321
-     * _add_screen_columns
2322
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2323
-     * the dynamic column template and we'll setup the column options for the page.
2324
-     *
2325
-     * @return void
2326
-     */
2327
-    private function _add_screen_columns()
2328
-    {
2329
-        if (is_array($this->_route_config)
2330
-            && isset($this->_route_config['columns'])
2331
-            && is_array($this->_route_config['columns'])
2332
-            && count($this->_route_config['columns']) === 2
2333
-        ) {
2334
-            add_screen_option(
2335
-                'layout_columns',
2336
-                array(
2337
-                    'max'     => (int) $this->_route_config['columns'][0],
2338
-                    'default' => (int) $this->_route_config['columns'][1],
2339
-                )
2340
-            );
2341
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2342
-            $screen_id = $this->_current_screen->id;
2343
-            $screen_columns = (int) get_user_option("screen_layout_{$screen_id}");
2344
-            $total_columns = ! empty($screen_columns)
2345
-                ? $screen_columns
2346
-                : $this->_route_config['columns'][1];
2347
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2348
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
2349
-            $this->_template_args['screen'] = $this->_current_screen;
2350
-            $this->_column_template_path = EE_ADMIN_TEMPLATE
2351
-                                           . 'admin_details_metabox_column_wrapper.template.php';
2352
-            // finally if we don't have has_metaboxes set in the route config
2353
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2354
-            $this->_route_config['has_metaboxes'] = true;
2355
-        }
2356
-    }
2357
-
2358
-
2359
-
2360
-    /** GLOBALLY AVAILABLE METABOXES **/
2361
-
2362
-
2363
-    /**
2364
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2365
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2366
-     * these get loaded on.
2367
-     */
2368
-    private function _espresso_news_post_box()
2369
-    {
2370
-        $news_box_title = apply_filters(
2371
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2372
-            esc_html__('New @ Event Espresso', 'event_espresso')
2373
-        );
2374
-        add_meta_box(
2375
-            'espresso_news_post_box',
2376
-            $news_box_title,
2377
-            array(
2378
-                $this,
2379
-                'espresso_news_post_box',
2380
-            ),
2381
-            $this->_wp_page_slug,
2382
-            'side'
2383
-        );
2384
-    }
2385
-
2386
-
2387
-    /**
2388
-     * Code for setting up espresso ratings request metabox.
2389
-     */
2390
-    protected function _espresso_ratings_request()
2391
-    {
2392
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2393
-            return;
2394
-        }
2395
-        $ratings_box_title = apply_filters(
2396
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2397
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2398
-        );
2399
-        add_meta_box(
2400
-            'espresso_ratings_request',
2401
-            $ratings_box_title,
2402
-            array(
2403
-                $this,
2404
-                'espresso_ratings_request',
2405
-            ),
2406
-            $this->_wp_page_slug,
2407
-            'side'
2408
-        );
2409
-    }
2410
-
2411
-
2412
-    /**
2413
-     * Code for setting up espresso ratings request metabox content.
2414
-     *
2415
-     * @throws DomainException
2416
-     */
2417
-    public function espresso_ratings_request()
2418
-    {
2419
-        EEH_Template::display_template(
2420
-            EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2421
-            array()
2422
-        );
2423
-    }
2424
-
2425
-
2426
-    public static function cached_rss_display($rss_id, $url)
2427
-    {
2428
-        $loading = '<p class="widget-loading hide-if-no-js">'
2429
-                   . __('Loading&#8230;', 'event_espresso')
2430
-                   . '</p><p class="hide-if-js">'
2431
-                   . esc_html__('This widget requires JavaScript.', 'event_espresso')
2432
-                   . '</p>';
2433
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
2434
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2435
-        $post = '</div>' . "\n";
2436
-        $cache_key = 'ee_rss_' . md5($rss_id);
2437
-        $output = get_transient($cache_key);
2438
-        if ($output !== false) {
2439
-            echo $pre . $output . $post;
2440
-            return true;
2441
-        }
2442
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2443
-            echo $pre . $loading . $post;
2444
-            return false;
2445
-        }
2446
-        ob_start();
2447
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2448
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2449
-        return true;
2450
-    }
2451
-
2452
-
2453
-    public function espresso_news_post_box()
2454
-    {
2455
-        ?>
2245
+		return $entries_per_page_dropdown;
2246
+	}
2247
+
2248
+
2249
+	/**
2250
+	 *        _set_search_attributes
2251
+	 *
2252
+	 * @return        void
2253
+	 */
2254
+	public function _set_search_attributes()
2255
+	{
2256
+		$this->_template_args['search']['btn_label'] = sprintf(
2257
+			esc_html__('Search %s', 'event_espresso'),
2258
+			empty($this->_search_btn_label) ? $this->page_label
2259
+				: $this->_search_btn_label
2260
+		);
2261
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
2262
+	}
2263
+
2264
+
2265
+
2266
+	/*** END LIST TABLE METHODS **/
2267
+
2268
+
2269
+	/**
2270
+	 * _add_registered_metaboxes
2271
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2272
+	 *
2273
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2274
+	 * @return void
2275
+	 * @throws EE_Error
2276
+	 */
2277
+	private function _add_registered_meta_boxes()
2278
+	{
2279
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2280
+		// we only add meta boxes if the page_route calls for it
2281
+		if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2282
+			&& is_array(
2283
+				$this->_route_config['metaboxes']
2284
+			)
2285
+		) {
2286
+			// this simply loops through the callbacks provided
2287
+			// and checks if there is a corresponding callback registered by the child
2288
+			// if there is then we go ahead and process the metabox loader.
2289
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2290
+				// first check for Closures
2291
+				if ($metabox_callback instanceof Closure) {
2292
+					$result = $metabox_callback();
2293
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2294
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2295
+				} else {
2296
+					$result = call_user_func(array($this, &$metabox_callback));
2297
+				}
2298
+				if ($result === false) {
2299
+					// user error msg
2300
+					$error_msg = esc_html__(
2301
+						'An error occurred. The  requested metabox could not be found.',
2302
+						'event_espresso'
2303
+					);
2304
+					// developer error msg
2305
+					$error_msg .= '||'
2306
+								  . sprintf(
2307
+									  esc_html__(
2308
+										  '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.',
2309
+										  'event_espresso'
2310
+									  ),
2311
+									  $metabox_callback
2312
+								  );
2313
+					throw new EE_Error($error_msg);
2314
+				}
2315
+			}
2316
+		}
2317
+	}
2318
+
2319
+
2320
+	/**
2321
+	 * _add_screen_columns
2322
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2323
+	 * the dynamic column template and we'll setup the column options for the page.
2324
+	 *
2325
+	 * @return void
2326
+	 */
2327
+	private function _add_screen_columns()
2328
+	{
2329
+		if (is_array($this->_route_config)
2330
+			&& isset($this->_route_config['columns'])
2331
+			&& is_array($this->_route_config['columns'])
2332
+			&& count($this->_route_config['columns']) === 2
2333
+		) {
2334
+			add_screen_option(
2335
+				'layout_columns',
2336
+				array(
2337
+					'max'     => (int) $this->_route_config['columns'][0],
2338
+					'default' => (int) $this->_route_config['columns'][1],
2339
+				)
2340
+			);
2341
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2342
+			$screen_id = $this->_current_screen->id;
2343
+			$screen_columns = (int) get_user_option("screen_layout_{$screen_id}");
2344
+			$total_columns = ! empty($screen_columns)
2345
+				? $screen_columns
2346
+				: $this->_route_config['columns'][1];
2347
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2348
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
2349
+			$this->_template_args['screen'] = $this->_current_screen;
2350
+			$this->_column_template_path = EE_ADMIN_TEMPLATE
2351
+										   . 'admin_details_metabox_column_wrapper.template.php';
2352
+			// finally if we don't have has_metaboxes set in the route config
2353
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2354
+			$this->_route_config['has_metaboxes'] = true;
2355
+		}
2356
+	}
2357
+
2358
+
2359
+
2360
+	/** GLOBALLY AVAILABLE METABOXES **/
2361
+
2362
+
2363
+	/**
2364
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2365
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2366
+	 * these get loaded on.
2367
+	 */
2368
+	private function _espresso_news_post_box()
2369
+	{
2370
+		$news_box_title = apply_filters(
2371
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2372
+			esc_html__('New @ Event Espresso', 'event_espresso')
2373
+		);
2374
+		add_meta_box(
2375
+			'espresso_news_post_box',
2376
+			$news_box_title,
2377
+			array(
2378
+				$this,
2379
+				'espresso_news_post_box',
2380
+			),
2381
+			$this->_wp_page_slug,
2382
+			'side'
2383
+		);
2384
+	}
2385
+
2386
+
2387
+	/**
2388
+	 * Code for setting up espresso ratings request metabox.
2389
+	 */
2390
+	protected function _espresso_ratings_request()
2391
+	{
2392
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2393
+			return;
2394
+		}
2395
+		$ratings_box_title = apply_filters(
2396
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2397
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2398
+		);
2399
+		add_meta_box(
2400
+			'espresso_ratings_request',
2401
+			$ratings_box_title,
2402
+			array(
2403
+				$this,
2404
+				'espresso_ratings_request',
2405
+			),
2406
+			$this->_wp_page_slug,
2407
+			'side'
2408
+		);
2409
+	}
2410
+
2411
+
2412
+	/**
2413
+	 * Code for setting up espresso ratings request metabox content.
2414
+	 *
2415
+	 * @throws DomainException
2416
+	 */
2417
+	public function espresso_ratings_request()
2418
+	{
2419
+		EEH_Template::display_template(
2420
+			EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2421
+			array()
2422
+		);
2423
+	}
2424
+
2425
+
2426
+	public static function cached_rss_display($rss_id, $url)
2427
+	{
2428
+		$loading = '<p class="widget-loading hide-if-no-js">'
2429
+				   . __('Loading&#8230;', 'event_espresso')
2430
+				   . '</p><p class="hide-if-js">'
2431
+				   . esc_html__('This widget requires JavaScript.', 'event_espresso')
2432
+				   . '</p>';
2433
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
2434
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2435
+		$post = '</div>' . "\n";
2436
+		$cache_key = 'ee_rss_' . md5($rss_id);
2437
+		$output = get_transient($cache_key);
2438
+		if ($output !== false) {
2439
+			echo $pre . $output . $post;
2440
+			return true;
2441
+		}
2442
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2443
+			echo $pre . $loading . $post;
2444
+			return false;
2445
+		}
2446
+		ob_start();
2447
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2448
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2449
+		return true;
2450
+	}
2451
+
2452
+
2453
+	public function espresso_news_post_box()
2454
+	{
2455
+		?>
2456 2456
         <div class="padding">
2457 2457
             <div id="espresso_news_post_box_content" class="infolinks">
2458 2458
                 <?php
2459
-                // Get RSS Feed(s)
2460
-                self::cached_rss_display(
2461
-                    'espresso_news_post_box_content',
2462
-                    urlencode(
2463
-                        apply_filters(
2464
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2465
-                            'http://eventespresso.com/feed/'
2466
-                        )
2467
-                    )
2468
-                );
2469
-                ?>
2459
+				// Get RSS Feed(s)
2460
+				self::cached_rss_display(
2461
+					'espresso_news_post_box_content',
2462
+					urlencode(
2463
+						apply_filters(
2464
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2465
+							'http://eventespresso.com/feed/'
2466
+						)
2467
+					)
2468
+				);
2469
+				?>
2470 2470
             </div>
2471 2471
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2472 2472
         </div>
2473 2473
         <?php
2474
-    }
2475
-
2476
-
2477
-    private function _espresso_links_post_box()
2478
-    {
2479
-        // Hiding until we actually have content to put in here...
2480
-        // 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');
2481
-    }
2482
-
2483
-
2484
-    public function espresso_links_post_box()
2485
-    {
2486
-        // Hiding until we actually have content to put in here...
2487
-        // EEH_Template::display_template(
2488
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2489
-        // );
2490
-    }
2491
-
2492
-
2493
-    protected function _espresso_sponsors_post_box()
2494
-    {
2495
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2496
-            add_meta_box(
2497
-                'espresso_sponsors_post_box',
2498
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2499
-                array($this, 'espresso_sponsors_post_box'),
2500
-                $this->_wp_page_slug,
2501
-                'side'
2502
-            );
2503
-        }
2504
-    }
2505
-
2506
-
2507
-    public function espresso_sponsors_post_box()
2508
-    {
2509
-        EEH_Template::display_template(
2510
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2511
-        );
2512
-    }
2513
-
2514
-
2515
-    private function _publish_post_box()
2516
-    {
2517
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2518
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2519
-        // then we'll use that for the metabox label.
2520
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2521
-        if (! empty($this->_labels['publishbox'])) {
2522
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2523
-                : $this->_labels['publishbox'];
2524
-        } else {
2525
-            $box_label = esc_html__('Publish', 'event_espresso');
2526
-        }
2527
-        $box_label = apply_filters(
2528
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2529
-            $box_label,
2530
-            $this->_req_action,
2531
-            $this
2532
-        );
2533
-        add_meta_box(
2534
-            $meta_box_ref,
2535
-            $box_label,
2536
-            array($this, 'editor_overview'),
2537
-            $this->_current_screen->id,
2538
-            'side',
2539
-            'high'
2540
-        );
2541
-    }
2542
-
2543
-
2544
-    public function editor_overview()
2545
-    {
2546
-        // if we have extra content set let's add it in if not make sure its empty
2547
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2548
-            ? $this->_template_args['publish_box_extra_content']
2549
-            : '';
2550
-        echo EEH_Template::display_template(
2551
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2552
-            $this->_template_args,
2553
-            true
2554
-        );
2555
-    }
2556
-
2557
-
2558
-    /** end of globally available metaboxes section **/
2559
-
2560
-
2561
-    /**
2562
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2563
-     * protected method.
2564
-     *
2565
-     * @see   $this->_set_publish_post_box_vars for param details
2566
-     * @since 4.6.0
2567
-     * @param string $name
2568
-     * @param int    $id
2569
-     * @param bool   $delete
2570
-     * @param string $save_close_redirect_URL
2571
-     * @param bool   $both_btns
2572
-     * @throws EE_Error
2573
-     * @throws InvalidArgumentException
2574
-     * @throws InvalidDataTypeException
2575
-     * @throws InvalidInterfaceException
2576
-     */
2577
-    public function set_publish_post_box_vars(
2578
-        $name = '',
2579
-        $id = 0,
2580
-        $delete = false,
2581
-        $save_close_redirect_URL = '',
2582
-        $both_btns = true
2583
-    ) {
2584
-        $this->_set_publish_post_box_vars(
2585
-            $name,
2586
-            $id,
2587
-            $delete,
2588
-            $save_close_redirect_URL,
2589
-            $both_btns
2590
-        );
2591
-    }
2592
-
2593
-
2594
-    /**
2595
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2596
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2597
-     * save, and save and close buttons to work properly, then you will want to include a
2598
-     * values for the name and id arguments.
2599
-     *
2600
-     * @todo  Add in validation for name/id arguments.
2601
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2602
-     * @param    int     $id                      id attached to the item published
2603
-     * @param    string  $delete                  page route callback for the delete action
2604
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2605
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2606
-     *                                            the Save button
2607
-     * @throws EE_Error
2608
-     * @throws InvalidArgumentException
2609
-     * @throws InvalidDataTypeException
2610
-     * @throws InvalidInterfaceException
2611
-     */
2612
-    protected function _set_publish_post_box_vars(
2613
-        $name = '',
2614
-        $id = 0,
2615
-        $delete = '',
2616
-        $save_close_redirect_URL = '',
2617
-        $both_btns = true
2618
-    ) {
2619
-        // if Save & Close, use a custom redirect URL or default to the main page?
2620
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2621
-            ? $save_close_redirect_URL
2622
-            : $this->_admin_base_url;
2623
-        // create the Save & Close and Save buttons
2624
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2625
-        // if we have extra content set let's add it in if not make sure its empty
2626
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2627
-            ? $this->_template_args['publish_box_extra_content']
2628
-            : '';
2629
-        if ($delete && ! empty($id)) {
2630
-            // make sure we have a default if just true is sent.
2631
-            $delete = ! empty($delete) ? $delete : 'delete';
2632
-            $delete_link_args = array($name => $id);
2633
-            $delete = $this->get_action_link_or_button(
2634
-                $delete,
2635
-                $delete,
2636
-                $delete_link_args,
2637
-                'submitdelete deletion',
2638
-                '',
2639
-                false
2640
-            );
2641
-        }
2642
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2643
-        if (! empty($name) && ! empty($id)) {
2644
-            $hidden_field_arr[ $name ] = array(
2645
-                'type'  => 'hidden',
2646
-                'value' => $id,
2647
-            );
2648
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2649
-        } else {
2650
-            $hf = '';
2651
-        }
2652
-        // add hidden field
2653
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2654
-            ? $hf[ $name ]['field']
2655
-            : $hf;
2656
-    }
2657
-
2658
-
2659
-    /**
2660
-     * displays an error message to ppl who have javascript disabled
2661
-     *
2662
-     * @return void
2663
-     */
2664
-    private function _display_no_javascript_warning()
2665
-    {
2666
-        ?>
2474
+	}
2475
+
2476
+
2477
+	private function _espresso_links_post_box()
2478
+	{
2479
+		// Hiding until we actually have content to put in here...
2480
+		// 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');
2481
+	}
2482
+
2483
+
2484
+	public function espresso_links_post_box()
2485
+	{
2486
+		// Hiding until we actually have content to put in here...
2487
+		// EEH_Template::display_template(
2488
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2489
+		// );
2490
+	}
2491
+
2492
+
2493
+	protected function _espresso_sponsors_post_box()
2494
+	{
2495
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2496
+			add_meta_box(
2497
+				'espresso_sponsors_post_box',
2498
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2499
+				array($this, 'espresso_sponsors_post_box'),
2500
+				$this->_wp_page_slug,
2501
+				'side'
2502
+			);
2503
+		}
2504
+	}
2505
+
2506
+
2507
+	public function espresso_sponsors_post_box()
2508
+	{
2509
+		EEH_Template::display_template(
2510
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2511
+		);
2512
+	}
2513
+
2514
+
2515
+	private function _publish_post_box()
2516
+	{
2517
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2518
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2519
+		// then we'll use that for the metabox label.
2520
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2521
+		if (! empty($this->_labels['publishbox'])) {
2522
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2523
+				: $this->_labels['publishbox'];
2524
+		} else {
2525
+			$box_label = esc_html__('Publish', 'event_espresso');
2526
+		}
2527
+		$box_label = apply_filters(
2528
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2529
+			$box_label,
2530
+			$this->_req_action,
2531
+			$this
2532
+		);
2533
+		add_meta_box(
2534
+			$meta_box_ref,
2535
+			$box_label,
2536
+			array($this, 'editor_overview'),
2537
+			$this->_current_screen->id,
2538
+			'side',
2539
+			'high'
2540
+		);
2541
+	}
2542
+
2543
+
2544
+	public function editor_overview()
2545
+	{
2546
+		// if we have extra content set let's add it in if not make sure its empty
2547
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2548
+			? $this->_template_args['publish_box_extra_content']
2549
+			: '';
2550
+		echo EEH_Template::display_template(
2551
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2552
+			$this->_template_args,
2553
+			true
2554
+		);
2555
+	}
2556
+
2557
+
2558
+	/** end of globally available metaboxes section **/
2559
+
2560
+
2561
+	/**
2562
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2563
+	 * protected method.
2564
+	 *
2565
+	 * @see   $this->_set_publish_post_box_vars for param details
2566
+	 * @since 4.6.0
2567
+	 * @param string $name
2568
+	 * @param int    $id
2569
+	 * @param bool   $delete
2570
+	 * @param string $save_close_redirect_URL
2571
+	 * @param bool   $both_btns
2572
+	 * @throws EE_Error
2573
+	 * @throws InvalidArgumentException
2574
+	 * @throws InvalidDataTypeException
2575
+	 * @throws InvalidInterfaceException
2576
+	 */
2577
+	public function set_publish_post_box_vars(
2578
+		$name = '',
2579
+		$id = 0,
2580
+		$delete = false,
2581
+		$save_close_redirect_URL = '',
2582
+		$both_btns = true
2583
+	) {
2584
+		$this->_set_publish_post_box_vars(
2585
+			$name,
2586
+			$id,
2587
+			$delete,
2588
+			$save_close_redirect_URL,
2589
+			$both_btns
2590
+		);
2591
+	}
2592
+
2593
+
2594
+	/**
2595
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2596
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2597
+	 * save, and save and close buttons to work properly, then you will want to include a
2598
+	 * values for the name and id arguments.
2599
+	 *
2600
+	 * @todo  Add in validation for name/id arguments.
2601
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2602
+	 * @param    int     $id                      id attached to the item published
2603
+	 * @param    string  $delete                  page route callback for the delete action
2604
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2605
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2606
+	 *                                            the Save button
2607
+	 * @throws EE_Error
2608
+	 * @throws InvalidArgumentException
2609
+	 * @throws InvalidDataTypeException
2610
+	 * @throws InvalidInterfaceException
2611
+	 */
2612
+	protected function _set_publish_post_box_vars(
2613
+		$name = '',
2614
+		$id = 0,
2615
+		$delete = '',
2616
+		$save_close_redirect_URL = '',
2617
+		$both_btns = true
2618
+	) {
2619
+		// if Save & Close, use a custom redirect URL or default to the main page?
2620
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2621
+			? $save_close_redirect_URL
2622
+			: $this->_admin_base_url;
2623
+		// create the Save & Close and Save buttons
2624
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2625
+		// if we have extra content set let's add it in if not make sure its empty
2626
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2627
+			? $this->_template_args['publish_box_extra_content']
2628
+			: '';
2629
+		if ($delete && ! empty($id)) {
2630
+			// make sure we have a default if just true is sent.
2631
+			$delete = ! empty($delete) ? $delete : 'delete';
2632
+			$delete_link_args = array($name => $id);
2633
+			$delete = $this->get_action_link_or_button(
2634
+				$delete,
2635
+				$delete,
2636
+				$delete_link_args,
2637
+				'submitdelete deletion',
2638
+				'',
2639
+				false
2640
+			);
2641
+		}
2642
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2643
+		if (! empty($name) && ! empty($id)) {
2644
+			$hidden_field_arr[ $name ] = array(
2645
+				'type'  => 'hidden',
2646
+				'value' => $id,
2647
+			);
2648
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2649
+		} else {
2650
+			$hf = '';
2651
+		}
2652
+		// add hidden field
2653
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2654
+			? $hf[ $name ]['field']
2655
+			: $hf;
2656
+	}
2657
+
2658
+
2659
+	/**
2660
+	 * displays an error message to ppl who have javascript disabled
2661
+	 *
2662
+	 * @return void
2663
+	 */
2664
+	private function _display_no_javascript_warning()
2665
+	{
2666
+		?>
2667 2667
         <noscript>
2668 2668
             <div id="no-js-message" class="error">
2669 2669
                 <p style="font-size:1.3em;">
2670 2670
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2671 2671
                     <?php esc_html_e(
2672
-                        '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.',
2673
-                        'event_espresso'
2674
-                    ); ?>
2672
+						'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.',
2673
+						'event_espresso'
2674
+					); ?>
2675 2675
                 </p>
2676 2676
             </div>
2677 2677
         </noscript>
2678 2678
         <?php
2679
-    }
2680
-
2681
-
2682
-    /**
2683
-     * displays espresso success and/or error notices
2684
-     *
2685
-     * @return void
2686
-     */
2687
-    private function _display_espresso_notices()
2688
-    {
2689
-        $notices = $this->_get_transient(true);
2690
-        echo stripslashes($notices);
2691
-    }
2692
-
2693
-
2694
-    /**
2695
-     * spinny things pacify the masses
2696
-     *
2697
-     * @return void
2698
-     */
2699
-    protected function _add_admin_page_ajax_loading_img()
2700
-    {
2701
-        ?>
2679
+	}
2680
+
2681
+
2682
+	/**
2683
+	 * displays espresso success and/or error notices
2684
+	 *
2685
+	 * @return void
2686
+	 */
2687
+	private function _display_espresso_notices()
2688
+	{
2689
+		$notices = $this->_get_transient(true);
2690
+		echo stripslashes($notices);
2691
+	}
2692
+
2693
+
2694
+	/**
2695
+	 * spinny things pacify the masses
2696
+	 *
2697
+	 * @return void
2698
+	 */
2699
+	protected function _add_admin_page_ajax_loading_img()
2700
+	{
2701
+		?>
2702 2702
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2703 2703
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2704
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2704
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2705 2705
         </div>
2706 2706
         <?php
2707
-    }
2707
+	}
2708 2708
 
2709 2709
 
2710
-    /**
2711
-     * add admin page overlay for modal boxes
2712
-     *
2713
-     * @return void
2714
-     */
2715
-    protected function _add_admin_page_overlay()
2716
-    {
2717
-        ?>
2710
+	/**
2711
+	 * add admin page overlay for modal boxes
2712
+	 *
2713
+	 * @return void
2714
+	 */
2715
+	protected function _add_admin_page_overlay()
2716
+	{
2717
+		?>
2718 2718
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2719 2719
         <?php
2720
-    }
2721
-
2722
-
2723
-    /**
2724
-     * facade for add_meta_box
2725
-     *
2726
-     * @param string  $action        where the metabox get's displayed
2727
-     * @param string  $title         Title of Metabox (output in metabox header)
2728
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2729
-     *                               instead of the one created in here.
2730
-     * @param array   $callback_args an array of args supplied for the metabox
2731
-     * @param string  $column        what metabox column
2732
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2733
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2734
-     *                               created but just set our own callback for wp's add_meta_box.
2735
-     * @throws \DomainException
2736
-     */
2737
-    public function _add_admin_page_meta_box(
2738
-        $action,
2739
-        $title,
2740
-        $callback,
2741
-        $callback_args,
2742
-        $column = 'normal',
2743
-        $priority = 'high',
2744
-        $create_func = true
2745
-    ) {
2746
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2747
-        // 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.
2748
-        if (empty($callback_args) && $create_func) {
2749
-            $callback_args = array(
2750
-                'template_path' => $this->_template_path,
2751
-                'template_args' => $this->_template_args,
2752
-            );
2753
-        }
2754
-        // 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)
2755
-        $call_back_func = $create_func
2756
-            ? function ($post, $metabox) {
2757
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2758
-                echo EEH_Template::display_template(
2759
-                    $metabox['args']['template_path'],
2760
-                    $metabox['args']['template_args'],
2761
-                    true
2762
-                );
2763
-            }
2764
-            : $callback;
2765
-        add_meta_box(
2766
-            str_replace('_', '-', $action) . '-mbox',
2767
-            $title,
2768
-            $call_back_func,
2769
-            $this->_wp_page_slug,
2770
-            $column,
2771
-            $priority,
2772
-            $callback_args
2773
-        );
2774
-    }
2775
-
2776
-
2777
-    /**
2778
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2779
-     *
2780
-     * @throws DomainException
2781
-     * @throws EE_Error
2782
-     */
2783
-    public function display_admin_page_with_metabox_columns()
2784
-    {
2785
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2786
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2787
-            $this->_column_template_path,
2788
-            $this->_template_args,
2789
-            true
2790
-        );
2791
-        // the final wrapper
2792
-        $this->admin_page_wrapper();
2793
-    }
2794
-
2795
-
2796
-    /**
2797
-     * generates  HTML wrapper for an admin details page
2798
-     *
2799
-     * @return void
2800
-     * @throws EE_Error
2801
-     * @throws DomainException
2802
-     */
2803
-    public function display_admin_page_with_sidebar()
2804
-    {
2805
-        $this->_display_admin_page(true);
2806
-    }
2807
-
2808
-
2809
-    /**
2810
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2811
-     *
2812
-     * @return void
2813
-     * @throws EE_Error
2814
-     * @throws DomainException
2815
-     */
2816
-    public function display_admin_page_with_no_sidebar()
2817
-    {
2818
-        $this->_display_admin_page();
2819
-    }
2820
-
2821
-
2822
-    /**
2823
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2824
-     *
2825
-     * @return void
2826
-     * @throws EE_Error
2827
-     * @throws DomainException
2828
-     */
2829
-    public function display_about_admin_page()
2830
-    {
2831
-        $this->_display_admin_page(false, true);
2832
-    }
2833
-
2834
-
2835
-    /**
2836
-     * display_admin_page
2837
-     * contains the code for actually displaying an admin page
2838
-     *
2839
-     * @param  boolean $sidebar true with sidebar, false without
2840
-     * @param  boolean $about   use the about admin wrapper instead of the default.
2841
-     * @return void
2842
-     * @throws DomainException
2843
-     * @throws EE_Error
2844
-     */
2845
-    private function _display_admin_page($sidebar = false, $about = false)
2846
-    {
2847
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2848
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2849
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2850
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2851
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2852
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2853
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2854
-            ? 'poststuff'
2855
-            : 'espresso-default-admin';
2856
-        $template_path = $sidebar
2857
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2858
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2859
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2860
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2861
-        }
2862
-        $template_path = ! empty($this->_column_template_path)
2863
-            ? $this->_column_template_path : $template_path;
2864
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content'])
2865
-            ? $this->_template_args['admin_page_content']
2866
-            : '';
2867
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2868
-            ? $this->_template_args['before_admin_page_content']
2869
-            : '';
2870
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content'])
2871
-            ? $this->_template_args['after_admin_page_content']
2872
-            : '';
2873
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2874
-            $template_path,
2875
-            $this->_template_args,
2876
-            true
2877
-        );
2878
-        // the final template wrapper
2879
-        $this->admin_page_wrapper($about);
2880
-    }
2881
-
2882
-
2883
-    /**
2884
-     * This is used to display caf preview pages.
2885
-     *
2886
-     * @since 4.3.2
2887
-     * @param string $utm_campaign_source what is the key used for google analytics link
2888
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2889
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2890
-     * @return void
2891
-     * @throws DomainException
2892
-     * @throws EE_Error
2893
-     * @throws InvalidArgumentException
2894
-     * @throws InvalidDataTypeException
2895
-     * @throws InvalidInterfaceException
2896
-     */
2897
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2898
-    {
2899
-        // let's generate a default preview action button if there isn't one already present.
2900
-        $this->_labels['buttons']['buy_now'] = esc_html__(
2901
-            'Upgrade to Event Espresso 4 Right Now',
2902
-            'event_espresso'
2903
-        );
2904
-        $buy_now_url = add_query_arg(
2905
-            array(
2906
-                'ee_ver'       => 'ee4',
2907
-                'utm_source'   => 'ee4_plugin_admin',
2908
-                'utm_medium'   => 'link',
2909
-                'utm_campaign' => $utm_campaign_source,
2910
-                'utm_content'  => 'buy_now_button',
2911
-            ),
2912
-            'http://eventespresso.com/pricing/'
2913
-        );
2914
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2915
-            ? $this->get_action_link_or_button(
2916
-                '',
2917
-                'buy_now',
2918
-                array(),
2919
-                'button-primary button-large',
2920
-                $buy_now_url,
2921
-                true
2922
-            )
2923
-            : $this->_template_args['preview_action_button'];
2924
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2925
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2926
-            $this->_template_args,
2927
-            true
2928
-        );
2929
-        $this->_display_admin_page($display_sidebar);
2930
-    }
2931
-
2932
-
2933
-    /**
2934
-     * display_admin_list_table_page_with_sidebar
2935
-     * generates HTML wrapper for an admin_page with list_table
2936
-     *
2937
-     * @return void
2938
-     * @throws EE_Error
2939
-     * @throws DomainException
2940
-     */
2941
-    public function display_admin_list_table_page_with_sidebar()
2942
-    {
2943
-        $this->_display_admin_list_table_page(true);
2944
-    }
2945
-
2946
-
2947
-    /**
2948
-     * display_admin_list_table_page_with_no_sidebar
2949
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2950
-     *
2951
-     * @return void
2952
-     * @throws EE_Error
2953
-     * @throws DomainException
2954
-     */
2955
-    public function display_admin_list_table_page_with_no_sidebar()
2956
-    {
2957
-        $this->_display_admin_list_table_page();
2958
-    }
2959
-
2960
-
2961
-    /**
2962
-     * generates html wrapper for an admin_list_table page
2963
-     *
2964
-     * @param boolean $sidebar whether to display with sidebar or not.
2965
-     * @return void
2966
-     * @throws DomainException
2967
-     * @throws EE_Error
2968
-     */
2969
-    private function _display_admin_list_table_page($sidebar = false)
2970
-    {
2971
-        // setup search attributes
2972
-        $this->_set_search_attributes();
2973
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2974
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2975
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
2976
-            ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2977
-            : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2978
-        $this->_template_args['list_table'] = $this->_list_table_object;
2979
-        $this->_template_args['current_route'] = $this->_req_action;
2980
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2981
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2982
-        if (! empty($ajax_sorting_callback)) {
2983
-            $sortable_list_table_form_fields = wp_nonce_field(
2984
-                $ajax_sorting_callback . '_nonce',
2985
-                $ajax_sorting_callback . '_nonce',
2986
-                false,
2987
-                false
2988
-            );
2989
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2990
-                                                . $this->page_slug
2991
-                                                . '" />';
2992
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2993
-                                                . $ajax_sorting_callback
2994
-                                                . '" />';
2995
-        } else {
2996
-            $sortable_list_table_form_fields = '';
2997
-        }
2998
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2999
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields'])
3000
-            ? $this->_template_args['list_table_hidden_fields']
3001
-            : '';
3002
-        $nonce_ref = $this->_req_action . '_nonce';
3003
-        $hidden_form_fields .= '<input type="hidden" name="'
3004
-                               . $nonce_ref
3005
-                               . '" value="'
3006
-                               . wp_create_nonce($nonce_ref)
3007
-                               . '">';
3008
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3009
-        // display message about search results?
3010
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3011
-            ? '<p class="ee-search-results">' . sprintf(
3012
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3013
-                trim($this->_req_data['s'], '%')
3014
-            ) . '</p>'
3015
-            : '';
3016
-        // filter before_list_table template arg
3017
-        $this->_template_args['before_list_table'] = apply_filters(
3018
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3019
-            $this->_template_args['before_list_table'],
3020
-            $this->page_slug,
3021
-            $this->_req_data,
3022
-            $this->_req_action
3023
-        );
3024
-        // convert to array and filter again
3025
-        // arrays are easier to inject new items in a specific location,
3026
-        // but would not be backwards compatible, so we have to add a new filter
3027
-        $this->_template_args['before_list_table'] = implode(
3028
-            " \n",
3029
-            (array) apply_filters(
3030
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3031
-                (array) $this->_template_args['before_list_table'],
3032
-                $this->page_slug,
3033
-                $this->_req_data,
3034
-                $this->_req_action
3035
-            )
3036
-        );
3037
-        // filter after_list_table template arg
3038
-        $this->_template_args['after_list_table'] = apply_filters(
3039
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3040
-            $this->_template_args['after_list_table'],
3041
-            $this->page_slug,
3042
-            $this->_req_data,
3043
-            $this->_req_action
3044
-        );
3045
-        // convert to array and filter again
3046
-        // arrays are easier to inject new items in a specific location,
3047
-        // but would not be backwards compatible, so we have to add a new filter
3048
-        $this->_template_args['after_list_table'] = implode(
3049
-            " \n",
3050
-            (array) apply_filters(
3051
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3052
-                (array) $this->_template_args['after_list_table'],
3053
-                $this->page_slug,
3054
-                $this->_req_data,
3055
-                $this->_req_action
3056
-            )
3057
-        );
3058
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3059
-            $template_path,
3060
-            $this->_template_args,
3061
-            true
3062
-        );
3063
-        // the final template wrapper
3064
-        if ($sidebar) {
3065
-            $this->display_admin_page_with_sidebar();
3066
-        } else {
3067
-            $this->display_admin_page_with_no_sidebar();
3068
-        }
3069
-    }
3070
-
3071
-
3072
-    /**
3073
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3074
-     * html string for the legend.
3075
-     * $items are expected in an array in the following format:
3076
-     * $legend_items = array(
3077
-     *        'item_id' => array(
3078
-     *            'icon' => 'http://url_to_icon_being_described.png',
3079
-     *            'desc' => esc_html__('localized description of item');
3080
-     *        )
3081
-     * );
3082
-     *
3083
-     * @param  array $items see above for format of array
3084
-     * @return string html string of legend
3085
-     * @throws DomainException
3086
-     */
3087
-    protected function _display_legend($items)
3088
-    {
3089
-        $this->_template_args['items'] = apply_filters(
3090
-            'FHEE__EE_Admin_Page___display_legend__items',
3091
-            (array) $items,
3092
-            $this
3093
-        );
3094
-        return EEH_Template::display_template(
3095
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3096
-            $this->_template_args,
3097
-            true
3098
-        );
3099
-    }
3100
-
3101
-
3102
-    /**
3103
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3104
-     * The returned json object is created from an array in the following format:
3105
-     * array(
3106
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3107
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3108
-     *  'notices' => '', // - contains any EE_Error formatted notices
3109
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3110
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3111
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3112
-     *  that might be included in here)
3113
-     * )
3114
-     * The json object is populated by whatever is set in the $_template_args property.
3115
-     *
3116
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3117
-     *                                 instead of displayed.
3118
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3119
-     * @return void
3120
-     * @throws EE_Error
3121
-     */
3122
-    protected function _return_json($sticky_notices = false, $notices_arguments = array())
3123
-    {
3124
-        // make sure any EE_Error notices have been handled.
3125
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3126
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3127
-        unset($this->_template_args['data']);
3128
-        $json = array(
3129
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3130
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3131
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3132
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3133
-            'notices'   => EE_Error::get_notices(),
3134
-            'content'   => isset($this->_template_args['admin_page_content'])
3135
-                ? $this->_template_args['admin_page_content'] : '',
3136
-            'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3137
-            'isEEajax'  => true
3138
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3139
-        );
3140
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3141
-        if (null === error_get_last() || ! headers_sent()) {
3142
-            header('Content-Type: application/json; charset=UTF-8');
3143
-        }
3144
-        echo wp_json_encode($json);
3145
-        exit();
3146
-    }
3147
-
3148
-
3149
-    /**
3150
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3151
-     *
3152
-     * @return void
3153
-     * @throws EE_Error
3154
-     */
3155
-    public function return_json()
3156
-    {
3157
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3158
-            $this->_return_json();
3159
-        } else {
3160
-            throw new EE_Error(
3161
-                sprintf(
3162
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3163
-                    __FUNCTION__
3164
-                )
3165
-            );
3166
-        }
3167
-    }
3168
-
3169
-
3170
-    /**
3171
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3172
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3173
-     *
3174
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3175
-     */
3176
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3177
-    {
3178
-        $this->_hook_obj = $hook_obj;
3179
-    }
3180
-
3181
-
3182
-    /**
3183
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3184
-     *
3185
-     * @param  boolean $about whether to use the special about page wrapper or default.
3186
-     * @return void
3187
-     * @throws DomainException
3188
-     * @throws EE_Error
3189
-     */
3190
-    public function admin_page_wrapper($about = false)
3191
-    {
3192
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3193
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
3194
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
3195
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
3196
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3197
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3198
-            isset($this->_template_args['before_admin_page_content'])
3199
-                ? $this->_template_args['before_admin_page_content']
3200
-                : ''
3201
-        );
3202
-        $this->_template_args['after_admin_page_content'] = apply_filters(
3203
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3204
-            isset($this->_template_args['after_admin_page_content'])
3205
-                ? $this->_template_args['after_admin_page_content']
3206
-                : ''
3207
-        );
3208
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3209
-        // load settings page wrapper template
3210
-        $template_path = ! defined('DOING_AJAX')
3211
-            ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3212
-            : EE_ADMIN_TEMPLATE
3213
-              . 'admin_wrapper_ajax.template.php';
3214
-        // about page?
3215
-        $template_path = $about
3216
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3217
-            : $template_path;
3218
-        if (defined('DOING_AJAX')) {
3219
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3220
-                $template_path,
3221
-                $this->_template_args,
3222
-                true
3223
-            );
3224
-            $this->_return_json();
3225
-        } else {
3226
-            EEH_Template::display_template($template_path, $this->_template_args);
3227
-        }
3228
-    }
3229
-
3230
-
3231
-    /**
3232
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3233
-     *
3234
-     * @return string html
3235
-     * @throws EE_Error
3236
-     */
3237
-    protected function _get_main_nav_tabs()
3238
-    {
3239
-        // let's generate the html using the EEH_Tabbed_Content helper.
3240
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3241
-        // (rather than setting in the page_routes array)
3242
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3243
-    }
3244
-
3245
-
3246
-    /**
3247
-     *        sort nav tabs
3248
-     *
3249
-     * @param $a
3250
-     * @param $b
3251
-     * @return int
3252
-     */
3253
-    private function _sort_nav_tabs($a, $b)
3254
-    {
3255
-        if ($a['order'] === $b['order']) {
3256
-            return 0;
3257
-        }
3258
-        return ($a['order'] < $b['order']) ? -1 : 1;
3259
-    }
3260
-
3261
-
3262
-    /**
3263
-     *    generates HTML for the forms used on admin pages
3264
-     *
3265
-     * @param    array $input_vars - array of input field details
3266
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to
3267
-     *                             use)
3268
-     * @param bool     $id
3269
-     * @return string
3270
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3271
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3272
-     */
3273
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
3274
-    {
3275
-        $content = $generator === 'string'
3276
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3277
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3278
-        return $content;
3279
-    }
3280
-
3281
-
3282
-    /**
3283
-     * generates the "Save" and "Save & Close" buttons for edit forms
3284
-     *
3285
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3286
-     *                                   Close" button.
3287
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3288
-     *                                   'Save', [1] => 'save & close')
3289
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3290
-     *                                   via the "name" value in the button).  We can also use this to just dump
3291
-     *                                   default actions by submitting some other value.
3292
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3293
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3294
-     *                                   close (normal form handling).
3295
-     */
3296
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3297
-    {
3298
-        // make sure $text and $actions are in an array
3299
-        $text = (array) $text;
3300
-        $actions = (array) $actions;
3301
-        $referrer_url = empty($referrer)
3302
-            ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3303
-              . $_SERVER['REQUEST_URI']
3304
-              . '" />'
3305
-            : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3306
-              . $referrer
3307
-              . '" />';
3308
-        $button_text = ! empty($text)
3309
-            ? $text
3310
-            : array(
3311
-                esc_html__('Save', 'event_espresso'),
3312
-                esc_html__('Save and Close', 'event_espresso'),
3313
-            );
3314
-        $default_names = array('save', 'save_and_close');
3315
-        // add in a hidden index for the current page (so save and close redirects properly)
3316
-        $this->_template_args['save_buttons'] = $referrer_url;
3317
-        foreach ($button_text as $key => $button) {
3318
-            $ref = $default_names[ $key ];
3319
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3320
-                                                     . $ref
3321
-                                                     . '" value="'
3322
-                                                     . $button
3323
-                                                     . '" name="'
3324
-                                                     . (! empty($actions) ? $actions[ $key ] : $ref)
3325
-                                                     . '" id="'
3326
-                                                     . $this->_current_view . '_' . $ref
3327
-                                                     . '" />';
3328
-            if (! $both) {
3329
-                break;
3330
-            }
3331
-        }
3332
-    }
3333
-
3334
-
3335
-    /**
3336
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3337
-     *
3338
-     * @see   $this->_set_add_edit_form_tags() for details on params
3339
-     * @since 4.6.0
3340
-     * @param string $route
3341
-     * @param array  $additional_hidden_fields
3342
-     */
3343
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3344
-    {
3345
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3346
-    }
3347
-
3348
-
3349
-    /**
3350
-     * set form open and close tags on add/edit pages.
3351
-     *
3352
-     * @param string $route                    the route you want the form to direct to
3353
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3354
-     * @return void
3355
-     */
3356
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3357
-    {
3358
-        if (empty($route)) {
3359
-            $user_msg = esc_html__(
3360
-                'An error occurred. No action was set for this page\'s form.',
3361
-                'event_espresso'
3362
-            );
3363
-            $dev_msg = $user_msg . "\n"
3364
-                       . sprintf(
3365
-                           esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3366
-                           __FUNCTION__,
3367
-                           __CLASS__
3368
-                       );
3369
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3370
-        }
3371
-        // open form
3372
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3373
-                                                             . $this->_admin_base_url
3374
-                                                             . '" id="'
3375
-                                                             . $route
3376
-                                                             . '_event_form" >';
3377
-        // add nonce
3378
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3379
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3380
-        // add REQUIRED form action
3381
-        $hidden_fields = array(
3382
-            'action' => array('type' => 'hidden', 'value' => $route),
3383
-        );
3384
-        // merge arrays
3385
-        $hidden_fields = is_array($additional_hidden_fields)
3386
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3387
-            : $hidden_fields;
3388
-        // generate form fields
3389
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3390
-        // add fields to form
3391
-        foreach ((array) $form_fields as $field_name => $form_field) {
3392
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3393
-        }
3394
-        // close form
3395
-        $this->_template_args['after_admin_page_content'] = '</form>';
3396
-    }
3397
-
3398
-
3399
-    /**
3400
-     * Public Wrapper for _redirect_after_action() method since its
3401
-     * discovered it would be useful for external code to have access.
3402
-     *
3403
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3404
-     * @since 4.5.0
3405
-     * @param bool   $success
3406
-     * @param string $what
3407
-     * @param string $action_desc
3408
-     * @param array  $query_args
3409
-     * @param bool   $override_overwrite
3410
-     * @throws EE_Error
3411
-     */
3412
-    public function redirect_after_action(
3413
-        $success = false,
3414
-        $what = 'item',
3415
-        $action_desc = 'processed',
3416
-        $query_args = array(),
3417
-        $override_overwrite = false
3418
-    ) {
3419
-        $this->_redirect_after_action(
3420
-            $success,
3421
-            $what,
3422
-            $action_desc,
3423
-            $query_args,
3424
-            $override_overwrite
3425
-        );
3426
-    }
3427
-
3428
-
3429
-    /**
3430
-     * Helper method for merging existing request data with the returned redirect url.
3431
-     *
3432
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3433
-     * filters are still applied.
3434
-     *
3435
-     * @param array $new_route_data
3436
-     * @return array
3437
-     */
3438
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3439
-    {
3440
-        foreach ($this->_req_data as $ref => $value) {
3441
-            // unset nonces
3442
-            if (strpos($ref, 'nonce') !== false) {
3443
-                unset($this->_req_data[ $ref ]);
3444
-                continue;
3445
-            }
3446
-            // urlencode values.
3447
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3448
-            $this->_req_data[ $ref ] = $value;
3449
-        }
3450
-        return array_merge($this->_req_data, $new_route_data);
3451
-    }
3452
-
3453
-
3454
-    /**
3455
-     *    _redirect_after_action
3456
-     *
3457
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3458
-     * @param string $what               - what the action was performed on
3459
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3460
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3461
-     *                                   action is completed
3462
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3463
-     *                                   override this so that they show.
3464
-     * @return void
3465
-     * @throws EE_Error
3466
-     */
3467
-    protected function _redirect_after_action(
3468
-        $success = 0,
3469
-        $what = 'item',
3470
-        $action_desc = 'processed',
3471
-        $query_args = array(),
3472
-        $override_overwrite = false
3473
-    ) {
3474
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3475
-        // class name for actions/filters.
3476
-        $classname = get_class($this);
3477
-        // set redirect url.
3478
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3479
-        // otherwise we go with whatever is set as the _admin_base_url
3480
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3481
-        $notices = EE_Error::get_notices(false);
3482
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3483
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3484
-            EE_Error::overwrite_success();
3485
-        }
3486
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3487
-            // how many records affected ? more than one record ? or just one ?
3488
-            if ($success > 1) {
3489
-                // set plural msg
3490
-                EE_Error::add_success(
3491
-                    sprintf(
3492
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3493
-                        $what,
3494
-                        $action_desc
3495
-                    ),
3496
-                    __FILE__,
3497
-                    __FUNCTION__,
3498
-                    __LINE__
3499
-                );
3500
-            } elseif ($success === 1) {
3501
-                // set singular msg
3502
-                EE_Error::add_success(
3503
-                    sprintf(
3504
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3505
-                        $what,
3506
-                        $action_desc
3507
-                    ),
3508
-                    __FILE__,
3509
-                    __FUNCTION__,
3510
-                    __LINE__
3511
-                );
3512
-            }
3513
-        }
3514
-        // check that $query_args isn't something crazy
3515
-        if (! is_array($query_args)) {
3516
-            $query_args = array();
3517
-        }
3518
-        /**
3519
-         * Allow injecting actions before the query_args are modified for possible different
3520
-         * redirections on save and close actions
3521
-         *
3522
-         * @since 4.2.0
3523
-         * @param array $query_args       The original query_args array coming into the
3524
-         *                                method.
3525
-         */
3526
-        do_action(
3527
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3528
-            $query_args
3529
-        );
3530
-        // calculate where we're going (if we have a "save and close" button pushed)
3531
-        if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3532
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3533
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3534
-            // regenerate query args array from referrer URL
3535
-            parse_str($parsed_url['query'], $query_args);
3536
-            // correct page and action will be in the query args now
3537
-            $redirect_url = admin_url('admin.php');
3538
-        }
3539
-        // merge any default query_args set in _default_route_query_args property
3540
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3541
-            $args_to_merge = array();
3542
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3543
-                // is there a wp_referer array in our _default_route_query_args property?
3544
-                if ($query_param === 'wp_referer') {
3545
-                    $query_value = (array) $query_value;
3546
-                    foreach ($query_value as $reference => $value) {
3547
-                        if (strpos($reference, 'nonce') !== false) {
3548
-                            continue;
3549
-                        }
3550
-                        // finally we will override any arguments in the referer with
3551
-                        // what might be set on the _default_route_query_args array.
3552
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3553
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3554
-                        } else {
3555
-                            $args_to_merge[ $reference ] = urlencode($value);
3556
-                        }
3557
-                    }
3558
-                    continue;
3559
-                }
3560
-                $args_to_merge[ $query_param ] = $query_value;
3561
-            }
3562
-            // now let's merge these arguments but override with what was specifically sent in to the
3563
-            // redirect.
3564
-            $query_args = array_merge($args_to_merge, $query_args);
3565
-        }
3566
-        $this->_process_notices($query_args);
3567
-        // generate redirect url
3568
-        // if redirecting to anything other than the main page, add a nonce
3569
-        if (isset($query_args['action'])) {
3570
-            // manually generate wp_nonce and merge that with the query vars
3571
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3572
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3573
-        }
3574
-        // we're adding some hooks and filters in here for processing any things just before redirects
3575
-        // (example: an admin page has done an insert or update and we want to run something after that).
3576
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3577
-        $redirect_url = apply_filters(
3578
-            'FHEE_redirect_' . $classname . $this->_req_action,
3579
-            self::add_query_args_and_nonce($query_args, $redirect_url),
3580
-            $query_args
3581
-        );
3582
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3583
-        if (defined('DOING_AJAX')) {
3584
-            $default_data = array(
3585
-                'close'        => true,
3586
-                'redirect_url' => $redirect_url,
3587
-                'where'        => 'main',
3588
-                'what'         => 'append',
3589
-            );
3590
-            $this->_template_args['success'] = $success;
3591
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge(
3592
-                $default_data,
3593
-                $this->_template_args['data']
3594
-            ) : $default_data;
3595
-            $this->_return_json();
3596
-        }
3597
-        wp_safe_redirect($redirect_url);
3598
-        exit();
3599
-    }
3600
-
3601
-
3602
-    /**
3603
-     * process any notices before redirecting (or returning ajax request)
3604
-     * This method sets the $this->_template_args['notices'] attribute;
3605
-     *
3606
-     * @param  array $query_args        any query args that need to be used for notice transient ('action')
3607
-     * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and
3608
-     *                                  page_routes haven't been defined yet.
3609
-     * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we
3610
-     *                                  still save a transient for the notice.
3611
-     * @return void
3612
-     * @throws EE_Error
3613
-     */
3614
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3615
-    {
3616
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3617
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3618
-            $notices = EE_Error::get_notices(false);
3619
-            if (empty($this->_template_args['success'])) {
3620
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3621
-            }
3622
-            if (empty($this->_template_args['errors'])) {
3623
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3624
-            }
3625
-            if (empty($this->_template_args['attention'])) {
3626
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3627
-            }
3628
-        }
3629
-        $this->_template_args['notices'] = EE_Error::get_notices();
3630
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3631
-        if (! defined('DOING_AJAX') || $sticky_notices) {
3632
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3633
-            $this->_add_transient(
3634
-                $route,
3635
-                $this->_template_args['notices'],
3636
-                true,
3637
-                $skip_route_verify
3638
-            );
3639
-        }
3640
-    }
3641
-
3642
-
3643
-    /**
3644
-     * get_action_link_or_button
3645
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3646
-     *
3647
-     * @param string $action        use this to indicate which action the url is generated with.
3648
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3649
-     *                              property.
3650
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3651
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3652
-     * @param string $base_url      If this is not provided
3653
-     *                              the _admin_base_url will be used as the default for the button base_url.
3654
-     *                              Otherwise this value will be used.
3655
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3656
-     * @return string
3657
-     * @throws InvalidArgumentException
3658
-     * @throws InvalidInterfaceException
3659
-     * @throws InvalidDataTypeException
3660
-     * @throws EE_Error
3661
-     */
3662
-    public function get_action_link_or_button(
3663
-        $action,
3664
-        $type = 'add',
3665
-        $extra_request = array(),
3666
-        $class = 'button-primary',
3667
-        $base_url = '',
3668
-        $exclude_nonce = false
3669
-    ) {
3670
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3671
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3672
-            throw new EE_Error(
3673
-                sprintf(
3674
-                    esc_html__(
3675
-                        'There is no page route for given action for the button.  This action was given: %s',
3676
-                        'event_espresso'
3677
-                    ),
3678
-                    $action
3679
-                )
3680
-            );
3681
-        }
3682
-        if (! isset($this->_labels['buttons'][ $type ])) {
3683
-            throw new EE_Error(
3684
-                sprintf(
3685
-                    __(
3686
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3687
-                        'event_espresso'
3688
-                    ),
3689
-                    $type
3690
-                )
3691
-            );
3692
-        }
3693
-        // finally check user access for this button.
3694
-        $has_access = $this->check_user_access($action, true);
3695
-        if (! $has_access) {
3696
-            return '';
3697
-        }
3698
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
3699
-        $query_args = array(
3700
-            'action' => $action,
3701
-        );
3702
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3703
-        if (! empty($extra_request)) {
3704
-            $query_args = array_merge($extra_request, $query_args);
3705
-        }
3706
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3707
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3708
-    }
3709
-
3710
-
3711
-    /**
3712
-     * _per_page_screen_option
3713
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3714
-     *
3715
-     * @return void
3716
-     * @throws InvalidArgumentException
3717
-     * @throws InvalidInterfaceException
3718
-     * @throws InvalidDataTypeException
3719
-     */
3720
-    protected function _per_page_screen_option()
3721
-    {
3722
-        $option = 'per_page';
3723
-        $args = array(
3724
-            'label'   => apply_filters(
3725
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3726
-                $this->_admin_page_title,
3727
-                $this
3728
-            ),
3729
-            'default' => (int) apply_filters(
3730
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3731
-                20
3732
-            ),
3733
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3734
-        );
3735
-        // ONLY add the screen option if the user has access to it.
3736
-        if ($this->check_user_access($this->_current_view, true)) {
3737
-            add_screen_option($option, $args);
3738
-        }
3739
-    }
3740
-
3741
-
3742
-    /**
3743
-     * set_per_page_screen_option
3744
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3745
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3746
-     * admin_menu.
3747
-     *
3748
-     * @return void
3749
-     */
3750
-    private function _set_per_page_screen_options()
3751
-    {
3752
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3753
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3754
-            if (! $user = wp_get_current_user()) {
3755
-                return;
3756
-            }
3757
-            $option = $_POST['wp_screen_options']['option'];
3758
-            $value = $_POST['wp_screen_options']['value'];
3759
-            if ($option != sanitize_key($option)) {
3760
-                return;
3761
-            }
3762
-            $map_option = $option;
3763
-            $option = str_replace('-', '_', $option);
3764
-            switch ($map_option) {
3765
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3766
-                    $value = (int) $value;
3767
-                    $max_value = apply_filters(
3768
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3769
-                        999,
3770
-                        $this->_current_page,
3771
-                        $this->_current_view
3772
-                    );
3773
-                    if ($value < 1) {
3774
-                        return;
3775
-                    }
3776
-                    $value = min($value, $max_value);
3777
-                    break;
3778
-                default:
3779
-                    $value = apply_filters(
3780
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3781
-                        false,
3782
-                        $option,
3783
-                        $value
3784
-                    );
3785
-                    if (false === $value) {
3786
-                        return;
3787
-                    }
3788
-                    break;
3789
-            }
3790
-            update_user_meta($user->ID, $option, $value);
3791
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3792
-            exit;
3793
-        }
3794
-    }
3795
-
3796
-
3797
-    /**
3798
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3799
-     *
3800
-     * @param array $data array that will be assigned to template args.
3801
-     */
3802
-    public function set_template_args($data)
3803
-    {
3804
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3805
-    }
3806
-
3807
-
3808
-    /**
3809
-     * This makes available the WP transient system for temporarily moving data between routes
3810
-     *
3811
-     * @param string $route             the route that should receive the transient
3812
-     * @param array  $data              the data that gets sent
3813
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3814
-     *                                  normal route transient.
3815
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3816
-     *                                  when we are adding a transient before page_routes have been defined.
3817
-     * @return void
3818
-     * @throws EE_Error
3819
-     */
3820
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3821
-    {
3822
-        $user_id = get_current_user_id();
3823
-        if (! $skip_route_verify) {
3824
-            $this->_verify_route($route);
3825
-        }
3826
-        // now let's set the string for what kind of transient we're setting
3827
-        $transient = $notices
3828
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3829
-            : 'rte_tx_' . $route . '_' . $user_id;
3830
-        $data = $notices ? array('notices' => $data) : $data;
3831
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3832
-        $existing = is_multisite() && is_network_admin()
3833
-            ? get_site_transient($transient)
3834
-            : get_transient($transient);
3835
-        if ($existing) {
3836
-            $data = array_merge((array) $data, (array) $existing);
3837
-        }
3838
-        if (is_multisite() && is_network_admin()) {
3839
-            set_site_transient($transient, $data, 8);
3840
-        } else {
3841
-            set_transient($transient, $data, 8);
3842
-        }
3843
-    }
3844
-
3845
-
3846
-    /**
3847
-     * this retrieves the temporary transient that has been set for moving data between routes.
3848
-     *
3849
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3850
-     * @param string $route
3851
-     * @return mixed data
3852
-     */
3853
-    protected function _get_transient($notices = false, $route = '')
3854
-    {
3855
-        $user_id = get_current_user_id();
3856
-        $route = ! $route ? $this->_req_action : $route;
3857
-        $transient = $notices
3858
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3859
-            : 'rte_tx_' . $route . '_' . $user_id;
3860
-        $data = is_multisite() && is_network_admin()
3861
-            ? get_site_transient($transient)
3862
-            : get_transient($transient);
3863
-        // delete transient after retrieval (just in case it hasn't expired);
3864
-        if (is_multisite() && is_network_admin()) {
3865
-            delete_site_transient($transient);
3866
-        } else {
3867
-            delete_transient($transient);
3868
-        }
3869
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3870
-    }
3871
-
3872
-
3873
-    /**
3874
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3875
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3876
-     * default route callback on the EE_Admin page you want it run.)
3877
-     *
3878
-     * @return void
3879
-     */
3880
-    protected function _transient_garbage_collection()
3881
-    {
3882
-        global $wpdb;
3883
-        // retrieve all existing transients
3884
-        $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3885
-        if ($results = $wpdb->get_results($query)) {
3886
-            foreach ($results as $result) {
3887
-                $transient = str_replace('_transient_', '', $result->option_name);
3888
-                get_transient($transient);
3889
-                if (is_multisite() && is_network_admin()) {
3890
-                    get_site_transient($transient);
3891
-                }
3892
-            }
3893
-        }
3894
-    }
3895
-
3896
-
3897
-    /**
3898
-     * get_view
3899
-     *
3900
-     * @return string content of _view property
3901
-     */
3902
-    public function get_view()
3903
-    {
3904
-        return $this->_view;
3905
-    }
3906
-
3907
-
3908
-    /**
3909
-     * getter for the protected $_views property
3910
-     *
3911
-     * @return array
3912
-     */
3913
-    public function get_views()
3914
-    {
3915
-        return $this->_views;
3916
-    }
3917
-
3918
-
3919
-    /**
3920
-     * get_current_page
3921
-     *
3922
-     * @return string _current_page property value
3923
-     */
3924
-    public function get_current_page()
3925
-    {
3926
-        return $this->_current_page;
3927
-    }
3928
-
3929
-
3930
-    /**
3931
-     * get_current_view
3932
-     *
3933
-     * @return string _current_view property value
3934
-     */
3935
-    public function get_current_view()
3936
-    {
3937
-        return $this->_current_view;
3938
-    }
3939
-
3940
-
3941
-    /**
3942
-     * get_current_screen
3943
-     *
3944
-     * @return object The current WP_Screen object
3945
-     */
3946
-    public function get_current_screen()
3947
-    {
3948
-        return $this->_current_screen;
3949
-    }
3950
-
3951
-
3952
-    /**
3953
-     * get_current_page_view_url
3954
-     *
3955
-     * @return string This returns the url for the current_page_view.
3956
-     */
3957
-    public function get_current_page_view_url()
3958
-    {
3959
-        return $this->_current_page_view_url;
3960
-    }
3961
-
3962
-
3963
-    /**
3964
-     * just returns the _req_data property
3965
-     *
3966
-     * @return array
3967
-     */
3968
-    public function get_request_data()
3969
-    {
3970
-        return $this->_req_data;
3971
-    }
3972
-
3973
-
3974
-    /**
3975
-     * returns the _req_data protected property
3976
-     *
3977
-     * @return string
3978
-     */
3979
-    public function get_req_action()
3980
-    {
3981
-        return $this->_req_action;
3982
-    }
3983
-
3984
-
3985
-    /**
3986
-     * @return bool  value of $_is_caf property
3987
-     */
3988
-    public function is_caf()
3989
-    {
3990
-        return $this->_is_caf;
3991
-    }
3992
-
3993
-
3994
-    /**
3995
-     * @return mixed
3996
-     */
3997
-    public function default_espresso_metaboxes()
3998
-    {
3999
-        return $this->_default_espresso_metaboxes;
4000
-    }
4001
-
4002
-
4003
-    /**
4004
-     * @return mixed
4005
-     */
4006
-    public function admin_base_url()
4007
-    {
4008
-        return $this->_admin_base_url;
4009
-    }
4010
-
4011
-
4012
-    /**
4013
-     * @return mixed
4014
-     */
4015
-    public function wp_page_slug()
4016
-    {
4017
-        return $this->_wp_page_slug;
4018
-    }
4019
-
4020
-
4021
-    /**
4022
-     * updates  espresso configuration settings
4023
-     *
4024
-     * @param string                   $tab
4025
-     * @param EE_Config_Base|EE_Config $config
4026
-     * @param string                   $file file where error occurred
4027
-     * @param string                   $func function  where error occurred
4028
-     * @param string                   $line line no where error occurred
4029
-     * @return boolean
4030
-     */
4031
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4032
-    {
4033
-        // remove any options that are NOT going to be saved with the config settings.
4034
-        if (isset($config->core->ee_ueip_optin)) {
4035
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
4036
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4037
-            update_option('ee_ueip_has_notified', true);
4038
-        }
4039
-        // and save it (note we're also doing the network save here)
4040
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4041
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
4042
-        if ($config_saved && $net_saved) {
4043
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4044
-            return true;
4045
-        }
4046
-        EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4047
-        return false;
4048
-    }
4049
-
4050
-
4051
-    /**
4052
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4053
-     *
4054
-     * @return array
4055
-     */
4056
-    public function get_yes_no_values()
4057
-    {
4058
-        return $this->_yes_no_values;
4059
-    }
4060
-
4061
-
4062
-    protected function _get_dir()
4063
-    {
4064
-        $reflector = new ReflectionClass(get_class($this));
4065
-        return dirname($reflector->getFileName());
4066
-    }
4067
-
4068
-
4069
-    /**
4070
-     * A helper for getting a "next link".
4071
-     *
4072
-     * @param string $url   The url to link to
4073
-     * @param string $class The class to use.
4074
-     * @return string
4075
-     */
4076
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4077
-    {
4078
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4079
-    }
4080
-
4081
-
4082
-    /**
4083
-     * A helper for getting a "previous link".
4084
-     *
4085
-     * @param string $url   The url to link to
4086
-     * @param string $class The class to use.
4087
-     * @return string
4088
-     */
4089
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4090
-    {
4091
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4092
-    }
4093
-
4094
-
4095
-
4096
-
4097
-
4098
-
4099
-
4100
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4101
-
4102
-
4103
-    /**
4104
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4105
-     * 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
4106
-     * _req_data array.
4107
-     *
4108
-     * @return bool success/fail
4109
-     * @throws EE_Error
4110
-     * @throws InvalidArgumentException
4111
-     * @throws ReflectionException
4112
-     * @throws InvalidDataTypeException
4113
-     * @throws InvalidInterfaceException
4114
-     */
4115
-    protected function _process_resend_registration()
4116
-    {
4117
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4118
-        do_action(
4119
-            'AHEE__EE_Admin_Page___process_resend_registration',
4120
-            $this->_template_args['success'],
4121
-            $this->_req_data
4122
-        );
4123
-        return $this->_template_args['success'];
4124
-    }
4125
-
4126
-
4127
-    /**
4128
-     * This automatically processes any payment message notifications when manual payment has been applied.
4129
-     *
4130
-     * @param \EE_Payment $payment
4131
-     * @return bool success/fail
4132
-     */
4133
-    protected function _process_payment_notification(EE_Payment $payment)
4134
-    {
4135
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4136
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4137
-        $this->_template_args['success'] = apply_filters(
4138
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4139
-            false,
4140
-            $payment
4141
-        );
4142
-        return $this->_template_args['success'];
4143
-    }
2720
+	}
2721
+
2722
+
2723
+	/**
2724
+	 * facade for add_meta_box
2725
+	 *
2726
+	 * @param string  $action        where the metabox get's displayed
2727
+	 * @param string  $title         Title of Metabox (output in metabox header)
2728
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2729
+	 *                               instead of the one created in here.
2730
+	 * @param array   $callback_args an array of args supplied for the metabox
2731
+	 * @param string  $column        what metabox column
2732
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2733
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2734
+	 *                               created but just set our own callback for wp's add_meta_box.
2735
+	 * @throws \DomainException
2736
+	 */
2737
+	public function _add_admin_page_meta_box(
2738
+		$action,
2739
+		$title,
2740
+		$callback,
2741
+		$callback_args,
2742
+		$column = 'normal',
2743
+		$priority = 'high',
2744
+		$create_func = true
2745
+	) {
2746
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2747
+		// 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.
2748
+		if (empty($callback_args) && $create_func) {
2749
+			$callback_args = array(
2750
+				'template_path' => $this->_template_path,
2751
+				'template_args' => $this->_template_args,
2752
+			);
2753
+		}
2754
+		// 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)
2755
+		$call_back_func = $create_func
2756
+			? function ($post, $metabox) {
2757
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2758
+				echo EEH_Template::display_template(
2759
+					$metabox['args']['template_path'],
2760
+					$metabox['args']['template_args'],
2761
+					true
2762
+				);
2763
+			}
2764
+			: $callback;
2765
+		add_meta_box(
2766
+			str_replace('_', '-', $action) . '-mbox',
2767
+			$title,
2768
+			$call_back_func,
2769
+			$this->_wp_page_slug,
2770
+			$column,
2771
+			$priority,
2772
+			$callback_args
2773
+		);
2774
+	}
2775
+
2776
+
2777
+	/**
2778
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2779
+	 *
2780
+	 * @throws DomainException
2781
+	 * @throws EE_Error
2782
+	 */
2783
+	public function display_admin_page_with_metabox_columns()
2784
+	{
2785
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2786
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2787
+			$this->_column_template_path,
2788
+			$this->_template_args,
2789
+			true
2790
+		);
2791
+		// the final wrapper
2792
+		$this->admin_page_wrapper();
2793
+	}
2794
+
2795
+
2796
+	/**
2797
+	 * generates  HTML wrapper for an admin details page
2798
+	 *
2799
+	 * @return void
2800
+	 * @throws EE_Error
2801
+	 * @throws DomainException
2802
+	 */
2803
+	public function display_admin_page_with_sidebar()
2804
+	{
2805
+		$this->_display_admin_page(true);
2806
+	}
2807
+
2808
+
2809
+	/**
2810
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2811
+	 *
2812
+	 * @return void
2813
+	 * @throws EE_Error
2814
+	 * @throws DomainException
2815
+	 */
2816
+	public function display_admin_page_with_no_sidebar()
2817
+	{
2818
+		$this->_display_admin_page();
2819
+	}
2820
+
2821
+
2822
+	/**
2823
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2824
+	 *
2825
+	 * @return void
2826
+	 * @throws EE_Error
2827
+	 * @throws DomainException
2828
+	 */
2829
+	public function display_about_admin_page()
2830
+	{
2831
+		$this->_display_admin_page(false, true);
2832
+	}
2833
+
2834
+
2835
+	/**
2836
+	 * display_admin_page
2837
+	 * contains the code for actually displaying an admin page
2838
+	 *
2839
+	 * @param  boolean $sidebar true with sidebar, false without
2840
+	 * @param  boolean $about   use the about admin wrapper instead of the default.
2841
+	 * @return void
2842
+	 * @throws DomainException
2843
+	 * @throws EE_Error
2844
+	 */
2845
+	private function _display_admin_page($sidebar = false, $about = false)
2846
+	{
2847
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2848
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2849
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2850
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2851
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2852
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2853
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2854
+			? 'poststuff'
2855
+			: 'espresso-default-admin';
2856
+		$template_path = $sidebar
2857
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2858
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2859
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2860
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2861
+		}
2862
+		$template_path = ! empty($this->_column_template_path)
2863
+			? $this->_column_template_path : $template_path;
2864
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content'])
2865
+			? $this->_template_args['admin_page_content']
2866
+			: '';
2867
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2868
+			? $this->_template_args['before_admin_page_content']
2869
+			: '';
2870
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content'])
2871
+			? $this->_template_args['after_admin_page_content']
2872
+			: '';
2873
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2874
+			$template_path,
2875
+			$this->_template_args,
2876
+			true
2877
+		);
2878
+		// the final template wrapper
2879
+		$this->admin_page_wrapper($about);
2880
+	}
2881
+
2882
+
2883
+	/**
2884
+	 * This is used to display caf preview pages.
2885
+	 *
2886
+	 * @since 4.3.2
2887
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2888
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2889
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2890
+	 * @return void
2891
+	 * @throws DomainException
2892
+	 * @throws EE_Error
2893
+	 * @throws InvalidArgumentException
2894
+	 * @throws InvalidDataTypeException
2895
+	 * @throws InvalidInterfaceException
2896
+	 */
2897
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2898
+	{
2899
+		// let's generate a default preview action button if there isn't one already present.
2900
+		$this->_labels['buttons']['buy_now'] = esc_html__(
2901
+			'Upgrade to Event Espresso 4 Right Now',
2902
+			'event_espresso'
2903
+		);
2904
+		$buy_now_url = add_query_arg(
2905
+			array(
2906
+				'ee_ver'       => 'ee4',
2907
+				'utm_source'   => 'ee4_plugin_admin',
2908
+				'utm_medium'   => 'link',
2909
+				'utm_campaign' => $utm_campaign_source,
2910
+				'utm_content'  => 'buy_now_button',
2911
+			),
2912
+			'http://eventespresso.com/pricing/'
2913
+		);
2914
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2915
+			? $this->get_action_link_or_button(
2916
+				'',
2917
+				'buy_now',
2918
+				array(),
2919
+				'button-primary button-large',
2920
+				$buy_now_url,
2921
+				true
2922
+			)
2923
+			: $this->_template_args['preview_action_button'];
2924
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2925
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2926
+			$this->_template_args,
2927
+			true
2928
+		);
2929
+		$this->_display_admin_page($display_sidebar);
2930
+	}
2931
+
2932
+
2933
+	/**
2934
+	 * display_admin_list_table_page_with_sidebar
2935
+	 * generates HTML wrapper for an admin_page with list_table
2936
+	 *
2937
+	 * @return void
2938
+	 * @throws EE_Error
2939
+	 * @throws DomainException
2940
+	 */
2941
+	public function display_admin_list_table_page_with_sidebar()
2942
+	{
2943
+		$this->_display_admin_list_table_page(true);
2944
+	}
2945
+
2946
+
2947
+	/**
2948
+	 * display_admin_list_table_page_with_no_sidebar
2949
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2950
+	 *
2951
+	 * @return void
2952
+	 * @throws EE_Error
2953
+	 * @throws DomainException
2954
+	 */
2955
+	public function display_admin_list_table_page_with_no_sidebar()
2956
+	{
2957
+		$this->_display_admin_list_table_page();
2958
+	}
2959
+
2960
+
2961
+	/**
2962
+	 * generates html wrapper for an admin_list_table page
2963
+	 *
2964
+	 * @param boolean $sidebar whether to display with sidebar or not.
2965
+	 * @return void
2966
+	 * @throws DomainException
2967
+	 * @throws EE_Error
2968
+	 */
2969
+	private function _display_admin_list_table_page($sidebar = false)
2970
+	{
2971
+		// setup search attributes
2972
+		$this->_set_search_attributes();
2973
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2974
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2975
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
2976
+			? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2977
+			: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2978
+		$this->_template_args['list_table'] = $this->_list_table_object;
2979
+		$this->_template_args['current_route'] = $this->_req_action;
2980
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2981
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2982
+		if (! empty($ajax_sorting_callback)) {
2983
+			$sortable_list_table_form_fields = wp_nonce_field(
2984
+				$ajax_sorting_callback . '_nonce',
2985
+				$ajax_sorting_callback . '_nonce',
2986
+				false,
2987
+				false
2988
+			);
2989
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2990
+												. $this->page_slug
2991
+												. '" />';
2992
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2993
+												. $ajax_sorting_callback
2994
+												. '" />';
2995
+		} else {
2996
+			$sortable_list_table_form_fields = '';
2997
+		}
2998
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2999
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields'])
3000
+			? $this->_template_args['list_table_hidden_fields']
3001
+			: '';
3002
+		$nonce_ref = $this->_req_action . '_nonce';
3003
+		$hidden_form_fields .= '<input type="hidden" name="'
3004
+							   . $nonce_ref
3005
+							   . '" value="'
3006
+							   . wp_create_nonce($nonce_ref)
3007
+							   . '">';
3008
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3009
+		// display message about search results?
3010
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3011
+			? '<p class="ee-search-results">' . sprintf(
3012
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3013
+				trim($this->_req_data['s'], '%')
3014
+			) . '</p>'
3015
+			: '';
3016
+		// filter before_list_table template arg
3017
+		$this->_template_args['before_list_table'] = apply_filters(
3018
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3019
+			$this->_template_args['before_list_table'],
3020
+			$this->page_slug,
3021
+			$this->_req_data,
3022
+			$this->_req_action
3023
+		);
3024
+		// convert to array and filter again
3025
+		// arrays are easier to inject new items in a specific location,
3026
+		// but would not be backwards compatible, so we have to add a new filter
3027
+		$this->_template_args['before_list_table'] = implode(
3028
+			" \n",
3029
+			(array) apply_filters(
3030
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3031
+				(array) $this->_template_args['before_list_table'],
3032
+				$this->page_slug,
3033
+				$this->_req_data,
3034
+				$this->_req_action
3035
+			)
3036
+		);
3037
+		// filter after_list_table template arg
3038
+		$this->_template_args['after_list_table'] = apply_filters(
3039
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3040
+			$this->_template_args['after_list_table'],
3041
+			$this->page_slug,
3042
+			$this->_req_data,
3043
+			$this->_req_action
3044
+		);
3045
+		// convert to array and filter again
3046
+		// arrays are easier to inject new items in a specific location,
3047
+		// but would not be backwards compatible, so we have to add a new filter
3048
+		$this->_template_args['after_list_table'] = implode(
3049
+			" \n",
3050
+			(array) apply_filters(
3051
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3052
+				(array) $this->_template_args['after_list_table'],
3053
+				$this->page_slug,
3054
+				$this->_req_data,
3055
+				$this->_req_action
3056
+			)
3057
+		);
3058
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3059
+			$template_path,
3060
+			$this->_template_args,
3061
+			true
3062
+		);
3063
+		// the final template wrapper
3064
+		if ($sidebar) {
3065
+			$this->display_admin_page_with_sidebar();
3066
+		} else {
3067
+			$this->display_admin_page_with_no_sidebar();
3068
+		}
3069
+	}
3070
+
3071
+
3072
+	/**
3073
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3074
+	 * html string for the legend.
3075
+	 * $items are expected in an array in the following format:
3076
+	 * $legend_items = array(
3077
+	 *        'item_id' => array(
3078
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3079
+	 *            'desc' => esc_html__('localized description of item');
3080
+	 *        )
3081
+	 * );
3082
+	 *
3083
+	 * @param  array $items see above for format of array
3084
+	 * @return string html string of legend
3085
+	 * @throws DomainException
3086
+	 */
3087
+	protected function _display_legend($items)
3088
+	{
3089
+		$this->_template_args['items'] = apply_filters(
3090
+			'FHEE__EE_Admin_Page___display_legend__items',
3091
+			(array) $items,
3092
+			$this
3093
+		);
3094
+		return EEH_Template::display_template(
3095
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3096
+			$this->_template_args,
3097
+			true
3098
+		);
3099
+	}
3100
+
3101
+
3102
+	/**
3103
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3104
+	 * The returned json object is created from an array in the following format:
3105
+	 * array(
3106
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3107
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3108
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3109
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3110
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3111
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3112
+	 *  that might be included in here)
3113
+	 * )
3114
+	 * The json object is populated by whatever is set in the $_template_args property.
3115
+	 *
3116
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3117
+	 *                                 instead of displayed.
3118
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3119
+	 * @return void
3120
+	 * @throws EE_Error
3121
+	 */
3122
+	protected function _return_json($sticky_notices = false, $notices_arguments = array())
3123
+	{
3124
+		// make sure any EE_Error notices have been handled.
3125
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3126
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3127
+		unset($this->_template_args['data']);
3128
+		$json = array(
3129
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3130
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3131
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3132
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3133
+			'notices'   => EE_Error::get_notices(),
3134
+			'content'   => isset($this->_template_args['admin_page_content'])
3135
+				? $this->_template_args['admin_page_content'] : '',
3136
+			'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3137
+			'isEEajax'  => true
3138
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3139
+		);
3140
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3141
+		if (null === error_get_last() || ! headers_sent()) {
3142
+			header('Content-Type: application/json; charset=UTF-8');
3143
+		}
3144
+		echo wp_json_encode($json);
3145
+		exit();
3146
+	}
3147
+
3148
+
3149
+	/**
3150
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3151
+	 *
3152
+	 * @return void
3153
+	 * @throws EE_Error
3154
+	 */
3155
+	public function return_json()
3156
+	{
3157
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3158
+			$this->_return_json();
3159
+		} else {
3160
+			throw new EE_Error(
3161
+				sprintf(
3162
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3163
+					__FUNCTION__
3164
+				)
3165
+			);
3166
+		}
3167
+	}
3168
+
3169
+
3170
+	/**
3171
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3172
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3173
+	 *
3174
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3175
+	 */
3176
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3177
+	{
3178
+		$this->_hook_obj = $hook_obj;
3179
+	}
3180
+
3181
+
3182
+	/**
3183
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3184
+	 *
3185
+	 * @param  boolean $about whether to use the special about page wrapper or default.
3186
+	 * @return void
3187
+	 * @throws DomainException
3188
+	 * @throws EE_Error
3189
+	 */
3190
+	public function admin_page_wrapper($about = false)
3191
+	{
3192
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3193
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
3194
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
3195
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
3196
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3197
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3198
+			isset($this->_template_args['before_admin_page_content'])
3199
+				? $this->_template_args['before_admin_page_content']
3200
+				: ''
3201
+		);
3202
+		$this->_template_args['after_admin_page_content'] = apply_filters(
3203
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3204
+			isset($this->_template_args['after_admin_page_content'])
3205
+				? $this->_template_args['after_admin_page_content']
3206
+				: ''
3207
+		);
3208
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3209
+		// load settings page wrapper template
3210
+		$template_path = ! defined('DOING_AJAX')
3211
+			? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3212
+			: EE_ADMIN_TEMPLATE
3213
+			  . 'admin_wrapper_ajax.template.php';
3214
+		// about page?
3215
+		$template_path = $about
3216
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3217
+			: $template_path;
3218
+		if (defined('DOING_AJAX')) {
3219
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3220
+				$template_path,
3221
+				$this->_template_args,
3222
+				true
3223
+			);
3224
+			$this->_return_json();
3225
+		} else {
3226
+			EEH_Template::display_template($template_path, $this->_template_args);
3227
+		}
3228
+	}
3229
+
3230
+
3231
+	/**
3232
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3233
+	 *
3234
+	 * @return string html
3235
+	 * @throws EE_Error
3236
+	 */
3237
+	protected function _get_main_nav_tabs()
3238
+	{
3239
+		// let's generate the html using the EEH_Tabbed_Content helper.
3240
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3241
+		// (rather than setting in the page_routes array)
3242
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3243
+	}
3244
+
3245
+
3246
+	/**
3247
+	 *        sort nav tabs
3248
+	 *
3249
+	 * @param $a
3250
+	 * @param $b
3251
+	 * @return int
3252
+	 */
3253
+	private function _sort_nav_tabs($a, $b)
3254
+	{
3255
+		if ($a['order'] === $b['order']) {
3256
+			return 0;
3257
+		}
3258
+		return ($a['order'] < $b['order']) ? -1 : 1;
3259
+	}
3260
+
3261
+
3262
+	/**
3263
+	 *    generates HTML for the forms used on admin pages
3264
+	 *
3265
+	 * @param    array $input_vars - array of input field details
3266
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to
3267
+	 *                             use)
3268
+	 * @param bool     $id
3269
+	 * @return string
3270
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3271
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3272
+	 */
3273
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
3274
+	{
3275
+		$content = $generator === 'string'
3276
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3277
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3278
+		return $content;
3279
+	}
3280
+
3281
+
3282
+	/**
3283
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3284
+	 *
3285
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3286
+	 *                                   Close" button.
3287
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3288
+	 *                                   'Save', [1] => 'save & close')
3289
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3290
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3291
+	 *                                   default actions by submitting some other value.
3292
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3293
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3294
+	 *                                   close (normal form handling).
3295
+	 */
3296
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3297
+	{
3298
+		// make sure $text and $actions are in an array
3299
+		$text = (array) $text;
3300
+		$actions = (array) $actions;
3301
+		$referrer_url = empty($referrer)
3302
+			? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3303
+			  . $_SERVER['REQUEST_URI']
3304
+			  . '" />'
3305
+			: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3306
+			  . $referrer
3307
+			  . '" />';
3308
+		$button_text = ! empty($text)
3309
+			? $text
3310
+			: array(
3311
+				esc_html__('Save', 'event_espresso'),
3312
+				esc_html__('Save and Close', 'event_espresso'),
3313
+			);
3314
+		$default_names = array('save', 'save_and_close');
3315
+		// add in a hidden index for the current page (so save and close redirects properly)
3316
+		$this->_template_args['save_buttons'] = $referrer_url;
3317
+		foreach ($button_text as $key => $button) {
3318
+			$ref = $default_names[ $key ];
3319
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3320
+													 . $ref
3321
+													 . '" value="'
3322
+													 . $button
3323
+													 . '" name="'
3324
+													 . (! empty($actions) ? $actions[ $key ] : $ref)
3325
+													 . '" id="'
3326
+													 . $this->_current_view . '_' . $ref
3327
+													 . '" />';
3328
+			if (! $both) {
3329
+				break;
3330
+			}
3331
+		}
3332
+	}
3333
+
3334
+
3335
+	/**
3336
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3337
+	 *
3338
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3339
+	 * @since 4.6.0
3340
+	 * @param string $route
3341
+	 * @param array  $additional_hidden_fields
3342
+	 */
3343
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3344
+	{
3345
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3346
+	}
3347
+
3348
+
3349
+	/**
3350
+	 * set form open and close tags on add/edit pages.
3351
+	 *
3352
+	 * @param string $route                    the route you want the form to direct to
3353
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3354
+	 * @return void
3355
+	 */
3356
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3357
+	{
3358
+		if (empty($route)) {
3359
+			$user_msg = esc_html__(
3360
+				'An error occurred. No action was set for this page\'s form.',
3361
+				'event_espresso'
3362
+			);
3363
+			$dev_msg = $user_msg . "\n"
3364
+					   . sprintf(
3365
+						   esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3366
+						   __FUNCTION__,
3367
+						   __CLASS__
3368
+					   );
3369
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3370
+		}
3371
+		// open form
3372
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3373
+															 . $this->_admin_base_url
3374
+															 . '" id="'
3375
+															 . $route
3376
+															 . '_event_form" >';
3377
+		// add nonce
3378
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3379
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3380
+		// add REQUIRED form action
3381
+		$hidden_fields = array(
3382
+			'action' => array('type' => 'hidden', 'value' => $route),
3383
+		);
3384
+		// merge arrays
3385
+		$hidden_fields = is_array($additional_hidden_fields)
3386
+			? array_merge($hidden_fields, $additional_hidden_fields)
3387
+			: $hidden_fields;
3388
+		// generate form fields
3389
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3390
+		// add fields to form
3391
+		foreach ((array) $form_fields as $field_name => $form_field) {
3392
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3393
+		}
3394
+		// close form
3395
+		$this->_template_args['after_admin_page_content'] = '</form>';
3396
+	}
3397
+
3398
+
3399
+	/**
3400
+	 * Public Wrapper for _redirect_after_action() method since its
3401
+	 * discovered it would be useful for external code to have access.
3402
+	 *
3403
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3404
+	 * @since 4.5.0
3405
+	 * @param bool   $success
3406
+	 * @param string $what
3407
+	 * @param string $action_desc
3408
+	 * @param array  $query_args
3409
+	 * @param bool   $override_overwrite
3410
+	 * @throws EE_Error
3411
+	 */
3412
+	public function redirect_after_action(
3413
+		$success = false,
3414
+		$what = 'item',
3415
+		$action_desc = 'processed',
3416
+		$query_args = array(),
3417
+		$override_overwrite = false
3418
+	) {
3419
+		$this->_redirect_after_action(
3420
+			$success,
3421
+			$what,
3422
+			$action_desc,
3423
+			$query_args,
3424
+			$override_overwrite
3425
+		);
3426
+	}
3427
+
3428
+
3429
+	/**
3430
+	 * Helper method for merging existing request data with the returned redirect url.
3431
+	 *
3432
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3433
+	 * filters are still applied.
3434
+	 *
3435
+	 * @param array $new_route_data
3436
+	 * @return array
3437
+	 */
3438
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3439
+	{
3440
+		foreach ($this->_req_data as $ref => $value) {
3441
+			// unset nonces
3442
+			if (strpos($ref, 'nonce') !== false) {
3443
+				unset($this->_req_data[ $ref ]);
3444
+				continue;
3445
+			}
3446
+			// urlencode values.
3447
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3448
+			$this->_req_data[ $ref ] = $value;
3449
+		}
3450
+		return array_merge($this->_req_data, $new_route_data);
3451
+	}
3452
+
3453
+
3454
+	/**
3455
+	 *    _redirect_after_action
3456
+	 *
3457
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3458
+	 * @param string $what               - what the action was performed on
3459
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3460
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3461
+	 *                                   action is completed
3462
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3463
+	 *                                   override this so that they show.
3464
+	 * @return void
3465
+	 * @throws EE_Error
3466
+	 */
3467
+	protected function _redirect_after_action(
3468
+		$success = 0,
3469
+		$what = 'item',
3470
+		$action_desc = 'processed',
3471
+		$query_args = array(),
3472
+		$override_overwrite = false
3473
+	) {
3474
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3475
+		// class name for actions/filters.
3476
+		$classname = get_class($this);
3477
+		// set redirect url.
3478
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3479
+		// otherwise we go with whatever is set as the _admin_base_url
3480
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3481
+		$notices = EE_Error::get_notices(false);
3482
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3483
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3484
+			EE_Error::overwrite_success();
3485
+		}
3486
+		if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3487
+			// how many records affected ? more than one record ? or just one ?
3488
+			if ($success > 1) {
3489
+				// set plural msg
3490
+				EE_Error::add_success(
3491
+					sprintf(
3492
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3493
+						$what,
3494
+						$action_desc
3495
+					),
3496
+					__FILE__,
3497
+					__FUNCTION__,
3498
+					__LINE__
3499
+				);
3500
+			} elseif ($success === 1) {
3501
+				// set singular msg
3502
+				EE_Error::add_success(
3503
+					sprintf(
3504
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3505
+						$what,
3506
+						$action_desc
3507
+					),
3508
+					__FILE__,
3509
+					__FUNCTION__,
3510
+					__LINE__
3511
+				);
3512
+			}
3513
+		}
3514
+		// check that $query_args isn't something crazy
3515
+		if (! is_array($query_args)) {
3516
+			$query_args = array();
3517
+		}
3518
+		/**
3519
+		 * Allow injecting actions before the query_args are modified for possible different
3520
+		 * redirections on save and close actions
3521
+		 *
3522
+		 * @since 4.2.0
3523
+		 * @param array $query_args       The original query_args array coming into the
3524
+		 *                                method.
3525
+		 */
3526
+		do_action(
3527
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3528
+			$query_args
3529
+		);
3530
+		// calculate where we're going (if we have a "save and close" button pushed)
3531
+		if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3532
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3533
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3534
+			// regenerate query args array from referrer URL
3535
+			parse_str($parsed_url['query'], $query_args);
3536
+			// correct page and action will be in the query args now
3537
+			$redirect_url = admin_url('admin.php');
3538
+		}
3539
+		// merge any default query_args set in _default_route_query_args property
3540
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3541
+			$args_to_merge = array();
3542
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3543
+				// is there a wp_referer array in our _default_route_query_args property?
3544
+				if ($query_param === 'wp_referer') {
3545
+					$query_value = (array) $query_value;
3546
+					foreach ($query_value as $reference => $value) {
3547
+						if (strpos($reference, 'nonce') !== false) {
3548
+							continue;
3549
+						}
3550
+						// finally we will override any arguments in the referer with
3551
+						// what might be set on the _default_route_query_args array.
3552
+						if (isset($this->_default_route_query_args[ $reference ])) {
3553
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3554
+						} else {
3555
+							$args_to_merge[ $reference ] = urlencode($value);
3556
+						}
3557
+					}
3558
+					continue;
3559
+				}
3560
+				$args_to_merge[ $query_param ] = $query_value;
3561
+			}
3562
+			// now let's merge these arguments but override with what was specifically sent in to the
3563
+			// redirect.
3564
+			$query_args = array_merge($args_to_merge, $query_args);
3565
+		}
3566
+		$this->_process_notices($query_args);
3567
+		// generate redirect url
3568
+		// if redirecting to anything other than the main page, add a nonce
3569
+		if (isset($query_args['action'])) {
3570
+			// manually generate wp_nonce and merge that with the query vars
3571
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3572
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3573
+		}
3574
+		// we're adding some hooks and filters in here for processing any things just before redirects
3575
+		// (example: an admin page has done an insert or update and we want to run something after that).
3576
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3577
+		$redirect_url = apply_filters(
3578
+			'FHEE_redirect_' . $classname . $this->_req_action,
3579
+			self::add_query_args_and_nonce($query_args, $redirect_url),
3580
+			$query_args
3581
+		);
3582
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3583
+		if (defined('DOING_AJAX')) {
3584
+			$default_data = array(
3585
+				'close'        => true,
3586
+				'redirect_url' => $redirect_url,
3587
+				'where'        => 'main',
3588
+				'what'         => 'append',
3589
+			);
3590
+			$this->_template_args['success'] = $success;
3591
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge(
3592
+				$default_data,
3593
+				$this->_template_args['data']
3594
+			) : $default_data;
3595
+			$this->_return_json();
3596
+		}
3597
+		wp_safe_redirect($redirect_url);
3598
+		exit();
3599
+	}
3600
+
3601
+
3602
+	/**
3603
+	 * process any notices before redirecting (or returning ajax request)
3604
+	 * This method sets the $this->_template_args['notices'] attribute;
3605
+	 *
3606
+	 * @param  array $query_args        any query args that need to be used for notice transient ('action')
3607
+	 * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and
3608
+	 *                                  page_routes haven't been defined yet.
3609
+	 * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we
3610
+	 *                                  still save a transient for the notice.
3611
+	 * @return void
3612
+	 * @throws EE_Error
3613
+	 */
3614
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3615
+	{
3616
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3617
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3618
+			$notices = EE_Error::get_notices(false);
3619
+			if (empty($this->_template_args['success'])) {
3620
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3621
+			}
3622
+			if (empty($this->_template_args['errors'])) {
3623
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3624
+			}
3625
+			if (empty($this->_template_args['attention'])) {
3626
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3627
+			}
3628
+		}
3629
+		$this->_template_args['notices'] = EE_Error::get_notices();
3630
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3631
+		if (! defined('DOING_AJAX') || $sticky_notices) {
3632
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3633
+			$this->_add_transient(
3634
+				$route,
3635
+				$this->_template_args['notices'],
3636
+				true,
3637
+				$skip_route_verify
3638
+			);
3639
+		}
3640
+	}
3641
+
3642
+
3643
+	/**
3644
+	 * get_action_link_or_button
3645
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3646
+	 *
3647
+	 * @param string $action        use this to indicate which action the url is generated with.
3648
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3649
+	 *                              property.
3650
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3651
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3652
+	 * @param string $base_url      If this is not provided
3653
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3654
+	 *                              Otherwise this value will be used.
3655
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3656
+	 * @return string
3657
+	 * @throws InvalidArgumentException
3658
+	 * @throws InvalidInterfaceException
3659
+	 * @throws InvalidDataTypeException
3660
+	 * @throws EE_Error
3661
+	 */
3662
+	public function get_action_link_or_button(
3663
+		$action,
3664
+		$type = 'add',
3665
+		$extra_request = array(),
3666
+		$class = 'button-primary',
3667
+		$base_url = '',
3668
+		$exclude_nonce = false
3669
+	) {
3670
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3671
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3672
+			throw new EE_Error(
3673
+				sprintf(
3674
+					esc_html__(
3675
+						'There is no page route for given action for the button.  This action was given: %s',
3676
+						'event_espresso'
3677
+					),
3678
+					$action
3679
+				)
3680
+			);
3681
+		}
3682
+		if (! isset($this->_labels['buttons'][ $type ])) {
3683
+			throw new EE_Error(
3684
+				sprintf(
3685
+					__(
3686
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3687
+						'event_espresso'
3688
+					),
3689
+					$type
3690
+				)
3691
+			);
3692
+		}
3693
+		// finally check user access for this button.
3694
+		$has_access = $this->check_user_access($action, true);
3695
+		if (! $has_access) {
3696
+			return '';
3697
+		}
3698
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
3699
+		$query_args = array(
3700
+			'action' => $action,
3701
+		);
3702
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3703
+		if (! empty($extra_request)) {
3704
+			$query_args = array_merge($extra_request, $query_args);
3705
+		}
3706
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3707
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3708
+	}
3709
+
3710
+
3711
+	/**
3712
+	 * _per_page_screen_option
3713
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3714
+	 *
3715
+	 * @return void
3716
+	 * @throws InvalidArgumentException
3717
+	 * @throws InvalidInterfaceException
3718
+	 * @throws InvalidDataTypeException
3719
+	 */
3720
+	protected function _per_page_screen_option()
3721
+	{
3722
+		$option = 'per_page';
3723
+		$args = array(
3724
+			'label'   => apply_filters(
3725
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3726
+				$this->_admin_page_title,
3727
+				$this
3728
+			),
3729
+			'default' => (int) apply_filters(
3730
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3731
+				20
3732
+			),
3733
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3734
+		);
3735
+		// ONLY add the screen option if the user has access to it.
3736
+		if ($this->check_user_access($this->_current_view, true)) {
3737
+			add_screen_option($option, $args);
3738
+		}
3739
+	}
3740
+
3741
+
3742
+	/**
3743
+	 * set_per_page_screen_option
3744
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3745
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3746
+	 * admin_menu.
3747
+	 *
3748
+	 * @return void
3749
+	 */
3750
+	private function _set_per_page_screen_options()
3751
+	{
3752
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3753
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3754
+			if (! $user = wp_get_current_user()) {
3755
+				return;
3756
+			}
3757
+			$option = $_POST['wp_screen_options']['option'];
3758
+			$value = $_POST['wp_screen_options']['value'];
3759
+			if ($option != sanitize_key($option)) {
3760
+				return;
3761
+			}
3762
+			$map_option = $option;
3763
+			$option = str_replace('-', '_', $option);
3764
+			switch ($map_option) {
3765
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3766
+					$value = (int) $value;
3767
+					$max_value = apply_filters(
3768
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3769
+						999,
3770
+						$this->_current_page,
3771
+						$this->_current_view
3772
+					);
3773
+					if ($value < 1) {
3774
+						return;
3775
+					}
3776
+					$value = min($value, $max_value);
3777
+					break;
3778
+				default:
3779
+					$value = apply_filters(
3780
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3781
+						false,
3782
+						$option,
3783
+						$value
3784
+					);
3785
+					if (false === $value) {
3786
+						return;
3787
+					}
3788
+					break;
3789
+			}
3790
+			update_user_meta($user->ID, $option, $value);
3791
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3792
+			exit;
3793
+		}
3794
+	}
3795
+
3796
+
3797
+	/**
3798
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3799
+	 *
3800
+	 * @param array $data array that will be assigned to template args.
3801
+	 */
3802
+	public function set_template_args($data)
3803
+	{
3804
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3805
+	}
3806
+
3807
+
3808
+	/**
3809
+	 * This makes available the WP transient system for temporarily moving data between routes
3810
+	 *
3811
+	 * @param string $route             the route that should receive the transient
3812
+	 * @param array  $data              the data that gets sent
3813
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3814
+	 *                                  normal route transient.
3815
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3816
+	 *                                  when we are adding a transient before page_routes have been defined.
3817
+	 * @return void
3818
+	 * @throws EE_Error
3819
+	 */
3820
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3821
+	{
3822
+		$user_id = get_current_user_id();
3823
+		if (! $skip_route_verify) {
3824
+			$this->_verify_route($route);
3825
+		}
3826
+		// now let's set the string for what kind of transient we're setting
3827
+		$transient = $notices
3828
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3829
+			: 'rte_tx_' . $route . '_' . $user_id;
3830
+		$data = $notices ? array('notices' => $data) : $data;
3831
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3832
+		$existing = is_multisite() && is_network_admin()
3833
+			? get_site_transient($transient)
3834
+			: get_transient($transient);
3835
+		if ($existing) {
3836
+			$data = array_merge((array) $data, (array) $existing);
3837
+		}
3838
+		if (is_multisite() && is_network_admin()) {
3839
+			set_site_transient($transient, $data, 8);
3840
+		} else {
3841
+			set_transient($transient, $data, 8);
3842
+		}
3843
+	}
3844
+
3845
+
3846
+	/**
3847
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3848
+	 *
3849
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3850
+	 * @param string $route
3851
+	 * @return mixed data
3852
+	 */
3853
+	protected function _get_transient($notices = false, $route = '')
3854
+	{
3855
+		$user_id = get_current_user_id();
3856
+		$route = ! $route ? $this->_req_action : $route;
3857
+		$transient = $notices
3858
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3859
+			: 'rte_tx_' . $route . '_' . $user_id;
3860
+		$data = is_multisite() && is_network_admin()
3861
+			? get_site_transient($transient)
3862
+			: get_transient($transient);
3863
+		// delete transient after retrieval (just in case it hasn't expired);
3864
+		if (is_multisite() && is_network_admin()) {
3865
+			delete_site_transient($transient);
3866
+		} else {
3867
+			delete_transient($transient);
3868
+		}
3869
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3870
+	}
3871
+
3872
+
3873
+	/**
3874
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3875
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3876
+	 * default route callback on the EE_Admin page you want it run.)
3877
+	 *
3878
+	 * @return void
3879
+	 */
3880
+	protected function _transient_garbage_collection()
3881
+	{
3882
+		global $wpdb;
3883
+		// retrieve all existing transients
3884
+		$query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3885
+		if ($results = $wpdb->get_results($query)) {
3886
+			foreach ($results as $result) {
3887
+				$transient = str_replace('_transient_', '', $result->option_name);
3888
+				get_transient($transient);
3889
+				if (is_multisite() && is_network_admin()) {
3890
+					get_site_transient($transient);
3891
+				}
3892
+			}
3893
+		}
3894
+	}
3895
+
3896
+
3897
+	/**
3898
+	 * get_view
3899
+	 *
3900
+	 * @return string content of _view property
3901
+	 */
3902
+	public function get_view()
3903
+	{
3904
+		return $this->_view;
3905
+	}
3906
+
3907
+
3908
+	/**
3909
+	 * getter for the protected $_views property
3910
+	 *
3911
+	 * @return array
3912
+	 */
3913
+	public function get_views()
3914
+	{
3915
+		return $this->_views;
3916
+	}
3917
+
3918
+
3919
+	/**
3920
+	 * get_current_page
3921
+	 *
3922
+	 * @return string _current_page property value
3923
+	 */
3924
+	public function get_current_page()
3925
+	{
3926
+		return $this->_current_page;
3927
+	}
3928
+
3929
+
3930
+	/**
3931
+	 * get_current_view
3932
+	 *
3933
+	 * @return string _current_view property value
3934
+	 */
3935
+	public function get_current_view()
3936
+	{
3937
+		return $this->_current_view;
3938
+	}
3939
+
3940
+
3941
+	/**
3942
+	 * get_current_screen
3943
+	 *
3944
+	 * @return object The current WP_Screen object
3945
+	 */
3946
+	public function get_current_screen()
3947
+	{
3948
+		return $this->_current_screen;
3949
+	}
3950
+
3951
+
3952
+	/**
3953
+	 * get_current_page_view_url
3954
+	 *
3955
+	 * @return string This returns the url for the current_page_view.
3956
+	 */
3957
+	public function get_current_page_view_url()
3958
+	{
3959
+		return $this->_current_page_view_url;
3960
+	}
3961
+
3962
+
3963
+	/**
3964
+	 * just returns the _req_data property
3965
+	 *
3966
+	 * @return array
3967
+	 */
3968
+	public function get_request_data()
3969
+	{
3970
+		return $this->_req_data;
3971
+	}
3972
+
3973
+
3974
+	/**
3975
+	 * returns the _req_data protected property
3976
+	 *
3977
+	 * @return string
3978
+	 */
3979
+	public function get_req_action()
3980
+	{
3981
+		return $this->_req_action;
3982
+	}
3983
+
3984
+
3985
+	/**
3986
+	 * @return bool  value of $_is_caf property
3987
+	 */
3988
+	public function is_caf()
3989
+	{
3990
+		return $this->_is_caf;
3991
+	}
3992
+
3993
+
3994
+	/**
3995
+	 * @return mixed
3996
+	 */
3997
+	public function default_espresso_metaboxes()
3998
+	{
3999
+		return $this->_default_espresso_metaboxes;
4000
+	}
4001
+
4002
+
4003
+	/**
4004
+	 * @return mixed
4005
+	 */
4006
+	public function admin_base_url()
4007
+	{
4008
+		return $this->_admin_base_url;
4009
+	}
4010
+
4011
+
4012
+	/**
4013
+	 * @return mixed
4014
+	 */
4015
+	public function wp_page_slug()
4016
+	{
4017
+		return $this->_wp_page_slug;
4018
+	}
4019
+
4020
+
4021
+	/**
4022
+	 * updates  espresso configuration settings
4023
+	 *
4024
+	 * @param string                   $tab
4025
+	 * @param EE_Config_Base|EE_Config $config
4026
+	 * @param string                   $file file where error occurred
4027
+	 * @param string                   $func function  where error occurred
4028
+	 * @param string                   $line line no where error occurred
4029
+	 * @return boolean
4030
+	 */
4031
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4032
+	{
4033
+		// remove any options that are NOT going to be saved with the config settings.
4034
+		if (isset($config->core->ee_ueip_optin)) {
4035
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
4036
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4037
+			update_option('ee_ueip_has_notified', true);
4038
+		}
4039
+		// and save it (note we're also doing the network save here)
4040
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4041
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
4042
+		if ($config_saved && $net_saved) {
4043
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4044
+			return true;
4045
+		}
4046
+		EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4047
+		return false;
4048
+	}
4049
+
4050
+
4051
+	/**
4052
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4053
+	 *
4054
+	 * @return array
4055
+	 */
4056
+	public function get_yes_no_values()
4057
+	{
4058
+		return $this->_yes_no_values;
4059
+	}
4060
+
4061
+
4062
+	protected function _get_dir()
4063
+	{
4064
+		$reflector = new ReflectionClass(get_class($this));
4065
+		return dirname($reflector->getFileName());
4066
+	}
4067
+
4068
+
4069
+	/**
4070
+	 * A helper for getting a "next link".
4071
+	 *
4072
+	 * @param string $url   The url to link to
4073
+	 * @param string $class The class to use.
4074
+	 * @return string
4075
+	 */
4076
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4077
+	{
4078
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4079
+	}
4080
+
4081
+
4082
+	/**
4083
+	 * A helper for getting a "previous link".
4084
+	 *
4085
+	 * @param string $url   The url to link to
4086
+	 * @param string $class The class to use.
4087
+	 * @return string
4088
+	 */
4089
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4090
+	{
4091
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4092
+	}
4093
+
4094
+
4095
+
4096
+
4097
+
4098
+
4099
+
4100
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4101
+
4102
+
4103
+	/**
4104
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4105
+	 * 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
4106
+	 * _req_data array.
4107
+	 *
4108
+	 * @return bool success/fail
4109
+	 * @throws EE_Error
4110
+	 * @throws InvalidArgumentException
4111
+	 * @throws ReflectionException
4112
+	 * @throws InvalidDataTypeException
4113
+	 * @throws InvalidInterfaceException
4114
+	 */
4115
+	protected function _process_resend_registration()
4116
+	{
4117
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4118
+		do_action(
4119
+			'AHEE__EE_Admin_Page___process_resend_registration',
4120
+			$this->_template_args['success'],
4121
+			$this->_req_data
4122
+		);
4123
+		return $this->_template_args['success'];
4124
+	}
4125
+
4126
+
4127
+	/**
4128
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4129
+	 *
4130
+	 * @param \EE_Payment $payment
4131
+	 * @return bool success/fail
4132
+	 */
4133
+	protected function _process_payment_notification(EE_Payment $payment)
4134
+	{
4135
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4136
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4137
+		$this->_template_args['success'] = apply_filters(
4138
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4139
+			false,
4140
+			$payment
4141
+		);
4142
+		return $this->_template_args['success'];
4143
+	}
4144 4144
 }
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_Registrations_Admin_Page.core.php 2 patches
Indentation   +1219 added lines, -1219 removed lines patch added patch discarded remove patch
@@ -16,1276 +16,1276 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * This is used to hold the reports template data which is setup early in the request.
21
-     *
22
-     * @type array
23
-     */
24
-    protected $_reports_template_data = array();
19
+	/**
20
+	 * This is used to hold the reports template data which is setup early in the request.
21
+	 *
22
+	 * @type array
23
+	 */
24
+	protected $_reports_template_data = array();
25 25
 
26 26
 
27
-    /**
28
-     * Extend_Registrations_Admin_Page constructor.
29
-     *
30
-     * @param bool $routing
31
-     */
32
-    public function __construct($routing = true)
33
-    {
34
-        parent::__construct($routing);
35
-        if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
39
-        }
40
-    }
27
+	/**
28
+	 * Extend_Registrations_Admin_Page constructor.
29
+	 *
30
+	 * @param bool $routing
31
+	 */
32
+	public function __construct($routing = true)
33
+	{
34
+		parent::__construct($routing);
35
+		if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
+			define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
+			define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
+			define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
39
+		}
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * Extending page configuration.
45
-     */
46
-    protected function _extend_page_config()
47
-    {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
-            ? $this->_req_data['_REG_ID']
51
-            : 0;
52
-        $new_page_routes = array(
53
-            'reports'                      => array(
54
-                'func'       => '_registration_reports',
55
-                'capability' => 'ee_read_registrations',
56
-            ),
57
-            'registration_checkins'        => array(
58
-                'func'       => '_registration_checkin_list_table',
59
-                'capability' => 'ee_read_checkins',
60
-            ),
61
-            'newsletter_selected_send'     => array(
62
-                'func'       => '_newsletter_selected_send',
63
-                'noheader'   => true,
64
-                'capability' => 'ee_send_message',
65
-            ),
66
-            'delete_checkin_rows'          => array(
67
-                'func'       => '_delete_checkin_rows',
68
-                'noheader'   => true,
69
-                'capability' => 'ee_delete_checkins',
70
-            ),
71
-            'delete_checkin_row'           => array(
72
-                'func'       => '_delete_checkin_row',
73
-                'noheader'   => true,
74
-                'capability' => 'ee_delete_checkin',
75
-                'obj_id'     => $reg_id,
76
-            ),
77
-            'toggle_checkin_status'        => array(
78
-                'func'       => '_toggle_checkin_status',
79
-                'noheader'   => true,
80
-                'capability' => 'ee_edit_checkin',
81
-                'obj_id'     => $reg_id,
82
-            ),
83
-            'toggle_checkin_status_bulk'   => array(
84
-                'func'       => '_toggle_checkin_status',
85
-                'noheader'   => true,
86
-                'capability' => 'ee_edit_checkins',
87
-            ),
88
-            'event_registrations'          => array(
89
-                'func'       => '_event_registrations_list_table',
90
-                'capability' => 'ee_read_checkins',
91
-            ),
92
-            'registrations_checkin_report' => array(
93
-                'func'       => '_registrations_checkin_report',
94
-                'noheader'   => true,
95
-                'capability' => 'ee_read_registrations',
96
-            ),
97
-        );
98
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
99
-        $new_page_config = array(
100
-            'reports'               => array(
101
-                'nav'           => array(
102
-                    'label' => esc_html__('Reports', 'event_espresso'),
103
-                    'order' => 30,
104
-                ),
105
-                'help_tabs'     => array(
106
-                    'registrations_reports_help_tab' => array(
107
-                        'title'    => esc_html__('Registration Reports', 'event_espresso'),
108
-                        'filename' => 'registrations_reports',
109
-                    ),
110
-                ),
111
-                /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
112
-                'require_nonce' => false,
113
-            ),
114
-            'event_registrations'   => array(
115
-                'nav'           => array(
116
-                    'label'      => esc_html__('Event Check-In', 'event_espresso'),
117
-                    'order'      => 10,
118
-                    'persistent' => true,
119
-                ),
120
-                'help_tabs'     => array(
121
-                    'registrations_event_checkin_help_tab'                       => array(
122
-                        'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
123
-                        'filename' => 'registrations_event_checkin',
124
-                    ),
125
-                    'registrations_event_checkin_table_column_headings_help_tab' => array(
126
-                        'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
127
-                        'filename' => 'registrations_event_checkin_table_column_headings',
128
-                    ),
129
-                    'registrations_event_checkin_filters_help_tab'               => array(
130
-                        'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
131
-                        'filename' => 'registrations_event_checkin_filters',
132
-                    ),
133
-                    'registrations_event_checkin_views_help_tab'                 => array(
134
-                        'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
135
-                        'filename' => 'registrations_event_checkin_views',
136
-                    ),
137
-                    'registrations_event_checkin_other_help_tab'                 => array(
138
-                        'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
139
-                        'filename' => 'registrations_event_checkin_other',
140
-                    ),
141
-                ),
142
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
143
-                // 'help_tour'     => array('Event_Checkin_Help_Tour'),
144
-                'qtips'         => array('Registration_List_Table_Tips'),
145
-                'list_table'    => 'EE_Event_Registrations_List_Table',
146
-                'metaboxes'     => array(),
147
-                'require_nonce' => false,
148
-            ),
149
-            'registration_checkins' => array(
150
-                'nav'           => array(
151
-                    'label'      => esc_html__('Check-In Records', 'event_espresso'),
152
-                    'order'      => 15,
153
-                    'persistent' => false,
154
-                    'url'        => '',
155
-                ),
156
-                'list_table'    => 'EE_Registration_CheckIn_List_Table',
157
-                // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
158
-                'metaboxes'     => array(),
159
-                'require_nonce' => false,
160
-            ),
161
-        );
162
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
163
-        $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
164
-        $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
165
-    }
43
+	/**
44
+	 * Extending page configuration.
45
+	 */
46
+	protected function _extend_page_config()
47
+	{
48
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
49
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50
+			? $this->_req_data['_REG_ID']
51
+			: 0;
52
+		$new_page_routes = array(
53
+			'reports'                      => array(
54
+				'func'       => '_registration_reports',
55
+				'capability' => 'ee_read_registrations',
56
+			),
57
+			'registration_checkins'        => array(
58
+				'func'       => '_registration_checkin_list_table',
59
+				'capability' => 'ee_read_checkins',
60
+			),
61
+			'newsletter_selected_send'     => array(
62
+				'func'       => '_newsletter_selected_send',
63
+				'noheader'   => true,
64
+				'capability' => 'ee_send_message',
65
+			),
66
+			'delete_checkin_rows'          => array(
67
+				'func'       => '_delete_checkin_rows',
68
+				'noheader'   => true,
69
+				'capability' => 'ee_delete_checkins',
70
+			),
71
+			'delete_checkin_row'           => array(
72
+				'func'       => '_delete_checkin_row',
73
+				'noheader'   => true,
74
+				'capability' => 'ee_delete_checkin',
75
+				'obj_id'     => $reg_id,
76
+			),
77
+			'toggle_checkin_status'        => array(
78
+				'func'       => '_toggle_checkin_status',
79
+				'noheader'   => true,
80
+				'capability' => 'ee_edit_checkin',
81
+				'obj_id'     => $reg_id,
82
+			),
83
+			'toggle_checkin_status_bulk'   => array(
84
+				'func'       => '_toggle_checkin_status',
85
+				'noheader'   => true,
86
+				'capability' => 'ee_edit_checkins',
87
+			),
88
+			'event_registrations'          => array(
89
+				'func'       => '_event_registrations_list_table',
90
+				'capability' => 'ee_read_checkins',
91
+			),
92
+			'registrations_checkin_report' => array(
93
+				'func'       => '_registrations_checkin_report',
94
+				'noheader'   => true,
95
+				'capability' => 'ee_read_registrations',
96
+			),
97
+		);
98
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
99
+		$new_page_config = array(
100
+			'reports'               => array(
101
+				'nav'           => array(
102
+					'label' => esc_html__('Reports', 'event_espresso'),
103
+					'order' => 30,
104
+				),
105
+				'help_tabs'     => array(
106
+					'registrations_reports_help_tab' => array(
107
+						'title'    => esc_html__('Registration Reports', 'event_espresso'),
108
+						'filename' => 'registrations_reports',
109
+					),
110
+				),
111
+				/*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
112
+				'require_nonce' => false,
113
+			),
114
+			'event_registrations'   => array(
115
+				'nav'           => array(
116
+					'label'      => esc_html__('Event Check-In', 'event_espresso'),
117
+					'order'      => 10,
118
+					'persistent' => true,
119
+				),
120
+				'help_tabs'     => array(
121
+					'registrations_event_checkin_help_tab'                       => array(
122
+						'title'    => esc_html__('Registrations Event Check-In', 'event_espresso'),
123
+						'filename' => 'registrations_event_checkin',
124
+					),
125
+					'registrations_event_checkin_table_column_headings_help_tab' => array(
126
+						'title'    => esc_html__('Event Check-In Table Column Headings', 'event_espresso'),
127
+						'filename' => 'registrations_event_checkin_table_column_headings',
128
+					),
129
+					'registrations_event_checkin_filters_help_tab'               => array(
130
+						'title'    => esc_html__('Event Check-In Filters', 'event_espresso'),
131
+						'filename' => 'registrations_event_checkin_filters',
132
+					),
133
+					'registrations_event_checkin_views_help_tab'                 => array(
134
+						'title'    => esc_html__('Event Check-In Views', 'event_espresso'),
135
+						'filename' => 'registrations_event_checkin_views',
136
+					),
137
+					'registrations_event_checkin_other_help_tab'                 => array(
138
+						'title'    => esc_html__('Event Check-In Other', 'event_espresso'),
139
+						'filename' => 'registrations_event_checkin_other',
140
+					),
141
+				),
142
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
143
+				// 'help_tour'     => array('Event_Checkin_Help_Tour'),
144
+				'qtips'         => array('Registration_List_Table_Tips'),
145
+				'list_table'    => 'EE_Event_Registrations_List_Table',
146
+				'metaboxes'     => array(),
147
+				'require_nonce' => false,
148
+			),
149
+			'registration_checkins' => array(
150
+				'nav'           => array(
151
+					'label'      => esc_html__('Check-In Records', 'event_espresso'),
152
+					'order'      => 15,
153
+					'persistent' => false,
154
+					'url'        => '',
155
+				),
156
+				'list_table'    => 'EE_Registration_CheckIn_List_Table',
157
+				// 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
158
+				'metaboxes'     => array(),
159
+				'require_nonce' => false,
160
+			),
161
+		);
162
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
163
+		$this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
164
+		$this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
165
+	}
166 166
 
167 167
 
168
-    /**
169
-     * Ajax hooks for all routes in this page.
170
-     */
171
-    protected function _ajax_hooks()
172
-    {
173
-        parent::_ajax_hooks();
174
-        add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
175
-    }
168
+	/**
169
+	 * Ajax hooks for all routes in this page.
170
+	 */
171
+	protected function _ajax_hooks()
172
+	{
173
+		parent::_ajax_hooks();
174
+		add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
175
+	}
176 176
 
177 177
 
178
-    /**
179
-     * Global scripts for all routes in this page.
180
-     */
181
-    public function load_scripts_styles()
182
-    {
183
-        parent::load_scripts_styles();
184
-        // if newsletter message type is active then let's add filter and load js for it.
185
-        if (EEH_MSG_Template::is_mt_active('newsletter')) {
186
-            // enqueue newsletter js
187
-            wp_enqueue_script(
188
-                'ee-newsletter-trigger',
189
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
190
-                array('ee-dialog'),
191
-                EVENT_ESPRESSO_VERSION,
192
-                true
193
-            );
194
-            wp_enqueue_style(
195
-                'ee-newsletter-trigger-css',
196
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
197
-                array(),
198
-                EVENT_ESPRESSO_VERSION
199
-            );
200
-            // hook in buttons for newsletter message type trigger.
201
-            add_action(
202
-                'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
203
-                array($this, 'add_newsletter_action_buttons'),
204
-                10
205
-            );
206
-        }
207
-    }
178
+	/**
179
+	 * Global scripts for all routes in this page.
180
+	 */
181
+	public function load_scripts_styles()
182
+	{
183
+		parent::load_scripts_styles();
184
+		// if newsletter message type is active then let's add filter and load js for it.
185
+		if (EEH_MSG_Template::is_mt_active('newsletter')) {
186
+			// enqueue newsletter js
187
+			wp_enqueue_script(
188
+				'ee-newsletter-trigger',
189
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
190
+				array('ee-dialog'),
191
+				EVENT_ESPRESSO_VERSION,
192
+				true
193
+			);
194
+			wp_enqueue_style(
195
+				'ee-newsletter-trigger-css',
196
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
197
+				array(),
198
+				EVENT_ESPRESSO_VERSION
199
+			);
200
+			// hook in buttons for newsletter message type trigger.
201
+			add_action(
202
+				'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
203
+				array($this, 'add_newsletter_action_buttons'),
204
+				10
205
+			);
206
+		}
207
+	}
208 208
 
209 209
 
210
-    /**
211
-     * Scripts and styles for just the reports route.
212
-     */
213
-    public function load_scripts_styles_reports()
214
-    {
215
-        wp_register_script(
216
-            'ee-reg-reports-js',
217
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
218
-            array('google-charts'),
219
-            EVENT_ESPRESSO_VERSION,
220
-            true
221
-        );
222
-        wp_enqueue_script('ee-reg-reports-js');
223
-        $this->_registration_reports_js_setup();
224
-    }
210
+	/**
211
+	 * Scripts and styles for just the reports route.
212
+	 */
213
+	public function load_scripts_styles_reports()
214
+	{
215
+		wp_register_script(
216
+			'ee-reg-reports-js',
217
+			REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
218
+			array('google-charts'),
219
+			EVENT_ESPRESSO_VERSION,
220
+			true
221
+		);
222
+		wp_enqueue_script('ee-reg-reports-js');
223
+		$this->_registration_reports_js_setup();
224
+	}
225 225
 
226 226
 
227
-    /**
228
-     * Register screen options for event_registrations route.
229
-     */
230
-    protected function _add_screen_options_event_registrations()
231
-    {
232
-        $this->_per_page_screen_option();
233
-    }
227
+	/**
228
+	 * Register screen options for event_registrations route.
229
+	 */
230
+	protected function _add_screen_options_event_registrations()
231
+	{
232
+		$this->_per_page_screen_option();
233
+	}
234 234
 
235 235
 
236
-    /**
237
-     * Register screen options for registration_checkins route
238
-     */
239
-    protected function _add_screen_options_registration_checkins()
240
-    {
241
-        $page_title = $this->_admin_page_title;
242
-        $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
243
-        $this->_per_page_screen_option();
244
-        $this->_admin_page_title = $page_title;
245
-    }
236
+	/**
237
+	 * Register screen options for registration_checkins route
238
+	 */
239
+	protected function _add_screen_options_registration_checkins()
240
+	{
241
+		$page_title = $this->_admin_page_title;
242
+		$this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso');
243
+		$this->_per_page_screen_option();
244
+		$this->_admin_page_title = $page_title;
245
+	}
246 246
 
247 247
 
248
-    /**
249
-     * Set views property for event_registrations route.
250
-     */
251
-    protected function _set_list_table_views_event_registrations()
252
-    {
253
-        $this->_views = array(
254
-            'all' => array(
255
-                'slug'        => 'all',
256
-                'label'       => esc_html__('All', 'event_espresso'),
257
-                'count'       => 0,
258
-                'bulk_action' => ! isset($this->_req_data['event_id'])
259
-                    ? array()
260
-                    : array(
261
-                        'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
262
-                    ),
263
-            ),
264
-        );
265
-    }
248
+	/**
249
+	 * Set views property for event_registrations route.
250
+	 */
251
+	protected function _set_list_table_views_event_registrations()
252
+	{
253
+		$this->_views = array(
254
+			'all' => array(
255
+				'slug'        => 'all',
256
+				'label'       => esc_html__('All', 'event_espresso'),
257
+				'count'       => 0,
258
+				'bulk_action' => ! isset($this->_req_data['event_id'])
259
+					? array()
260
+					: array(
261
+						'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'),
262
+					),
263
+			),
264
+		);
265
+	}
266 266
 
267 267
 
268
-    /**
269
-     * Set views property for registration_checkins route.
270
-     */
271
-    protected function _set_list_table_views_registration_checkins()
272
-    {
273
-        $this->_views = array(
274
-            'all' => array(
275
-                'slug'        => 'all',
276
-                'label'       => esc_html__('All', 'event_espresso'),
277
-                'count'       => 0,
278
-                'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
279
-            ),
280
-        );
281
-    }
268
+	/**
269
+	 * Set views property for registration_checkins route.
270
+	 */
271
+	protected function _set_list_table_views_registration_checkins()
272
+	{
273
+		$this->_views = array(
274
+			'all' => array(
275
+				'slug'        => 'all',
276
+				'label'       => esc_html__('All', 'event_espresso'),
277
+				'count'       => 0,
278
+				'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')),
279
+			),
280
+		);
281
+	}
282 282
 
283 283
 
284
-    /**
285
-     * callback for ajax action.
286
-     *
287
-     * @since 4.3.0
288
-     * @return void (JSON)
289
-     * @throws EE_Error
290
-     * @throws InvalidArgumentException
291
-     * @throws InvalidDataTypeException
292
-     * @throws InvalidInterfaceException
293
-     */
294
-    public function get_newsletter_form_content()
295
-    {
296
-        // do a nonce check cause we're not coming in from an normal route here.
297
-        $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
298
-            $this->_req_data['get_newsletter_form_content_nonce']
299
-        ) : '';
300
-        $nonce_ref = 'get_newsletter_form_content_nonce';
301
-        $this->_verify_nonce($nonce, $nonce_ref);
302
-        // let's get the mtp for the incoming MTP_ ID
303
-        if (! isset($this->_req_data['GRP_ID'])) {
304
-            EE_Error::add_error(
305
-                esc_html__(
306
-                    'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
307
-                    'event_espresso'
308
-                ),
309
-                __FILE__,
310
-                __FUNCTION__,
311
-                __LINE__
312
-            );
313
-            $this->_template_args['success'] = false;
314
-            $this->_template_args['error'] = true;
315
-            $this->_return_json();
316
-        }
317
-        $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
318
-        if (! $MTPG instanceof EE_Message_Template_Group) {
319
-            EE_Error::add_error(
320
-                sprintf(
321
-                    esc_html__(
322
-                        'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
323
-                        'event_espresso'
324
-                    ),
325
-                    $this->_req_data['GRP_ID']
326
-                ),
327
-                __FILE__,
328
-                __FUNCTION__,
329
-                __LINE__
330
-            );
331
-            $this->_template_args['success'] = false;
332
-            $this->_template_args['error'] = true;
333
-            $this->_return_json();
334
-        }
335
-        $MTPs = $MTPG->context_templates();
336
-        $MTPs = $MTPs['attendee'];
337
-        $template_fields = array();
338
-        /** @var EE_Message_Template $MTP */
339
-        foreach ($MTPs as $MTP) {
340
-            $field = $MTP->get('MTP_template_field');
341
-            if ($field === 'content') {
342
-                $content = $MTP->get('MTP_content');
343
-                if (! empty($content['newsletter_content'])) {
344
-                    $template_fields['newsletter_content'] = $content['newsletter_content'];
345
-                }
346
-                continue;
347
-            }
348
-            $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
349
-        }
350
-        $this->_template_args['success'] = true;
351
-        $this->_template_args['error'] = false;
352
-        $this->_template_args['data'] = array(
353
-            'batch_message_from'    => isset($template_fields['from'])
354
-                ? $template_fields['from']
355
-                : '',
356
-            'batch_message_subject' => isset($template_fields['subject'])
357
-                ? $template_fields['subject']
358
-                : '',
359
-            'batch_message_content' => isset($template_fields['newsletter_content'])
360
-                ? $template_fields['newsletter_content']
361
-                : '',
362
-        );
363
-        $this->_return_json();
364
-    }
284
+	/**
285
+	 * callback for ajax action.
286
+	 *
287
+	 * @since 4.3.0
288
+	 * @return void (JSON)
289
+	 * @throws EE_Error
290
+	 * @throws InvalidArgumentException
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws InvalidInterfaceException
293
+	 */
294
+	public function get_newsletter_form_content()
295
+	{
296
+		// do a nonce check cause we're not coming in from an normal route here.
297
+		$nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
298
+			$this->_req_data['get_newsletter_form_content_nonce']
299
+		) : '';
300
+		$nonce_ref = 'get_newsletter_form_content_nonce';
301
+		$this->_verify_nonce($nonce, $nonce_ref);
302
+		// let's get the mtp for the incoming MTP_ ID
303
+		if (! isset($this->_req_data['GRP_ID'])) {
304
+			EE_Error::add_error(
305
+				esc_html__(
306
+					'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
307
+					'event_espresso'
308
+				),
309
+				__FILE__,
310
+				__FUNCTION__,
311
+				__LINE__
312
+			);
313
+			$this->_template_args['success'] = false;
314
+			$this->_template_args['error'] = true;
315
+			$this->_return_json();
316
+		}
317
+		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
318
+		if (! $MTPG instanceof EE_Message_Template_Group) {
319
+			EE_Error::add_error(
320
+				sprintf(
321
+					esc_html__(
322
+						'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
323
+						'event_espresso'
324
+					),
325
+					$this->_req_data['GRP_ID']
326
+				),
327
+				__FILE__,
328
+				__FUNCTION__,
329
+				__LINE__
330
+			);
331
+			$this->_template_args['success'] = false;
332
+			$this->_template_args['error'] = true;
333
+			$this->_return_json();
334
+		}
335
+		$MTPs = $MTPG->context_templates();
336
+		$MTPs = $MTPs['attendee'];
337
+		$template_fields = array();
338
+		/** @var EE_Message_Template $MTP */
339
+		foreach ($MTPs as $MTP) {
340
+			$field = $MTP->get('MTP_template_field');
341
+			if ($field === 'content') {
342
+				$content = $MTP->get('MTP_content');
343
+				if (! empty($content['newsletter_content'])) {
344
+					$template_fields['newsletter_content'] = $content['newsletter_content'];
345
+				}
346
+				continue;
347
+			}
348
+			$template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
349
+		}
350
+		$this->_template_args['success'] = true;
351
+		$this->_template_args['error'] = false;
352
+		$this->_template_args['data'] = array(
353
+			'batch_message_from'    => isset($template_fields['from'])
354
+				? $template_fields['from']
355
+				: '',
356
+			'batch_message_subject' => isset($template_fields['subject'])
357
+				? $template_fields['subject']
358
+				: '',
359
+			'batch_message_content' => isset($template_fields['newsletter_content'])
360
+				? $template_fields['newsletter_content']
361
+				: '',
362
+		);
363
+		$this->_return_json();
364
+	}
365 365
 
366 366
 
367
-    /**
368
-     * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
369
-     *
370
-     * @since 4.3.0
371
-     * @param EE_Admin_List_Table $list_table
372
-     * @return void
373
-     * @throws InvalidArgumentException
374
-     * @throws InvalidDataTypeException
375
-     * @throws InvalidInterfaceException
376
-     */
377
-    public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
378
-    {
379
-        if (! EE_Registry::instance()->CAP->current_user_can(
380
-            'ee_send_message',
381
-            'espresso_registrations_newsletter_selected_send'
382
-        )
383
-        ) {
384
-            return;
385
-        }
386
-        $routes_to_add_to = array(
387
-            'contact_list',
388
-            'event_registrations',
389
-            'default',
390
-        );
391
-        if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
392
-            if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
393
-                || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
394
-            ) {
395
-                echo '';
396
-            } else {
397
-                $button_text = sprintf(
398
-                    esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
399
-                    '<span class="send-selected-newsletter-count">0</span>'
400
-                );
401
-                echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
402
-                     . '<span class="dashicons dashicons-email "></span>'
403
-                     . $button_text
404
-                     . '</button>';
405
-                add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
406
-            }
407
-        }
408
-    }
367
+	/**
368
+	 * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
369
+	 *
370
+	 * @since 4.3.0
371
+	 * @param EE_Admin_List_Table $list_table
372
+	 * @return void
373
+	 * @throws InvalidArgumentException
374
+	 * @throws InvalidDataTypeException
375
+	 * @throws InvalidInterfaceException
376
+	 */
377
+	public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
378
+	{
379
+		if (! EE_Registry::instance()->CAP->current_user_can(
380
+			'ee_send_message',
381
+			'espresso_registrations_newsletter_selected_send'
382
+		)
383
+		) {
384
+			return;
385
+		}
386
+		$routes_to_add_to = array(
387
+			'contact_list',
388
+			'event_registrations',
389
+			'default',
390
+		);
391
+		if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
392
+			if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
393
+				|| (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
394
+			) {
395
+				echo '';
396
+			} else {
397
+				$button_text = sprintf(
398
+					esc_html__('Send Batch Message (%s selected)', 'event_espresso'),
399
+					'<span class="send-selected-newsletter-count">0</span>'
400
+				);
401
+				echo '<button id="selected-batch-send-trigger" class="button secondary-button">'
402
+					 . '<span class="dashicons dashicons-email "></span>'
403
+					 . $button_text
404
+					 . '</button>';
405
+				add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
406
+			}
407
+		}
408
+	}
409 409
 
410 410
 
411
-    /**
412
-     * @throws DomainException
413
-     * @throws EE_Error
414
-     * @throws InvalidArgumentException
415
-     * @throws InvalidDataTypeException
416
-     * @throws InvalidInterfaceException
417
-     */
418
-    public function newsletter_send_form_skeleton()
419
-    {
420
-        $list_table = $this->_list_table_object;
421
-        $codes = array();
422
-        // need to templates for the newsletter message type for the template selector.
423
-        $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
424
-        $mtps = EEM_Message_Template_Group::instance()->get_all(
425
-            array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
426
-        );
427
-        foreach ($mtps as $mtp) {
428
-            $name = $mtp->name();
429
-            $values[] = array(
430
-                'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
431
-                'id'   => $mtp->ID(),
432
-            );
433
-        }
434
-        // need to get a list of shortcodes that are available for the newsletter message type.
435
-        $shortcodes = EEH_MSG_Template::get_shortcodes(
436
-            'newsletter',
437
-            'email',
438
-            array(),
439
-            'attendee',
440
-            false
441
-        );
442
-        foreach ($shortcodes as $field => $shortcode_array) {
443
-            $available_shortcodes = array();
444
-            foreach ($shortcode_array as $shortcode => $shortcode_details) {
445
-                $field_id = $field === '[NEWSLETTER_CONTENT]'
446
-                    ? 'content'
447
-                    : $field;
448
-                $field_id = 'batch-message-' . strtolower($field_id);
449
-                $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
450
-                                          . $shortcode
451
-                                          . '" data-linked-input-id="' . $field_id . '">'
452
-                                          . $shortcode
453
-                                          . '</span>';
454
-            }
455
-            $codes[ $field ] = implode(', ', $available_shortcodes);
456
-        }
457
-        $shortcodes = $codes;
458
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
459
-        $form_template_args = array(
460
-            'form_action'       => admin_url('admin.php?page=espresso_registrations'),
461
-            'form_route'        => 'newsletter_selected_send',
462
-            'form_nonce_name'   => 'newsletter_selected_send_nonce',
463
-            'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
464
-            'redirect_back_to'  => $this->_req_action,
465
-            'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
466
-            'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
467
-            'shortcodes'        => $shortcodes,
468
-            'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
469
-        );
470
-        EEH_Template::display_template($form_template, $form_template_args);
471
-    }
411
+	/**
412
+	 * @throws DomainException
413
+	 * @throws EE_Error
414
+	 * @throws InvalidArgumentException
415
+	 * @throws InvalidDataTypeException
416
+	 * @throws InvalidInterfaceException
417
+	 */
418
+	public function newsletter_send_form_skeleton()
419
+	{
420
+		$list_table = $this->_list_table_object;
421
+		$codes = array();
422
+		// need to templates for the newsletter message type for the template selector.
423
+		$values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0);
424
+		$mtps = EEM_Message_Template_Group::instance()->get_all(
425
+			array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
426
+		);
427
+		foreach ($mtps as $mtp) {
428
+			$name = $mtp->name();
429
+			$values[] = array(
430
+				'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name,
431
+				'id'   => $mtp->ID(),
432
+			);
433
+		}
434
+		// need to get a list of shortcodes that are available for the newsletter message type.
435
+		$shortcodes = EEH_MSG_Template::get_shortcodes(
436
+			'newsletter',
437
+			'email',
438
+			array(),
439
+			'attendee',
440
+			false
441
+		);
442
+		foreach ($shortcodes as $field => $shortcode_array) {
443
+			$available_shortcodes = array();
444
+			foreach ($shortcode_array as $shortcode => $shortcode_details) {
445
+				$field_id = $field === '[NEWSLETTER_CONTENT]'
446
+					? 'content'
447
+					: $field;
448
+				$field_id = 'batch-message-' . strtolower($field_id);
449
+				$available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
450
+										  . $shortcode
451
+										  . '" data-linked-input-id="' . $field_id . '">'
452
+										  . $shortcode
453
+										  . '</span>';
454
+			}
455
+			$codes[ $field ] = implode(', ', $available_shortcodes);
456
+		}
457
+		$shortcodes = $codes;
458
+		$form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
459
+		$form_template_args = array(
460
+			'form_action'       => admin_url('admin.php?page=espresso_registrations'),
461
+			'form_route'        => 'newsletter_selected_send',
462
+			'form_nonce_name'   => 'newsletter_selected_send_nonce',
463
+			'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
464
+			'redirect_back_to'  => $this->_req_action,
465
+			'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
466
+			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
467
+			'shortcodes'        => $shortcodes,
468
+			'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
469
+		);
470
+		EEH_Template::display_template($form_template, $form_template_args);
471
+	}
472 472
 
473 473
 
474
-    /**
475
-     * Handles sending selected registrations/contacts a newsletter.
476
-     *
477
-     * @since  4.3.0
478
-     * @return void
479
-     * @throws EE_Error
480
-     * @throws InvalidArgumentException
481
-     * @throws InvalidDataTypeException
482
-     * @throws InvalidInterfaceException
483
-     */
484
-    protected function _newsletter_selected_send()
485
-    {
486
-        $success = true;
487
-        // first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
488
-        if (empty($this->_req_data['newsletter_mtp_selected'])) {
489
-            EE_Error::add_error(
490
-                esc_html__(
491
-                    'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
492
-                    'event_espresso'
493
-                ),
494
-                __FILE__,
495
-                __FUNCTION__,
496
-                __LINE__
497
-            );
498
-            $success = false;
499
-        }
500
-        if ($success) {
501
-            // update Message template in case there are any changes
502
-            $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
503
-                $this->_req_data['newsletter_mtp_selected']
504
-            );
505
-            $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
506
-                ? $Message_Template_Group->context_templates()
507
-                : array();
508
-            if (empty($Message_Templates)) {
509
-                EE_Error::add_error(
510
-                    esc_html__(
511
-                        'Unable to retrieve message template fields from the db. Messages not sent.',
512
-                        'event_espresso'
513
-                    ),
514
-                    __FILE__,
515
-                    __FUNCTION__,
516
-                    __LINE__
517
-                );
518
-            }
519
-            // let's just update the specific fields
520
-            foreach ($Message_Templates['attendee'] as $Message_Template) {
521
-                if ($Message_Template instanceof EE_Message_Template) {
522
-                    $field = $Message_Template->get('MTP_template_field');
523
-                    $content = $Message_Template->get('MTP_content');
524
-                    $new_content = $content;
525
-                    switch ($field) {
526
-                        case 'from':
527
-                            $new_content = ! empty($this->_req_data['batch_message']['from'])
528
-                                ? $this->_req_data['batch_message']['from']
529
-                                : $content;
530
-                            break;
531
-                        case 'subject':
532
-                            $new_content = ! empty($this->_req_data['batch_message']['subject'])
533
-                                ? $this->_req_data['batch_message']['subject']
534
-                                : $content;
535
-                            break;
536
-                        case 'content':
537
-                            $new_content = $content;
538
-                            $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
539
-                                ? $this->_req_data['batch_message']['content']
540
-                                : $content['newsletter_content'];
541
-                            break;
542
-                        default:
543
-                            // continue the foreach loop, we don't want to set $new_content nor save.
544
-                            continue 2;
545
-                    }
546
-                    $Message_Template->set('MTP_content', $new_content);
547
-                    $Message_Template->save();
548
-                }
549
-            }
550
-            // great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
551
-            $id_type = ! empty($this->_req_data['batch_message']['id_type'])
552
-                ? $this->_req_data['batch_message']['id_type']
553
-                : 'registration';
554
-            // id_type will affect how we assemble the ids.
555
-            $ids = ! empty($this->_req_data['batch_message']['ids'])
556
-                ? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
557
-                : array();
558
-            $registrations_used_for_contact_data = array();
559
-            // using switch because eventually we'll have other contexts that will be used for generating messages.
560
-            switch ($id_type) {
561
-                case 'registration':
562
-                    $registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
563
-                        array(
564
-                            array(
565
-                                'REG_ID' => array('IN', $ids),
566
-                            ),
567
-                        )
568
-                    );
569
-                    break;
570
-                case 'contact':
571
-                    $registrations_used_for_contact_data = EEM_Registration::instance()
572
-                                                                           ->get_latest_registration_for_each_of_given_contacts(
573
-                                                                               $ids
574
-                                                                           );
575
-                    break;
576
-            }
577
-            do_action_ref_array(
578
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
579
-                array(
580
-                    $registrations_used_for_contact_data,
581
-                    $Message_Template_Group->ID(),
582
-                )
583
-            );
584
-            // kept for backward compat, internally we no longer use this action.
585
-            // @deprecated 4.8.36.rc.002
586
-            $contacts = $id_type === 'registration'
587
-                ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
588
-                : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
589
-            do_action_ref_array(
590
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
591
-                array(
592
-                    $contacts,
593
-                    $Message_Template_Group->ID(),
594
-                )
595
-            );
596
-        }
597
-        $query_args = array(
598
-            'action' => ! empty($this->_req_data['redirect_back_to'])
599
-                ? $this->_req_data['redirect_back_to']
600
-                : 'default',
601
-        );
602
-        $this->_redirect_after_action(false, '', '', $query_args, true);
603
-    }
474
+	/**
475
+	 * Handles sending selected registrations/contacts a newsletter.
476
+	 *
477
+	 * @since  4.3.0
478
+	 * @return void
479
+	 * @throws EE_Error
480
+	 * @throws InvalidArgumentException
481
+	 * @throws InvalidDataTypeException
482
+	 * @throws InvalidInterfaceException
483
+	 */
484
+	protected function _newsletter_selected_send()
485
+	{
486
+		$success = true;
487
+		// first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
488
+		if (empty($this->_req_data['newsletter_mtp_selected'])) {
489
+			EE_Error::add_error(
490
+				esc_html__(
491
+					'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
492
+					'event_espresso'
493
+				),
494
+				__FILE__,
495
+				__FUNCTION__,
496
+				__LINE__
497
+			);
498
+			$success = false;
499
+		}
500
+		if ($success) {
501
+			// update Message template in case there are any changes
502
+			$Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
503
+				$this->_req_data['newsletter_mtp_selected']
504
+			);
505
+			$Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
506
+				? $Message_Template_Group->context_templates()
507
+				: array();
508
+			if (empty($Message_Templates)) {
509
+				EE_Error::add_error(
510
+					esc_html__(
511
+						'Unable to retrieve message template fields from the db. Messages not sent.',
512
+						'event_espresso'
513
+					),
514
+					__FILE__,
515
+					__FUNCTION__,
516
+					__LINE__
517
+				);
518
+			}
519
+			// let's just update the specific fields
520
+			foreach ($Message_Templates['attendee'] as $Message_Template) {
521
+				if ($Message_Template instanceof EE_Message_Template) {
522
+					$field = $Message_Template->get('MTP_template_field');
523
+					$content = $Message_Template->get('MTP_content');
524
+					$new_content = $content;
525
+					switch ($field) {
526
+						case 'from':
527
+							$new_content = ! empty($this->_req_data['batch_message']['from'])
528
+								? $this->_req_data['batch_message']['from']
529
+								: $content;
530
+							break;
531
+						case 'subject':
532
+							$new_content = ! empty($this->_req_data['batch_message']['subject'])
533
+								? $this->_req_data['batch_message']['subject']
534
+								: $content;
535
+							break;
536
+						case 'content':
537
+							$new_content = $content;
538
+							$new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
539
+								? $this->_req_data['batch_message']['content']
540
+								: $content['newsletter_content'];
541
+							break;
542
+						default:
543
+							// continue the foreach loop, we don't want to set $new_content nor save.
544
+							continue 2;
545
+					}
546
+					$Message_Template->set('MTP_content', $new_content);
547
+					$Message_Template->save();
548
+				}
549
+			}
550
+			// great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
551
+			$id_type = ! empty($this->_req_data['batch_message']['id_type'])
552
+				? $this->_req_data['batch_message']['id_type']
553
+				: 'registration';
554
+			// id_type will affect how we assemble the ids.
555
+			$ids = ! empty($this->_req_data['batch_message']['ids'])
556
+				? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
557
+				: array();
558
+			$registrations_used_for_contact_data = array();
559
+			// using switch because eventually we'll have other contexts that will be used for generating messages.
560
+			switch ($id_type) {
561
+				case 'registration':
562
+					$registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
563
+						array(
564
+							array(
565
+								'REG_ID' => array('IN', $ids),
566
+							),
567
+						)
568
+					);
569
+					break;
570
+				case 'contact':
571
+					$registrations_used_for_contact_data = EEM_Registration::instance()
572
+																		   ->get_latest_registration_for_each_of_given_contacts(
573
+																			   $ids
574
+																		   );
575
+					break;
576
+			}
577
+			do_action_ref_array(
578
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
579
+				array(
580
+					$registrations_used_for_contact_data,
581
+					$Message_Template_Group->ID(),
582
+				)
583
+			);
584
+			// kept for backward compat, internally we no longer use this action.
585
+			// @deprecated 4.8.36.rc.002
586
+			$contacts = $id_type === 'registration'
587
+				? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
588
+				: EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
589
+			do_action_ref_array(
590
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
591
+				array(
592
+					$contacts,
593
+					$Message_Template_Group->ID(),
594
+				)
595
+			);
596
+		}
597
+		$query_args = array(
598
+			'action' => ! empty($this->_req_data['redirect_back_to'])
599
+				? $this->_req_data['redirect_back_to']
600
+				: 'default',
601
+		);
602
+		$this->_redirect_after_action(false, '', '', $query_args, true);
603
+	}
604 604
 
605 605
 
606
-    /**
607
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
608
-     * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
609
-     */
610
-    protected function _registration_reports_js_setup()
611
-    {
612
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
613
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
614
-    }
606
+	/**
607
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
608
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
609
+	 */
610
+	protected function _registration_reports_js_setup()
611
+	{
612
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
613
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
614
+	}
615 615
 
616 616
 
617
-    /**
618
-     *        generates Business Reports regarding Registrations
619
-     *
620
-     * @access protected
621
-     * @return void
622
-     * @throws DomainException
623
-     */
624
-    protected function _registration_reports()
625
-    {
626
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
627
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
628
-            $template_path,
629
-            $this->_reports_template_data,
630
-            true
631
-        );
632
-        // the final template wrapper
633
-        $this->display_admin_page_with_no_sidebar();
634
-    }
617
+	/**
618
+	 *        generates Business Reports regarding Registrations
619
+	 *
620
+	 * @access protected
621
+	 * @return void
622
+	 * @throws DomainException
623
+	 */
624
+	protected function _registration_reports()
625
+	{
626
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
627
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
628
+			$template_path,
629
+			$this->_reports_template_data,
630
+			true
631
+		);
632
+		// the final template wrapper
633
+		$this->display_admin_page_with_no_sidebar();
634
+	}
635 635
 
636 636
 
637
-    /**
638
-     * Generates Business Report showing total registrations per day.
639
-     *
640
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
641
-     * @return string
642
-     * @throws EE_Error
643
-     * @throws InvalidArgumentException
644
-     * @throws InvalidDataTypeException
645
-     * @throws InvalidInterfaceException
646
-     */
647
-    private function _registrations_per_day_report($period = '-1 month')
648
-    {
649
-        $report_ID = 'reg-admin-registrations-per-day-report-dv';
650
-        $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
651
-        $results = (array) $results;
652
-        $regs = array();
653
-        $subtitle = '';
654
-        if ($results) {
655
-            $column_titles = array();
656
-            $tracker = 0;
657
-            foreach ($results as $result) {
658
-                $report_column_values = array();
659
-                foreach ($result as $property_name => $property_value) {
660
-                    $property_value = $property_name === 'Registration_REG_date' ? $property_value
661
-                        : (int) $property_value;
662
-                    $report_column_values[] = $property_value;
663
-                    if ($tracker === 0) {
664
-                        if ($property_name === 'Registration_REG_date') {
665
-                            $column_titles[] = esc_html__(
666
-                                'Date (only days with registrations are shown)',
667
-                                'event_espresso'
668
-                            );
669
-                        } else {
670
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
671
-                        }
672
-                    }
673
-                }
674
-                $tracker++;
675
-                $regs[] = $report_column_values;
676
-            }
677
-            // make sure the column_titles is pushed to the beginning of the array
678
-            array_unshift($regs, $column_titles);
679
-            // setup the date range.
680
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
681
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
682
-            $ending_date = new DateTime("now", $DateTimeZone);
683
-            $subtitle = sprintf(
684
-                wp_strip_all_tags(
685
-                    _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso')
686
-                ),
687
-                $beginning_date->format('Y-m-d'),
688
-                $ending_date->format('Y-m-d')
689
-            );
690
-        }
691
-        $report_title = wp_strip_all_tags(__('Total Registrations per Day', 'event_espresso'));
692
-        $report_params = array(
693
-            'title'     => $report_title,
694
-            'subtitle'  => $subtitle,
695
-            'id'        => $report_ID,
696
-            'regs'      => $regs,
697
-            'noResults' => empty($regs),
698
-            'noRegsMsg' => sprintf(
699
-                wp_strip_all_tags(
700
-                    __(
701
-                        '%sThere are currently no registration records in the last month for this report.%s',
702
-                        'event_espresso'
703
-                    )
704
-                ),
705
-                '<h2>' . $report_title . '</h2><p>',
706
-                '</p>'
707
-            ),
708
-        );
709
-        wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
710
-        return $report_ID;
711
-    }
637
+	/**
638
+	 * Generates Business Report showing total registrations per day.
639
+	 *
640
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
641
+	 * @return string
642
+	 * @throws EE_Error
643
+	 * @throws InvalidArgumentException
644
+	 * @throws InvalidDataTypeException
645
+	 * @throws InvalidInterfaceException
646
+	 */
647
+	private function _registrations_per_day_report($period = '-1 month')
648
+	{
649
+		$report_ID = 'reg-admin-registrations-per-day-report-dv';
650
+		$results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
651
+		$results = (array) $results;
652
+		$regs = array();
653
+		$subtitle = '';
654
+		if ($results) {
655
+			$column_titles = array();
656
+			$tracker = 0;
657
+			foreach ($results as $result) {
658
+				$report_column_values = array();
659
+				foreach ($result as $property_name => $property_value) {
660
+					$property_value = $property_name === 'Registration_REG_date' ? $property_value
661
+						: (int) $property_value;
662
+					$report_column_values[] = $property_value;
663
+					if ($tracker === 0) {
664
+						if ($property_name === 'Registration_REG_date') {
665
+							$column_titles[] = esc_html__(
666
+								'Date (only days with registrations are shown)',
667
+								'event_espresso'
668
+							);
669
+						} else {
670
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
671
+						}
672
+					}
673
+				}
674
+				$tracker++;
675
+				$regs[] = $report_column_values;
676
+			}
677
+			// make sure the column_titles is pushed to the beginning of the array
678
+			array_unshift($regs, $column_titles);
679
+			// setup the date range.
680
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
681
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
682
+			$ending_date = new DateTime("now", $DateTimeZone);
683
+			$subtitle = sprintf(
684
+				wp_strip_all_tags(
685
+					_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso')
686
+				),
687
+				$beginning_date->format('Y-m-d'),
688
+				$ending_date->format('Y-m-d')
689
+			);
690
+		}
691
+		$report_title = wp_strip_all_tags(__('Total Registrations per Day', 'event_espresso'));
692
+		$report_params = array(
693
+			'title'     => $report_title,
694
+			'subtitle'  => $subtitle,
695
+			'id'        => $report_ID,
696
+			'regs'      => $regs,
697
+			'noResults' => empty($regs),
698
+			'noRegsMsg' => sprintf(
699
+				wp_strip_all_tags(
700
+					__(
701
+						'%sThere are currently no registration records in the last month for this report.%s',
702
+						'event_espresso'
703
+					)
704
+				),
705
+				'<h2>' . $report_title . '</h2><p>',
706
+				'</p>'
707
+			),
708
+		);
709
+		wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
710
+		return $report_ID;
711
+	}
712 712
 
713 713
 
714
-    /**
715
-     * Generates Business Report showing total registrations per event.
716
-     *
717
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
718
-     * @return string
719
-     * @throws EE_Error
720
-     * @throws InvalidArgumentException
721
-     * @throws InvalidDataTypeException
722
-     * @throws InvalidInterfaceException
723
-     */
724
-    private function _registrations_per_event_report($period = '-1 month')
725
-    {
726
-        $report_ID = 'reg-admin-registrations-per-event-report-dv';
727
-        $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
728
-        $results = (array) $results;
729
-        $regs = array();
730
-        $subtitle = '';
731
-        if ($results) {
732
-            $column_titles = array();
733
-            $tracker = 0;
734
-            foreach ($results as $result) {
735
-                $report_column_values = array();
736
-                foreach ($result as $property_name => $property_value) {
737
-                    $property_value = $property_name === 'Registration_Event' ? wp_trim_words(
738
-                        $property_value,
739
-                        4,
740
-                        '...'
741
-                    ) : (int) $property_value;
742
-                    $report_column_values[] = $property_value;
743
-                    if ($tracker === 0) {
744
-                        if ($property_name === 'Registration_Event') {
745
-                            $column_titles[] = esc_html__('Event', 'event_espresso');
746
-                        } else {
747
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
748
-                        }
749
-                    }
750
-                }
751
-                $tracker++;
752
-                $regs[] = $report_column_values;
753
-            }
754
-            // make sure the column_titles is pushed to the beginning of the array
755
-            array_unshift($regs, $column_titles);
756
-            // setup the date range.
757
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
758
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
759
-            $ending_date = new DateTime("now", $DateTimeZone);
760
-            $subtitle = sprintf(
761
-                wp_strip_all_tags(
762
-                    _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso')
763
-                ),
764
-                $beginning_date->format('Y-m-d'),
765
-                $ending_date->format('Y-m-d')
766
-            );
767
-        }
768
-        $report_title = wp_strip_all_tags(__('Total Registrations per Event', 'event_espresso'));
769
-        $report_params = array(
770
-            'title'     => $report_title,
771
-            'subtitle'  => $subtitle,
772
-            'id'        => $report_ID,
773
-            'regs'      => $regs,
774
-            'noResults' => empty($regs),
775
-            'noRegsMsg' => sprintf(
776
-                wp_strip_all_tags(
777
-                    __(
778
-                        '%sThere are currently no registration records in the last month for this report.%s',
779
-                        'event_espresso'
780
-                    )
781
-                ),
782
-                '<h2>' . $report_title . '</h2><p>',
783
-                '</p>'
784
-            ),
785
-        );
786
-        wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
787
-        return $report_ID;
788
-    }
714
+	/**
715
+	 * Generates Business Report showing total registrations per event.
716
+	 *
717
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
718
+	 * @return string
719
+	 * @throws EE_Error
720
+	 * @throws InvalidArgumentException
721
+	 * @throws InvalidDataTypeException
722
+	 * @throws InvalidInterfaceException
723
+	 */
724
+	private function _registrations_per_event_report($period = '-1 month')
725
+	{
726
+		$report_ID = 'reg-admin-registrations-per-event-report-dv';
727
+		$results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
728
+		$results = (array) $results;
729
+		$regs = array();
730
+		$subtitle = '';
731
+		if ($results) {
732
+			$column_titles = array();
733
+			$tracker = 0;
734
+			foreach ($results as $result) {
735
+				$report_column_values = array();
736
+				foreach ($result as $property_name => $property_value) {
737
+					$property_value = $property_name === 'Registration_Event' ? wp_trim_words(
738
+						$property_value,
739
+						4,
740
+						'...'
741
+					) : (int) $property_value;
742
+					$report_column_values[] = $property_value;
743
+					if ($tracker === 0) {
744
+						if ($property_name === 'Registration_Event') {
745
+							$column_titles[] = esc_html__('Event', 'event_espresso');
746
+						} else {
747
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
748
+						}
749
+					}
750
+				}
751
+				$tracker++;
752
+				$regs[] = $report_column_values;
753
+			}
754
+			// make sure the column_titles is pushed to the beginning of the array
755
+			array_unshift($regs, $column_titles);
756
+			// setup the date range.
757
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
758
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
759
+			$ending_date = new DateTime("now", $DateTimeZone);
760
+			$subtitle = sprintf(
761
+				wp_strip_all_tags(
762
+					_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso')
763
+				),
764
+				$beginning_date->format('Y-m-d'),
765
+				$ending_date->format('Y-m-d')
766
+			);
767
+		}
768
+		$report_title = wp_strip_all_tags(__('Total Registrations per Event', 'event_espresso'));
769
+		$report_params = array(
770
+			'title'     => $report_title,
771
+			'subtitle'  => $subtitle,
772
+			'id'        => $report_ID,
773
+			'regs'      => $regs,
774
+			'noResults' => empty($regs),
775
+			'noRegsMsg' => sprintf(
776
+				wp_strip_all_tags(
777
+					__(
778
+						'%sThere are currently no registration records in the last month for this report.%s',
779
+						'event_espresso'
780
+					)
781
+				),
782
+				'<h2>' . $report_title . '</h2><p>',
783
+				'</p>'
784
+			),
785
+		);
786
+		wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
787
+		return $report_ID;
788
+	}
789 789
 
790 790
 
791
-    /**
792
-     * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
793
-     *
794
-     * @access protected
795
-     * @return void
796
-     * @throws EE_Error
797
-     * @throws InvalidArgumentException
798
-     * @throws InvalidDataTypeException
799
-     * @throws InvalidInterfaceException
800
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
801
-     */
802
-    protected function _registration_checkin_list_table()
803
-    {
804
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
805
-        $reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null;
806
-        /** @var EE_Registration $registration */
807
-        $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
808
-        if (! $registration instanceof EE_Registration) {
809
-            throw new EE_Error(
810
-                sprintf(
811
-                    esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
812
-                    $reg_id
813
-                )
814
-            );
815
-        }
816
-        $attendee = $registration->attendee();
817
-        $this->_admin_page_title .= $this->get_action_link_or_button(
818
-            'new_registration',
819
-            'add-registrant',
820
-            array('event_id' => $registration->event_ID()),
821
-            'add-new-h2'
822
-        );
823
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
824
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
825
-        $legend_items = array(
826
-            'checkin'  => array(
827
-                'class' => $checked_in->cssClasses(),
828
-                'desc'  => $checked_in->legendLabel(),
829
-            ),
830
-            'checkout' => array(
831
-                'class' => $checked_out->cssClasses(),
832
-                'desc'  => $checked_out->legendLabel(),
833
-            ),
834
-        );
835
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
836
-        $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
837
-        /** @var EE_Datetime $datetime */
838
-        $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
839
-        $datetime_label = '';
840
-        if ($datetime instanceof EE_Datetime) {
841
-            $datetime_label = $datetime->get_dtt_display_name(true);
842
-            $datetime_label .= ! empty($datetime_label)
843
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
844
-                : $datetime->get_dtt_display_name();
845
-        }
846
-        $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
847
-            ? EE_Admin_Page::add_query_args_and_nonce(
848
-                array(
849
-                    'action'   => 'event_registrations',
850
-                    'event_id' => $registration->event_ID(),
851
-                    'DTT_ID'   => $dtt_id,
852
-                ),
853
-                $this->_admin_base_url
854
-            )
855
-            : '';
856
-        $datetime_link = ! empty($datetime_link)
857
-            ? '<a href="' . $datetime_link . '">'
858
-              . '<span id="checkin-dtt">'
859
-              . $datetime_label
860
-              . '</span></a>'
861
-            : $datetime_label;
862
-        $attendee_name = $attendee instanceof EE_Attendee
863
-            ? $attendee->full_name()
864
-            : '';
865
-        $attendee_link = $attendee instanceof EE_Attendee
866
-            ? $attendee->get_admin_details_link()
867
-            : '';
868
-        $attendee_link = ! empty($attendee_link)
869
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
870
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
871
-              . '<span id="checkin-attendee-name">'
872
-              . $attendee_name
873
-              . '</span></a>'
874
-            : '';
875
-        $event_link = $registration->event() instanceof EE_Event
876
-            ? $registration->event()->get_admin_details_link()
877
-            : '';
878
-        $event_link = ! empty($event_link)
879
-            ? '<a href="' . $event_link . '"'
880
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
881
-              . '<span id="checkin-event-name">'
882
-              . $registration->event_name()
883
-              . '</span>'
884
-              . '</a>'
885
-            : '';
886
-        $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
887
-            ? '<h2>' . sprintf(
888
-                esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
889
-                $attendee_link,
890
-                $datetime_link,
891
-                $event_link
892
-            ) . '</h2>'
893
-            : '';
894
-        $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
895
-            ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
896
-        $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
897
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
898
-        $this->display_admin_list_table_page_with_no_sidebar();
899
-    }
791
+	/**
792
+	 * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
793
+	 *
794
+	 * @access protected
795
+	 * @return void
796
+	 * @throws EE_Error
797
+	 * @throws InvalidArgumentException
798
+	 * @throws InvalidDataTypeException
799
+	 * @throws InvalidInterfaceException
800
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
801
+	 */
802
+	protected function _registration_checkin_list_table()
803
+	{
804
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
805
+		$reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null;
806
+		/** @var EE_Registration $registration */
807
+		$registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
808
+		if (! $registration instanceof EE_Registration) {
809
+			throw new EE_Error(
810
+				sprintf(
811
+					esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
812
+					$reg_id
813
+				)
814
+			);
815
+		}
816
+		$attendee = $registration->attendee();
817
+		$this->_admin_page_title .= $this->get_action_link_or_button(
818
+			'new_registration',
819
+			'add-registrant',
820
+			array('event_id' => $registration->event_ID()),
821
+			'add-new-h2'
822
+		);
823
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
824
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
825
+		$legend_items = array(
826
+			'checkin'  => array(
827
+				'class' => $checked_in->cssClasses(),
828
+				'desc'  => $checked_in->legendLabel(),
829
+			),
830
+			'checkout' => array(
831
+				'class' => $checked_out->cssClasses(),
832
+				'desc'  => $checked_out->legendLabel(),
833
+			),
834
+		);
835
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
836
+		$dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
837
+		/** @var EE_Datetime $datetime */
838
+		$datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
839
+		$datetime_label = '';
840
+		if ($datetime instanceof EE_Datetime) {
841
+			$datetime_label = $datetime->get_dtt_display_name(true);
842
+			$datetime_label .= ! empty($datetime_label)
843
+				? ' (' . $datetime->get_dtt_display_name() . ')'
844
+				: $datetime->get_dtt_display_name();
845
+		}
846
+		$datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
847
+			? EE_Admin_Page::add_query_args_and_nonce(
848
+				array(
849
+					'action'   => 'event_registrations',
850
+					'event_id' => $registration->event_ID(),
851
+					'DTT_ID'   => $dtt_id,
852
+				),
853
+				$this->_admin_base_url
854
+			)
855
+			: '';
856
+		$datetime_link = ! empty($datetime_link)
857
+			? '<a href="' . $datetime_link . '">'
858
+			  . '<span id="checkin-dtt">'
859
+			  . $datetime_label
860
+			  . '</span></a>'
861
+			: $datetime_label;
862
+		$attendee_name = $attendee instanceof EE_Attendee
863
+			? $attendee->full_name()
864
+			: '';
865
+		$attendee_link = $attendee instanceof EE_Attendee
866
+			? $attendee->get_admin_details_link()
867
+			: '';
868
+		$attendee_link = ! empty($attendee_link)
869
+			? '<a href="' . $attendee->get_admin_details_link() . '"'
870
+			  . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
871
+			  . '<span id="checkin-attendee-name">'
872
+			  . $attendee_name
873
+			  . '</span></a>'
874
+			: '';
875
+		$event_link = $registration->event() instanceof EE_Event
876
+			? $registration->event()->get_admin_details_link()
877
+			: '';
878
+		$event_link = ! empty($event_link)
879
+			? '<a href="' . $event_link . '"'
880
+			  . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
881
+			  . '<span id="checkin-event-name">'
882
+			  . $registration->event_name()
883
+			  . '</span>'
884
+			  . '</a>'
885
+			: '';
886
+		$this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
887
+			? '<h2>' . sprintf(
888
+				esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
889
+				$attendee_link,
890
+				$datetime_link,
891
+				$event_link
892
+			) . '</h2>'
893
+			: '';
894
+		$this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
895
+			? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
896
+		$this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
897
+			? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
898
+		$this->display_admin_list_table_page_with_no_sidebar();
899
+	}
900 900
 
901 901
 
902
-    /**
903
-     * toggle the Check-in status for the given registration (coming from ajax)
904
-     *
905
-     * @return void (JSON)
906
-     * @throws EE_Error
907
-     * @throws InvalidArgumentException
908
-     * @throws InvalidDataTypeException
909
-     * @throws InvalidInterfaceException
910
-     */
911
-    public function toggle_checkin_status()
912
-    {
913
-        // first make sure we have the necessary data
914
-        if (! isset($this->_req_data['_regid'])) {
915
-            EE_Error::add_error(
916
-                esc_html__(
917
-                    'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
918
-                    'event_espresso'
919
-                ),
920
-                __FILE__,
921
-                __FUNCTION__,
922
-                __LINE__
923
-            );
924
-            $this->_template_args['success'] = false;
925
-            $this->_template_args['error'] = true;
926
-            $this->_return_json();
927
-        };
928
-        // do a nonce check cause we're not coming in from an normal route here.
929
-        $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
930
-            : '';
931
-        $nonce_ref = 'checkin_nonce';
932
-        $this->_verify_nonce($nonce, $nonce_ref);
933
-        // beautiful! Made it this far so let's get the status.
934
-        $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
935
-        // setup new class to return via ajax
936
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
937
-        $this->_template_args['success'] = true;
938
-        $this->_return_json();
939
-    }
902
+	/**
903
+	 * toggle the Check-in status for the given registration (coming from ajax)
904
+	 *
905
+	 * @return void (JSON)
906
+	 * @throws EE_Error
907
+	 * @throws InvalidArgumentException
908
+	 * @throws InvalidDataTypeException
909
+	 * @throws InvalidInterfaceException
910
+	 */
911
+	public function toggle_checkin_status()
912
+	{
913
+		// first make sure we have the necessary data
914
+		if (! isset($this->_req_data['_regid'])) {
915
+			EE_Error::add_error(
916
+				esc_html__(
917
+					'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
918
+					'event_espresso'
919
+				),
920
+				__FILE__,
921
+				__FUNCTION__,
922
+				__LINE__
923
+			);
924
+			$this->_template_args['success'] = false;
925
+			$this->_template_args['error'] = true;
926
+			$this->_return_json();
927
+		};
928
+		// do a nonce check cause we're not coming in from an normal route here.
929
+		$nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
930
+			: '';
931
+		$nonce_ref = 'checkin_nonce';
932
+		$this->_verify_nonce($nonce, $nonce_ref);
933
+		// beautiful! Made it this far so let's get the status.
934
+		$new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
935
+		// setup new class to return via ajax
936
+		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
937
+		$this->_template_args['success'] = true;
938
+		$this->_return_json();
939
+	}
940 940
 
941 941
 
942
-    /**
943
-     * handles toggling the checkin status for the registration,
944
-     *
945
-     * @access protected
946
-     * @return int|void
947
-     * @throws EE_Error
948
-     * @throws InvalidArgumentException
949
-     * @throws InvalidDataTypeException
950
-     * @throws InvalidInterfaceException
951
-     */
952
-    protected function _toggle_checkin_status()
953
-    {
954
-        // first let's get the query args out of the way for the redirect
955
-        $query_args = array(
956
-            'action'   => 'event_registrations',
957
-            'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
958
-            'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
959
-        );
960
-        $new_status = false;
961
-        // bulk action check in toggle
962
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
963
-            // cycle thru checkboxes
964
-            while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
965
-                $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
966
-                $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
967
-            }
968
-        } elseif (isset($this->_req_data['_regid'])) {
969
-            // coming from ajax request
970
-            $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
971
-            $query_args['DTT_ID'] = $DTT_ID;
972
-            $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
973
-        } else {
974
-            EE_Error::add_error(
975
-                esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
976
-                __FILE__,
977
-                __FUNCTION__,
978
-                __LINE__
979
-            );
980
-        }
981
-        if (defined('DOING_AJAX')) {
982
-            return $new_status;
983
-        }
984
-        $this->_redirect_after_action(false, '', '', $query_args, true);
985
-    }
942
+	/**
943
+	 * handles toggling the checkin status for the registration,
944
+	 *
945
+	 * @access protected
946
+	 * @return int|void
947
+	 * @throws EE_Error
948
+	 * @throws InvalidArgumentException
949
+	 * @throws InvalidDataTypeException
950
+	 * @throws InvalidInterfaceException
951
+	 */
952
+	protected function _toggle_checkin_status()
953
+	{
954
+		// first let's get the query args out of the way for the redirect
955
+		$query_args = array(
956
+			'action'   => 'event_registrations',
957
+			'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
958
+			'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
959
+		);
960
+		$new_status = false;
961
+		// bulk action check in toggle
962
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
963
+			// cycle thru checkboxes
964
+			while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
965
+				$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
966
+				$new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
967
+			}
968
+		} elseif (isset($this->_req_data['_regid'])) {
969
+			// coming from ajax request
970
+			$DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
971
+			$query_args['DTT_ID'] = $DTT_ID;
972
+			$new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
973
+		} else {
974
+			EE_Error::add_error(
975
+				esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'),
976
+				__FILE__,
977
+				__FUNCTION__,
978
+				__LINE__
979
+			);
980
+		}
981
+		if (defined('DOING_AJAX')) {
982
+			return $new_status;
983
+		}
984
+		$this->_redirect_after_action(false, '', '', $query_args, true);
985
+	}
986 986
 
987 987
 
988
-    /**
989
-     * This is toggles a single Check-in for the given registration and datetime.
990
-     *
991
-     * @param  int $REG_ID The registration we're toggling
992
-     * @param  int $DTT_ID The datetime we're toggling
993
-     * @return int The new status toggled to.
994
-     * @throws EE_Error
995
-     * @throws InvalidArgumentException
996
-     * @throws InvalidDataTypeException
997
-     * @throws InvalidInterfaceException
998
-     */
999
-    private function _toggle_checkin($REG_ID, $DTT_ID)
1000
-    {
1001
-        /** @var EE_Registration $REG */
1002
-        $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1003
-        $new_status = $REG->toggle_checkin_status($DTT_ID);
1004
-        if ($new_status !== false) {
1005
-            EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
1006
-        } else {
1007
-            EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
1008
-            $new_status = false;
1009
-        }
1010
-        return $new_status;
1011
-    }
988
+	/**
989
+	 * This is toggles a single Check-in for the given registration and datetime.
990
+	 *
991
+	 * @param  int $REG_ID The registration we're toggling
992
+	 * @param  int $DTT_ID The datetime we're toggling
993
+	 * @return int The new status toggled to.
994
+	 * @throws EE_Error
995
+	 * @throws InvalidArgumentException
996
+	 * @throws InvalidDataTypeException
997
+	 * @throws InvalidInterfaceException
998
+	 */
999
+	private function _toggle_checkin($REG_ID, $DTT_ID)
1000
+	{
1001
+		/** @var EE_Registration $REG */
1002
+		$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1003
+		$new_status = $REG->toggle_checkin_status($DTT_ID);
1004
+		if ($new_status !== false) {
1005
+			EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
1006
+		} else {
1007
+			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
1008
+			$new_status = false;
1009
+		}
1010
+		return $new_status;
1011
+	}
1012 1012
 
1013 1013
 
1014
-    /**
1015
-     * Takes care of deleting multiple EE_Checkin table rows
1016
-     *
1017
-     * @access protected
1018
-     * @return void
1019
-     * @throws EE_Error
1020
-     * @throws InvalidArgumentException
1021
-     * @throws InvalidDataTypeException
1022
-     * @throws InvalidInterfaceException
1023
-     */
1024
-    protected function _delete_checkin_rows()
1025
-    {
1026
-        $query_args = array(
1027
-            'action'  => 'registration_checkins',
1028
-            'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1029
-            '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1030
-        );
1031
-        $errors = 0;
1032
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1033
-            while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1034
-                if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1035
-                    $errors++;
1036
-                }
1037
-            }
1038
-        } else {
1039
-            EE_Error::add_error(
1040
-                esc_html__(
1041
-                    'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1042
-                    'event_espresso'
1043
-                ),
1044
-                __FILE__,
1045
-                __FUNCTION__,
1046
-                __LINE__
1047
-            );
1048
-            $this->_redirect_after_action(false, '', '', $query_args, true);
1049
-        }
1050
-        if ($errors > 0) {
1051
-            EE_Error::add_error(
1052
-                sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1053
-                __FILE__,
1054
-                __FUNCTION__,
1055
-                __LINE__
1056
-            );
1057
-        } else {
1058
-            EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
1059
-        }
1060
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1061
-    }
1014
+	/**
1015
+	 * Takes care of deleting multiple EE_Checkin table rows
1016
+	 *
1017
+	 * @access protected
1018
+	 * @return void
1019
+	 * @throws EE_Error
1020
+	 * @throws InvalidArgumentException
1021
+	 * @throws InvalidDataTypeException
1022
+	 * @throws InvalidInterfaceException
1023
+	 */
1024
+	protected function _delete_checkin_rows()
1025
+	{
1026
+		$query_args = array(
1027
+			'action'  => 'registration_checkins',
1028
+			'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1029
+			'_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1030
+		);
1031
+		$errors = 0;
1032
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1033
+			while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1034
+				if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1035
+					$errors++;
1036
+				}
1037
+			}
1038
+		} else {
1039
+			EE_Error::add_error(
1040
+				esc_html__(
1041
+					'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
1042
+					'event_espresso'
1043
+				),
1044
+				__FILE__,
1045
+				__FUNCTION__,
1046
+				__LINE__
1047
+			);
1048
+			$this->_redirect_after_action(false, '', '', $query_args, true);
1049
+		}
1050
+		if ($errors > 0) {
1051
+			EE_Error::add_error(
1052
+				sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
1053
+				__FILE__,
1054
+				__FUNCTION__,
1055
+				__LINE__
1056
+			);
1057
+		} else {
1058
+			EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
1059
+		}
1060
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1061
+	}
1062 1062
 
1063 1063
 
1064
-    /**
1065
-     * Deletes a single EE_Checkin row
1066
-     *
1067
-     * @return void
1068
-     * @throws EE_Error
1069
-     * @throws InvalidArgumentException
1070
-     * @throws InvalidDataTypeException
1071
-     * @throws InvalidInterfaceException
1072
-     */
1073
-    protected function _delete_checkin_row()
1074
-    {
1075
-        $query_args = array(
1076
-            'action'  => 'registration_checkins',
1077
-            'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1078
-            '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1079
-        );
1080
-        if (! empty($this->_req_data['CHK_ID'])) {
1081
-            if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1082
-                EE_Error::add_error(
1083
-                    esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1084
-                    __FILE__,
1085
-                    __FUNCTION__,
1086
-                    __LINE__
1087
-                );
1088
-            } else {
1089
-                EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1090
-            }
1091
-        } else {
1092
-            EE_Error::add_error(
1093
-                esc_html__(
1094
-                    'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1095
-                    'event_espresso'
1096
-                ),
1097
-                __FILE__,
1098
-                __FUNCTION__,
1099
-                __LINE__
1100
-            );
1101
-        }
1102
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1103
-    }
1064
+	/**
1065
+	 * Deletes a single EE_Checkin row
1066
+	 *
1067
+	 * @return void
1068
+	 * @throws EE_Error
1069
+	 * @throws InvalidArgumentException
1070
+	 * @throws InvalidDataTypeException
1071
+	 * @throws InvalidInterfaceException
1072
+	 */
1073
+	protected function _delete_checkin_row()
1074
+	{
1075
+		$query_args = array(
1076
+			'action'  => 'registration_checkins',
1077
+			'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1078
+			'_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1079
+		);
1080
+		if (! empty($this->_req_data['CHK_ID'])) {
1081
+			if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1082
+				EE_Error::add_error(
1083
+					esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1084
+					__FILE__,
1085
+					__FUNCTION__,
1086
+					__LINE__
1087
+				);
1088
+			} else {
1089
+				EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1090
+			}
1091
+		} else {
1092
+			EE_Error::add_error(
1093
+				esc_html__(
1094
+					'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1095
+					'event_espresso'
1096
+				),
1097
+				__FILE__,
1098
+				__FUNCTION__,
1099
+				__LINE__
1100
+			);
1101
+		}
1102
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1103
+	}
1104 1104
 
1105 1105
 
1106
-    /**
1107
-     *        generates HTML for the Event Registrations List Table
1108
-     *
1109
-     * @access protected
1110
-     * @return void
1111
-     * @throws EE_Error
1112
-     * @throws InvalidArgumentException
1113
-     * @throws InvalidDataTypeException
1114
-     * @throws InvalidInterfaceException
1115
-     */
1116
-    protected function _event_registrations_list_table()
1117
-    {
1118
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1119
-        $this->_admin_page_title .= isset($this->_req_data['event_id'])
1120
-            ? $this->get_action_link_or_button(
1121
-                'new_registration',
1122
-                'add-registrant',
1123
-                array('event_id' => $this->_req_data['event_id']),
1124
-                'add-new-h2',
1125
-                '',
1126
-                false
1127
-            )
1128
-            : '';
1129
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1130
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1131
-        $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1132
-        $legend_items = array(
1133
-            'star-icon'        => array(
1134
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1135
-                'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1136
-            ),
1137
-            'checkin'          => array(
1138
-                'class' => $checked_in->cssClasses(),
1139
-                'desc'  => $checked_in->legendLabel(),
1140
-            ),
1141
-            'checkout'         => array(
1142
-                'class' => $checked_out->cssClasses(),
1143
-                'desc'  => $checked_out->legendLabel(),
1144
-            ),
1145
-            'nocheckinrecord'  => array(
1146
-                'class' => $checked_never->cssClasses(),
1147
-                'desc'  => $checked_never->legendLabel(),
1148
-            ),
1149
-            'approved_status'  => array(
1150
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1151
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1152
-            ),
1153
-            'cancelled_status' => array(
1154
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1155
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1156
-            ),
1157
-            'declined_status'  => array(
1158
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1159
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1160
-            ),
1161
-            'not_approved'     => array(
1162
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1163
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1164
-            ),
1165
-            'pending_status'   => array(
1166
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1167
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1168
-            ),
1169
-            'wait_list'        => array(
1170
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1171
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1172
-            ),
1173
-        );
1174
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1175
-        $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1176
-        /** @var EE_Event $event */
1177
-        $event = EEM_Event::instance()->get_one_by_ID($event_id);
1178
-        $this->_template_args['before_list_table'] = $event instanceof EE_Event
1179
-            ? '<h2>' . sprintf(
1180
-                esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1181
-                EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1182
-            ) . '</h2>'
1183
-            : '';
1184
-        // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1185
-        // the event.
1186
-        $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1187
-        $datetime = null;
1188
-        if ($event instanceof EE_Event) {
1189
-            $datetimes_on_event = $event->datetimes();
1190
-            if (count($datetimes_on_event) === 1) {
1191
-                $datetime = reset($datetimes_on_event);
1192
-            }
1193
-        }
1194
-        $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1195
-        if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1196
-            $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1197
-            $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1198
-            $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1199
-            $this->_template_args['before_list_table'] .= $datetime->name();
1200
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1201
-            $this->_template_args['before_list_table'] .= '</span></h2>';
1202
-        }
1203
-        // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1204
-        // column represents
1205
-        if (! $datetime instanceof EE_Datetime) {
1206
-            $this->_template_args['before_list_table'] .= '<br><p class="description">'
1207
-                                                          . esc_html__(
1208
-                                                              'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1209
-                                                              'event_espresso'
1210
-                                                          )
1211
-                                                          . '</p>';
1212
-        }
1213
-        $this->display_admin_list_table_page_with_no_sidebar();
1214
-    }
1106
+	/**
1107
+	 *        generates HTML for the Event Registrations List Table
1108
+	 *
1109
+	 * @access protected
1110
+	 * @return void
1111
+	 * @throws EE_Error
1112
+	 * @throws InvalidArgumentException
1113
+	 * @throws InvalidDataTypeException
1114
+	 * @throws InvalidInterfaceException
1115
+	 */
1116
+	protected function _event_registrations_list_table()
1117
+	{
1118
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1119
+		$this->_admin_page_title .= isset($this->_req_data['event_id'])
1120
+			? $this->get_action_link_or_button(
1121
+				'new_registration',
1122
+				'add-registrant',
1123
+				array('event_id' => $this->_req_data['event_id']),
1124
+				'add-new-h2',
1125
+				'',
1126
+				false
1127
+			)
1128
+			: '';
1129
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1130
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1131
+		$checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1132
+		$legend_items = array(
1133
+			'star-icon'        => array(
1134
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1135
+				'desc'  => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'),
1136
+			),
1137
+			'checkin'          => array(
1138
+				'class' => $checked_in->cssClasses(),
1139
+				'desc'  => $checked_in->legendLabel(),
1140
+			),
1141
+			'checkout'         => array(
1142
+				'class' => $checked_out->cssClasses(),
1143
+				'desc'  => $checked_out->legendLabel(),
1144
+			),
1145
+			'nocheckinrecord'  => array(
1146
+				'class' => $checked_never->cssClasses(),
1147
+				'desc'  => $checked_never->legendLabel(),
1148
+			),
1149
+			'approved_status'  => array(
1150
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1151
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1152
+			),
1153
+			'cancelled_status' => array(
1154
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1155
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1156
+			),
1157
+			'declined_status'  => array(
1158
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1159
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1160
+			),
1161
+			'not_approved'     => array(
1162
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1163
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1164
+			),
1165
+			'pending_status'   => array(
1166
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1167
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1168
+			),
1169
+			'wait_list'        => array(
1170
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1171
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1172
+			),
1173
+		);
1174
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1175
+		$event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1176
+		/** @var EE_Event $event */
1177
+		$event = EEM_Event::instance()->get_one_by_ID($event_id);
1178
+		$this->_template_args['before_list_table'] = $event instanceof EE_Event
1179
+			? '<h2>' . sprintf(
1180
+				esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1181
+				EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1182
+			) . '</h2>'
1183
+			: '';
1184
+		// need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1185
+		// the event.
1186
+		$DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1187
+		$datetime = null;
1188
+		if ($event instanceof EE_Event) {
1189
+			$datetimes_on_event = $event->datetimes();
1190
+			if (count($datetimes_on_event) === 1) {
1191
+				$datetime = reset($datetimes_on_event);
1192
+			}
1193
+		}
1194
+		$datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1195
+		if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1196
+			$this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1197
+			$this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1198
+			$this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1199
+			$this->_template_args['before_list_table'] .= $datetime->name();
1200
+			$this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1201
+			$this->_template_args['before_list_table'] .= '</span></h2>';
1202
+		}
1203
+		// if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1204
+		// column represents
1205
+		if (! $datetime instanceof EE_Datetime) {
1206
+			$this->_template_args['before_list_table'] .= '<br><p class="description">'
1207
+														  . esc_html__(
1208
+															  'In this view, the check-in status represents the latest check-in record for the registration in that row.',
1209
+															  'event_espresso'
1210
+														  )
1211
+														  . '</p>';
1212
+		}
1213
+		$this->display_admin_list_table_page_with_no_sidebar();
1214
+	}
1215 1215
 
1216
-    /**
1217
-     * Download the registrations check-in report (same as the normal registration report, but with different where
1218
-     * conditions)
1219
-     *
1220
-     * @return void ends the request by a redirect or download
1221
-     */
1222
-    public function _registrations_checkin_report()
1223
-    {
1224
-        $this->_registrations_report_base('_get_checkin_query_params_from_request');
1225
-    }
1216
+	/**
1217
+	 * Download the registrations check-in report (same as the normal registration report, but with different where
1218
+	 * conditions)
1219
+	 *
1220
+	 * @return void ends the request by a redirect or download
1221
+	 */
1222
+	public function _registrations_checkin_report()
1223
+	{
1224
+		$this->_registrations_report_base('_get_checkin_query_params_from_request');
1225
+	}
1226 1226
 
1227
-    /**
1228
-     * Gets the query params from the request, plus adds a where condition for the registration status,
1229
-     * because on the checkin page we only ever want to see approved and pending-approval registrations
1230
-     *
1231
-     * @param array $request
1232
-     * @param int   $per_page
1233
-     * @param bool  $count
1234
-     * @return array
1235
-     * @throws EE_Error
1236
-     */
1237
-    protected function _get_checkin_query_params_from_request(
1238
-        $request,
1239
-        $per_page = 10,
1240
-        $count = false
1241
-    ) {
1242
-        $query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1243
-        // unlike the regular registrations list table,
1244
-        $status_ids_array = apply_filters(
1245
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1246
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1247
-        );
1248
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1249
-        return $query_params;
1250
-    }
1227
+	/**
1228
+	 * Gets the query params from the request, plus adds a where condition for the registration status,
1229
+	 * because on the checkin page we only ever want to see approved and pending-approval registrations
1230
+	 *
1231
+	 * @param array $request
1232
+	 * @param int   $per_page
1233
+	 * @param bool  $count
1234
+	 * @return array
1235
+	 * @throws EE_Error
1236
+	 */
1237
+	protected function _get_checkin_query_params_from_request(
1238
+		$request,
1239
+		$per_page = 10,
1240
+		$count = false
1241
+	) {
1242
+		$query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1243
+		// unlike the regular registrations list table,
1244
+		$status_ids_array = apply_filters(
1245
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1246
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1247
+		);
1248
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1249
+		return $query_params;
1250
+	}
1251 1251
 
1252 1252
 
1253
-    /**
1254
-     * Gets registrations for an event
1255
-     *
1256
-     * @param int    $per_page
1257
-     * @param bool   $count whether to return count or data.
1258
-     * @param bool   $trash
1259
-     * @param string $orderby
1260
-     * @return EE_Registration[]|int
1261
-     * @throws EE_Error
1262
-     * @throws InvalidArgumentException
1263
-     * @throws InvalidDataTypeException
1264
-     * @throws InvalidInterfaceException
1265
-     */
1266
-    public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1267
-    {
1268
-        // normalize some request params that get setup by the parent `get_registrations` method.
1269
-        $request = $this->_req_data;
1270
-        $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1271
-        $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1272
-        if ($trash) {
1273
-            $request['status'] = 'trash';
1274
-        }
1275
-        $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1276
-        /**
1277
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1278
-         *
1279
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1280
-         * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1281
-         *                             or if you have the development copy of EE you can view this at the path:
1282
-         *                             /docs/G--Model-System/model-query-params.md
1283
-         */
1284
-        $query_params['group_by'] = '';
1253
+	/**
1254
+	 * Gets registrations for an event
1255
+	 *
1256
+	 * @param int    $per_page
1257
+	 * @param bool   $count whether to return count or data.
1258
+	 * @param bool   $trash
1259
+	 * @param string $orderby
1260
+	 * @return EE_Registration[]|int
1261
+	 * @throws EE_Error
1262
+	 * @throws InvalidArgumentException
1263
+	 * @throws InvalidDataTypeException
1264
+	 * @throws InvalidInterfaceException
1265
+	 */
1266
+	public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1267
+	{
1268
+		// normalize some request params that get setup by the parent `get_registrations` method.
1269
+		$request = $this->_req_data;
1270
+		$request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1271
+		$request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1272
+		if ($trash) {
1273
+			$request['status'] = 'trash';
1274
+		}
1275
+		$query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1276
+		/**
1277
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1278
+		 *
1279
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1280
+		 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1281
+		 *                             or if you have the development copy of EE you can view this at the path:
1282
+		 *                             /docs/G--Model-System/model-query-params.md
1283
+		 */
1284
+		$query_params['group_by'] = '';
1285 1285
 
1286
-        return $count
1287
-            ? EEM_Registration::instance()->count($query_params)
1288
-            /** @type EE_Registration[] */
1289
-            : EEM_Registration::instance()->get_all($query_params);
1290
-    }
1286
+		return $count
1287
+			? EEM_Registration::instance()->count($query_params)
1288
+			/** @type EE_Registration[] */
1289
+			: EEM_Registration::instance()->get_all($query_params);
1290
+	}
1291 1291
 }
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
     public function __construct($routing = true)
33 33
     {
34 34
         parent::__construct($routing);
35
-        if (! defined('REG_CAF_TEMPLATE_PATH')) {
36
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
37
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
38
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
35
+        if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
36
+            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/');
37
+            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/');
38
+            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/');
39 39
         }
40 40
     }
41 41
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      */
46 46
     protected function _extend_page_config()
47 47
     {
48
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
48
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations';
49 49
         $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
50 50
             ? $this->_req_data['_REG_ID']
51 51
             : 0;
@@ -186,14 +186,14 @@  discard block
 block discarded – undo
186 186
             // enqueue newsletter js
187 187
             wp_enqueue_script(
188 188
                 'ee-newsletter-trigger',
189
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
189
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js',
190 190
                 array('ee-dialog'),
191 191
                 EVENT_ESPRESSO_VERSION,
192 192
                 true
193 193
             );
194 194
             wp_enqueue_style(
195 195
                 'ee-newsletter-trigger-css',
196
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
196
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css',
197 197
                 array(),
198 198
                 EVENT_ESPRESSO_VERSION
199 199
             );
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
     {
215 215
         wp_register_script(
216 216
             'ee-reg-reports-js',
217
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
217
+            REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js',
218 218
             array('google-charts'),
219 219
             EVENT_ESPRESSO_VERSION,
220 220
             true
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
         $nonce_ref = 'get_newsletter_form_content_nonce';
301 301
         $this->_verify_nonce($nonce, $nonce_ref);
302 302
         // let's get the mtp for the incoming MTP_ ID
303
-        if (! isset($this->_req_data['GRP_ID'])) {
303
+        if ( ! isset($this->_req_data['GRP_ID'])) {
304 304
             EE_Error::add_error(
305 305
                 esc_html__(
306 306
                     'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
             $this->_return_json();
316 316
         }
317 317
         $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
318
-        if (! $MTPG instanceof EE_Message_Template_Group) {
318
+        if ( ! $MTPG instanceof EE_Message_Template_Group) {
319 319
             EE_Error::add_error(
320 320
                 sprintf(
321 321
                     esc_html__(
@@ -340,12 +340,12 @@  discard block
 block discarded – undo
340 340
             $field = $MTP->get('MTP_template_field');
341 341
             if ($field === 'content') {
342 342
                 $content = $MTP->get('MTP_content');
343
-                if (! empty($content['newsletter_content'])) {
343
+                if ( ! empty($content['newsletter_content'])) {
344 344
                     $template_fields['newsletter_content'] = $content['newsletter_content'];
345 345
                 }
346 346
                 continue;
347 347
             }
348
-            $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content');
348
+            $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
349 349
         }
350 350
         $this->_template_args['success'] = true;
351 351
         $this->_template_args['error'] = false;
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
      */
377 377
     public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
378 378
     {
379
-        if (! EE_Registry::instance()->CAP->current_user_can(
379
+        if ( ! EE_Registry::instance()->CAP->current_user_can(
380 380
             'ee_send_message',
381 381
             'espresso_registrations_newsletter_selected_send'
382 382
         )
@@ -445,17 +445,17 @@  discard block
 block discarded – undo
445 445
                 $field_id = $field === '[NEWSLETTER_CONTENT]'
446 446
                     ? 'content'
447 447
                     : $field;
448
-                $field_id = 'batch-message-' . strtolower($field_id);
448
+                $field_id = 'batch-message-'.strtolower($field_id);
449 449
                 $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="'
450 450
                                           . $shortcode
451
-                                          . '" data-linked-input-id="' . $field_id . '">'
451
+                                          . '" data-linked-input-id="'.$field_id.'">'
452 452
                                           . $shortcode
453 453
                                           . '</span>';
454 454
             }
455
-            $codes[ $field ] = implode(', ', $available_shortcodes);
455
+            $codes[$field] = implode(', ', $available_shortcodes);
456 456
         }
457 457
         $shortcodes = $codes;
458
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
458
+        $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php';
459 459
         $form_template_args = array(
460 460
             'form_action'       => admin_url('admin.php?page=espresso_registrations'),
461 461
             'form_route'        => 'newsletter_selected_send',
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
      */
624 624
     protected function _registration_reports()
625 625
     {
626
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
626
+        $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
627 627
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
628 628
             $template_path,
629 629
             $this->_reports_template_data,
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
             array_unshift($regs, $column_titles);
679 679
             // setup the date range.
680 680
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
681
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
681
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
682 682
             $ending_date = new DateTime("now", $DateTimeZone);
683 683
             $subtitle = sprintf(
684 684
                 wp_strip_all_tags(
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
                         'event_espresso'
703 703
                     )
704 704
                 ),
705
-                '<h2>' . $report_title . '</h2><p>',
705
+                '<h2>'.$report_title.'</h2><p>',
706 706
                 '</p>'
707 707
             ),
708 708
         );
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
             array_unshift($regs, $column_titles);
756 756
             // setup the date range.
757 757
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
758
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
758
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
759 759
             $ending_date = new DateTime("now", $DateTimeZone);
760 760
             $subtitle = sprintf(
761 761
                 wp_strip_all_tags(
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
                         'event_espresso'
780 780
                     )
781 781
                 ),
782
-                '<h2>' . $report_title . '</h2><p>',
782
+                '<h2>'.$report_title.'</h2><p>',
783 783
                 '</p>'
784 784
             ),
785 785
         );
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
         $reg_id = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : null;
806 806
         /** @var EE_Registration $registration */
807 807
         $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
808
-        if (! $registration instanceof EE_Registration) {
808
+        if ( ! $registration instanceof EE_Registration) {
809 809
             throw new EE_Error(
810 810
                 sprintf(
811 811
                     esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'),
@@ -840,7 +840,7 @@  discard block
 block discarded – undo
840 840
         if ($datetime instanceof EE_Datetime) {
841 841
             $datetime_label = $datetime->get_dtt_display_name(true);
842 842
             $datetime_label .= ! empty($datetime_label)
843
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
843
+                ? ' ('.$datetime->get_dtt_display_name().')'
844 844
                 : $datetime->get_dtt_display_name();
845 845
         }
846 846
         $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
@@ -854,7 +854,7 @@  discard block
 block discarded – undo
854 854
             )
855 855
             : '';
856 856
         $datetime_link = ! empty($datetime_link)
857
-            ? '<a href="' . $datetime_link . '">'
857
+            ? '<a href="'.$datetime_link.'">'
858 858
               . '<span id="checkin-dtt">'
859 859
               . $datetime_label
860 860
               . '</span></a>'
@@ -866,8 +866,8 @@  discard block
 block discarded – undo
866 866
             ? $attendee->get_admin_details_link()
867 867
             : '';
868 868
         $attendee_link = ! empty($attendee_link)
869
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
870
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
869
+            ? '<a href="'.$attendee->get_admin_details_link().'"'
870
+              . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">'
871 871
               . '<span id="checkin-attendee-name">'
872 872
               . $attendee_name
873 873
               . '</span></a>'
@@ -876,25 +876,25 @@  discard block
 block discarded – undo
876 876
             ? $registration->event()->get_admin_details_link()
877 877
             : '';
878 878
         $event_link = ! empty($event_link)
879
-            ? '<a href="' . $event_link . '"'
880
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
879
+            ? '<a href="'.$event_link.'"'
880
+              . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">'
881 881
               . '<span id="checkin-event-name">'
882 882
               . $registration->event_name()
883 883
               . '</span>'
884 884
               . '</a>'
885 885
             : '';
886 886
         $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
887
-            ? '<h2>' . sprintf(
887
+            ? '<h2>'.sprintf(
888 888
                 esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
889 889
                 $attendee_link,
890 890
                 $datetime_link,
891 891
                 $event_link
892
-            ) . '</h2>'
892
+            ).'</h2>'
893 893
             : '';
894 894
         $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
895
-            ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : '';
895
+            ? '<input type="hidden" name="_REG_ID" value="'.$reg_id.'">' : '';
896 896
         $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
897
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
897
+            ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : '';
898 898
         $this->display_admin_list_table_page_with_no_sidebar();
899 899
     }
900 900
 
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
     public function toggle_checkin_status()
912 912
     {
913 913
         // first make sure we have the necessary data
914
-        if (! isset($this->_req_data['_regid'])) {
914
+        if ( ! isset($this->_req_data['_regid'])) {
915 915
             EE_Error::add_error(
916 916
                 esc_html__(
917 917
                     'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
         // beautiful! Made it this far so let's get the status.
934 934
         $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
935 935
         // setup new class to return via ajax
936
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
936
+        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin '.$new_status->cssClasses();
937 937
         $this->_template_args['success'] = true;
938 938
         $this->_return_json();
939 939
     }
@@ -959,7 +959,7 @@  discard block
 block discarded – undo
959 959
         );
960 960
         $new_status = false;
961 961
         // bulk action check in toggle
962
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
962
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
963 963
             // cycle thru checkboxes
964 964
             while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
965 965
                 $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
@@ -1029,9 +1029,9 @@  discard block
 block discarded – undo
1029 1029
             '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1030 1030
         );
1031 1031
         $errors = 0;
1032
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1032
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1033 1033
             while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
1034
-                if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1034
+                if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
1035 1035
                     $errors++;
1036 1036
                 }
1037 1037
             }
@@ -1077,8 +1077,8 @@  discard block
 block discarded – undo
1077 1077
             'DTT_ID'  => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
1078 1078
             '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0,
1079 1079
         );
1080
-        if (! empty($this->_req_data['CHK_ID'])) {
1081
-            if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1080
+        if ( ! empty($this->_req_data['CHK_ID'])) {
1081
+            if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
1082 1082
                 EE_Error::add_error(
1083 1083
                     esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
1084 1084
                     __FILE__,
@@ -1147,27 +1147,27 @@  discard block
 block discarded – undo
1147 1147
                 'desc'  => $checked_never->legendLabel(),
1148 1148
             ),
1149 1149
             'approved_status'  => array(
1150
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1150
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
1151 1151
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1152 1152
             ),
1153 1153
             'cancelled_status' => array(
1154
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1154
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1155 1155
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1156 1156
             ),
1157 1157
             'declined_status'  => array(
1158
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1158
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
1159 1159
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1160 1160
             ),
1161 1161
             'not_approved'     => array(
1162
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1162
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
1163 1163
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1164 1164
             ),
1165 1165
             'pending_status'   => array(
1166
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1166
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
1167 1167
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1168 1168
             ),
1169 1169
             'wait_list'        => array(
1170
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1170
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
1171 1171
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1172 1172
             ),
1173 1173
         );
@@ -1176,10 +1176,10 @@  discard block
 block discarded – undo
1176 1176
         /** @var EE_Event $event */
1177 1177
         $event = EEM_Event::instance()->get_one_by_ID($event_id);
1178 1178
         $this->_template_args['before_list_table'] = $event instanceof EE_Event
1179
-            ? '<h2>' . sprintf(
1179
+            ? '<h2>'.sprintf(
1180 1180
                 esc_html__('Viewing Registrations for Event: %s', 'event_espresso'),
1181 1181
                 EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1182
-            ) . '</h2>'
1182
+            ).'</h2>'
1183 1183
             : '';
1184 1184
         // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on
1185 1185
         // the event.
@@ -1197,12 +1197,12 @@  discard block
 block discarded – undo
1197 1197
             $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1198 1198
             $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1199 1199
             $this->_template_args['before_list_table'] .= $datetime->name();
1200
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1200
+            $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )';
1201 1201
             $this->_template_args['before_list_table'] .= '</span></h2>';
1202 1202
         }
1203 1203
         // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status
1204 1204
         // column represents
1205
-        if (! $datetime instanceof EE_Datetime) {
1205
+        if ( ! $datetime instanceof EE_Datetime) {
1206 1206
             $this->_template_args['before_list_table'] .= '<br><p class="description">'
1207 1207
                                                           . esc_html__(
1208 1208
                                                               'In this view, the check-in status represents the latest check-in record for the registration in that row.',
Please login to merge, or discard this patch.