Completed
Branch FET-Wait-List (743369)
by
unknown
10:59
created
core/admin/EE_Admin_Page_CPT_Init.core.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -30,44 +30,44 @@  discard block
 block discarded – undo
30 30
 {
31 31
 
32 32
 
33
-    public function do_initial_loads()
34
-    {
35
-        //we want to use the corresponding admin page object (but not route it!).  To do this we just set _routing to false.  That way this page object is being loaded on all pages to make sure we hook into admin properly.  But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;)
36
-        //This is important because we have hooks that help redirect custom post type saves
37
-        if (! isset($_REQUEST['page'])
38
-            || (isset($_REQUEST['page'])
39
-                && $_REQUEST['page']
40
-                   != $this->_menu_map->menu_slug)) {
41
-            $this->_routing = false;
42
-            $this->_initialize_admin_page();
43
-        } else {
44
-            //normal init loads
45
-            $this->_initialize_admin_page();
46
-            //added for 4.1 to completely disable autosave for our pages. This can be removed once we fully enable autosave functionality
47
-            remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization');
48
-            add_filter('wp_print_scripts', array($this, 'wp_just_in_time_script_localization'), 100);
49
-            //end removal of autosave functionality.
50
-        }
51
-    }
33
+	public function do_initial_loads()
34
+	{
35
+		//we want to use the corresponding admin page object (but not route it!).  To do this we just set _routing to false.  That way this page object is being loaded on all pages to make sure we hook into admin properly.  But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;)
36
+		//This is important because we have hooks that help redirect custom post type saves
37
+		if (! isset($_REQUEST['page'])
38
+			|| (isset($_REQUEST['page'])
39
+				&& $_REQUEST['page']
40
+				   != $this->_menu_map->menu_slug)) {
41
+			$this->_routing = false;
42
+			$this->_initialize_admin_page();
43
+		} else {
44
+			//normal init loads
45
+			$this->_initialize_admin_page();
46
+			//added for 4.1 to completely disable autosave for our pages. This can be removed once we fully enable autosave functionality
47
+			remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization');
48
+			add_filter('wp_print_scripts', array($this, 'wp_just_in_time_script_localization'), 100);
49
+			//end removal of autosave functionality.
50
+		}
51
+	}
52 52
 
53 53
 
54
-    public function wp_just_in_time_script_localization()
55
-    {
56
-        wp_localize_script(
57
-            'autosave',
58
-            'autosaveL10n',
59
-            array(
60
-                'autosaveInterval' => 172800,
61
-                'savingText'       => __('Saving Draft&#8230;'),
62
-                'saveAlert'        => __('The changes you made will be lost if you navigate away from this page.'),
63
-            )
64
-        );
65
-    }
54
+	public function wp_just_in_time_script_localization()
55
+	{
56
+		wp_localize_script(
57
+			'autosave',
58
+			'autosaveL10n',
59
+			array(
60
+				'autosaveInterval' => 172800,
61
+				'savingText'       => __('Saving Draft&#8230;'),
62
+				'saveAlert'        => __('The changes you made will be lost if you navigate away from this page.'),
63
+			)
64
+		);
65
+	}
66 66
 
67 67
 
68 68
 
69
-    public function adjust_post_lock_window($interval)
70
-    {
71
-        return 172800;
72
-    }
69
+	public function adjust_post_lock_window($interval)
70
+	{
71
+		return 172800;
72
+	}
73 73
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 /**
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     {
35 35
         //we want to use the corresponding admin page object (but not route it!).  To do this we just set _routing to false.  That way this page object is being loaded on all pages to make sure we hook into admin properly.  But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;)
36 36
         //This is important because we have hooks that help redirect custom post type saves
37
-        if (! isset($_REQUEST['page'])
37
+        if ( ! isset($_REQUEST['page'])
38 38
             || (isset($_REQUEST['page'])
39 39
                 && $_REQUEST['page']
40 40
                    != $this->_menu_map->menu_slug)) {
Please login to merge, or discard this patch.
core/admin/EE_Admin_Hooks.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -222,7 +222,7 @@
 block discarded – undo
222 222
     /**
223 223
      * constructor
224 224
      *
225
-     * @param EE_Admin_Page $admin_page the calling admin_page_object
225
+     * @param EE_Admin_Page $adminpage the calling admin_page_object
226 226
      */
227 227
     public function __construct(EE_Admin_Page $adminpage)
228 228
     {
Please login to merge, or discard this patch.
Indentation   +726 added lines, -726 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -28,729 +28,729 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    /**
32
-     * we're just going to use this to hold the name of the caller class (child class name)
33
-     *
34
-     * @var string
35
-     */
36
-    public $caller;
37
-
38
-
39
-
40
-    /**
41
-     * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e.
42
-     * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks).  This flag is
43
-     * used later to make sure we require the needed files.
44
-     *
45
-     * @var bool
46
-     */
47
-    protected $_extend;
48
-
49
-
50
-
51
-    /**
52
-     * child classes MUST set this property so that the page object can be loaded correctly
53
-     *
54
-     * @var string
55
-     */
56
-    protected $_name;
57
-
58
-
59
-
60
-    /**
61
-     * This is set by child classes and is an associative array of ajax hooks in the format:
62
-     * array(
63
-     *    'ajax_action_ref' => 'executing_method'; //must be public
64
-     * )
65
-     *
66
-     * @var array
67
-     */
68
-    protected $_ajax_func;
69
-
70
-
71
-    /**
72
-     * This is an array of methods that get executed on a page routes admin_init hook. Use the following format:
73
-     * array(
74
-     *    'page_route' => 'executing_method' //must be public
75
-     * )
76
-     *
77
-     * @var array
78
-     */
79
-    protected $_init_func;
80
-
81
-
82
-
83
-    /**
84
-     * This is an array of methods that output metabox content for the given page route.  Use the following format:
85
-     * array(
86
-     *    0 => array(
87
-     *        'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected
88
-     *        with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox
89
-     *        will be added to each route.
90
-     *        'func' =>  'executing_method',  //must be public (i.e. public function executing_method($post,
91
-     *        $callback_args){} ).  Note if you include callback args in the array then you need to declare them in the
92
-     *        method arguments.
93
-     *        'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it
94
-     *        automatically)
95
-     *        'priority' => 'default', //default 'default' (optional)
96
-     *        'label' => __('Localized Title', 'event_espresso'),
97
-     *        'context' => 'advanced' //advanced is default (optional),
98
-     *    'callback_args' => array() //any callback args to include (optional)
99
-     * )
100
-     * Why are we indexing numerically?  Because it's possible there may be more than one metabox per page_route.
101
-     *
102
-     * @var array
103
-     */
104
-    protected $_metaboxes;
105
-
106
-
107
-
108
-    /**
109
-     * This is an array of values that indicate any metaboxes we want removed from a given page route.  Usually this is
110
-     * used when caffeinated functionality is replacing decaffeinated functionality.  Use the following format for the
111
-     * array: array(
112
-     *    0 => array(
113
-     *        'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s)
114
-     *        that are in the class being connected with (i.e. 'edit', or 'create_new').
115
-     *        'id' => 'identifier_for_metabox', //what the id is of the metabox being removed
116
-     *        'context' => 'normal', //the context for the metabox being removed (has to match)
117
-     *        'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox
118
-     *        using the currently loaded screen object->id  however, there may be cases where you have to specify the
119
-     *        id for the screen the metabox is on.
120
-     *    )
121
-     * )
122
-     *
123
-     * @var array
124
-     */
125
-    protected $_remove_metaboxes;
126
-
127
-
128
-
129
-    /**
130
-     * This parent class takes care of loading the scripts and styles if the child class has set the properties for
131
-     * them in the following format.  Note, the first array index ('register') is for defining all the registers.  The
132
-     * second array index is for indicating what routes each script/style loads on. array(
133
-     * 'registers' => array(
134
-     *        'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency'
135
-     *        argument to link scripts together.
136
-     *            'type' => 'js' // 'js' or 'css' (defaults to js).  This tells us what type of wp_function to use
137
-     *            'url' => 'http://urltoscript.css.js',
138
-     *            'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has
139
-     *            already been registered elsewhere in the system.  You can just use the depends array to make sure it
140
-     *            gets loaded before the one you are setting here.
141
-     *            'footer' => TRUE //defaults to true (styles don't use this parameter)
142
-     *        ),
143
-     *    'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes
144
-     *    the script gets enqueued on.
145
-     *        'script_ref' => array('route_one', 'route_two')
146
-     *    ),
147
-     *    'localize' => array( //this allows you to set a localize object.  Indicate which script the object is being
148
-     *    attached to and then include an array indexed by the name of the object and the array of key/value pairs for
149
-     *    the object.
150
-     *        'scrip_ref' => array(
151
-     *            'NAME_OF_JS_OBJECT' => array(
152
-     *                'translate_ref' => __('localized_string', 'event_espresso'),
153
-     *                'some_data' => 5
154
-     *            )
155
-     *        )
156
-     *    )
157
-     * )
158
-     *
159
-     * @var array
160
-     */
161
-    protected $_scripts_styles;
162
-
163
-
164
-    /**
165
-     * This is a property that will contain the current route.
166
-     *
167
-     * @var string;
168
-     */
169
-    protected $_current_route;
170
-
171
-
172
-
173
-    /**
174
-     * this optional property can be set by child classes to override the priority for the automatic action/filter hook
175
-     * loading in the `_load_routed_hooks()` method.  Please follow this format: array(
176
-     *    'wp_hook_reference' => 1
177
-     *    )
178
-     * )
179
-     *
180
-     * @var array
181
-     */
182
-    protected $_wp_action_filters_priority;
183
-
184
-
185
-
186
-    /**
187
-     * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST
188
-     *
189
-     * @var array
190
-     */
191
-    protected $_req_data;
192
-
193
-
194
-
195
-    /**
196
-     * This just holds an instance of the page object for this hook
197
-     *
198
-     * @var EE_Admin_Page
199
-     */
200
-    protected $_page_object;
201
-
202
-
203
-
204
-    /**
205
-     * This holds the EE_Admin_Page object from the calling admin page that this object hooks into.
206
-     *
207
-     * @var EE_Admin_Page|EE_Admin_Page_CPT
208
-     */
209
-    protected $_adminpage_obj;
210
-
211
-
212
-
213
-    /**
214
-     * Holds EE_Registry object
215
-     *
216
-     * @var EE_Registry
217
-     */
218
-    protected $EE = null;
219
-
220
-
221
-
222
-    /**
223
-     * constructor
224
-     *
225
-     * @param EE_Admin_Page $admin_page the calling admin_page_object
226
-     */
227
-    public function __construct(EE_Admin_Page $adminpage)
228
-    {
229
-
230
-        $this->_adminpage_obj = $adminpage;
231
-        $this->_req_data      = array_merge($_GET, $_POST);
232
-        $this->_set_defaults();
233
-        $this->_set_hooks_properties();
234
-        //first let's verify we're on the right page
235
-        if (! isset($this->_req_data['page'])
236
-            || (isset($this->_req_data['page'])
237
-                && $this->_adminpage_obj->page_slug
238
-                   != $this->_req_data['page'])) {
239
-            return;
240
-        } //get out nothing more to be done here.
241
-        //allow for extends to modify properties
242
-        if (method_exists($this, '_extend_properties')) {
243
-            $this->_extend_properties();
244
-        }
245
-        $this->_set_page_object();
246
-        $this->_init_hooks();
247
-        $this->_load_custom_methods();
248
-        $this->_load_routed_hooks();
249
-        add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
250
-        add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20);
251
-        add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15);
252
-        $this->_ajax_hooks();
253
-    }
254
-
255
-
256
-
257
-    /**
258
-     * used by child classes to set the following properties:
259
-     * $_ajax_func (optional)
260
-     * $_init_func (optional)
261
-     * $_metaboxes (optional)
262
-     * $_scripts (optional)
263
-     * $_styles (optional)
264
-     * $_name (required)
265
-     * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the
266
-     * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen
267
-     * really early on page load (just after admin_init) if they want to have them registered for handling early.
268
-     *
269
-     * @access protected
270
-     * @abstract
271
-     * @return void
272
-     */
273
-    abstract protected function _set_hooks_properties();
274
-
275
-
276
-
277
-    /**
278
-     * The hooks for enqueue_scripts and enqueue_styles will be run in here.  Child classes need to define their
279
-     * scripts and styles in the relevant $_scripts and $_styles properties.  Child classes must have also already
280
-     * registered the scripts and styles using wp_register_script and wp_register_style functions.
281
-     *
282
-     * @access public
283
-     * @return void
284
-     */
285
-    public function enqueue_scripts_styles()
286
-    {
287
-
288
-        if (! empty($this->_scripts_styles)) {
289
-            //first let's do all the registrations
290
-            if (! isset($this->_scripts_styles['registers'])) {
291
-                $msg[] = __(
292
-                    'There is no "registers" index in the <code>$this->_scripts_styles</code> property.',
293
-                    'event_espresso'
294
-                );
295
-                $msg[] = sprintf(
296
-                    __(
297
-                        'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child',
298
-                        'event_espresso'
299
-                    ),
300
-                    '<strong>' . $this->caller . '</strong>'
301
-                );
302
-                throw new EE_Error(implode('||', $msg));
303
-            }
304
-            foreach ($this->_scripts_styles['registers'] as $ref => $details) {
305
-                $defaults = array(
306
-                    'type'    => 'js',
307
-                    'url'     => '',
308
-                    'depends' => array(),
309
-                    'version' => EVENT_ESPRESSO_VERSION,
310
-                    'footer'  => true,
311
-                );
312
-                $details  = wp_parse_args($details, $defaults);
313
-                extract($details);
314
-                //let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do
315
-                $this->_scripts_styles['registers'][$ref]['type'] = $type;
316
-                //let's make sure we're not missing any REQUIRED parameters
317
-                if (empty($url)) {
318
-                    $msg[] = sprintf(
319
-                        __('Missing the url for the requested %s', 'event_espresso'),
320
-                        $type == 'js' ? 'script' : 'stylesheet'
321
-                    );
322
-                    $msg[] = sprintf(
323
-                        __(
324
-                            'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref',
325
-                            'event_espresso'
326
-                        ),
327
-                        '<strong>' . $this->caller . '</strong>',
328
-                        $ref
329
-                    );
330
-                    throw new EE_Error(implode('||', $msg));
331
-                }
332
-                //made it here so let's do the appropriate registration
333
-                $type == 'js'
334
-                    ? wp_register_script($ref, $url, $depends, $version, $footer)
335
-                    : wp_register_style(
336
-                    $ref,
337
-                    $url,
338
-                    $depends,
339
-                    $version
340
-                );
341
-            }
342
-            //k now lets do the enqueues
343
-            if (! isset($this->_scripts_styles['enqueues'])) {
344
-                return;
345
-            }  //not sure if we should throw an error here or not.
346
-            foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) {
347
-                //make sure $routes is an array
348
-                $routes = (array)$routes;
349
-                if (in_array($this->_current_route, $routes)) {
350
-                    $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref)
351
-                        : wp_enqueue_style($ref);
352
-                    //if we have a localization for the script let's do that too.
353
-                    if (isset($this->_scripts_styles['localize'][$ref])) {
354
-                        foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) {
355
-                            wp_localize_script(
356
-                                $ref,
357
-                                $object_name,
358
-                                $this->_scripts_styles['localize'][$ref][$object_name]
359
-                            );
360
-                        }
361
-                    }
362
-                }
363
-            }
364
-            //let's do the deregisters
365
-            if (! isset($this->_scripts_styles['deregisters'])) {
366
-                return;
367
-            }
368
-            foreach ($this->_scripts_styles['deregisters'] as $ref => $details) {
369
-                $defaults = array(
370
-                    'type' => 'js',
371
-                );
372
-                $details  = wp_parse_args($details, $defaults);
373
-                extract($details);
374
-                $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref);
375
-            }
376
-        }
377
-    }
378
-
379
-
380
-
381
-    /**
382
-     * just set the defaults for the hooks properties.
383
-     *
384
-     * @access private
385
-     * @return void
386
-     */
387
-    private function _set_defaults()
388
-    {
389
-        $this->_ajax_func     = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array();
390
-        $this->_current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
391
-        $this->caller         = get_class($this);
392
-        $this->_extend        = stripos($this->caller, 'Extend') ? true : false;
393
-    }
394
-
395
-
396
-
397
-    /**
398
-     * this sets the _page_object property
399
-     *
400
-     * @access protected
401
-     * @return void
402
-     */
403
-    protected function _set_page_object()
404
-    {
405
-        //first make sure $this->_name is set
406
-        if (empty($this->_name)) {
407
-            $msg[] = __('We can\'t load the page object', 'event_espresso');
408
-            $msg[] = sprintf(
409
-                __("This is because the %s child class has not set the '_name' property", 'event_espresso'),
410
-                $this->caller
411
-            );
412
-            throw new EE_Error(implode('||', $msg));
413
-        }
414
-        $ref = str_replace('_', ' ', $this->_name); //take the_message -> the message
415
-        $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; //take the message -> The_Message
416
-        //first default file (if exists)
417
-        $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php';
418
-        if (is_readable($decaf_file)) {
419
-            require_once($decaf_file);
420
-        }
421
-        //now we have to do require for extended file (if needed)
422
-        if ($this->_extend) {
423
-            require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php');
424
-        }
425
-        //if we've got an extended class we use that!
426
-        $ref = $this->_extend ? 'Extend_' . $ref : $ref;
427
-        //let's make sure the class exists
428
-        if (! class_exists($ref)) {
429
-            $msg[] = __('We can\'t load the page object', 'event_espresso');
430
-            $msg[] = sprintf(
431
-                __(
432
-                    'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class',
433
-                    'event_espresso'
434
-                ),
435
-                $ref
436
-            );
437
-            throw new EE_Error(implode('||', $msg));
438
-        }
439
-        $a                  = new ReflectionClass($ref);
440
-        $this->_page_object = $a->newInstance(false);
441
-    }
442
-
443
-
444
-    /**
445
-     * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded.  The
446
-     * advantage of this is when doing things like running our own db interactions on saves etc.  Remember that
447
-     * $this->_req_data (all the _POST and _GET data) is available to your methods.
448
-     *
449
-     * @access private
450
-     * @return void
451
-     */
452
-    private function _load_custom_methods()
453
-    {
454
-        /**
455
-         * method cannot be named 'default' (@see http://us3.php
456
-         * .net/manual/en/reserved.keywords.php) so need to
457
-         * handle routes that are "default"
458
-         *
459
-         * @since 4.3.0
460
-         */
461
-        $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route;
462
-        //these run before the Admin_Page route executes.
463
-        if (method_exists($this, $method_callback)) {
464
-            call_user_func(array($this, $method_callback));
465
-        }
466
-        //these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes.  There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens.
467
-        //first the actions
468
-        //note that these action hooks will have the $query_args value available.
469
-        $admin_class_name = get_class($this->_adminpage_obj);
470
-        if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) {
471
-            add_action(
472
-                'AHEE__'
473
-                . $admin_class_name
474
-                . '___redirect_after_action__before_redirect_modification_'
475
-                . $this->_current_route,
476
-                array($this, '_redirect_action_early_' . $this->_current_route),
477
-                10
478
-            );
479
-        }
480
-        if (method_exists($this, '_redirect_action_' . $this->_current_route)) {
481
-            add_action(
482
-                'AHEE_redirect_' . $admin_class_name . $this->_current_route,
483
-                array($this, '_redirect_action_' . $this->_current_route),
484
-                10
485
-            );
486
-        }
487
-        //let's hook into the _redirect itself and allow for changing where the user goes after redirect.  This will have $query_args and $redirect_url available.
488
-        if (method_exists($this, '_redirect_filter_' . $this->_current_route)) {
489
-            add_filter(
490
-                'FHEE_redirect_' . $admin_class_name . $this->_current_route,
491
-                array($this, '_redirect_filter_' . $this->_current_route),
492
-                10,
493
-                2
494
-            );
495
-        }
496
-    }
497
-
498
-
499
-
500
-    /**
501
-     * This method will search for a corresponding method with a name matching the route and the wp_hook to run.  This
502
-     * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route.
503
-     * just remember, methods MUST be public Future hooks should be added in here to be access by child classes.
504
-     *
505
-     * @return void
506
-     */
507
-    private function _load_routed_hooks()
508
-    {
509
-
510
-        //this array provides the hook action names that will be referenced.  Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook.  We'll default all priorities for automatic hooks to 10.
511
-        $hook_filter_array = array(
512
-            'admin_footer'                                                                            => array(
513
-                'type'     => 'action',
514
-                'argnum'   => 1,
515
-                'priority' => 10,
516
-            ),
517
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array(
518
-                'type'     => 'filter',
519
-                'argnum'   => 1,
520
-                'priority' => 10,
521
-            ),
522
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug                               => array(
523
-                'type'     => 'filter',
524
-                'argnum'   => 1,
525
-                'priority' => 10,
526
-            ),
527
-            'FHEE_list_table_views'                                                                   => array(
528
-                'type'     => 'filter',
529
-                'argnum'   => 1,
530
-                'priority' => 10,
531
-            ),
532
-            'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'                              => array(
533
-                'type'     => 'action',
534
-                'argnum'   => 1,
535
-                'priority' => 10,
536
-            ),
537
-        );
538
-        foreach ($hook_filter_array as $hook => $args) {
539
-            if (method_exists($this, $this->_current_route . '_' . $hook)) {
540
-                if (isset($this->_wp_action_filters_priority[$hook])) {
541
-                    $args['priority'] = $this->_wp_action_filters_priority[$hook];
542
-                }
543
-                if ($args['type'] == 'action') {
544
-                    add_action(
545
-                        $hook,
546
-                        array($this, $this->_current_route . '_' . $hook),
547
-                        $args['priority'],
548
-                        $args['argnum']
549
-                    );
550
-                } else {
551
-                    add_filter(
552
-                        $hook,
553
-                        array($this, $this->_current_route . '_' . $hook),
554
-                        $args['priority'],
555
-                        $args['argnum']
556
-                    );
557
-                }
558
-            }
559
-        }
560
-    }
561
-
562
-
563
-    /**
564
-     * Loop throught the $_ajax_func array and add_actions for the array.
565
-     *
566
-     * @return void
567
-     */
568
-    private function _ajax_hooks()
569
-    {
570
-
571
-        if (empty($this->_ajax_func)) {
572
-            return;
573
-        } //get out there's nothing to take care of.
574
-        foreach ($this->_ajax_func as $action => $method) {
575
-            //make sure method exists
576
-            if (! method_exists($this, $method)) {
577
-                $msg[] = __(
578
-                             'There is no corresponding method for the hook labeled in the _ajax_func array',
579
-                             'event_espresso'
580
-                         ) . '<br />';
581
-                $msg[] = sprintf(
582
-                    __(
583
-                        'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
584
-                        'event_espresso'
585
-                    ),
586
-                    $method,
587
-                    $this->caller
588
-                );
589
-                throw new EE_Error(implode('||', $msg));
590
-            }
591
-            add_action('wp_ajax_' . $action, array($this, $method));
592
-        }
593
-    }
594
-
595
-
596
-
597
-    /**
598
-     * Loop throught the $_init_func array and add_actions for the array.
599
-     *
600
-     * @return void
601
-     */
602
-    protected function _init_hooks()
603
-    {
604
-        if (empty($this->_init_func)) {
605
-            return;
606
-        } //get out there's nothing to take care of.
607
-        //We need to determine what page_route we are on!
608
-        $current_route = isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
609
-        foreach ($this->_init_func as $route => $method) {
610
-            //make sure method exists
611
-            if (! method_exists($this, $method)) {
612
-                $msg[] = __(
613
-                             'There is no corresponding method for the hook labeled in the _init_func array',
614
-                             'event_espresso'
615
-                         ) . '<br />';
616
-                $msg[] = sprintf(
617
-                    __(
618
-                        'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
619
-                        'event_espresso'
620
-                    ),
621
-                    $method,
622
-                    $this->caller
623
-                );
624
-                throw new EE_Error(implode('||', $msg));
625
-            }
626
-            if ($route == $this->_current_route) {
627
-                add_action('admin_init', array($this, $method));
628
-            }
629
-        }
630
-    }
631
-
632
-
633
-
634
-    /**
635
-     * Loop through the _metaboxes property and add_metaboxes accordingly
636
-     * //todo we could eventually make this a config component class (i.e. new EE_Metabox);
637
-     *
638
-     * @access public
639
-     * @return void
640
-     */
641
-    public function add_metaboxes()
642
-    {
643
-        if (empty($this->_metaboxes)) {
644
-            return;
645
-        } //get out we don't have any metaboxes to set for this connection
646
-        $this->_handle_metabox_array($this->_metaboxes);
647
-    }
648
-
649
-
650
-
651
-    private function _handle_metabox_array($boxes, $add = true)
652
-    {
653
-
654
-        foreach ($boxes as $box) {
655
-            if (! isset($box['page_route'])) {
656
-                continue;
657
-            } //we dont' have a valid array
658
-            //let's make sure $box['page_route'] is an array so the "foreach" will work.
659
-            $box['page_route'] = (array)$box['page_route'];
660
-            foreach ($box['page_route'] as $route) {
661
-                if ($route != $this->_current_route) {
662
-                    continue;
663
-                } //get out we only add metaboxes for set route.
664
-                if ($add) {
665
-                    $this->_add_metabox($box);
666
-                } else {
667
-                    $this->_remove_metabox($box);
668
-                }
669
-            }
670
-        }
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     * Loop through the _remove_metaboxes property and remove metaboxes accordingly.
677
-     *
678
-     * @access public
679
-     * @return void
680
-     */
681
-    public function remove_metaboxes()
682
-    {
683
-
684
-        if (empty($this->_remove_metaboxes)) {
685
-            return;
686
-        } //get out there are no metaboxes to remove
687
-        $this->_handle_metabox_array($this->_remove_metaboxes, false);
688
-    }
689
-
690
-
691
-    /**
692
-     * This just handles adding a metabox
693
-     *
694
-     * @access private
695
-     * @param array $args an array of args that have been set for this metabox by the child class
696
-     */
697
-    private function _add_metabox($args)
698
-    {
699
-        $current_screen = get_current_screen();
700
-        $screen_id      = is_object($current_screen) ? $current_screen->id : null;
701
-        $func           = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
702
-        //set defaults
703
-        $defaults = array(
704
-            'func'          => $func,
705
-            'id'            => $this->caller . '_' . $func . '_metabox',
706
-            'priority'      => 'default',
707
-            'label'         => $this->caller,
708
-            'context'       => 'advanced',
709
-            'callback_args' => array(),
710
-            'page'          => isset($args['page']) ? $args['page'] : $screen_id,
711
-        );
712
-        $args = wp_parse_args($args, $defaults);
713
-        extract($args);
714
-        //make sure method exists
715
-        if (! method_exists($this, $func)) {
716
-            $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />';
717
-            $msg[] = sprintf(
718
-                __(
719
-                    'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
720
-                    'event_espresso'
721
-                ),
722
-                $func,
723
-                $this->caller
724
-            );
725
-            throw new EE_Error(implode('||', $msg));
726
-        }
727
-        //everything checks out so lets add the metabox
728
-        add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args);
729
-    }
730
-
731
-
732
-
733
-    private function _remove_metabox($args)
734
-    {
735
-        $current_screen = get_current_screen();
736
-        $screen_id      = is_object($current_screen) ? $current_screen->id : null;
737
-        $func           = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
738
-        //set defaults
739
-        $defaults = array(
740
-            'id'      => isset($args['id'])
741
-                ? $args['id']
742
-                : $this->_current_route
743
-                  . '_'
744
-                  . $this->caller
745
-                  . '_'
746
-                  . $func
747
-                  . '_metabox',
748
-            'context' => 'default',
749
-            'screen'  => isset($args['screen']) ? $args['screen'] : $screen_id
750
-        );
751
-        $args = wp_parse_args($args, $defaults);
752
-        extract($args);
753
-        //everything checks out so lets remove the box!
754
-        remove_meta_box($id, $screen, $context);
755
-    }
31
+	/**
32
+	 * we're just going to use this to hold the name of the caller class (child class name)
33
+	 *
34
+	 * @var string
35
+	 */
36
+	public $caller;
37
+
38
+
39
+
40
+	/**
41
+	 * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e.
42
+	 * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks).  This flag is
43
+	 * used later to make sure we require the needed files.
44
+	 *
45
+	 * @var bool
46
+	 */
47
+	protected $_extend;
48
+
49
+
50
+
51
+	/**
52
+	 * child classes MUST set this property so that the page object can be loaded correctly
53
+	 *
54
+	 * @var string
55
+	 */
56
+	protected $_name;
57
+
58
+
59
+
60
+	/**
61
+	 * This is set by child classes and is an associative array of ajax hooks in the format:
62
+	 * array(
63
+	 *    'ajax_action_ref' => 'executing_method'; //must be public
64
+	 * )
65
+	 *
66
+	 * @var array
67
+	 */
68
+	protected $_ajax_func;
69
+
70
+
71
+	/**
72
+	 * This is an array of methods that get executed on a page routes admin_init hook. Use the following format:
73
+	 * array(
74
+	 *    'page_route' => 'executing_method' //must be public
75
+	 * )
76
+	 *
77
+	 * @var array
78
+	 */
79
+	protected $_init_func;
80
+
81
+
82
+
83
+	/**
84
+	 * This is an array of methods that output metabox content for the given page route.  Use the following format:
85
+	 * array(
86
+	 *    0 => array(
87
+	 *        'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected
88
+	 *        with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox
89
+	 *        will be added to each route.
90
+	 *        'func' =>  'executing_method',  //must be public (i.e. public function executing_method($post,
91
+	 *        $callback_args){} ).  Note if you include callback args in the array then you need to declare them in the
92
+	 *        method arguments.
93
+	 *        'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it
94
+	 *        automatically)
95
+	 *        'priority' => 'default', //default 'default' (optional)
96
+	 *        'label' => __('Localized Title', 'event_espresso'),
97
+	 *        'context' => 'advanced' //advanced is default (optional),
98
+	 *    'callback_args' => array() //any callback args to include (optional)
99
+	 * )
100
+	 * Why are we indexing numerically?  Because it's possible there may be more than one metabox per page_route.
101
+	 *
102
+	 * @var array
103
+	 */
104
+	protected $_metaboxes;
105
+
106
+
107
+
108
+	/**
109
+	 * This is an array of values that indicate any metaboxes we want removed from a given page route.  Usually this is
110
+	 * used when caffeinated functionality is replacing decaffeinated functionality.  Use the following format for the
111
+	 * array: array(
112
+	 *    0 => array(
113
+	 *        'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s)
114
+	 *        that are in the class being connected with (i.e. 'edit', or 'create_new').
115
+	 *        'id' => 'identifier_for_metabox', //what the id is of the metabox being removed
116
+	 *        'context' => 'normal', //the context for the metabox being removed (has to match)
117
+	 *        'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox
118
+	 *        using the currently loaded screen object->id  however, there may be cases where you have to specify the
119
+	 *        id for the screen the metabox is on.
120
+	 *    )
121
+	 * )
122
+	 *
123
+	 * @var array
124
+	 */
125
+	protected $_remove_metaboxes;
126
+
127
+
128
+
129
+	/**
130
+	 * This parent class takes care of loading the scripts and styles if the child class has set the properties for
131
+	 * them in the following format.  Note, the first array index ('register') is for defining all the registers.  The
132
+	 * second array index is for indicating what routes each script/style loads on. array(
133
+	 * 'registers' => array(
134
+	 *        'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency'
135
+	 *        argument to link scripts together.
136
+	 *            'type' => 'js' // 'js' or 'css' (defaults to js).  This tells us what type of wp_function to use
137
+	 *            'url' => 'http://urltoscript.css.js',
138
+	 *            'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has
139
+	 *            already been registered elsewhere in the system.  You can just use the depends array to make sure it
140
+	 *            gets loaded before the one you are setting here.
141
+	 *            'footer' => TRUE //defaults to true (styles don't use this parameter)
142
+	 *        ),
143
+	 *    'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes
144
+	 *    the script gets enqueued on.
145
+	 *        'script_ref' => array('route_one', 'route_two')
146
+	 *    ),
147
+	 *    'localize' => array( //this allows you to set a localize object.  Indicate which script the object is being
148
+	 *    attached to and then include an array indexed by the name of the object and the array of key/value pairs for
149
+	 *    the object.
150
+	 *        'scrip_ref' => array(
151
+	 *            'NAME_OF_JS_OBJECT' => array(
152
+	 *                'translate_ref' => __('localized_string', 'event_espresso'),
153
+	 *                'some_data' => 5
154
+	 *            )
155
+	 *        )
156
+	 *    )
157
+	 * )
158
+	 *
159
+	 * @var array
160
+	 */
161
+	protected $_scripts_styles;
162
+
163
+
164
+	/**
165
+	 * This is a property that will contain the current route.
166
+	 *
167
+	 * @var string;
168
+	 */
169
+	protected $_current_route;
170
+
171
+
172
+
173
+	/**
174
+	 * this optional property can be set by child classes to override the priority for the automatic action/filter hook
175
+	 * loading in the `_load_routed_hooks()` method.  Please follow this format: array(
176
+	 *    'wp_hook_reference' => 1
177
+	 *    )
178
+	 * )
179
+	 *
180
+	 * @var array
181
+	 */
182
+	protected $_wp_action_filters_priority;
183
+
184
+
185
+
186
+	/**
187
+	 * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST
188
+	 *
189
+	 * @var array
190
+	 */
191
+	protected $_req_data;
192
+
193
+
194
+
195
+	/**
196
+	 * This just holds an instance of the page object for this hook
197
+	 *
198
+	 * @var EE_Admin_Page
199
+	 */
200
+	protected $_page_object;
201
+
202
+
203
+
204
+	/**
205
+	 * This holds the EE_Admin_Page object from the calling admin page that this object hooks into.
206
+	 *
207
+	 * @var EE_Admin_Page|EE_Admin_Page_CPT
208
+	 */
209
+	protected $_adminpage_obj;
210
+
211
+
212
+
213
+	/**
214
+	 * Holds EE_Registry object
215
+	 *
216
+	 * @var EE_Registry
217
+	 */
218
+	protected $EE = null;
219
+
220
+
221
+
222
+	/**
223
+	 * constructor
224
+	 *
225
+	 * @param EE_Admin_Page $admin_page the calling admin_page_object
226
+	 */
227
+	public function __construct(EE_Admin_Page $adminpage)
228
+	{
229
+
230
+		$this->_adminpage_obj = $adminpage;
231
+		$this->_req_data      = array_merge($_GET, $_POST);
232
+		$this->_set_defaults();
233
+		$this->_set_hooks_properties();
234
+		//first let's verify we're on the right page
235
+		if (! isset($this->_req_data['page'])
236
+			|| (isset($this->_req_data['page'])
237
+				&& $this->_adminpage_obj->page_slug
238
+				   != $this->_req_data['page'])) {
239
+			return;
240
+		} //get out nothing more to be done here.
241
+		//allow for extends to modify properties
242
+		if (method_exists($this, '_extend_properties')) {
243
+			$this->_extend_properties();
244
+		}
245
+		$this->_set_page_object();
246
+		$this->_init_hooks();
247
+		$this->_load_custom_methods();
248
+		$this->_load_routed_hooks();
249
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
250
+		add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20);
251
+		add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15);
252
+		$this->_ajax_hooks();
253
+	}
254
+
255
+
256
+
257
+	/**
258
+	 * used by child classes to set the following properties:
259
+	 * $_ajax_func (optional)
260
+	 * $_init_func (optional)
261
+	 * $_metaboxes (optional)
262
+	 * $_scripts (optional)
263
+	 * $_styles (optional)
264
+	 * $_name (required)
265
+	 * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the
266
+	 * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen
267
+	 * really early on page load (just after admin_init) if they want to have them registered for handling early.
268
+	 *
269
+	 * @access protected
270
+	 * @abstract
271
+	 * @return void
272
+	 */
273
+	abstract protected function _set_hooks_properties();
274
+
275
+
276
+
277
+	/**
278
+	 * The hooks for enqueue_scripts and enqueue_styles will be run in here.  Child classes need to define their
279
+	 * scripts and styles in the relevant $_scripts and $_styles properties.  Child classes must have also already
280
+	 * registered the scripts and styles using wp_register_script and wp_register_style functions.
281
+	 *
282
+	 * @access public
283
+	 * @return void
284
+	 */
285
+	public function enqueue_scripts_styles()
286
+	{
287
+
288
+		if (! empty($this->_scripts_styles)) {
289
+			//first let's do all the registrations
290
+			if (! isset($this->_scripts_styles['registers'])) {
291
+				$msg[] = __(
292
+					'There is no "registers" index in the <code>$this->_scripts_styles</code> property.',
293
+					'event_espresso'
294
+				);
295
+				$msg[] = sprintf(
296
+					__(
297
+						'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child',
298
+						'event_espresso'
299
+					),
300
+					'<strong>' . $this->caller . '</strong>'
301
+				);
302
+				throw new EE_Error(implode('||', $msg));
303
+			}
304
+			foreach ($this->_scripts_styles['registers'] as $ref => $details) {
305
+				$defaults = array(
306
+					'type'    => 'js',
307
+					'url'     => '',
308
+					'depends' => array(),
309
+					'version' => EVENT_ESPRESSO_VERSION,
310
+					'footer'  => true,
311
+				);
312
+				$details  = wp_parse_args($details, $defaults);
313
+				extract($details);
314
+				//let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do
315
+				$this->_scripts_styles['registers'][$ref]['type'] = $type;
316
+				//let's make sure we're not missing any REQUIRED parameters
317
+				if (empty($url)) {
318
+					$msg[] = sprintf(
319
+						__('Missing the url for the requested %s', 'event_espresso'),
320
+						$type == 'js' ? 'script' : 'stylesheet'
321
+					);
322
+					$msg[] = sprintf(
323
+						__(
324
+							'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref',
325
+							'event_espresso'
326
+						),
327
+						'<strong>' . $this->caller . '</strong>',
328
+						$ref
329
+					);
330
+					throw new EE_Error(implode('||', $msg));
331
+				}
332
+				//made it here so let's do the appropriate registration
333
+				$type == 'js'
334
+					? wp_register_script($ref, $url, $depends, $version, $footer)
335
+					: wp_register_style(
336
+					$ref,
337
+					$url,
338
+					$depends,
339
+					$version
340
+				);
341
+			}
342
+			//k now lets do the enqueues
343
+			if (! isset($this->_scripts_styles['enqueues'])) {
344
+				return;
345
+			}  //not sure if we should throw an error here or not.
346
+			foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) {
347
+				//make sure $routes is an array
348
+				$routes = (array)$routes;
349
+				if (in_array($this->_current_route, $routes)) {
350
+					$this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref)
351
+						: wp_enqueue_style($ref);
352
+					//if we have a localization for the script let's do that too.
353
+					if (isset($this->_scripts_styles['localize'][$ref])) {
354
+						foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) {
355
+							wp_localize_script(
356
+								$ref,
357
+								$object_name,
358
+								$this->_scripts_styles['localize'][$ref][$object_name]
359
+							);
360
+						}
361
+					}
362
+				}
363
+			}
364
+			//let's do the deregisters
365
+			if (! isset($this->_scripts_styles['deregisters'])) {
366
+				return;
367
+			}
368
+			foreach ($this->_scripts_styles['deregisters'] as $ref => $details) {
369
+				$defaults = array(
370
+					'type' => 'js',
371
+				);
372
+				$details  = wp_parse_args($details, $defaults);
373
+				extract($details);
374
+				$type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref);
375
+			}
376
+		}
377
+	}
378
+
379
+
380
+
381
+	/**
382
+	 * just set the defaults for the hooks properties.
383
+	 *
384
+	 * @access private
385
+	 * @return void
386
+	 */
387
+	private function _set_defaults()
388
+	{
389
+		$this->_ajax_func     = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array();
390
+		$this->_current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
391
+		$this->caller         = get_class($this);
392
+		$this->_extend        = stripos($this->caller, 'Extend') ? true : false;
393
+	}
394
+
395
+
396
+
397
+	/**
398
+	 * this sets the _page_object property
399
+	 *
400
+	 * @access protected
401
+	 * @return void
402
+	 */
403
+	protected function _set_page_object()
404
+	{
405
+		//first make sure $this->_name is set
406
+		if (empty($this->_name)) {
407
+			$msg[] = __('We can\'t load the page object', 'event_espresso');
408
+			$msg[] = sprintf(
409
+				__("This is because the %s child class has not set the '_name' property", 'event_espresso'),
410
+				$this->caller
411
+			);
412
+			throw new EE_Error(implode('||', $msg));
413
+		}
414
+		$ref = str_replace('_', ' ', $this->_name); //take the_message -> the message
415
+		$ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; //take the message -> The_Message
416
+		//first default file (if exists)
417
+		$decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php';
418
+		if (is_readable($decaf_file)) {
419
+			require_once($decaf_file);
420
+		}
421
+		//now we have to do require for extended file (if needed)
422
+		if ($this->_extend) {
423
+			require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php');
424
+		}
425
+		//if we've got an extended class we use that!
426
+		$ref = $this->_extend ? 'Extend_' . $ref : $ref;
427
+		//let's make sure the class exists
428
+		if (! class_exists($ref)) {
429
+			$msg[] = __('We can\'t load the page object', 'event_espresso');
430
+			$msg[] = sprintf(
431
+				__(
432
+					'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class',
433
+					'event_espresso'
434
+				),
435
+				$ref
436
+			);
437
+			throw new EE_Error(implode('||', $msg));
438
+		}
439
+		$a                  = new ReflectionClass($ref);
440
+		$this->_page_object = $a->newInstance(false);
441
+	}
442
+
443
+
444
+	/**
445
+	 * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded.  The
446
+	 * advantage of this is when doing things like running our own db interactions on saves etc.  Remember that
447
+	 * $this->_req_data (all the _POST and _GET data) is available to your methods.
448
+	 *
449
+	 * @access private
450
+	 * @return void
451
+	 */
452
+	private function _load_custom_methods()
453
+	{
454
+		/**
455
+		 * method cannot be named 'default' (@see http://us3.php
456
+		 * .net/manual/en/reserved.keywords.php) so need to
457
+		 * handle routes that are "default"
458
+		 *
459
+		 * @since 4.3.0
460
+		 */
461
+		$method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route;
462
+		//these run before the Admin_Page route executes.
463
+		if (method_exists($this, $method_callback)) {
464
+			call_user_func(array($this, $method_callback));
465
+		}
466
+		//these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes.  There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens.
467
+		//first the actions
468
+		//note that these action hooks will have the $query_args value available.
469
+		$admin_class_name = get_class($this->_adminpage_obj);
470
+		if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) {
471
+			add_action(
472
+				'AHEE__'
473
+				. $admin_class_name
474
+				. '___redirect_after_action__before_redirect_modification_'
475
+				. $this->_current_route,
476
+				array($this, '_redirect_action_early_' . $this->_current_route),
477
+				10
478
+			);
479
+		}
480
+		if (method_exists($this, '_redirect_action_' . $this->_current_route)) {
481
+			add_action(
482
+				'AHEE_redirect_' . $admin_class_name . $this->_current_route,
483
+				array($this, '_redirect_action_' . $this->_current_route),
484
+				10
485
+			);
486
+		}
487
+		//let's hook into the _redirect itself and allow for changing where the user goes after redirect.  This will have $query_args and $redirect_url available.
488
+		if (method_exists($this, '_redirect_filter_' . $this->_current_route)) {
489
+			add_filter(
490
+				'FHEE_redirect_' . $admin_class_name . $this->_current_route,
491
+				array($this, '_redirect_filter_' . $this->_current_route),
492
+				10,
493
+				2
494
+			);
495
+		}
496
+	}
497
+
498
+
499
+
500
+	/**
501
+	 * This method will search for a corresponding method with a name matching the route and the wp_hook to run.  This
502
+	 * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route.
503
+	 * just remember, methods MUST be public Future hooks should be added in here to be access by child classes.
504
+	 *
505
+	 * @return void
506
+	 */
507
+	private function _load_routed_hooks()
508
+	{
509
+
510
+		//this array provides the hook action names that will be referenced.  Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook.  We'll default all priorities for automatic hooks to 10.
511
+		$hook_filter_array = array(
512
+			'admin_footer'                                                                            => array(
513
+				'type'     => 'action',
514
+				'argnum'   => 1,
515
+				'priority' => 10,
516
+			),
517
+			'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array(
518
+				'type'     => 'filter',
519
+				'argnum'   => 1,
520
+				'priority' => 10,
521
+			),
522
+			'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug                               => array(
523
+				'type'     => 'filter',
524
+				'argnum'   => 1,
525
+				'priority' => 10,
526
+			),
527
+			'FHEE_list_table_views'                                                                   => array(
528
+				'type'     => 'filter',
529
+				'argnum'   => 1,
530
+				'priority' => 10,
531
+			),
532
+			'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'                              => array(
533
+				'type'     => 'action',
534
+				'argnum'   => 1,
535
+				'priority' => 10,
536
+			),
537
+		);
538
+		foreach ($hook_filter_array as $hook => $args) {
539
+			if (method_exists($this, $this->_current_route . '_' . $hook)) {
540
+				if (isset($this->_wp_action_filters_priority[$hook])) {
541
+					$args['priority'] = $this->_wp_action_filters_priority[$hook];
542
+				}
543
+				if ($args['type'] == 'action') {
544
+					add_action(
545
+						$hook,
546
+						array($this, $this->_current_route . '_' . $hook),
547
+						$args['priority'],
548
+						$args['argnum']
549
+					);
550
+				} else {
551
+					add_filter(
552
+						$hook,
553
+						array($this, $this->_current_route . '_' . $hook),
554
+						$args['priority'],
555
+						$args['argnum']
556
+					);
557
+				}
558
+			}
559
+		}
560
+	}
561
+
562
+
563
+	/**
564
+	 * Loop throught the $_ajax_func array and add_actions for the array.
565
+	 *
566
+	 * @return void
567
+	 */
568
+	private function _ajax_hooks()
569
+	{
570
+
571
+		if (empty($this->_ajax_func)) {
572
+			return;
573
+		} //get out there's nothing to take care of.
574
+		foreach ($this->_ajax_func as $action => $method) {
575
+			//make sure method exists
576
+			if (! method_exists($this, $method)) {
577
+				$msg[] = __(
578
+							 'There is no corresponding method for the hook labeled in the _ajax_func array',
579
+							 'event_espresso'
580
+						 ) . '<br />';
581
+				$msg[] = sprintf(
582
+					__(
583
+						'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
584
+						'event_espresso'
585
+					),
586
+					$method,
587
+					$this->caller
588
+				);
589
+				throw new EE_Error(implode('||', $msg));
590
+			}
591
+			add_action('wp_ajax_' . $action, array($this, $method));
592
+		}
593
+	}
594
+
595
+
596
+
597
+	/**
598
+	 * Loop throught the $_init_func array and add_actions for the array.
599
+	 *
600
+	 * @return void
601
+	 */
602
+	protected function _init_hooks()
603
+	{
604
+		if (empty($this->_init_func)) {
605
+			return;
606
+		} //get out there's nothing to take care of.
607
+		//We need to determine what page_route we are on!
608
+		$current_route = isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
609
+		foreach ($this->_init_func as $route => $method) {
610
+			//make sure method exists
611
+			if (! method_exists($this, $method)) {
612
+				$msg[] = __(
613
+							 'There is no corresponding method for the hook labeled in the _init_func array',
614
+							 'event_espresso'
615
+						 ) . '<br />';
616
+				$msg[] = sprintf(
617
+					__(
618
+						'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
619
+						'event_espresso'
620
+					),
621
+					$method,
622
+					$this->caller
623
+				);
624
+				throw new EE_Error(implode('||', $msg));
625
+			}
626
+			if ($route == $this->_current_route) {
627
+				add_action('admin_init', array($this, $method));
628
+			}
629
+		}
630
+	}
631
+
632
+
633
+
634
+	/**
635
+	 * Loop through the _metaboxes property and add_metaboxes accordingly
636
+	 * //todo we could eventually make this a config component class (i.e. new EE_Metabox);
637
+	 *
638
+	 * @access public
639
+	 * @return void
640
+	 */
641
+	public function add_metaboxes()
642
+	{
643
+		if (empty($this->_metaboxes)) {
644
+			return;
645
+		} //get out we don't have any metaboxes to set for this connection
646
+		$this->_handle_metabox_array($this->_metaboxes);
647
+	}
648
+
649
+
650
+
651
+	private function _handle_metabox_array($boxes, $add = true)
652
+	{
653
+
654
+		foreach ($boxes as $box) {
655
+			if (! isset($box['page_route'])) {
656
+				continue;
657
+			} //we dont' have a valid array
658
+			//let's make sure $box['page_route'] is an array so the "foreach" will work.
659
+			$box['page_route'] = (array)$box['page_route'];
660
+			foreach ($box['page_route'] as $route) {
661
+				if ($route != $this->_current_route) {
662
+					continue;
663
+				} //get out we only add metaboxes for set route.
664
+				if ($add) {
665
+					$this->_add_metabox($box);
666
+				} else {
667
+					$this->_remove_metabox($box);
668
+				}
669
+			}
670
+		}
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 * Loop through the _remove_metaboxes property and remove metaboxes accordingly.
677
+	 *
678
+	 * @access public
679
+	 * @return void
680
+	 */
681
+	public function remove_metaboxes()
682
+	{
683
+
684
+		if (empty($this->_remove_metaboxes)) {
685
+			return;
686
+		} //get out there are no metaboxes to remove
687
+		$this->_handle_metabox_array($this->_remove_metaboxes, false);
688
+	}
689
+
690
+
691
+	/**
692
+	 * This just handles adding a metabox
693
+	 *
694
+	 * @access private
695
+	 * @param array $args an array of args that have been set for this metabox by the child class
696
+	 */
697
+	private function _add_metabox($args)
698
+	{
699
+		$current_screen = get_current_screen();
700
+		$screen_id      = is_object($current_screen) ? $current_screen->id : null;
701
+		$func           = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
702
+		//set defaults
703
+		$defaults = array(
704
+			'func'          => $func,
705
+			'id'            => $this->caller . '_' . $func . '_metabox',
706
+			'priority'      => 'default',
707
+			'label'         => $this->caller,
708
+			'context'       => 'advanced',
709
+			'callback_args' => array(),
710
+			'page'          => isset($args['page']) ? $args['page'] : $screen_id,
711
+		);
712
+		$args = wp_parse_args($args, $defaults);
713
+		extract($args);
714
+		//make sure method exists
715
+		if (! method_exists($this, $func)) {
716
+			$msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />';
717
+			$msg[] = sprintf(
718
+				__(
719
+					'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
720
+					'event_espresso'
721
+				),
722
+				$func,
723
+				$this->caller
724
+			);
725
+			throw new EE_Error(implode('||', $msg));
726
+		}
727
+		//everything checks out so lets add the metabox
728
+		add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args);
729
+	}
730
+
731
+
732
+
733
+	private function _remove_metabox($args)
734
+	{
735
+		$current_screen = get_current_screen();
736
+		$screen_id      = is_object($current_screen) ? $current_screen->id : null;
737
+		$func           = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
738
+		//set defaults
739
+		$defaults = array(
740
+			'id'      => isset($args['id'])
741
+				? $args['id']
742
+				: $this->_current_route
743
+				  . '_'
744
+				  . $this->caller
745
+				  . '_'
746
+				  . $func
747
+				  . '_metabox',
748
+			'context' => 'default',
749
+			'screen'  => isset($args['screen']) ? $args['screen'] : $screen_id
750
+		);
751
+		$args = wp_parse_args($args, $defaults);
752
+		extract($args);
753
+		//everything checks out so lets remove the box!
754
+		remove_meta_box($id, $screen, $context);
755
+	}
756 756
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
         $this->_set_defaults();
233 233
         $this->_set_hooks_properties();
234 234
         //first let's verify we're on the right page
235
-        if (! isset($this->_req_data['page'])
235
+        if ( ! isset($this->_req_data['page'])
236 236
             || (isset($this->_req_data['page'])
237 237
                 && $this->_adminpage_obj->page_slug
238 238
                    != $this->_req_data['page'])) {
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
     public function enqueue_scripts_styles()
286 286
     {
287 287
 
288
-        if (! empty($this->_scripts_styles)) {
288
+        if ( ! empty($this->_scripts_styles)) {
289 289
             //first let's do all the registrations
290
-            if (! isset($this->_scripts_styles['registers'])) {
290
+            if ( ! isset($this->_scripts_styles['registers'])) {
291 291
                 $msg[] = __(
292 292
                     'There is no "registers" index in the <code>$this->_scripts_styles</code> property.',
293 293
                     'event_espresso'
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
                         'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child',
298 298
                         'event_espresso'
299 299
                     ),
300
-                    '<strong>' . $this->caller . '</strong>'
300
+                    '<strong>'.$this->caller.'</strong>'
301 301
                 );
302 302
                 throw new EE_Error(implode('||', $msg));
303 303
             }
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
                     'version' => EVENT_ESPRESSO_VERSION,
310 310
                     'footer'  => true,
311 311
                 );
312
-                $details  = wp_parse_args($details, $defaults);
312
+                $details = wp_parse_args($details, $defaults);
313 313
                 extract($details);
314 314
                 //let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do
315 315
                 $this->_scripts_styles['registers'][$ref]['type'] = $type;
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
                             'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref',
325 325
                             'event_espresso'
326 326
                         ),
327
-                        '<strong>' . $this->caller . '</strong>',
327
+                        '<strong>'.$this->caller.'</strong>',
328 328
                         $ref
329 329
                     );
330 330
                     throw new EE_Error(implode('||', $msg));
@@ -340,12 +340,12 @@  discard block
 block discarded – undo
340 340
                 );
341 341
             }
342 342
             //k now lets do the enqueues
343
-            if (! isset($this->_scripts_styles['enqueues'])) {
343
+            if ( ! isset($this->_scripts_styles['enqueues'])) {
344 344
                 return;
345 345
             }  //not sure if we should throw an error here or not.
346 346
             foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) {
347 347
                 //make sure $routes is an array
348
-                $routes = (array)$routes;
348
+                $routes = (array) $routes;
349 349
                 if (in_array($this->_current_route, $routes)) {
350 350
                     $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref)
351 351
                         : wp_enqueue_style($ref);
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
                 }
363 363
             }
364 364
             //let's do the deregisters
365
-            if (! isset($this->_scripts_styles['deregisters'])) {
365
+            if ( ! isset($this->_scripts_styles['deregisters'])) {
366 366
                 return;
367 367
             }
368 368
             foreach ($this->_scripts_styles['deregisters'] as $ref => $details) {
@@ -412,20 +412,20 @@  discard block
 block discarded – undo
412 412
             throw new EE_Error(implode('||', $msg));
413 413
         }
414 414
         $ref = str_replace('_', ' ', $this->_name); //take the_message -> the message
415
-        $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; //take the message -> The_Message
415
+        $ref = str_replace(' ', '_', ucwords($ref)).'_Admin_Page'; //take the message -> The_Message
416 416
         //first default file (if exists)
417
-        $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php';
417
+        $decaf_file = EE_ADMIN_PAGES.$this->_name.DS.$ref.'.core.php';
418 418
         if (is_readable($decaf_file)) {
419 419
             require_once($decaf_file);
420 420
         }
421 421
         //now we have to do require for extended file (if needed)
422 422
         if ($this->_extend) {
423
-            require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php');
423
+            require_once(EE_CORE_CAF_ADMIN_EXTEND.$this->_name.DS.'Extend_'.$ref.'.core.php');
424 424
         }
425 425
         //if we've got an extended class we use that!
426
-        $ref = $this->_extend ? 'Extend_' . $ref : $ref;
426
+        $ref = $this->_extend ? 'Extend_'.$ref : $ref;
427 427
         //let's make sure the class exists
428
-        if (! class_exists($ref)) {
428
+        if ( ! class_exists($ref)) {
429 429
             $msg[] = __('We can\'t load the page object', 'event_espresso');
430 430
             $msg[] = sprintf(
431 431
                 __(
@@ -467,28 +467,28 @@  discard block
 block discarded – undo
467 467
         //first the actions
468 468
         //note that these action hooks will have the $query_args value available.
469 469
         $admin_class_name = get_class($this->_adminpage_obj);
470
-        if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) {
470
+        if (method_exists($this, '_redirect_action_early_'.$this->_current_route)) {
471 471
             add_action(
472 472
                 'AHEE__'
473 473
                 . $admin_class_name
474 474
                 . '___redirect_after_action__before_redirect_modification_'
475 475
                 . $this->_current_route,
476
-                array($this, '_redirect_action_early_' . $this->_current_route),
476
+                array($this, '_redirect_action_early_'.$this->_current_route),
477 477
                 10
478 478
             );
479 479
         }
480
-        if (method_exists($this, '_redirect_action_' . $this->_current_route)) {
480
+        if (method_exists($this, '_redirect_action_'.$this->_current_route)) {
481 481
             add_action(
482
-                'AHEE_redirect_' . $admin_class_name . $this->_current_route,
483
-                array($this, '_redirect_action_' . $this->_current_route),
482
+                'AHEE_redirect_'.$admin_class_name.$this->_current_route,
483
+                array($this, '_redirect_action_'.$this->_current_route),
484 484
                 10
485 485
             );
486 486
         }
487 487
         //let's hook into the _redirect itself and allow for changing where the user goes after redirect.  This will have $query_args and $redirect_url available.
488
-        if (method_exists($this, '_redirect_filter_' . $this->_current_route)) {
488
+        if (method_exists($this, '_redirect_filter_'.$this->_current_route)) {
489 489
             add_filter(
490
-                'FHEE_redirect_' . $admin_class_name . $this->_current_route,
491
-                array($this, '_redirect_filter_' . $this->_current_route),
490
+                'FHEE_redirect_'.$admin_class_name.$this->_current_route,
491
+                array($this, '_redirect_filter_'.$this->_current_route),
492 492
                 10,
493 493
                 2
494 494
             );
@@ -514,12 +514,12 @@  discard block
 block discarded – undo
514 514
                 'argnum'   => 1,
515 515
                 'priority' => 10,
516 516
             ),
517
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array(
517
+            'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug.'_'.$this->_current_route => array(
518 518
                 'type'     => 'filter',
519 519
                 'argnum'   => 1,
520 520
                 'priority' => 10,
521 521
             ),
522
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug                               => array(
522
+            'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug                               => array(
523 523
                 'type'     => 'filter',
524 524
                 'argnum'   => 1,
525 525
                 'priority' => 10,
@@ -536,21 +536,21 @@  discard block
 block discarded – undo
536 536
             ),
537 537
         );
538 538
         foreach ($hook_filter_array as $hook => $args) {
539
-            if (method_exists($this, $this->_current_route . '_' . $hook)) {
539
+            if (method_exists($this, $this->_current_route.'_'.$hook)) {
540 540
                 if (isset($this->_wp_action_filters_priority[$hook])) {
541 541
                     $args['priority'] = $this->_wp_action_filters_priority[$hook];
542 542
                 }
543 543
                 if ($args['type'] == 'action') {
544 544
                     add_action(
545 545
                         $hook,
546
-                        array($this, $this->_current_route . '_' . $hook),
546
+                        array($this, $this->_current_route.'_'.$hook),
547 547
                         $args['priority'],
548 548
                         $args['argnum']
549 549
                     );
550 550
                 } else {
551 551
                     add_filter(
552 552
                         $hook,
553
-                        array($this, $this->_current_route . '_' . $hook),
553
+                        array($this, $this->_current_route.'_'.$hook),
554 554
                         $args['priority'],
555 555
                         $args['argnum']
556 556
                     );
@@ -573,11 +573,11 @@  discard block
 block discarded – undo
573 573
         } //get out there's nothing to take care of.
574 574
         foreach ($this->_ajax_func as $action => $method) {
575 575
             //make sure method exists
576
-            if (! method_exists($this, $method)) {
576
+            if ( ! method_exists($this, $method)) {
577 577
                 $msg[] = __(
578 578
                              'There is no corresponding method for the hook labeled in the _ajax_func array',
579 579
                              'event_espresso'
580
-                         ) . '<br />';
580
+                         ).'<br />';
581 581
                 $msg[] = sprintf(
582 582
                     __(
583 583
                         'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
                 );
589 589
                 throw new EE_Error(implode('||', $msg));
590 590
             }
591
-            add_action('wp_ajax_' . $action, array($this, $method));
591
+            add_action('wp_ajax_'.$action, array($this, $method));
592 592
         }
593 593
     }
594 594
 
@@ -608,11 +608,11 @@  discard block
 block discarded – undo
608 608
         $current_route = isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
609 609
         foreach ($this->_init_func as $route => $method) {
610 610
             //make sure method exists
611
-            if (! method_exists($this, $method)) {
611
+            if ( ! method_exists($this, $method)) {
612 612
                 $msg[] = __(
613 613
                              'There is no corresponding method for the hook labeled in the _init_func array',
614 614
                              'event_espresso'
615
-                         ) . '<br />';
615
+                         ).'<br />';
616 616
                 $msg[] = sprintf(
617 617
                     __(
618 618
                         'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
@@ -652,11 +652,11 @@  discard block
 block discarded – undo
652 652
     {
653 653
 
654 654
         foreach ($boxes as $box) {
655
-            if (! isset($box['page_route'])) {
655
+            if ( ! isset($box['page_route'])) {
656 656
                 continue;
657 657
             } //we dont' have a valid array
658 658
             //let's make sure $box['page_route'] is an array so the "foreach" will work.
659
-            $box['page_route'] = (array)$box['page_route'];
659
+            $box['page_route'] = (array) $box['page_route'];
660 660
             foreach ($box['page_route'] as $route) {
661 661
                 if ($route != $this->_current_route) {
662 662
                     continue;
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
         //set defaults
703 703
         $defaults = array(
704 704
             'func'          => $func,
705
-            'id'            => $this->caller . '_' . $func . '_metabox',
705
+            'id'            => $this->caller.'_'.$func.'_metabox',
706 706
             'priority'      => 'default',
707 707
             'label'         => $this->caller,
708 708
             'context'       => 'advanced',
@@ -712,8 +712,8 @@  discard block
 block discarded – undo
712 712
         $args = wp_parse_args($args, $defaults);
713 713
         extract($args);
714 714
         //make sure method exists
715
-        if (! method_exists($this, $func)) {
716
-            $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />';
715
+        if ( ! method_exists($this, $func)) {
716
+            $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso').'<br />';
717 717
             $msg[] = sprintf(
718 718
                 __(
719 719
                     'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Init.core.php 3 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -205,7 +205,6 @@  discard block
 block discarded – undo
205 205
      *
206 206
      * @access  public
207 207
      * @uses    _initialize_admin_page()
208
-     * @param  string $dir_name directory name for specific admin_page being loaded.
209 208
      * @return void
210 209
      */
211 210
     public function initialize_admin_page()
@@ -221,6 +220,9 @@  discard block
 block discarded – undo
221 220
 
222 221
 
223 222
 
223
+    /**
224
+     * @param string $wp_page_slug
225
+     */
224 226
     public function set_page_dependencies($wp_page_slug)
225 227
     {
226 228
         if (! $this->_load_page) {
Please login to merge, or discard this patch.
Indentation   +438 added lines, -438 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -28,443 +28,443 @@  discard block
 block discarded – undo
28 28
 abstract class EE_Admin_Page_Init extends EE_Base
29 29
 {
30 30
 
31
-    //identity properties (set in _set_defaults and _set_init_properties)
32
-    public $label;
33
-
34
-    /**
35
-     * Menu map has a capability.  However, this allows admin pages to have separate capability requirements for menus
36
-     * and accessing pages.  If capability is NOT set, then it defaults to the menu_map capability.
37
-     *
38
-     * @var string
39
-     */
40
-    public $capability;
41
-
42
-
43
-    /**
44
-     * This holds the menu map object for this admin page.
45
-     *
46
-     * @var EE_Admin_Page_Menu_Map
47
-     */
48
-    protected $_menu_map;
49
-
50
-    /**
51
-     * deprecated
52
-     */
53
-    public $menu_label;
54
-    public $menu_slug;
55
-
56
-
57
-
58
-    //set in _set_defaults
59
-    protected $_folder_name;
60
-    protected $_folder_path;
61
-    protected $_file_name;
62
-    public    $hook_file;
63
-    protected $_wp_page_slug;
64
-    protected $_routing;
65
-
66
-
67
-    //will hold page object.
68
-    protected $_loaded_page_object;
69
-
70
-
71
-    //for caf
72
-    protected $_files_hooked;
73
-    protected $_hook_paths;
74
-
75
-    //load_page?
76
-    private $_load_page;
77
-
78
-
79
-
80
-    /**
81
-     * @Constructor
82
-     * @access public
83
-     * @return void
84
-     */
85
-    public function __construct()
86
-    {
87
-        //set global defaults
88
-        $this->_set_defaults();
89
-        //set properties that are always available with objects.
90
-        $this->_set_init_properties();
91
-        //global styles/scripts across all wp admin pages
92
-        add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5);
93
-        //load initial stuff.
94
-        $this->_set_file_and_folder_name();
95
-        $this->_set_menu_map();
96
-        if (empty($this->_menu_map) || is_array($this->_menu_map)) {
97
-            EE_Error::doing_it_wrong(
98
-                get_class($this) . '::$_menu_map',
99
-                sprintf(
100
-                    __(
101
-                        'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core.  Please see Admin_Page_Init class examples in core for the new way of setting this property up.',
102
-                        'event_espresso'
103
-                    ),
104
-                    get_class($this)
105
-                ),
106
-                '4.4.0'
107
-            );
108
-            return;
109
-        }
110
-        //set default capability
111
-        $this->_set_capability();
112
-    }
113
-
114
-
115
-
116
-    /**
117
-     * _set_init_properties
118
-     * Child classes use to set the following properties:
119
-     * $label
120
-     *
121
-     * @abstract
122
-     * @access protected
123
-     * @return void
124
-     */
125
-    abstract protected function _set_init_properties();
126
-
127
-
128
-
129
-    /**
130
-     * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of
131
-     * EE_Admin_Page_Menu_Map.  Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu.
132
-     *
133
-     * @since 4.4.0
134
-     * @ return void.
135
-     */
136
-    protected function _set_menu_map()
137
-    {
138
-        return array();
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * returns the menu map for this admin page
145
-     *
146
-     * @since 4.4.0
147
-     * @return EE_Admin_Page_Menu_Map
148
-     */
149
-    public function get_menu_map()
150
-    {
151
-        return $this->_menu_map;
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * This loads scripts and styles for the EE_Admin system
158
-     * that must be available on ALL WP admin pages (i.e. EE_menu items)
159
-     *
160
-     * @return void
161
-     */
162
-    public function load_wp_global_scripts_styles()
163
-    {
164
-        wp_register_style(
165
-            'espresso_menu',
166
-            EE_ADMIN_URL . 'assets/admin-menu-styles.css',
167
-            array('dashicons'),
168
-            EVENT_ESPRESSO_VERSION
169
-        );
170
-        wp_enqueue_style('espresso_menu');
171
-    }
172
-
173
-
174
-
175
-    /**
176
-     * this sets default properties (might be overridden in _set_init_properties);
177
-     *
178
-     * @access private
179
-     * @return  void
180
-     */
181
-    private function _set_defaults()
182
-    {
183
-        $this->_file_name    = $this->_folder_name = $this->_wp_page_slug = $this->capability = null;
184
-        $this->_routing      = true;
185
-        $this->_load_page    = false;
186
-        $this->_files_hooked = $this->_hook_paths = array();
187
-        //menu_map
188
-        $this->_menu_map = $this->get_menu_map();
189
-    }
190
-
191
-
192
-
193
-    protected function _set_capability()
194
-    {
195
-        $capability       = empty($this->capability) ? $this->_menu_map->capability : $this->capability;
196
-        $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability);
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * initialize_admin_page
203
-     * This method is what executes the loading of the specific page class for the given dir_name as called by the
204
-     * EE_Admin_Init class.
205
-     *
206
-     * @access  public
207
-     * @uses    _initialize_admin_page()
208
-     * @param  string $dir_name directory name for specific admin_page being loaded.
209
-     * @return void
210
-     */
211
-    public function initialize_admin_page()
212
-    {
213
-        //let's check user access first
214
-        $this->_check_user_access();
215
-        if (! is_object($this->_loaded_page_object)) {
216
-            return;
217
-        }
218
-        $this->_loaded_page_object->route_admin_request();
219
-        return;
220
-    }
221
-
222
-
223
-
224
-    public function set_page_dependencies($wp_page_slug)
225
-    {
226
-        if (! $this->_load_page) {
227
-            return;
228
-        }
229
-        if (! is_object($this->_loaded_page_object)) {
230
-            $msg[] = __(
231
-                'We can\'t load the page because we\'re missing a valid page object that tells us what to load',
232
-                'event_espresso'
233
-            );
234
-            $msg[] = $msg[0] . "\r\n" . sprintf(
235
-                    __(
236
-                        'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory',
237
-                        'event_espresso'
238
-                    ),
239
-                    $this->_file_name,
240
-                    $this->_file_name,
241
-                    $this->_folder_path . $this->_file_name,
242
-                    $this->_menu_map->menu_slug
243
-                );
244
-            throw new EE_Error(implode('||', $msg));
245
-        }
246
-        $this->_loaded_page_object->set_wp_page_slug($wp_page_slug);
247
-        $page_hook = 'load-' . $wp_page_slug;
248
-        //hook into page load hook so all page specific stuff get's loaded.
249
-        if (! empty($wp_page_slug)) {
250
-            add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies'));
251
-        }
252
-    }
253
-
254
-
255
-    /**
256
-     * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run
257
-     * before the load-page... hook. Note, the page loads are happening around the wp_init hook.
258
-     *
259
-     * @return void
260
-     */
261
-    public function do_initial_loads()
262
-    {
263
-        //no loading or initializing if menu map is setup incorrectly.
264
-        if (empty($this->_menu_map) || is_array($this->_menu_map)) {
265
-            return;
266
-        }
267
-        $this->_initialize_admin_page();
268
-    }
269
-
270
-
271
-    /**
272
-     * all we're doing here is setting the $_file_name property for later use.
273
-     *
274
-     * @access private
275
-     * @return void
276
-     */
277
-    private function _set_file_and_folder_name()
278
-    {
279
-        $bt = debug_backtrace();
280
-        //for more reliable determination of folder name
281
-        //we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this).  Why?  Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins)
282
-        $class = get_class($this);
283
-        foreach ($bt as $index => $values) {
284
-            if (isset($values['class']) && $values['class'] == $class) {
285
-                $file_index         = $index - 1;
286
-                $this->_folder_name = basename(dirname($bt[$file_index]['file']));
287
-                if (! empty($this->_folder_name)) {
288
-                    break;
289
-                }
290
-            }
291
-        }
292
-        $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS;
293
-        $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name);
294
-        $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name));
295
-        $this->_file_name = str_replace(' ', '_', $this->_file_name);
296
-    }
297
-
298
-
299
-    /**
300
-     * This automatically checks if we have a hook class in the loaded child directory.  If we DO then we will register
301
-     * it with the appropriate pages.  That way all we have to do is make sure the file is named correctly and
302
-     * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do:
303
-     * events_Messages_Hooks.class.php
304
-     *
305
-     * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks
306
-     *                     files/classes
307
-     * @return array
308
-     */
309
-    public function register_hooks($extend = false)
310
-    {
311
-
312
-        //get a list of files in the directory that have the "Hook" in their name an
313
-        //if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property.  Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf.
314
-        if ($extend) {
315
-            $hook_files_glob_path = apply_filters(
316
-                'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend',
317
-                EE_CORE_CAF_ADMIN_EXTEND
318
-                . $this->_folder_name
319
-                . DS
320
-                . '*'
321
-                . $this->_file_name
322
-                . '_Hooks_Extend.class.php'
323
-            );
324
-            $this->_hook_paths    = $this->_register_hook_files($hook_files_glob_path, $extend);
325
-        }
326
-        //loop through decaf folders
327
-        $hook_files_glob_path = apply_filters(
328
-            'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path',
329
-            $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php'
330
-        );
331
-        $this->_hook_paths    = array_merge(
332
-            $this->_register_hook_files($hook_files_glob_path),
333
-            $this->_hook_paths
334
-        );  //making sure any extended hook paths are later in the array than the core hook paths!
335
-        return $this->_hook_paths;
336
-    }
337
-
338
-
339
-
340
-    protected function _register_hook_files($hook_files_glob_path, $extend = false)
341
-    {
342
-        $hook_paths = array();
343
-        if ($hook_files = glob($hook_files_glob_path)) {
344
-            if (empty($hook_files)) {
345
-                return array();
346
-            }
347
-            foreach ($hook_files as $file) {
348
-                //lets get the linked admin.
349
-                $hook_file    = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file)
350
-                    : str_replace($this->_folder_path, '', $file);
351
-                $replace      = $extend
352
-                    ? '_' . $this->_file_name . '_Hooks_Extend.class.php'
353
-                    : '_'
354
-                      . $this->_file_name
355
-                      . '_Hooks.class.php';
356
-                $rel_admin    = str_replace($replace, '', $hook_file);
357
-                $rel_admin    = strtolower($rel_admin);
358
-                $hook_paths[] = $file;
359
-                //make sure we haven't already got a hook setup for this page path
360
-                if (in_array($rel_admin, $this->_files_hooked)) {
361
-                    continue;
362
-                }
363
-                $this->hook_file       = $hook_file;
364
-                $rel_admin_hook        = 'FHEE_do_other_page_hooks_' . $rel_admin;
365
-                $filter                = add_filter($rel_admin_hook, array($this, 'load_admin_hook'));
366
-                $this->_files_hooked[] = $rel_admin;
367
-            }
368
-        }
369
-        return $hook_paths;
370
-    }
371
-
372
-
373
-
374
-    public function load_admin_hook($registered_pages)
375
-    {
376
-        $this->hook_file;
377
-        $hook_file = (array)$this->hook_file;
378
-        return array_merge($hook_file, $registered_pages);
379
-    }
380
-
381
-
382
-    /**
383
-     * _initialize_admin_page
384
-     *
385
-     * @see  initialize_admin_page() for info
386
-     */
387
-    protected function _initialize_admin_page()
388
-    {
389
-
390
-        //JUST CHECK WE'RE ON RIGHT PAGE.
391
-        if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) {
392
-            return;
393
-        } //not on the right page so let's get out.
394
-        $this->_load_page = true;
395
-        //let's set page specific autoloaders.  Note that this just sets autoloaders for THIS set of admin pages.
396
-        //		spl_autoload_register(array( $this, 'set_autoloaders') );
397
-        //we don't need to do a page_request check here because it's only called via WP menu system.
398
-        $admin_page  = $this->_file_name . '_Admin_Page';
399
-        $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page;
400
-        $admin_page  = apply_filters(
401
-            "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}",
402
-            $admin_page
403
-        );
404
-        // define requested admin page class name then load the file and instantiate
405
-        $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php');
406
-        $path_to_file = apply_filters(
407
-            "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}",
408
-            $path_to_file
409
-        );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page
410
-        if (is_readable($path_to_file)) {
411
-            // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place
412
-            do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization');
413
-            do_action(
414
-                'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug
415
-            );
416
-            require_once($path_to_file);
417
-            $a                         = new ReflectionClass($admin_page);
418
-            $this->_loaded_page_object = $a->newInstance($this->_routing);
419
-        }
420
-        do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization');
421
-        do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug);
422
-    }
423
-
424
-
425
-
426
-    public function get_admin_page_name()
427
-    {
428
-        return $this->_file_name . '_Admin_Page';
429
-    }
430
-
431
-
432
-
433
-    /**
434
-     * @return mixed
435
-     */
436
-    public function loaded_page_object()
437
-    {
438
-        return $this->_loaded_page_object;
439
-    }
440
-
441
-
442
-
443
-
444
-
445
-    //	public function set_autoloaders( $className ) {
446
-    //		$dir_ref = array(
447
-    //			$this->_folder_path => array('core','class')
448
-    //			);
449
-    //		EEH_Autoloader::try_autoload($dir_ref, $className );
450
-    //	}
451
-    /**
452
-     * _check_user_access
453
-     * verifies user access for this admin page.  If no user access is available then let's gracefully exit with a
454
-     * WordPress die message.
455
-     *
456
-     * @return bool|die true if pass (or admin) wp_die if fail
457
-     */
458
-    private function _check_user_access()
459
-    {
460
-        if (! EE_Registry::instance()->CAP->current_user_can(
461
-            $this->_menu_map->capability,
462
-            $this->_menu_map->menu_slug
463
-        )) {
464
-            wp_die(__('You don\'t have access to this page.'), '', array('back_link' => true));
465
-        }
466
-        return true;
467
-    }
31
+	//identity properties (set in _set_defaults and _set_init_properties)
32
+	public $label;
33
+
34
+	/**
35
+	 * Menu map has a capability.  However, this allows admin pages to have separate capability requirements for menus
36
+	 * and accessing pages.  If capability is NOT set, then it defaults to the menu_map capability.
37
+	 *
38
+	 * @var string
39
+	 */
40
+	public $capability;
41
+
42
+
43
+	/**
44
+	 * This holds the menu map object for this admin page.
45
+	 *
46
+	 * @var EE_Admin_Page_Menu_Map
47
+	 */
48
+	protected $_menu_map;
49
+
50
+	/**
51
+	 * deprecated
52
+	 */
53
+	public $menu_label;
54
+	public $menu_slug;
55
+
56
+
57
+
58
+	//set in _set_defaults
59
+	protected $_folder_name;
60
+	protected $_folder_path;
61
+	protected $_file_name;
62
+	public    $hook_file;
63
+	protected $_wp_page_slug;
64
+	protected $_routing;
65
+
66
+
67
+	//will hold page object.
68
+	protected $_loaded_page_object;
69
+
70
+
71
+	//for caf
72
+	protected $_files_hooked;
73
+	protected $_hook_paths;
74
+
75
+	//load_page?
76
+	private $_load_page;
77
+
78
+
79
+
80
+	/**
81
+	 * @Constructor
82
+	 * @access public
83
+	 * @return void
84
+	 */
85
+	public function __construct()
86
+	{
87
+		//set global defaults
88
+		$this->_set_defaults();
89
+		//set properties that are always available with objects.
90
+		$this->_set_init_properties();
91
+		//global styles/scripts across all wp admin pages
92
+		add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5);
93
+		//load initial stuff.
94
+		$this->_set_file_and_folder_name();
95
+		$this->_set_menu_map();
96
+		if (empty($this->_menu_map) || is_array($this->_menu_map)) {
97
+			EE_Error::doing_it_wrong(
98
+				get_class($this) . '::$_menu_map',
99
+				sprintf(
100
+					__(
101
+						'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core.  Please see Admin_Page_Init class examples in core for the new way of setting this property up.',
102
+						'event_espresso'
103
+					),
104
+					get_class($this)
105
+				),
106
+				'4.4.0'
107
+			);
108
+			return;
109
+		}
110
+		//set default capability
111
+		$this->_set_capability();
112
+	}
113
+
114
+
115
+
116
+	/**
117
+	 * _set_init_properties
118
+	 * Child classes use to set the following properties:
119
+	 * $label
120
+	 *
121
+	 * @abstract
122
+	 * @access protected
123
+	 * @return void
124
+	 */
125
+	abstract protected function _set_init_properties();
126
+
127
+
128
+
129
+	/**
130
+	 * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of
131
+	 * EE_Admin_Page_Menu_Map.  Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu.
132
+	 *
133
+	 * @since 4.4.0
134
+	 * @ return void.
135
+	 */
136
+	protected function _set_menu_map()
137
+	{
138
+		return array();
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * returns the menu map for this admin page
145
+	 *
146
+	 * @since 4.4.0
147
+	 * @return EE_Admin_Page_Menu_Map
148
+	 */
149
+	public function get_menu_map()
150
+	{
151
+		return $this->_menu_map;
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * This loads scripts and styles for the EE_Admin system
158
+	 * that must be available on ALL WP admin pages (i.e. EE_menu items)
159
+	 *
160
+	 * @return void
161
+	 */
162
+	public function load_wp_global_scripts_styles()
163
+	{
164
+		wp_register_style(
165
+			'espresso_menu',
166
+			EE_ADMIN_URL . 'assets/admin-menu-styles.css',
167
+			array('dashicons'),
168
+			EVENT_ESPRESSO_VERSION
169
+		);
170
+		wp_enqueue_style('espresso_menu');
171
+	}
172
+
173
+
174
+
175
+	/**
176
+	 * this sets default properties (might be overridden in _set_init_properties);
177
+	 *
178
+	 * @access private
179
+	 * @return  void
180
+	 */
181
+	private function _set_defaults()
182
+	{
183
+		$this->_file_name    = $this->_folder_name = $this->_wp_page_slug = $this->capability = null;
184
+		$this->_routing      = true;
185
+		$this->_load_page    = false;
186
+		$this->_files_hooked = $this->_hook_paths = array();
187
+		//menu_map
188
+		$this->_menu_map = $this->get_menu_map();
189
+	}
190
+
191
+
192
+
193
+	protected function _set_capability()
194
+	{
195
+		$capability       = empty($this->capability) ? $this->_menu_map->capability : $this->capability;
196
+		$this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability);
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * initialize_admin_page
203
+	 * This method is what executes the loading of the specific page class for the given dir_name as called by the
204
+	 * EE_Admin_Init class.
205
+	 *
206
+	 * @access  public
207
+	 * @uses    _initialize_admin_page()
208
+	 * @param  string $dir_name directory name for specific admin_page being loaded.
209
+	 * @return void
210
+	 */
211
+	public function initialize_admin_page()
212
+	{
213
+		//let's check user access first
214
+		$this->_check_user_access();
215
+		if (! is_object($this->_loaded_page_object)) {
216
+			return;
217
+		}
218
+		$this->_loaded_page_object->route_admin_request();
219
+		return;
220
+	}
221
+
222
+
223
+
224
+	public function set_page_dependencies($wp_page_slug)
225
+	{
226
+		if (! $this->_load_page) {
227
+			return;
228
+		}
229
+		if (! is_object($this->_loaded_page_object)) {
230
+			$msg[] = __(
231
+				'We can\'t load the page because we\'re missing a valid page object that tells us what to load',
232
+				'event_espresso'
233
+			);
234
+			$msg[] = $msg[0] . "\r\n" . sprintf(
235
+					__(
236
+						'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory',
237
+						'event_espresso'
238
+					),
239
+					$this->_file_name,
240
+					$this->_file_name,
241
+					$this->_folder_path . $this->_file_name,
242
+					$this->_menu_map->menu_slug
243
+				);
244
+			throw new EE_Error(implode('||', $msg));
245
+		}
246
+		$this->_loaded_page_object->set_wp_page_slug($wp_page_slug);
247
+		$page_hook = 'load-' . $wp_page_slug;
248
+		//hook into page load hook so all page specific stuff get's loaded.
249
+		if (! empty($wp_page_slug)) {
250
+			add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies'));
251
+		}
252
+	}
253
+
254
+
255
+	/**
256
+	 * This executes the intial page loads for EE_Admin pages to take care of any ajax or other code needing to run
257
+	 * before the load-page... hook. Note, the page loads are happening around the wp_init hook.
258
+	 *
259
+	 * @return void
260
+	 */
261
+	public function do_initial_loads()
262
+	{
263
+		//no loading or initializing if menu map is setup incorrectly.
264
+		if (empty($this->_menu_map) || is_array($this->_menu_map)) {
265
+			return;
266
+		}
267
+		$this->_initialize_admin_page();
268
+	}
269
+
270
+
271
+	/**
272
+	 * all we're doing here is setting the $_file_name property for later use.
273
+	 *
274
+	 * @access private
275
+	 * @return void
276
+	 */
277
+	private function _set_file_and_folder_name()
278
+	{
279
+		$bt = debug_backtrace();
280
+		//for more reliable determination of folder name
281
+		//we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this).  Why?  Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins)
282
+		$class = get_class($this);
283
+		foreach ($bt as $index => $values) {
284
+			if (isset($values['class']) && $values['class'] == $class) {
285
+				$file_index         = $index - 1;
286
+				$this->_folder_name = basename(dirname($bt[$file_index]['file']));
287
+				if (! empty($this->_folder_name)) {
288
+					break;
289
+				}
290
+			}
291
+		}
292
+		$this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS;
293
+		$this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name);
294
+		$this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name));
295
+		$this->_file_name = str_replace(' ', '_', $this->_file_name);
296
+	}
297
+
298
+
299
+	/**
300
+	 * This automatically checks if we have a hook class in the loaded child directory.  If we DO then we will register
301
+	 * it with the appropriate pages.  That way all we have to do is make sure the file is named correctly and
302
+	 * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do:
303
+	 * events_Messages_Hooks.class.php
304
+	 *
305
+	 * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks
306
+	 *                     files/classes
307
+	 * @return array
308
+	 */
309
+	public function register_hooks($extend = false)
310
+	{
311
+
312
+		//get a list of files in the directory that have the "Hook" in their name an
313
+		//if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property.  Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf.
314
+		if ($extend) {
315
+			$hook_files_glob_path = apply_filters(
316
+				'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend',
317
+				EE_CORE_CAF_ADMIN_EXTEND
318
+				. $this->_folder_name
319
+				. DS
320
+				. '*'
321
+				. $this->_file_name
322
+				. '_Hooks_Extend.class.php'
323
+			);
324
+			$this->_hook_paths    = $this->_register_hook_files($hook_files_glob_path, $extend);
325
+		}
326
+		//loop through decaf folders
327
+		$hook_files_glob_path = apply_filters(
328
+			'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path',
329
+			$this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php'
330
+		);
331
+		$this->_hook_paths    = array_merge(
332
+			$this->_register_hook_files($hook_files_glob_path),
333
+			$this->_hook_paths
334
+		);  //making sure any extended hook paths are later in the array than the core hook paths!
335
+		return $this->_hook_paths;
336
+	}
337
+
338
+
339
+
340
+	protected function _register_hook_files($hook_files_glob_path, $extend = false)
341
+	{
342
+		$hook_paths = array();
343
+		if ($hook_files = glob($hook_files_glob_path)) {
344
+			if (empty($hook_files)) {
345
+				return array();
346
+			}
347
+			foreach ($hook_files as $file) {
348
+				//lets get the linked admin.
349
+				$hook_file    = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file)
350
+					: str_replace($this->_folder_path, '', $file);
351
+				$replace      = $extend
352
+					? '_' . $this->_file_name . '_Hooks_Extend.class.php'
353
+					: '_'
354
+					  . $this->_file_name
355
+					  . '_Hooks.class.php';
356
+				$rel_admin    = str_replace($replace, '', $hook_file);
357
+				$rel_admin    = strtolower($rel_admin);
358
+				$hook_paths[] = $file;
359
+				//make sure we haven't already got a hook setup for this page path
360
+				if (in_array($rel_admin, $this->_files_hooked)) {
361
+					continue;
362
+				}
363
+				$this->hook_file       = $hook_file;
364
+				$rel_admin_hook        = 'FHEE_do_other_page_hooks_' . $rel_admin;
365
+				$filter                = add_filter($rel_admin_hook, array($this, 'load_admin_hook'));
366
+				$this->_files_hooked[] = $rel_admin;
367
+			}
368
+		}
369
+		return $hook_paths;
370
+	}
371
+
372
+
373
+
374
+	public function load_admin_hook($registered_pages)
375
+	{
376
+		$this->hook_file;
377
+		$hook_file = (array)$this->hook_file;
378
+		return array_merge($hook_file, $registered_pages);
379
+	}
380
+
381
+
382
+	/**
383
+	 * _initialize_admin_page
384
+	 *
385
+	 * @see  initialize_admin_page() for info
386
+	 */
387
+	protected function _initialize_admin_page()
388
+	{
389
+
390
+		//JUST CHECK WE'RE ON RIGHT PAGE.
391
+		if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) {
392
+			return;
393
+		} //not on the right page so let's get out.
394
+		$this->_load_page = true;
395
+		//let's set page specific autoloaders.  Note that this just sets autoloaders for THIS set of admin pages.
396
+		//		spl_autoload_register(array( $this, 'set_autoloaders') );
397
+		//we don't need to do a page_request check here because it's only called via WP menu system.
398
+		$admin_page  = $this->_file_name . '_Admin_Page';
399
+		$hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page;
400
+		$admin_page  = apply_filters(
401
+			"FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}",
402
+			$admin_page
403
+		);
404
+		// define requested admin page class name then load the file and instantiate
405
+		$path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php');
406
+		$path_to_file = apply_filters(
407
+			"FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}",
408
+			$path_to_file
409
+		);//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page
410
+		if (is_readable($path_to_file)) {
411
+			// This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place
412
+			do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization');
413
+			do_action(
414
+				'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug
415
+			);
416
+			require_once($path_to_file);
417
+			$a                         = new ReflectionClass($admin_page);
418
+			$this->_loaded_page_object = $a->newInstance($this->_routing);
419
+		}
420
+		do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization');
421
+		do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug);
422
+	}
423
+
424
+
425
+
426
+	public function get_admin_page_name()
427
+	{
428
+		return $this->_file_name . '_Admin_Page';
429
+	}
430
+
431
+
432
+
433
+	/**
434
+	 * @return mixed
435
+	 */
436
+	public function loaded_page_object()
437
+	{
438
+		return $this->_loaded_page_object;
439
+	}
440
+
441
+
442
+
443
+
444
+
445
+	//	public function set_autoloaders( $className ) {
446
+	//		$dir_ref = array(
447
+	//			$this->_folder_path => array('core','class')
448
+	//			);
449
+	//		EEH_Autoloader::try_autoload($dir_ref, $className );
450
+	//	}
451
+	/**
452
+	 * _check_user_access
453
+	 * verifies user access for this admin page.  If no user access is available then let's gracefully exit with a
454
+	 * WordPress die message.
455
+	 *
456
+	 * @return bool|die true if pass (or admin) wp_die if fail
457
+	 */
458
+	private function _check_user_access()
459
+	{
460
+		if (! EE_Registry::instance()->CAP->current_user_can(
461
+			$this->_menu_map->capability,
462
+			$this->_menu_map->menu_slug
463
+		)) {
464
+			wp_die(__('You don\'t have access to this page.'), '', array('back_link' => true));
465
+		}
466
+		return true;
467
+	}
468 468
 
469 469
 }
470 470
 // end of file:  includes/core/admin/EE_Admin_Page_Init.core.php
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 /**
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
         $this->_set_menu_map();
96 96
         if (empty($this->_menu_map) || is_array($this->_menu_map)) {
97 97
             EE_Error::doing_it_wrong(
98
-                get_class($this) . '::$_menu_map',
98
+                get_class($this).'::$_menu_map',
99 99
                 sprintf(
100 100
                     __(
101 101
                         'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core.  Please see Admin_Page_Init class examples in core for the new way of setting this property up.',
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
     {
164 164
         wp_register_style(
165 165
             'espresso_menu',
166
-            EE_ADMIN_URL . 'assets/admin-menu-styles.css',
166
+            EE_ADMIN_URL.'assets/admin-menu-styles.css',
167 167
             array('dashicons'),
168 168
             EVENT_ESPRESSO_VERSION
169 169
         );
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
     protected function _set_capability()
194 194
     {
195 195
         $capability       = empty($this->capability) ? $this->_menu_map->capability : $this->capability;
196
-        $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability);
196
+        $this->capability = apply_filters('FHEE_'.$this->_menu_map->menu_slug.'_capability', $capability);
197 197
     }
198 198
 
199 199
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
     {
213 213
         //let's check user access first
214 214
         $this->_check_user_access();
215
-        if (! is_object($this->_loaded_page_object)) {
215
+        if ( ! is_object($this->_loaded_page_object)) {
216 216
             return;
217 217
         }
218 218
         $this->_loaded_page_object->route_admin_request();
@@ -223,30 +223,30 @@  discard block
 block discarded – undo
223 223
 
224 224
     public function set_page_dependencies($wp_page_slug)
225 225
     {
226
-        if (! $this->_load_page) {
226
+        if ( ! $this->_load_page) {
227 227
             return;
228 228
         }
229
-        if (! is_object($this->_loaded_page_object)) {
229
+        if ( ! is_object($this->_loaded_page_object)) {
230 230
             $msg[] = __(
231 231
                 'We can\'t load the page because we\'re missing a valid page object that tells us what to load',
232 232
                 'event_espresso'
233 233
             );
234
-            $msg[] = $msg[0] . "\r\n" . sprintf(
234
+            $msg[] = $msg[0]."\r\n".sprintf(
235 235
                     __(
236 236
                         'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory',
237 237
                         'event_espresso'
238 238
                     ),
239 239
                     $this->_file_name,
240 240
                     $this->_file_name,
241
-                    $this->_folder_path . $this->_file_name,
241
+                    $this->_folder_path.$this->_file_name,
242 242
                     $this->_menu_map->menu_slug
243 243
                 );
244 244
             throw new EE_Error(implode('||', $msg));
245 245
         }
246 246
         $this->_loaded_page_object->set_wp_page_slug($wp_page_slug);
247
-        $page_hook = 'load-' . $wp_page_slug;
247
+        $page_hook = 'load-'.$wp_page_slug;
248 248
         //hook into page load hook so all page specific stuff get's loaded.
249
-        if (! empty($wp_page_slug)) {
249
+        if ( ! empty($wp_page_slug)) {
250 250
             add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies'));
251 251
         }
252 252
     }
@@ -284,12 +284,12 @@  discard block
 block discarded – undo
284 284
             if (isset($values['class']) && $values['class'] == $class) {
285 285
                 $file_index         = $index - 1;
286 286
                 $this->_folder_name = basename(dirname($bt[$file_index]['file']));
287
-                if (! empty($this->_folder_name)) {
287
+                if ( ! empty($this->_folder_name)) {
288 288
                     break;
289 289
                 }
290 290
             }
291 291
         }
292
-        $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . DS;
292
+        $this->_folder_path = EE_ADMIN_PAGES.$this->_folder_name.DS;
293 293
         $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name);
294 294
         $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name));
295 295
         $this->_file_name = str_replace(' ', '_', $this->_file_name);
@@ -321,17 +321,17 @@  discard block
 block discarded – undo
321 321
                 . $this->_file_name
322 322
                 . '_Hooks_Extend.class.php'
323 323
             );
324
-            $this->_hook_paths    = $this->_register_hook_files($hook_files_glob_path, $extend);
324
+            $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend);
325 325
         }
326 326
         //loop through decaf folders
327 327
         $hook_files_glob_path = apply_filters(
328 328
             'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path',
329
-            $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php'
329
+            $this->_folder_path.'*'.$this->_file_name.'_Hooks.class.php'
330 330
         );
331
-        $this->_hook_paths    = array_merge(
331
+        $this->_hook_paths = array_merge(
332 332
             $this->_register_hook_files($hook_files_glob_path),
333 333
             $this->_hook_paths
334
-        );  //making sure any extended hook paths are later in the array than the core hook paths!
334
+        ); //making sure any extended hook paths are later in the array than the core hook paths!
335 335
         return $this->_hook_paths;
336 336
     }
337 337
 
@@ -346,10 +346,10 @@  discard block
 block discarded – undo
346 346
             }
347 347
             foreach ($hook_files as $file) {
348 348
                 //lets get the linked admin.
349
-                $hook_file    = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . DS, '', $file)
349
+                $hook_file    = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND.$this->_folder_name.DS, '', $file)
350 350
                     : str_replace($this->_folder_path, '', $file);
351 351
                 $replace      = $extend
352
-                    ? '_' . $this->_file_name . '_Hooks_Extend.class.php'
352
+                    ? '_'.$this->_file_name.'_Hooks_Extend.class.php'
353 353
                     : '_'
354 354
                       . $this->_file_name
355 355
                       . '_Hooks.class.php';
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
                     continue;
362 362
                 }
363 363
                 $this->hook_file       = $hook_file;
364
-                $rel_admin_hook        = 'FHEE_do_other_page_hooks_' . $rel_admin;
364
+                $rel_admin_hook        = 'FHEE_do_other_page_hooks_'.$rel_admin;
365 365
                 $filter                = add_filter($rel_admin_hook, array($this, 'load_admin_hook'));
366 366
                 $this->_files_hooked[] = $rel_admin;
367 367
             }
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
     public function load_admin_hook($registered_pages)
375 375
     {
376 376
         $this->hook_file;
377
-        $hook_file = (array)$this->hook_file;
377
+        $hook_file = (array) $this->hook_file;
378 378
         return array_merge($hook_file, $registered_pages);
379 379
     }
380 380
 
@@ -388,44 +388,44 @@  discard block
 block discarded – undo
388 388
     {
389 389
 
390 390
         //JUST CHECK WE'RE ON RIGHT PAGE.
391
-        if ((! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) {
391
+        if (( ! isset($_REQUEST['page']) || $_REQUEST['page'] != $this->_menu_map->menu_slug) && $this->_routing) {
392 392
             return;
393 393
         } //not on the right page so let's get out.
394 394
         $this->_load_page = true;
395 395
         //let's set page specific autoloaders.  Note that this just sets autoloaders for THIS set of admin pages.
396 396
         //		spl_autoload_register(array( $this, 'set_autoloaders') );
397 397
         //we don't need to do a page_request check here because it's only called via WP menu system.
398
-        $admin_page  = $this->_file_name . '_Admin_Page';
399
-        $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page;
398
+        $admin_page  = $this->_file_name.'_Admin_Page';
399
+        $hook_suffix = $this->_menu_map->menu_slug.'_'.$admin_page;
400 400
         $admin_page  = apply_filters(
401 401
             "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}",
402 402
             $admin_page
403 403
         );
404 404
         // define requested admin page class name then load the file and instantiate
405
-        $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path . $admin_page . '.core.php');
405
+        $path_to_file = str_replace(array('\\', '/'), DS, $this->_folder_path.$admin_page.'.core.php');
406 406
         $path_to_file = apply_filters(
407 407
             "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}",
408 408
             $path_to_file
409
-        );//so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page
409
+        ); //so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php, the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page
410 410
         if (is_readable($path_to_file)) {
411 411
             // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place
412 412
             do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization');
413 413
             do_action(
414
-                'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug
414
+                'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_'.$this->_menu_map->menu_slug
415 415
             );
416 416
             require_once($path_to_file);
417 417
             $a                         = new ReflectionClass($admin_page);
418 418
             $this->_loaded_page_object = $a->newInstance($this->_routing);
419 419
         }
420 420
         do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization');
421
-        do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug);
421
+        do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_'.$this->_menu_map->menu_slug);
422 422
     }
423 423
 
424 424
 
425 425
 
426 426
     public function get_admin_page_name()
427 427
     {
428
-        return $this->_file_name . '_Admin_Page';
428
+        return $this->_file_name.'_Admin_Page';
429 429
     }
430 430
 
431 431
 
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
      */
458 458
     private function _check_user_access()
459 459
     {
460
-        if (! EE_Registry::instance()->CAP->current_user_can(
460
+        if ( ! EE_Registry::instance()->CAP->current_user_can(
461 461
             $this->_menu_map->capability,
462 462
             $this->_menu_map->menu_slug
463 463
         )) {
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Loader.core.php 2 patches
Indentation   +745 added lines, -745 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -26,750 +26,750 @@  discard block
 block discarded – undo
26 26
 class EE_Admin_Page_Loader
27 27
 {
28 28
 
29
-    /**
30
-     * _installed_pages
31
-     * objects for page_init objects detected and loaded
32
-     *
33
-     * @access private
34
-     * @var \EE_Admin_Page_Init[]
35
-     */
36
-    private $_installed_pages = array();
37
-
38
-
39
-
40
-    /**
41
-     * this is used to hold the registry of menu slugs for all the installed admin pages
42
-     *
43
-     * @var array
44
-     */
45
-    private $_menu_slugs = array();
46
-
47
-
48
-    /**
49
-     * _caffeinated_extends
50
-     * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
51
-     * pieces needed to do so).  This property is defined in the _set_caffeinated method.
52
-     *
53
-     * @var array
54
-     */
55
-    private $_caffeinated_extends = array();
56
-
57
-
58
-
59
-    /**
60
-     * _current_caf_extend_slug
61
-     * This property is used for holding the page slug that is required for referencing the correct
62
-     * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed.
63
-     *
64
-     * @var array
65
-     */
66
-    private $_current_caf_extend_slug;
67
-
68
-
69
-
70
-    /**
71
-     * _caf_autoloader
72
-     * This property is used for holding an array of folder names of any NEW EE_Admin_Pages found in the
73
-     * caffeinated/new directory.  This array is then used to setup a corresponding dynamic autoloader for these pages
74
-     * classes.
75
-     *
76
-     * @var array
77
-     */
78
-    //	private $_caf_autoloader = array();
79
-    /**
80
-     * _prepped_menu_maps
81
-     * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu.
82
-     *
83
-     * @since  4.4.0
84
-     * @var EE_Admin_Page_Menu_Map[]
85
-     */
86
-    private $_prepped_menu_maps = array();
87
-
88
-
89
-
90
-    /**
91
-     * _admin_menu_groups
92
-     * array that holds the group headings and details for
93
-     *
94
-     * @access private
95
-     * @var array
96
-     */
97
-    private $_admin_menu_groups = array();
98
-
99
-
100
-
101
-    /**
102
-     * This property will hold the hook file for setting up the filter that does all the connections between admin
103
-     * pages.
104
-     *
105
-     * @var string
106
-     */
107
-    public $hook_file;
108
-
109
-
110
-
111
-    /**
112
-     * constructor
113
-     *
114
-     * @access public
115
-     * @return \EE_Admin_Page_Loader
116
-     */
117
-    public function __construct()
118
-    {
119
-        //load menu_map classes
120
-        EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core');
121
-        //define the default "groups" for the admin_pages
122
-        $this->_set_menu_groups();
123
-        //let's set default autoloaders.  Note that this just sets autoloaders for root admin files.
124
-        //		spl_autoload_register( array( $this, 'init_autoloaders') );
125
-        //let's do a scan and see what installed pages we have
126
-        $this->_get_installed_pages();
127
-        //set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to).
128
-        add_action('admin_menu', array($this, 'set_menus'));
129
-        add_action('network_admin_menu', array($this, 'set_network_menus'));
130
-    }
131
-
132
-
133
-
134
-    /**
135
-     * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
136
-     * files in the caffeinated folder.
137
-     *
138
-     * @access private
139
-     * @return void
140
-     */
141
-    private function _define_caffeinated_constants()
142
-    {
143
-        if (! defined('EE_CORE_CAF_ADMIN')) {
144
-            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
145
-            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
146
-            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
147
-            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
148
-            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
149
-            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
150
-        }
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * _set_menu_groups
157
-     * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
158
-     *
159
-     * @access private
160
-     * @return void
161
-     */
162
-    private function _set_menu_groups()
163
-    {
164
-
165
-        //set array of EE_Admin_Page_Menu_Group objects
166
-        $groups = array(
167
-            'main'       => new EE_Admin_Page_Menu_Group(
168
-                array(
169
-                    'menu_label'   => __('Main', 'event_espresso'),
170
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::NONE,
171
-                    'menu_slug'    => 'main',
172
-                    'capability'   => 'ee_read_ee',
173
-                    'menu_order'   => 0,
174
-                    'parent_slug'  => 'espresso_events',
175
-                )
176
-            ),
177
-            'management' => new EE_Admin_Page_Menu_Group(
178
-                array(
179
-                    'menu_label'   => __('Management', 'event_espresso'),
180
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
181
-                    'menu_slug'    => 'management',
182
-                    'capability'   => 'ee_read_ee',
183
-                    'menu_order'   => 10,
184
-                    'parent_slug'  => 'espresso_events',
185
-                )
186
-            ),
187
-            'settings'   => new EE_Admin_Page_Menu_Group(
188
-                array(
189
-                    'menu_label'   => __('Settings', 'event_espresso'),
190
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
191
-                    'menu_slug'    => 'settings',
192
-                    'capability'   => 'ee_read_ee',
193
-                    'menu_order'   => 30,
194
-                    'parent_slug'  => 'espresso_events',
195
-                )
196
-            ),
197
-            'templates'  => new EE_Admin_Page_Menu_Group(
198
-                array(
199
-                    'menu_label'   => __('Templates', 'event_espresso'),
200
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
201
-                    'menu_slug'    => 'templates',
202
-                    'capability'   => 'ee_read_ee',
203
-                    'menu_order'   => 40,
204
-                    'parent_slug'  => 'espresso_events',
205
-                )
206
-            ),
207
-            'extras'     => new EE_Admin_Page_Menu_Group(
208
-                array(
209
-                    'menu_label'              => __('Extras', 'event_espresso'),
210
-                    'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
211
-                    'menu_slug'               => 'extras',
212
-                    'capability'              => 'ee_read_ee',
213
-                    'menu_order'              => 50,
214
-                    'parent_slug'             => 'espresso_events',
215
-                    'maintenance_mode_parent' => 'espresso_maintenance_settings',
216
-                )
217
-            ),
218
-            'tools'      => new EE_Admin_Page_Menu_Group(
219
-                array(
220
-                    'menu_label'   => __("Tools", "event_espresso"),
221
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
222
-                    'menu_slug'    => 'tools',
223
-                    'capability'   => 'ee_read_ee',
224
-                    'menu_order'   => 60,
225
-                    'parent_slug'  => 'espresso_events',
226
-                )
227
-            ),
228
-            'addons'     => new EE_Admin_Page_Menu_Group(
229
-                array(
230
-                    'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
231
-                    'menu_label'   => __('Add-ons', 'event_espresso'),
232
-                    'menu_slug'    => 'addons',
233
-                    'capability'   => 'ee_read_ee',
234
-                    'menu_order'   => 20,
235
-                    'parent_slug'  => 'espresso_events',
236
-                )
237
-            ),
238
-        );
239
-        $this->_admin_menu_groups = apply_filters(
240
-            'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
241
-            $groups
242
-        );
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group
249
-     * slug.  The other utility with this function is it validates that all the groups are instances of
250
-     * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons).
251
-     *
252
-     * @since  4.4.0
253
-     * @throws \EE_Error
254
-     * @return EE_Admin_Page_Menu_Group[]
255
-     */
256
-    private function _rearrange_menu_groups()
257
-    {
258
-        $groups = array();
259
-        //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
260
-        usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
261
-        foreach ($this->_admin_menu_groups as $group) {
262
-            if (! $group instanceof EE_Admin_Page_Menu_Group) {
263
-                throw new EE_Error(
264
-                    sprintf(
265
-                        __(
266
-                            'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups.  All values in this array are required to be a EE_Admin_Page_Menu_Group object.  Instead there was: %s',
267
-                            'event_espresso'
268
-                        ),
269
-                        print_r($group, true)
270
-                    )
271
-                );
272
-            }
273
-            $groups[$group->menu_slug] = $group;
274
-        }
275
-        return $groups;
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * _get_installed_pages
282
-     * This just gets the list of installed EE_Admin_pages.
283
-     *
284
-     * @access private
285
-     * @throws EE_Error
286
-     * @return void
287
-     */
288
-    private function _get_installed_pages()
289
-    {
290
-        $installed_refs = array();
291
-        $exclude        = array('assets', 'templates');
292
-        // grab everything in the  admin core directory
293
-        $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
294
-        if ($admin_screens) {
295
-            foreach ($admin_screens as $admin_screen) {
296
-                // files and anything in the exclude array need not apply
297
-                if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
298
-                    // these folders represent the different EE admin pages
299
-                    $installed_refs[basename($admin_screen)] = $admin_screen;
300
-                }
301
-            }
302
-        }
303
-        if (empty($installed_refs)) {
304
-            $error_msg[] = __(
305
-                'There are no EE_Admin pages detected, it looks like EE did not install properly',
306
-                'event_espresso'
307
-            );
308
-            $error_msg[] = $error_msg[0] . "\r\n" . sprintf(
309
-                    __(
310
-                        'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
311
-                        'event_espresso'
312
-                    ),
313
-                    EE_ADMIN_PAGES
314
-                );
315
-            throw new EE_Error(implode('||', $error_msg));
316
-        }
317
-        //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
318
-        $installed_refs = $this->_set_caffeinated($installed_refs);
319
-        //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
320
-        $installed_refs             = apply_filters(
321
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
322
-            $installed_refs
323
-        );
324
-        $this->_caffeinated_extends = apply_filters(
325
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
326
-            $this->_caffeinated_extends
327
-        );
328
-        //loop through admin pages and setup the $_installed_pages array.
329
-        $hooks_ref = array();
330
-        foreach ($installed_refs as $page => $path) {
331
-            // set autoloaders for our admin page classes based on included path information
332
-            EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path);
333
-            // build list of installed pages
334
-            $this->_installed_pages[$page] = $this->_load_admin_page($page, $path);
335
-            // verify returned object
336
-            if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
337
-                if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
338
-                    continue;
339
-                }
340
-                //skip if in full maintenance mode and maintenance_mode_parent is set
341
-                $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent;
342
-                if (empty($maintenance_mode_parent)
343
-                    && EE_Maintenance_Mode::instance()->level()
344
-                       == EE_Maintenance_Mode::level_2_complete_maintenance) {
345
-                    unset($installed_refs[$page]);
346
-                    continue;
347
-                }
348
-                $this->_menu_slugs[$this->_installed_pages[$page]->get_menu_map()->menu_slug] = $page;
349
-                //flag for register hooks on extended pages b/c extended pages use the default INIT.
350
-                $extend = false;
351
-                //now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
352
-                if (isset($this->_caffeinated_extends[$page])) {
353
-                    $this->_current_caf_extend_slug = $page;
354
-                    $path_hook                      = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__'
355
-                                                      . $this->_installed_pages[$page]->get_menu_map()->menu_slug
356
-                                                      . '_'
357
-                                                      . $this->_installed_pages[$page]->get_admin_page_name();
358
-                    $path_runtime                   = 'return "'
359
-                                                      . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["path"]
360
-                                                      . '";';
361
-                    $page_hook                      = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__'
362
-                                                      . $this->_installed_pages[$page]->get_menu_map()->menu_slug
363
-                                                      . '_'
364
-                                                      . $this->_installed_pages[$page]->get_admin_page_name();
365
-                    $page_runtime                   = 'return "'
366
-                                                      . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["admin_page"]
367
-                                                      . '";';
368
-                    $hook_function_path = create_function('$path_to_file', $path_runtime);
369
-                    $hook_function_page = create_function('$admin_page', $page_runtime);
370
-                    add_filter($path_hook, $hook_function_path);
371
-                    add_filter($page_hook, $hook_function_page);
372
-                    $extend = true;
373
-                }
374
-                //let's do the registered hooks
375
-                $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend);
376
-                $hooks_ref      = array_merge($hooks_ref, $extended_hooks);
377
-            }
378
-        }
379
-        //the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder.  So we want to make sure we load the file for the parent.
380
-        //first make sure we've got unique values
381
-        $hooks_ref = array_unique($hooks_ref);
382
-        //now let's loop and require!
383
-        foreach ($hooks_ref as $path) {
384
-            require_once($path);
385
-        }
386
-        //make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested.
387
-        global $ee_menu_slugs;
388
-        $ee_menu_slugs = $this->_menu_slugs;
389
-        //we need to loop again to run any early code
390
-        foreach ($installed_refs as $page => $path) {
391
-            if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
392
-                $this->_installed_pages[$page]->do_initial_loads();
393
-            }
394
-        }
395
-        do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     * get_admin_page_object
402
-     *
403
-     * @param string $page_slug
404
-     * @return EE_Admin_Page
405
-     */
406
-    public function get_admin_page_object($page_slug = '')
407
-    {
408
-        if (isset($this->_installed_pages[$page_slug])) {
409
-            return $this->_installed_pages[$page_slug]->loaded_page_object();
410
-        }
411
-        return null;
412
-    }
413
-
414
-
415
-
416
-    /**
417
-     * _get_classname_for_admin_page
418
-     * generates an "Admin Page" class based on the directory  name
419
-     *
420
-     * @param $dir_name
421
-     * @return string
422
-     */
423
-    private function _get_classname_for_admin_page($dir_name = '')
424
-    {
425
-        $class_name = str_replace('_', ' ', strtolower($dir_name));
426
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
427
-    }
428
-
429
-
430
-
431
-    /**
432
-     * _get_classname_for_admin_init_page
433
-     * generates an "Admin Page Init" class based on the directory  name
434
-     *
435
-     * @param $dir_name
436
-     * @return string
437
-     */
438
-    private function _get_classname_for_admin_init_page($dir_name = '')
439
-    {
440
-        $class_name = str_replace('_', ' ', strtolower($dir_name));
441
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
442
-    }
443
-
444
-
445
-
446
-    /**
447
-     * _load_admin_page
448
-     * Loads and instantiates page_init object for a single EE_admin page.
449
-     *
450
-     * @param  string $page page_reference
451
-     * @param string  $path
452
-     * @throws EE_Error
453
-     * @return object|bool  return page object if valid, bool false if not.
454
-     */
455
-    private function _load_admin_page($page = '', $path = '')
456
-    {
457
-        $class_name = $this->_get_classname_for_admin_init_page($page);
458
-        EE_Registry::instance()->load_file($path, $class_name, 'core');
459
-        if (! class_exists($class_name)) {
460
-            $inner_error_msg = '<br />' . sprintf(
461
-                    esc_html__(
462
-                        'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
463
-                        'event_espresso'
464
-                    ),
465
-                    '<strong>' . $class_name . '</strong>'
466
-                );
467
-            $error_msg[]     = sprintf(
468
-                __('Something went wrong with loading the %s admin page.', 'event_espresso'),
469
-                $page
470
-            );
471
-            $error_msg[]     = $error_msg[0]
472
-                               . "\r\n"
473
-                               . sprintf(
474
-                                   esc_html__(
475
-                                       'There is no Init class in place for the %s admin page.',
476
-                                       'event_espresso'
477
-                                   ),
478
-                                   $page
479
-                               )
480
-                               . $inner_error_msg;
481
-            throw new EE_Error(implode('||', $error_msg));
482
-        }
483
-        $a = new ReflectionClass($class_name);
484
-        return $a->newInstance();
485
-    }
486
-
487
-
488
-
489
-    /**
490
-     * set_menus
491
-     * This method sets up the menus for EE Admin Pages
492
-     *
493
-     * @access private
494
-     * @return void
495
-     */
496
-    public function set_menus()
497
-    {
498
-        //prep the menu pages (sort, group.)
499
-        $this->_prep_pages();
500
-        foreach ($this->_prepped_menu_maps as $menu_map) {
501
-            if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
502
-                $menu_map->add_menu_page(false);
503
-            }
504
-        }
505
-    }
506
-
507
-
508
-    /**
509
-     * set_network_menus
510
-     * This method sets up the menus for network EE Admin Pages.
511
-     * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
512
-     * are only added to the menu map if they are intended for the admin menu
513
-     *
514
-     * @return void
515
-     */
516
-    public function set_network_menus()
517
-    {
518
-        $this->_prep_pages();
519
-        foreach ($this->_prepped_menu_maps as $menu_map) {
520
-            if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
521
-                $menu_map->add_menu_page(true);
522
-            }
523
-        }
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     * _prep_pages
530
-     * sets the _prepped_menu_maps property
531
-     *
532
-     * @access private
533
-     * @throws EE_Error
534
-     * @return void
535
-     */
536
-    private function _prep_pages()
537
-    {
538
-        $pages_array = array();
539
-        //rearrange _admin_menu_groups to be indexed by group slug.
540
-        $menu_groups = $this->_rearrange_menu_groups();
541
-        foreach ($this->_installed_pages as $page) {
542
-            if ($page instanceof EE_Admin_page_Init) {
543
-                $page_map = $page->get_menu_map();
544
-                //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
545
-                if (is_array($page_map) || empty($page_map)) {
546
-                    EE_Error::add_persistent_admin_notice(
547
-                        'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
548
-                        sprintf(
549
-                            __(
550
-                                'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
551
-                                'event_espresso'
552
-                            ),
553
-                            $page->label
554
-                        )
555
-                    );
556
-                    continue;
557
-                }
558
-                //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
559
-                if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
560
-                    throw new EE_Error(
561
-                        sprintf(
562
-                            __(
563
-                                'The menu map for %s must be an EE_Admin_Page_Menu_Map object.  Instead it is %s.  Please double check that the menu map has been configured correctly.',
564
-                                'event_espresso'
565
-                            ),
566
-                            $page->label,
567
-                            $page_map
568
-                        )
569
-                    );
570
-                }
571
-                //use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array.
572
-                if (empty($page_map->maintenance_mode_parent)
573
-                    && EE_Maintenance_Mode::instance()->level()
574
-                       == EE_Maintenance_Mode::level_2_complete_maintenance) {
575
-                    continue;
576
-                }
577
-                //assign to group (remember $page_map has the admin page stored in it).
578
-                $pages_array[$page_map->menu_group][] = $page_map;
579
-            }
580
-        }
581
-        if (empty($pages_array)) {
582
-            throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso'));
583
-        }
584
-        //let's sort the groups, make sure it's a valid group, add header (if to show).
585
-        foreach ($pages_array as $group => $menu_maps) {
586
-            //valid_group?
587
-            if (! array_key_exists($group, $menu_groups)) {
588
-                continue;
589
-            }
590
-            //sort pages.
591
-            usort($menu_maps, array($this, '_sort_menu_maps'));
592
-            //prepend header
593
-            array_unshift($menu_maps, $menu_groups[$group]);
594
-            //reset $pages_array with prepped data
595
-            $pages_array[$group] = $menu_maps;
596
-        }
597
-        //now let's setup the _prepped_menu_maps property
598
-        foreach ($menu_groups as $group => $group_objs) {
599
-            if (isset($pages_array[$group])) {
600
-                $this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]);
601
-            }
602
-        }/**/
603
-    }
604
-
605
-
606
-
607
-    /**
608
-     * This method is the "workhorse" for detecting and setting up caffeinated functionality.
609
-     * In this method there are three checks being done:
610
-     * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $installed_refs
611
-     * array) etc.  (new page sets are found in caffeinated/new/{page})
612
-     * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
613
-     * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
614
-     * Extend_Events_Admin_Page extends Events_Admin_Page.
615
-     * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
616
-     * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
617
-     * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
618
-     * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
619
-     * admin_pages)
620
-     *
621
-     * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be
622
-     *                              loaded.
623
-     * @return array
624
-     */
625
-    private function _set_caffeinated($installed_refs)
626
-    {
627
-
628
-        //first let's check if there IS a caffeinated folder. If there is not then lets get out.
629
-        if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) {
630
-            return $installed_refs;
631
-        }
632
-        $this->_define_caffeinated_constants();
633
-        $exclude = array('tickets');
634
-        //okay let's setup an "New" pages first (we'll return installed refs later)
635
-        $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
636
-        if ($new_admin_screens) {
637
-            foreach ($new_admin_screens as $admin_screen) {
638
-                // files and anything in the exclude array need not apply
639
-                if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
640
-                    // these folders represent the different NEW EE admin pages
641
-                    $installed_refs[basename($admin_screen)] = $admin_screen;
642
-                    // set autoloaders for our admin page classes based on included path information
643
-                    EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen);
644
-                    //					$this->_caf_autoloader[] = array(
645
-                    //						'dir' => 'new',
646
-                    //						'folder' => basename( $admin_screen )
647
-                    //					);
648
-                }
649
-            }
650
-        }
651
-        //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
652
-        $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
653
-        if ($extends) {
654
-            foreach ($extends as $extend) {
655
-                if (is_dir($extend)) {
656
-                    $extend_ref = basename($extend);
657
-                    //now let's make sure there is a file that matches the expected format
658
-                    $filename                                              = str_replace(
659
-                        ' ',
660
-                        '_',
661
-                        ucwords(
662
-                            str_replace(
663
-                                '_',
664
-                                ' ',
665
-                                $extend_ref
666
-                            )
667
-                        )
668
-                    );
669
-                    $filename                                              = 'Extend_' . $filename . '_Admin_Page';
670
-                    $this->_caffeinated_extends[$extend_ref]['path']       = str_replace(
671
-                        array('\\', '/'),
672
-                        DS,
673
-                        EE_CORE_CAF_ADMIN
674
-                        . 'extend'
675
-                        . DS
676
-                        . $extend_ref
677
-                        . DS
678
-                        . $filename
679
-                        . '.core.php'
680
-                    );
681
-                    $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename;
682
-                    // set autoloaders for our admin page classes based on included path information
683
-                    EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend);
684
-                    //					$this->_caf_autoloader[] = array(
685
-                    //						'dir' => 'extend',
686
-                    //						'folder' => $extend_ref
687
-                    //					);
688
-                }
689
-            }
690
-        }
691
-        //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
692
-        $ee_admin_hooks = array();
693
-        $hooks          = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
694
-        if ($hooks) {
695
-            foreach ($hooks as $hook) {
696
-                if (is_readable($hook)) {
697
-                    require_once $hook;
698
-                    $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
699
-                    $classname = str_replace('.class.php', '', $classname);
700
-                    if (class_exists($classname)) {
701
-                        $a                = new ReflectionClass($classname);
702
-                        $ee_admin_hooks[] = $a->newInstance();
703
-                    }
704
-                }
705
-            }
706
-        }/**/
707
-        $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
708
-        return $installed_refs;
709
-    }
710
-
711
-
712
-
713
-
714
-
715
-    /**
716
-     * Initial autoloader registration
717
-     * This just sets up the autoloader for the root admin files
718
-     *
719
-     * @param  string $className incoming classname to check for autoload
720
-     * @return void
721
-     */
722
-    //	public function init_autoloaders( $className ) {
723
-    //		$dir_ref = array(
724
-    //			EE_ADMIN => array('core', 'class')
725
-    //		);
726
-    //		EEH_Autoloader::try_autoload($dir_ref, $className );
727
-    //	}
728
-    /**
729
-     * This method takes care of setting up the autoloader dynamically for any NEW EE_Admin pages found in the
730
-     * caffeinated folders.
731
-     *
732
-     * @access public
733
-     * @param  string $className in coming classname being called
734
-     * @return void
735
-     */
736
-    //	public function caffeinated_autoloaders( $className ) {
737
-    //		//let's setup an array of paths to check (for each subsystem)
738
-    //		$dir_ref = array();
739
-    //		foreach ( $this->_caf_autoloader as $pathinfo) {
740
-    //			$dir_ref[ EE_CORE_CAF_ADMIN . $pathinfo['dir'] . DS . $pathinfo['folder'] . DS] = array('core', 'class');
741
-    //		}
742
-    //
743
-    //		EEH_Autoloader::try_autoload($dir_ref, $className );
744
-    //	}
745
-    /**
746
-     * Utility method for sorting the _menu_maps (callback for usort php function)
747
-     *
748
-     * @since  4.4.0
749
-     * @param  EE_Admin_Page_Menu_Map $a menu_map object
750
-     * @param  EE_Admin_Page_Menu_Map $b being compared to
751
-     * @return int    sort order
752
-     */
753
-    private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b)
754
-    {
755
-        if ($a->menu_order == $b->menu_order) {
756
-            return 0;
757
-        }
758
-        return ($a->menu_order < $b->menu_order) ? -1 : 1;
759
-    }
760
-
761
-
762
-
763
-    /**
764
-     * _default_header_link
765
-     * This is just a dummy method to use with header submenu items
766
-     *
767
-     * @return bool false
768
-     */
769
-    public function _default_header_link()
770
-    {
771
-        return false;
772
-    }
29
+	/**
30
+	 * _installed_pages
31
+	 * objects for page_init objects detected and loaded
32
+	 *
33
+	 * @access private
34
+	 * @var \EE_Admin_Page_Init[]
35
+	 */
36
+	private $_installed_pages = array();
37
+
38
+
39
+
40
+	/**
41
+	 * this is used to hold the registry of menu slugs for all the installed admin pages
42
+	 *
43
+	 * @var array
44
+	 */
45
+	private $_menu_slugs = array();
46
+
47
+
48
+	/**
49
+	 * _caffeinated_extends
50
+	 * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
51
+	 * pieces needed to do so).  This property is defined in the _set_caffeinated method.
52
+	 *
53
+	 * @var array
54
+	 */
55
+	private $_caffeinated_extends = array();
56
+
57
+
58
+
59
+	/**
60
+	 * _current_caf_extend_slug
61
+	 * This property is used for holding the page slug that is required for referencing the correct
62
+	 * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed.
63
+	 *
64
+	 * @var array
65
+	 */
66
+	private $_current_caf_extend_slug;
67
+
68
+
69
+
70
+	/**
71
+	 * _caf_autoloader
72
+	 * This property is used for holding an array of folder names of any NEW EE_Admin_Pages found in the
73
+	 * caffeinated/new directory.  This array is then used to setup a corresponding dynamic autoloader for these pages
74
+	 * classes.
75
+	 *
76
+	 * @var array
77
+	 */
78
+	//	private $_caf_autoloader = array();
79
+	/**
80
+	 * _prepped_menu_maps
81
+	 * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu.
82
+	 *
83
+	 * @since  4.4.0
84
+	 * @var EE_Admin_Page_Menu_Map[]
85
+	 */
86
+	private $_prepped_menu_maps = array();
87
+
88
+
89
+
90
+	/**
91
+	 * _admin_menu_groups
92
+	 * array that holds the group headings and details for
93
+	 *
94
+	 * @access private
95
+	 * @var array
96
+	 */
97
+	private $_admin_menu_groups = array();
98
+
99
+
100
+
101
+	/**
102
+	 * This property will hold the hook file for setting up the filter that does all the connections between admin
103
+	 * pages.
104
+	 *
105
+	 * @var string
106
+	 */
107
+	public $hook_file;
108
+
109
+
110
+
111
+	/**
112
+	 * constructor
113
+	 *
114
+	 * @access public
115
+	 * @return \EE_Admin_Page_Loader
116
+	 */
117
+	public function __construct()
118
+	{
119
+		//load menu_map classes
120
+		EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core');
121
+		//define the default "groups" for the admin_pages
122
+		$this->_set_menu_groups();
123
+		//let's set default autoloaders.  Note that this just sets autoloaders for root admin files.
124
+		//		spl_autoload_register( array( $this, 'init_autoloaders') );
125
+		//let's do a scan and see what installed pages we have
126
+		$this->_get_installed_pages();
127
+		//set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to).
128
+		add_action('admin_menu', array($this, 'set_menus'));
129
+		add_action('network_admin_menu', array($this, 'set_network_menus'));
130
+	}
131
+
132
+
133
+
134
+	/**
135
+	 * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
136
+	 * files in the caffeinated folder.
137
+	 *
138
+	 * @access private
139
+	 * @return void
140
+	 */
141
+	private function _define_caffeinated_constants()
142
+	{
143
+		if (! defined('EE_CORE_CAF_ADMIN')) {
144
+			define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
145
+			define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
146
+			define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
147
+			define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
148
+			define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
149
+			define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
150
+		}
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * _set_menu_groups
157
+	 * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
158
+	 *
159
+	 * @access private
160
+	 * @return void
161
+	 */
162
+	private function _set_menu_groups()
163
+	{
164
+
165
+		//set array of EE_Admin_Page_Menu_Group objects
166
+		$groups = array(
167
+			'main'       => new EE_Admin_Page_Menu_Group(
168
+				array(
169
+					'menu_label'   => __('Main', 'event_espresso'),
170
+					'show_on_menu' => EE_Admin_Page_Menu_Map::NONE,
171
+					'menu_slug'    => 'main',
172
+					'capability'   => 'ee_read_ee',
173
+					'menu_order'   => 0,
174
+					'parent_slug'  => 'espresso_events',
175
+				)
176
+			),
177
+			'management' => new EE_Admin_Page_Menu_Group(
178
+				array(
179
+					'menu_label'   => __('Management', 'event_espresso'),
180
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
181
+					'menu_slug'    => 'management',
182
+					'capability'   => 'ee_read_ee',
183
+					'menu_order'   => 10,
184
+					'parent_slug'  => 'espresso_events',
185
+				)
186
+			),
187
+			'settings'   => new EE_Admin_Page_Menu_Group(
188
+				array(
189
+					'menu_label'   => __('Settings', 'event_espresso'),
190
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
191
+					'menu_slug'    => 'settings',
192
+					'capability'   => 'ee_read_ee',
193
+					'menu_order'   => 30,
194
+					'parent_slug'  => 'espresso_events',
195
+				)
196
+			),
197
+			'templates'  => new EE_Admin_Page_Menu_Group(
198
+				array(
199
+					'menu_label'   => __('Templates', 'event_espresso'),
200
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
201
+					'menu_slug'    => 'templates',
202
+					'capability'   => 'ee_read_ee',
203
+					'menu_order'   => 40,
204
+					'parent_slug'  => 'espresso_events',
205
+				)
206
+			),
207
+			'extras'     => new EE_Admin_Page_Menu_Group(
208
+				array(
209
+					'menu_label'              => __('Extras', 'event_espresso'),
210
+					'show_on_menu'            => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
211
+					'menu_slug'               => 'extras',
212
+					'capability'              => 'ee_read_ee',
213
+					'menu_order'              => 50,
214
+					'parent_slug'             => 'espresso_events',
215
+					'maintenance_mode_parent' => 'espresso_maintenance_settings',
216
+				)
217
+			),
218
+			'tools'      => new EE_Admin_Page_Menu_Group(
219
+				array(
220
+					'menu_label'   => __("Tools", "event_espresso"),
221
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY,
222
+					'menu_slug'    => 'tools',
223
+					'capability'   => 'ee_read_ee',
224
+					'menu_order'   => 60,
225
+					'parent_slug'  => 'espresso_events',
226
+				)
227
+			),
228
+			'addons'     => new EE_Admin_Page_Menu_Group(
229
+				array(
230
+					'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN,
231
+					'menu_label'   => __('Add-ons', 'event_espresso'),
232
+					'menu_slug'    => 'addons',
233
+					'capability'   => 'ee_read_ee',
234
+					'menu_order'   => 20,
235
+					'parent_slug'  => 'espresso_events',
236
+				)
237
+			),
238
+		);
239
+		$this->_admin_menu_groups = apply_filters(
240
+			'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
241
+			$groups
242
+		);
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group
249
+	 * slug.  The other utility with this function is it validates that all the groups are instances of
250
+	 * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons).
251
+	 *
252
+	 * @since  4.4.0
253
+	 * @throws \EE_Error
254
+	 * @return EE_Admin_Page_Menu_Group[]
255
+	 */
256
+	private function _rearrange_menu_groups()
257
+	{
258
+		$groups = array();
259
+		//first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
260
+		usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
261
+		foreach ($this->_admin_menu_groups as $group) {
262
+			if (! $group instanceof EE_Admin_Page_Menu_Group) {
263
+				throw new EE_Error(
264
+					sprintf(
265
+						__(
266
+							'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups.  All values in this array are required to be a EE_Admin_Page_Menu_Group object.  Instead there was: %s',
267
+							'event_espresso'
268
+						),
269
+						print_r($group, true)
270
+					)
271
+				);
272
+			}
273
+			$groups[$group->menu_slug] = $group;
274
+		}
275
+		return $groups;
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * _get_installed_pages
282
+	 * This just gets the list of installed EE_Admin_pages.
283
+	 *
284
+	 * @access private
285
+	 * @throws EE_Error
286
+	 * @return void
287
+	 */
288
+	private function _get_installed_pages()
289
+	{
290
+		$installed_refs = array();
291
+		$exclude        = array('assets', 'templates');
292
+		// grab everything in the  admin core directory
293
+		$admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
294
+		if ($admin_screens) {
295
+			foreach ($admin_screens as $admin_screen) {
296
+				// files and anything in the exclude array need not apply
297
+				if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
298
+					// these folders represent the different EE admin pages
299
+					$installed_refs[basename($admin_screen)] = $admin_screen;
300
+				}
301
+			}
302
+		}
303
+		if (empty($installed_refs)) {
304
+			$error_msg[] = __(
305
+				'There are no EE_Admin pages detected, it looks like EE did not install properly',
306
+				'event_espresso'
307
+			);
308
+			$error_msg[] = $error_msg[0] . "\r\n" . sprintf(
309
+					__(
310
+						'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
311
+						'event_espresso'
312
+					),
313
+					EE_ADMIN_PAGES
314
+				);
315
+			throw new EE_Error(implode('||', $error_msg));
316
+		}
317
+		//this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
318
+		$installed_refs = $this->_set_caffeinated($installed_refs);
319
+		//allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
320
+		$installed_refs             = apply_filters(
321
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
322
+			$installed_refs
323
+		);
324
+		$this->_caffeinated_extends = apply_filters(
325
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
326
+			$this->_caffeinated_extends
327
+		);
328
+		//loop through admin pages and setup the $_installed_pages array.
329
+		$hooks_ref = array();
330
+		foreach ($installed_refs as $page => $path) {
331
+			// set autoloaders for our admin page classes based on included path information
332
+			EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($path);
333
+			// build list of installed pages
334
+			$this->_installed_pages[$page] = $this->_load_admin_page($page, $path);
335
+			// verify returned object
336
+			if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
337
+				if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
338
+					continue;
339
+				}
340
+				//skip if in full maintenance mode and maintenance_mode_parent is set
341
+				$maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent;
342
+				if (empty($maintenance_mode_parent)
343
+					&& EE_Maintenance_Mode::instance()->level()
344
+					   == EE_Maintenance_Mode::level_2_complete_maintenance) {
345
+					unset($installed_refs[$page]);
346
+					continue;
347
+				}
348
+				$this->_menu_slugs[$this->_installed_pages[$page]->get_menu_map()->menu_slug] = $page;
349
+				//flag for register hooks on extended pages b/c extended pages use the default INIT.
350
+				$extend = false;
351
+				//now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals.  If there are then let's hook into the init admin filter and load our extend instead.
352
+				if (isset($this->_caffeinated_extends[$page])) {
353
+					$this->_current_caf_extend_slug = $page;
354
+					$path_hook                      = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__'
355
+													  . $this->_installed_pages[$page]->get_menu_map()->menu_slug
356
+													  . '_'
357
+													  . $this->_installed_pages[$page]->get_admin_page_name();
358
+					$path_runtime                   = 'return "'
359
+													  . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["path"]
360
+													  . '";';
361
+					$page_hook                      = 'FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__'
362
+													  . $this->_installed_pages[$page]->get_menu_map()->menu_slug
363
+													  . '_'
364
+													  . $this->_installed_pages[$page]->get_admin_page_name();
365
+					$page_runtime                   = 'return "'
366
+													  . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["admin_page"]
367
+													  . '";';
368
+					$hook_function_path = create_function('$path_to_file', $path_runtime);
369
+					$hook_function_page = create_function('$admin_page', $page_runtime);
370
+					add_filter($path_hook, $hook_function_path);
371
+					add_filter($page_hook, $hook_function_page);
372
+					$extend = true;
373
+				}
374
+				//let's do the registered hooks
375
+				$extended_hooks = $this->_installed_pages[$page]->register_hooks($extend);
376
+				$hooks_ref      = array_merge($hooks_ref, $extended_hooks);
377
+			}
378
+		}
379
+		//the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder.  So we want to make sure we load the file for the parent.
380
+		//first make sure we've got unique values
381
+		$hooks_ref = array_unique($hooks_ref);
382
+		//now let's loop and require!
383
+		foreach ($hooks_ref as $path) {
384
+			require_once($path);
385
+		}
386
+		//make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested.
387
+		global $ee_menu_slugs;
388
+		$ee_menu_slugs = $this->_menu_slugs;
389
+		//we need to loop again to run any early code
390
+		foreach ($installed_refs as $page => $path) {
391
+			if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
392
+				$this->_installed_pages[$page]->do_initial_loads();
393
+			}
394
+		}
395
+		do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 * get_admin_page_object
402
+	 *
403
+	 * @param string $page_slug
404
+	 * @return EE_Admin_Page
405
+	 */
406
+	public function get_admin_page_object($page_slug = '')
407
+	{
408
+		if (isset($this->_installed_pages[$page_slug])) {
409
+			return $this->_installed_pages[$page_slug]->loaded_page_object();
410
+		}
411
+		return null;
412
+	}
413
+
414
+
415
+
416
+	/**
417
+	 * _get_classname_for_admin_page
418
+	 * generates an "Admin Page" class based on the directory  name
419
+	 *
420
+	 * @param $dir_name
421
+	 * @return string
422
+	 */
423
+	private function _get_classname_for_admin_page($dir_name = '')
424
+	{
425
+		$class_name = str_replace('_', ' ', strtolower($dir_name));
426
+		return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
427
+	}
428
+
429
+
430
+
431
+	/**
432
+	 * _get_classname_for_admin_init_page
433
+	 * generates an "Admin Page Init" class based on the directory  name
434
+	 *
435
+	 * @param $dir_name
436
+	 * @return string
437
+	 */
438
+	private function _get_classname_for_admin_init_page($dir_name = '')
439
+	{
440
+		$class_name = str_replace('_', ' ', strtolower($dir_name));
441
+		return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
442
+	}
443
+
444
+
445
+
446
+	/**
447
+	 * _load_admin_page
448
+	 * Loads and instantiates page_init object for a single EE_admin page.
449
+	 *
450
+	 * @param  string $page page_reference
451
+	 * @param string  $path
452
+	 * @throws EE_Error
453
+	 * @return object|bool  return page object if valid, bool false if not.
454
+	 */
455
+	private function _load_admin_page($page = '', $path = '')
456
+	{
457
+		$class_name = $this->_get_classname_for_admin_init_page($page);
458
+		EE_Registry::instance()->load_file($path, $class_name, 'core');
459
+		if (! class_exists($class_name)) {
460
+			$inner_error_msg = '<br />' . sprintf(
461
+					esc_html__(
462
+						'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
463
+						'event_espresso'
464
+					),
465
+					'<strong>' . $class_name . '</strong>'
466
+				);
467
+			$error_msg[]     = sprintf(
468
+				__('Something went wrong with loading the %s admin page.', 'event_espresso'),
469
+				$page
470
+			);
471
+			$error_msg[]     = $error_msg[0]
472
+							   . "\r\n"
473
+							   . sprintf(
474
+								   esc_html__(
475
+									   'There is no Init class in place for the %s admin page.',
476
+									   'event_espresso'
477
+								   ),
478
+								   $page
479
+							   )
480
+							   . $inner_error_msg;
481
+			throw new EE_Error(implode('||', $error_msg));
482
+		}
483
+		$a = new ReflectionClass($class_name);
484
+		return $a->newInstance();
485
+	}
486
+
487
+
488
+
489
+	/**
490
+	 * set_menus
491
+	 * This method sets up the menus for EE Admin Pages
492
+	 *
493
+	 * @access private
494
+	 * @return void
495
+	 */
496
+	public function set_menus()
497
+	{
498
+		//prep the menu pages (sort, group.)
499
+		$this->_prep_pages();
500
+		foreach ($this->_prepped_menu_maps as $menu_map) {
501
+			if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
502
+				$menu_map->add_menu_page(false);
503
+			}
504
+		}
505
+	}
506
+
507
+
508
+	/**
509
+	 * set_network_menus
510
+	 * This method sets up the menus for network EE Admin Pages.
511
+	 * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
512
+	 * are only added to the menu map if they are intended for the admin menu
513
+	 *
514
+	 * @return void
515
+	 */
516
+	public function set_network_menus()
517
+	{
518
+		$this->_prep_pages();
519
+		foreach ($this->_prepped_menu_maps as $menu_map) {
520
+			if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) {
521
+				$menu_map->add_menu_page(true);
522
+			}
523
+		}
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 * _prep_pages
530
+	 * sets the _prepped_menu_maps property
531
+	 *
532
+	 * @access private
533
+	 * @throws EE_Error
534
+	 * @return void
535
+	 */
536
+	private function _prep_pages()
537
+	{
538
+		$pages_array = array();
539
+		//rearrange _admin_menu_groups to be indexed by group slug.
540
+		$menu_groups = $this->_rearrange_menu_groups();
541
+		foreach ($this->_installed_pages as $page) {
542
+			if ($page instanceof EE_Admin_page_Init) {
543
+				$page_map = $page->get_menu_map();
544
+				//if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
545
+				if (is_array($page_map) || empty($page_map)) {
546
+					EE_Error::add_persistent_admin_notice(
547
+						'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
548
+						sprintf(
549
+							__(
550
+								'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
551
+								'event_espresso'
552
+							),
553
+							$page->label
554
+						)
555
+					);
556
+					continue;
557
+				}
558
+				//if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
559
+				if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
560
+					throw new EE_Error(
561
+						sprintf(
562
+							__(
563
+								'The menu map for %s must be an EE_Admin_Page_Menu_Map object.  Instead it is %s.  Please double check that the menu map has been configured correctly.',
564
+								'event_espresso'
565
+							),
566
+							$page->label,
567
+							$page_map
568
+						)
569
+					);
570
+				}
571
+				//use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array.
572
+				if (empty($page_map->maintenance_mode_parent)
573
+					&& EE_Maintenance_Mode::instance()->level()
574
+					   == EE_Maintenance_Mode::level_2_complete_maintenance) {
575
+					continue;
576
+				}
577
+				//assign to group (remember $page_map has the admin page stored in it).
578
+				$pages_array[$page_map->menu_group][] = $page_map;
579
+			}
580
+		}
581
+		if (empty($pages_array)) {
582
+			throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso'));
583
+		}
584
+		//let's sort the groups, make sure it's a valid group, add header (if to show).
585
+		foreach ($pages_array as $group => $menu_maps) {
586
+			//valid_group?
587
+			if (! array_key_exists($group, $menu_groups)) {
588
+				continue;
589
+			}
590
+			//sort pages.
591
+			usort($menu_maps, array($this, '_sort_menu_maps'));
592
+			//prepend header
593
+			array_unshift($menu_maps, $menu_groups[$group]);
594
+			//reset $pages_array with prepped data
595
+			$pages_array[$group] = $menu_maps;
596
+		}
597
+		//now let's setup the _prepped_menu_maps property
598
+		foreach ($menu_groups as $group => $group_objs) {
599
+			if (isset($pages_array[$group])) {
600
+				$this->_prepped_menu_maps = array_merge($this->_prepped_menu_maps, $pages_array[$group]);
601
+			}
602
+		}/**/
603
+	}
604
+
605
+
606
+
607
+	/**
608
+	 * This method is the "workhorse" for detecting and setting up caffeinated functionality.
609
+	 * In this method there are three checks being done:
610
+	 * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $installed_refs
611
+	 * array) etc.  (new page sets are found in caffeinated/new/{page})
612
+	 * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
613
+	 * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
614
+	 * Extend_Events_Admin_Page extends Events_Admin_Page.
615
+	 * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
616
+	 * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
617
+	 * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
618
+	 * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
619
+	 * admin_pages)
620
+	 *
621
+	 * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be
622
+	 *                              loaded.
623
+	 * @return array
624
+	 */
625
+	private function _set_caffeinated($installed_refs)
626
+	{
627
+
628
+		//first let's check if there IS a caffeinated folder. If there is not then lets get out.
629
+		if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) {
630
+			return $installed_refs;
631
+		}
632
+		$this->_define_caffeinated_constants();
633
+		$exclude = array('tickets');
634
+		//okay let's setup an "New" pages first (we'll return installed refs later)
635
+		$new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
636
+		if ($new_admin_screens) {
637
+			foreach ($new_admin_screens as $admin_screen) {
638
+				// files and anything in the exclude array need not apply
639
+				if (is_dir($admin_screen) && ! in_array(basename($admin_screen), $exclude)) {
640
+					// these folders represent the different NEW EE admin pages
641
+					$installed_refs[basename($admin_screen)] = $admin_screen;
642
+					// set autoloaders for our admin page classes based on included path information
643
+					EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($admin_screen);
644
+					//					$this->_caf_autoloader[] = array(
645
+					//						'dir' => 'new',
646
+					//						'folder' => basename( $admin_screen )
647
+					//					);
648
+				}
649
+			}
650
+		}
651
+		//let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
652
+		$extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
653
+		if ($extends) {
654
+			foreach ($extends as $extend) {
655
+				if (is_dir($extend)) {
656
+					$extend_ref = basename($extend);
657
+					//now let's make sure there is a file that matches the expected format
658
+					$filename                                              = str_replace(
659
+						' ',
660
+						'_',
661
+						ucwords(
662
+							str_replace(
663
+								'_',
664
+								' ',
665
+								$extend_ref
666
+							)
667
+						)
668
+					);
669
+					$filename                                              = 'Extend_' . $filename . '_Admin_Page';
670
+					$this->_caffeinated_extends[$extend_ref]['path']       = str_replace(
671
+						array('\\', '/'),
672
+						DS,
673
+						EE_CORE_CAF_ADMIN
674
+						. 'extend'
675
+						. DS
676
+						. $extend_ref
677
+						. DS
678
+						. $filename
679
+						. '.core.php'
680
+					);
681
+					$this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename;
682
+					// set autoloaders for our admin page classes based on included path information
683
+					EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder($extend);
684
+					//					$this->_caf_autoloader[] = array(
685
+					//						'dir' => 'extend',
686
+					//						'folder' => $extend_ref
687
+					//					);
688
+				}
689
+			}
690
+		}
691
+		//let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
692
+		$ee_admin_hooks = array();
693
+		$hooks          = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
694
+		if ($hooks) {
695
+			foreach ($hooks as $hook) {
696
+				if (is_readable($hook)) {
697
+					require_once $hook;
698
+					$classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
699
+					$classname = str_replace('.class.php', '', $classname);
700
+					if (class_exists($classname)) {
701
+						$a                = new ReflectionClass($classname);
702
+						$ee_admin_hooks[] = $a->newInstance();
703
+					}
704
+				}
705
+			}
706
+		}/**/
707
+		$ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
708
+		return $installed_refs;
709
+	}
710
+
711
+
712
+
713
+
714
+
715
+	/**
716
+	 * Initial autoloader registration
717
+	 * This just sets up the autoloader for the root admin files
718
+	 *
719
+	 * @param  string $className incoming classname to check for autoload
720
+	 * @return void
721
+	 */
722
+	//	public function init_autoloaders( $className ) {
723
+	//		$dir_ref = array(
724
+	//			EE_ADMIN => array('core', 'class')
725
+	//		);
726
+	//		EEH_Autoloader::try_autoload($dir_ref, $className );
727
+	//	}
728
+	/**
729
+	 * This method takes care of setting up the autoloader dynamically for any NEW EE_Admin pages found in the
730
+	 * caffeinated folders.
731
+	 *
732
+	 * @access public
733
+	 * @param  string $className in coming classname being called
734
+	 * @return void
735
+	 */
736
+	//	public function caffeinated_autoloaders( $className ) {
737
+	//		//let's setup an array of paths to check (for each subsystem)
738
+	//		$dir_ref = array();
739
+	//		foreach ( $this->_caf_autoloader as $pathinfo) {
740
+	//			$dir_ref[ EE_CORE_CAF_ADMIN . $pathinfo['dir'] . DS . $pathinfo['folder'] . DS] = array('core', 'class');
741
+	//		}
742
+	//
743
+	//		EEH_Autoloader::try_autoload($dir_ref, $className );
744
+	//	}
745
+	/**
746
+	 * Utility method for sorting the _menu_maps (callback for usort php function)
747
+	 *
748
+	 * @since  4.4.0
749
+	 * @param  EE_Admin_Page_Menu_Map $a menu_map object
750
+	 * @param  EE_Admin_Page_Menu_Map $b being compared to
751
+	 * @return int    sort order
752
+	 */
753
+	private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b)
754
+	{
755
+		if ($a->menu_order == $b->menu_order) {
756
+			return 0;
757
+		}
758
+		return ($a->menu_order < $b->menu_order) ? -1 : 1;
759
+	}
760
+
761
+
762
+
763
+	/**
764
+	 * _default_header_link
765
+	 * This is just a dummy method to use with header submenu items
766
+	 *
767
+	 * @return bool false
768
+	 */
769
+	public function _default_header_link()
770
+	{
771
+		return false;
772
+	}
773 773
 
774 774
 
775 775
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 
@@ -140,13 +140,13 @@  discard block
 block discarded – undo
140 140
      */
141 141
     private function _define_caffeinated_constants()
142 142
     {
143
-        if (! defined('EE_CORE_CAF_ADMIN')) {
144
-            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
145
-            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
146
-            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
147
-            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
148
-            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
149
-            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
143
+        if ( ! defined('EE_CORE_CAF_ADMIN')) {
144
+            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/');
145
+            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/');
146
+            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/');
147
+            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/');
148
+            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/');
149
+            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/');
150 150
         }
151 151
     }
152 152
 
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
         //first let's order the menu groups by their internal menu order (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects )
260 260
         usort($this->_admin_menu_groups, array($this, '_sort_menu_maps'));
261 261
         foreach ($this->_admin_menu_groups as $group) {
262
-            if (! $group instanceof EE_Admin_Page_Menu_Group) {
262
+            if ( ! $group instanceof EE_Admin_Page_Menu_Group) {
263 263
                 throw new EE_Error(
264 264
                     sprintf(
265 265
                         __(
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
         $installed_refs = array();
291 291
         $exclude        = array('assets', 'templates');
292 292
         // grab everything in the  admin core directory
293
-        $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR);
293
+        $admin_screens = glob(EE_ADMIN_PAGES.'*', GLOB_ONLYDIR);
294 294
         if ($admin_screens) {
295 295
             foreach ($admin_screens as $admin_screen) {
296 296
                 // files and anything in the exclude array need not apply
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
                 'There are no EE_Admin pages detected, it looks like EE did not install properly',
306 306
                 'event_espresso'
307 307
             );
308
-            $error_msg[] = $error_msg[0] . "\r\n" . sprintf(
308
+            $error_msg[] = $error_msg[0]."\r\n".sprintf(
309 309
                     __(
310 310
                         'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
311 311
                         'event_espresso'
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
         //this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
318 318
         $installed_refs = $this->_set_caffeinated($installed_refs);
319 319
         //allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.;
320
-        $installed_refs             = apply_filters(
320
+        $installed_refs = apply_filters(
321 321
             'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
322 322
             $installed_refs
323 323
         );
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
             $this->_installed_pages[$page] = $this->_load_admin_page($page, $path);
335 335
             // verify returned object
336 336
             if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) {
337
-                if (! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
337
+                if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) {
338 338
                     continue;
339 339
                 }
340 340
                 //skip if in full maintenance mode and maintenance_mode_parent is set
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
                                                       . $this->_installed_pages[$page]->get_menu_map()->menu_slug
363 363
                                                       . '_'
364 364
                                                       . $this->_installed_pages[$page]->get_admin_page_name();
365
-                    $page_runtime                   = 'return "'
365
+                    $page_runtime = 'return "'
366 366
                                                       . $this->_caffeinated_extends[$this->_current_caf_extend_slug]["admin_page"]
367 367
                                                       . '";';
368 368
                     $hook_function_path = create_function('$path_to_file', $path_runtime);
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
     private function _get_classname_for_admin_page($dir_name = '')
424 424
     {
425 425
         $class_name = str_replace('_', ' ', strtolower($dir_name));
426
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page';
426
+        return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page';
427 427
     }
428 428
 
429 429
 
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
     private function _get_classname_for_admin_init_page($dir_name = '')
439 439
     {
440 440
         $class_name = str_replace('_', ' ', strtolower($dir_name));
441
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
441
+        return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init';
442 442
     }
443 443
 
444 444
 
@@ -456,19 +456,19 @@  discard block
 block discarded – undo
456 456
     {
457 457
         $class_name = $this->_get_classname_for_admin_init_page($page);
458 458
         EE_Registry::instance()->load_file($path, $class_name, 'core');
459
-        if (! class_exists($class_name)) {
460
-            $inner_error_msg = '<br />' . sprintf(
459
+        if ( ! class_exists($class_name)) {
460
+            $inner_error_msg = '<br />'.sprintf(
461 461
                     esc_html__(
462 462
                         'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
463 463
                         'event_espresso'
464 464
                     ),
465
-                    '<strong>' . $class_name . '</strong>'
465
+                    '<strong>'.$class_name.'</strong>'
466 466
                 );
467
-            $error_msg[]     = sprintf(
467
+            $error_msg[] = sprintf(
468 468
                 __('Something went wrong with loading the %s admin page.', 'event_espresso'),
469 469
                 $page
470 470
             );
471
-            $error_msg[]     = $error_msg[0]
471
+            $error_msg[] = $error_msg[0]
472 472
                                . "\r\n"
473 473
                                . sprintf(
474 474
                                    esc_html__(
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
                 //if we've got an array then the menu map is in the old format so let's throw a persistent notice that the admin system isn't setup correctly for this item.
545 545
                 if (is_array($page_map) || empty($page_map)) {
546 546
                     EE_Error::add_persistent_admin_notice(
547
-                        'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION,
547
+                        'menu_map_warning_'.str_replace(' ', '_', $page->label).'_'.EVENT_ESPRESSO_VERSION,
548 548
                         sprintf(
549 549
                             __(
550 550
                                 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core.  This means that full functionality for this component is not available.  This error message usually appears with an Add-on that is out of date.  Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.',
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
                     continue;
557 557
                 }
558 558
                 //if page map is NOT a EE_Admin_Page_Menu_Map object then throw error.
559
-                if (! $page_map instanceof EE_Admin_Page_Menu_Map) {
559
+                if ( ! $page_map instanceof EE_Admin_Page_Menu_Map) {
560 560
                     throw new EE_Error(
561 561
                         sprintf(
562 562
                             __(
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
         //let's sort the groups, make sure it's a valid group, add header (if to show).
585 585
         foreach ($pages_array as $group => $menu_maps) {
586 586
             //valid_group?
587
-            if (! array_key_exists($group, $menu_groups)) {
587
+            if ( ! array_key_exists($group, $menu_groups)) {
588 588
                 continue;
589 589
             }
590 590
             //sort pages.
@@ -626,13 +626,13 @@  discard block
 block discarded – undo
626 626
     {
627 627
 
628 628
         //first let's check if there IS a caffeinated folder. If there is not then lets get out.
629
-        if (! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated' . DS . 'admin') || (defined('EE_DECAF') && EE_DECAF)) {
629
+        if ( ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated'.DS.'admin') || (defined('EE_DECAF') && EE_DECAF)) {
630 630
             return $installed_refs;
631 631
         }
632 632
         $this->_define_caffeinated_constants();
633 633
         $exclude = array('tickets');
634 634
         //okay let's setup an "New" pages first (we'll return installed refs later)
635
-        $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR);
635
+        $new_admin_screens = glob(EE_CORE_CAF_ADMIN.'new/*', GLOB_ONLYDIR);
636 636
         if ($new_admin_screens) {
637 637
             foreach ($new_admin_screens as $admin_screen) {
638 638
                 // files and anything in the exclude array need not apply
@@ -649,13 +649,13 @@  discard block
 block discarded – undo
649 649
             }
650 650
         }
651 651
         //let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
652
-        $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR);
652
+        $extends = glob(EE_CORE_CAF_ADMIN.'extend/*', GLOB_ONLYDIR);
653 653
         if ($extends) {
654 654
             foreach ($extends as $extend) {
655 655
                 if (is_dir($extend)) {
656 656
                     $extend_ref = basename($extend);
657 657
                     //now let's make sure there is a file that matches the expected format
658
-                    $filename                                              = str_replace(
658
+                    $filename = str_replace(
659 659
                         ' ',
660 660
                         '_',
661 661
                         ucwords(
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
                             )
667 667
                         )
668 668
                     );
669
-                    $filename                                              = 'Extend_' . $filename . '_Admin_Page';
669
+                    $filename                                              = 'Extend_'.$filename.'_Admin_Page';
670 670
                     $this->_caffeinated_extends[$extend_ref]['path']       = str_replace(
671 671
                         array('\\', '/'),
672 672
                         DS,
@@ -690,12 +690,12 @@  discard block
 block discarded – undo
690 690
         }
691 691
         //let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
692 692
         $ee_admin_hooks = array();
693
-        $hooks          = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php');
693
+        $hooks          = glob(EE_CORE_CAF_ADMIN.'hooks/*.class.php');
694 694
         if ($hooks) {
695 695
             foreach ($hooks as $hook) {
696 696
                 if (is_readable($hook)) {
697 697
                     require_once $hook;
698
-                    $classname = str_replace(EE_CORE_CAF_ADMIN . 'hooks/', '', $hook);
698
+                    $classname = str_replace(EE_CORE_CAF_ADMIN.'hooks/', '', $hook);
699 699
                     $classname = str_replace('.class.php', '', $classname);
700 700
                     if (class_exists($classname)) {
701 701
                         $a                = new ReflectionClass($classname);
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 1 patch
Indentation   +3589 added lines, -3589 removed lines patch added patch discarded remove patch
@@ -30,2276 +30,2276 @@  discard block
 block discarded – undo
30 30
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
31 31
 {
32 32
 
33
-    /**
34
-     * @var EE_Registration
35
-     */
36
-    private $_registration;
37
-
38
-    /**
39
-     * @var EE_Event
40
-     */
41
-    private $_reg_event;
42
-
43
-    /**
44
-     * @var EE_Session
45
-     */
46
-    private $_session;
47
-
48
-    private static $_reg_status;
49
-
50
-    /**
51
-     * Form for displaying the custom questions for this registration.
52
-     * This gets used a few times throughout the request so its best to cache it
53
-     *
54
-     * @var EE_Registration_Custom_Questions_Form
55
-     */
56
-    protected $_reg_custom_questions_form = null;
57
-
58
-
59
-    /**
60
-     *        constructor
61
-     *
62
-     * @Constructor
63
-     * @access public
64
-     * @param bool $routing
65
-     * @return Registrations_Admin_Page
66
-     */
67
-    public function __construct($routing = true)
68
-    {
69
-        parent::__construct($routing);
70
-        add_action('wp_loaded', array($this, 'wp_loaded'));
71
-    }
72
-
73
-
74
-    public function wp_loaded()
75
-    {
76
-        // when adding a new registration...
77
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78
-            EE_System::do_not_cache();
79
-            if (! isset($this->_req_data['processing_registration'])
80
-                 || absint($this->_req_data['processing_registration']) !== 1
81
-            ) {
82
-                // and it's NOT the attendee information reg step
83
-                // force cookie expiration by setting time to last week
84
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
85
-                // and update the global
86
-                $_COOKIE['ee_registration_added'] = 0;
87
-            }
88
-        }
89
-    }
90
-
91
-
92
-    protected function _init_page_props()
93
-    {
94
-        $this->page_slug        = REG_PG_SLUG;
95
-        $this->_admin_base_url  = REG_ADMIN_URL;
96
-        $this->_admin_base_path = REG_ADMIN;
97
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
98
-        $this->_cpt_routes      = array(
99
-            'add_new_attendee' => 'espresso_attendees',
100
-            'edit_attendee'    => 'espresso_attendees',
101
-            'insert_attendee'  => 'espresso_attendees',
102
-            'update_attendee'  => 'espresso_attendees',
103
-        );
104
-        $this->_cpt_model_names = array(
105
-            'add_new_attendee' => 'EEM_Attendee',
106
-            'edit_attendee'    => 'EEM_Attendee',
107
-        );
108
-        $this->_cpt_edit_routes = array(
109
-            'espresso_attendees' => 'edit_attendee',
110
-        );
111
-        $this->_pagenow_map     = array(
112
-            'add_new_attendee' => 'post-new.php',
113
-            'edit_attendee'    => 'post.php',
114
-            'trash'            => 'post.php',
115
-        );
116
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
117
-        //add filters so that the comment urls don't take users to a confusing 404 page
118
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
119
-    }
120
-
121
-
122
-    public function clear_comment_link($link, $comment, $args)
123
-    {
124
-        //gotta make sure this only happens on this route
125
-        $post_type = get_post_type($comment->comment_post_ID);
126
-        if ($post_type === 'espresso_attendees') {
127
-            return '#commentsdiv';
128
-        }
129
-        return $link;
130
-    }
131
-
132
-
133
-    protected function _ajax_hooks()
134
-    {
135
-        //todo: all hooks for registrations ajax goes in here
136
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
137
-    }
138
-
139
-
140
-    protected function _define_page_props()
141
-    {
142
-        $this->_admin_page_title = $this->page_label;
143
-        $this->_labels           = array(
144
-            'buttons'                      => array(
145
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
146
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
147
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
148
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
149
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
150
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
151
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
152
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
153
-            ),
154
-            'publishbox'                   => array(
155
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
156
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
157
-            ),
158
-            'hide_add_button_on_cpt_route' => array(
159
-                'edit_attendee' => true,
160
-            ),
161
-        );
162
-    }
163
-
164
-
165
-    /**
166
-     *        grab url requests and route them
167
-     *
168
-     * @access private
169
-     * @return void
170
-     */
171
-    public function _set_page_routes()
172
-    {
173
-        $this->_get_registration_status_array();
174
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175
-            ? $this->_req_data['_REG_ID'] : 0;
176
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
178
-            : $reg_id;
179
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
180
-            ? $this->_req_data['ATT_ID'] : 0;
181
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
182
-            ? $this->_req_data['post']
183
-            : $att_id;
184
-        $this->_page_routes = array(
185
-            'default'                            => array(
186
-                'func'       => '_registrations_overview_list_table',
187
-                'capability' => 'ee_read_registrations',
188
-            ),
189
-            'view_registration'                  => array(
190
-                'func'       => '_registration_details',
191
-                'capability' => 'ee_read_registration',
192
-                'obj_id'     => $reg_id,
193
-            ),
194
-            'edit_registration'                  => array(
195
-                'func'               => '_update_attendee_registration_form',
196
-                'noheader'           => true,
197
-                'headers_sent_route' => 'view_registration',
198
-                'capability'         => 'ee_edit_registration',
199
-                'obj_id'             => $reg_id,
200
-                '_REG_ID'            => $reg_id,
201
-            ),
202
-            'trash_registrations'                => array(
203
-                'func'       => '_trash_or_restore_registrations',
204
-                'args'       => array('trash' => true),
205
-                'noheader'   => true,
206
-                'capability' => 'ee_delete_registrations',
207
-            ),
208
-            'restore_registrations'              => array(
209
-                'func'       => '_trash_or_restore_registrations',
210
-                'args'       => array('trash' => false),
211
-                'noheader'   => true,
212
-                'capability' => 'ee_delete_registrations',
213
-            ),
214
-            'delete_registrations'               => array(
215
-                'func'       => '_delete_registrations',
216
-                'noheader'   => true,
217
-                'capability' => 'ee_delete_registrations',
218
-            ),
219
-            'new_registration'                   => array(
220
-                'func'       => 'new_registration',
221
-                'capability' => 'ee_edit_registrations',
222
-            ),
223
-            'process_reg_step'                   => array(
224
-                'func'       => 'process_reg_step',
225
-                'noheader'   => true,
226
-                'capability' => 'ee_edit_registrations',
227
-            ),
228
-            'redirect_to_txn'                    => array(
229
-                'func'       => 'redirect_to_txn',
230
-                'noheader'   => true,
231
-                'capability' => 'ee_edit_registrations',
232
-            ),
233
-            'change_reg_status'                  => array(
234
-                'func'       => '_change_reg_status',
235
-                'noheader'   => true,
236
-                'capability' => 'ee_edit_registration',
237
-                'obj_id'     => $reg_id,
238
-            ),
239
-            'approve_registration'               => array(
240
-                'func'       => 'approve_registration',
241
-                'noheader'   => true,
242
-                'capability' => 'ee_edit_registration',
243
-                'obj_id'     => $reg_id,
244
-            ),
245
-            'approve_and_notify_registration'    => array(
246
-                'func'       => 'approve_registration',
247
-                'noheader'   => true,
248
-                'args'       => array(true),
249
-                'capability' => 'ee_edit_registration',
250
-                'obj_id'     => $reg_id,
251
-            ),
252
-            'approve_registrations'               => array(
253
-                'func'       => 'bulk_action_on_registrations',
254
-                'noheader'   => true,
255
-                'capability' => 'ee_edit_registrations',
256
-                'args' => array('approve')
257
-            ),
258
-            'approve_and_notify_registrations'               => array(
259
-                'func'       => 'bulk_action_on_registrations',
260
-                'noheader'   => true,
261
-                'capability' => 'ee_edit_registrations',
262
-                'args' => array('approve', true)
263
-            ),
264
-            'decline_registration'               => array(
265
-                'func'       => 'decline_registration',
266
-                'noheader'   => true,
267
-                'capability' => 'ee_edit_registration',
268
-                'obj_id'     => $reg_id,
269
-            ),
270
-            'decline_and_notify_registration'    => array(
271
-                'func'       => 'decline_registration',
272
-                'noheader'   => true,
273
-                'args'       => array(true),
274
-                'capability' => 'ee_edit_registration',
275
-                'obj_id'     => $reg_id,
276
-            ),
277
-            'decline_registrations'               => array(
278
-                'func'       => 'bulk_action_on_registrations',
279
-                'noheader'   => true,
280
-                'capability' => 'ee_edit_registrations',
281
-                'args' => array('decline')
282
-            ),
283
-            'decline_and_notify_registrations'    => array(
284
-                'func'       => 'bulk_action_on_registrations',
285
-                'noheader'   => true,
286
-                'capability' => 'ee_edit_registrations',
287
-                'args' => array('decline', true)
288
-            ),
289
-            'pending_registration'               => array(
290
-                'func'       => 'pending_registration',
291
-                'noheader'   => true,
292
-                'capability' => 'ee_edit_registration',
293
-                'obj_id'     => $reg_id,
294
-            ),
295
-            'pending_and_notify_registration'    => array(
296
-                'func'       => 'pending_registration',
297
-                'noheader'   => true,
298
-                'args'       => array(true),
299
-                'capability' => 'ee_edit_registration',
300
-                'obj_id'     => $reg_id,
301
-            ),
302
-            'pending_registrations'               => array(
303
-                'func'       => 'bulk_action_on_registrations',
304
-                'noheader'   => true,
305
-                'capability' => 'ee_edit_registrations',
306
-                'args' => array('pending')
307
-            ),
308
-            'pending_and_notify_registrations'    => array(
309
-                'func'       => 'bulk_action_on_registrations',
310
-                'noheader'   => true,
311
-                'capability' => 'ee_edit_registrations',
312
-                'args' => array('pending', true)
313
-            ),
314
-            'no_approve_registration'            => array(
315
-                'func'       => 'not_approve_registration',
316
-                'noheader'   => true,
317
-                'capability' => 'ee_edit_registration',
318
-                'obj_id'     => $reg_id,
319
-            ),
320
-            'no_approve_and_notify_registration' => array(
321
-                'func'       => 'not_approve_registration',
322
-                'noheader'   => true,
323
-                'args'       => array(true),
324
-                'capability' => 'ee_edit_registration',
325
-                'obj_id'     => $reg_id,
326
-            ),
327
-            'no_approve_registrations'            => array(
328
-                'func'       => 'bulk_action_on_registrations',
329
-                'noheader'   => true,
330
-                'capability' => 'ee_edit_registrations',
331
-                'args' => array('not_approve')
332
-            ),
333
-            'no_approve_and_notify_registrations' => array(
334
-                'func'       => 'bulk_action_on_registrations',
335
-                'noheader'   => true,
336
-                'capability' => 'ee_edit_registrations',
337
-                'args' => array('not_approve', true)
338
-            ),
339
-            'cancel_registration'                => array(
340
-                'func'       => 'cancel_registration',
341
-                'noheader'   => true,
342
-                'capability' => 'ee_edit_registration',
343
-                'obj_id'     => $reg_id,
344
-            ),
345
-            'cancel_and_notify_registration'     => array(
346
-                'func'       => 'cancel_registration',
347
-                'noheader'   => true,
348
-                'args'       => array(true),
349
-                'capability' => 'ee_edit_registration',
350
-                'obj_id'     => $reg_id,
351
-            ),
352
-            'cancel_registrations'                => array(
353
-                'func'       => 'bulk_action_on_registrations',
354
-                'noheader'   => true,
355
-                'capability' => 'ee_edit_registrations',
356
-                'args' => array('cancel')
357
-            ),
358
-            'cancel_and_notify_registrations'     => array(
359
-                'func'       => 'bulk_action_on_registrations',
360
-                'noheader'   => true,
361
-                'capability' => 'ee_edit_registrations',
362
-                'args' => array('cancel', true)
363
-            ),
364
-            'wait_list_registration' => array(
365
-                'func'       => 'wait_list_registration',
366
-                'noheader'   => true,
367
-                'capability' => 'ee_edit_registration',
368
-                'obj_id'     => $reg_id,
369
-            ),
370
-            'wait_list_and_notify_registration' => array(
371
-                'func'       => 'wait_list_registration',
372
-                'noheader'   => true,
373
-                'args'       => array(true),
374
-                'capability' => 'ee_edit_registration',
375
-                'obj_id'     => $reg_id,
376
-            ),
377
-            'contact_list'                       => array(
378
-                'func'       => '_attendee_contact_list_table',
379
-                'capability' => 'ee_read_contacts',
380
-            ),
381
-            'add_new_attendee'                   => array(
382
-                'func' => '_create_new_cpt_item',
383
-                'args' => array(
384
-                    'new_attendee' => true,
385
-                    'capability'   => 'ee_edit_contacts',
386
-                ),
387
-            ),
388
-            'edit_attendee'                      => array(
389
-                'func'       => '_edit_cpt_item',
390
-                'capability' => 'ee_edit_contacts',
391
-                'obj_id'     => $att_id,
392
-            ),
393
-            'duplicate_attendee'                 => array(
394
-                'func'       => '_duplicate_attendee',
395
-                'noheader'   => true,
396
-                'capability' => 'ee_edit_contacts',
397
-                'obj_id'     => $att_id,
398
-            ),
399
-            'insert_attendee'                    => array(
400
-                'func'       => '_insert_or_update_attendee',
401
-                'args'       => array(
402
-                    'new_attendee' => true,
403
-                ),
404
-                'noheader'   => true,
405
-                'capability' => 'ee_edit_contacts',
406
-            ),
407
-            'update_attendee'                    => array(
408
-                'func'       => '_insert_or_update_attendee',
409
-                'args'       => array(
410
-                    'new_attendee' => false,
411
-                ),
412
-                'noheader'   => true,
413
-                'capability' => 'ee_edit_contacts',
414
-                'obj_id'     => $att_id,
415
-            ),
416
-            'trash_attendees' => array(
417
-                'func' => '_trash_or_restore_attendees',
418
-                'args' => array(
419
-                    'trash' => 'true'
420
-                ),
421
-                'noheader' => true,
422
-                'capability' => 'ee_delete_contacts'
423
-            ),
424
-            'trash_attendee'                    => array(
425
-                'func'       => '_trash_or_restore_attendees',
426
-                'args'       => array(
427
-                    'trash' => true,
428
-                ),
429
-                'noheader'   => true,
430
-                'capability' => 'ee_delete_contacts',
431
-                'obj_id'     => $att_id,
432
-            ),
433
-            'restore_attendees'                  => array(
434
-                'func'       => '_trash_or_restore_attendees',
435
-                'args'       => array(
436
-                    'trash' => false,
437
-                ),
438
-                'noheader'   => true,
439
-                'capability' => 'ee_delete_contacts',
440
-                'obj_id'     => $att_id,
441
-            ),
442
-            'resend_registration'                => array(
443
-                'func'       => '_resend_registration',
444
-                'noheader'   => true,
445
-                'capability' => 'ee_send_message',
446
-            ),
447
-            'registrations_report'               => array(
448
-                'func'       => '_registrations_report',
449
-                'noheader'   => true,
450
-                'capability' => 'ee_read_registrations',
451
-            ),
452
-            'contact_list_export'                => array(
453
-                'func'       => '_contact_list_export',
454
-                'noheader'   => true,
455
-                'capability' => 'export',
456
-            ),
457
-            'contact_list_report'                => array(
458
-                'func'       => '_contact_list_report',
459
-                'noheader'   => true,
460
-                'capability' => 'ee_read_contacts',
461
-            ),
462
-        );
463
-    }
464
-
465
-
466
-    protected function _set_page_config()
467
-    {
468
-        $this->_page_config = array(
469
-            'default'           => array(
470
-                'nav'           => array(
471
-                    'label' => esc_html__('Overview', 'event_espresso'),
472
-                    'order' => 5,
473
-                ),
474
-                'help_tabs'     => array(
475
-                    'registrations_overview_help_tab'                       => array(
476
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
477
-                        'filename' => 'registrations_overview',
478
-                    ),
479
-                    'registrations_overview_table_column_headings_help_tab' => array(
480
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
481
-                        'filename' => 'registrations_overview_table_column_headings',
482
-                    ),
483
-                    'registrations_overview_filters_help_tab'               => array(
484
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
485
-                        'filename' => 'registrations_overview_filters',
486
-                    ),
487
-                    'registrations_overview_views_help_tab'                 => array(
488
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
489
-                        'filename' => 'registrations_overview_views',
490
-                    ),
491
-                    'registrations_regoverview_other_help_tab'              => array(
492
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
493
-                        'filename' => 'registrations_overview_other',
494
-                    ),
495
-                ),
496
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
497
-                'qtips'         => array('Registration_List_Table_Tips'),
498
-                'list_table'    => 'EE_Registrations_List_Table',
499
-                'require_nonce' => false,
500
-            ),
501
-            'view_registration' => array(
502
-                'nav'           => array(
503
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
504
-                    'order'      => 15,
505
-                    'url'        => isset($this->_req_data['_REG_ID'])
506
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
507
-                        : $this->_admin_base_url,
508
-                    'persistent' => false,
509
-                ),
510
-                'help_tabs'     => array(
511
-                    'registrations_details_help_tab'                    => array(
512
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
513
-                        'filename' => 'registrations_details',
514
-                    ),
515
-                    'registrations_details_table_help_tab'              => array(
516
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
517
-                        'filename' => 'registrations_details_table',
518
-                    ),
519
-                    'registrations_details_form_answers_help_tab'       => array(
520
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
521
-                        'filename' => 'registrations_details_form_answers',
522
-                    ),
523
-                    'registrations_details_registrant_details_help_tab' => array(
524
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
525
-                        'filename' => 'registrations_details_registrant_details',
526
-                    ),
527
-                ),
528
-                'help_tour'     => array('Registration_Details_Help_Tour'),
529
-                'metaboxes'     => array_merge(
530
-                    $this->_default_espresso_metaboxes,
531
-                    array('_registration_details_metaboxes')
532
-                ),
533
-                'require_nonce' => false,
534
-            ),
535
-            'new_registration'  => array(
536
-                'nav'           => array(
537
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
538
-                    'url'        => '#',
539
-                    'order'      => 15,
540
-                    'persistent' => false,
541
-                ),
542
-                'metaboxes'     => $this->_default_espresso_metaboxes,
543
-                'labels'        => array(
544
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
545
-                ),
546
-                'require_nonce' => false,
547
-            ),
548
-            'add_new_attendee'  => array(
549
-                'nav'           => array(
550
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
551
-                    'order'      => 15,
552
-                    'persistent' => false,
553
-                ),
554
-                'metaboxes'     => array_merge(
555
-                    $this->_default_espresso_metaboxes,
556
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
557
-                ),
558
-                'require_nonce' => false,
559
-            ),
560
-            'edit_attendee'     => array(
561
-                'nav'           => array(
562
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
563
-                    'order'      => 15,
564
-                    'persistent' => false,
565
-                    'url'        => isset($this->_req_data['ATT_ID'])
566
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
567
-                        : $this->_admin_base_url,
568
-                ),
569
-                'metaboxes'     => array('attendee_editor_metaboxes'),
570
-                'require_nonce' => false,
571
-            ),
572
-            'contact_list'      => array(
573
-                'nav'           => array(
574
-                    'label' => esc_html__('Contact List', 'event_espresso'),
575
-                    'order' => 20,
576
-                ),
577
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
578
-                'help_tabs'     => array(
579
-                    'registrations_contact_list_help_tab'                       => array(
580
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
581
-                        'filename' => 'registrations_contact_list',
582
-                    ),
583
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
584
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
585
-                        'filename' => 'registrations_contact_list_table_column_headings',
586
-                    ),
587
-                    'registrations_contact_list_views_help_tab'                 => array(
588
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
589
-                        'filename' => 'registrations_contact_list_views',
590
-                    ),
591
-                    'registrations_contact_list_other_help_tab'                 => array(
592
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
593
-                        'filename' => 'registrations_contact_list_other',
594
-                    ),
595
-                ),
596
-                'help_tour'     => array('Contact_List_Help_Tour'),
597
-                'metaboxes'     => array(),
598
-                'require_nonce' => false,
599
-            ),
600
-            //override default cpt routes
601
-            'create_new'        => '',
602
-            'edit'              => '',
603
-        );
604
-    }
605
-
606
-
607
-    /**
608
-     * The below methods aren't used by this class currently
609
-     */
610
-    protected function _add_screen_options()
611
-    {
612
-    }
613
-
614
-
615
-    protected function _add_feature_pointers()
616
-    {
617
-    }
618
-
619
-
620
-    public function admin_init()
621
-    {
622
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
623
-            'click "Update Registration Questions" to save your changes',
624
-            'event_espresso'
625
-        );
626
-    }
627
-
628
-
629
-    public function admin_notices()
630
-    {
631
-    }
632
-
633
-
634
-    public function admin_footer_scripts()
635
-    {
636
-    }
637
-
638
-
639
-    /**
640
-     *        get list of registration statuses
641
-     *
642
-     * @access private
643
-     * @return void
644
-     */
645
-    private function _get_registration_status_array()
646
-    {
647
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
648
-    }
649
-
650
-
651
-    protected function _add_screen_options_default()
652
-    {
653
-        $this->_per_page_screen_option();
654
-    }
655
-
656
-
657
-    protected function _add_screen_options_contact_list()
658
-    {
659
-        $page_title              = $this->_admin_page_title;
660
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
661
-        $this->_per_page_screen_option();
662
-        $this->_admin_page_title = $page_title;
663
-    }
664
-
665
-
666
-    public function load_scripts_styles()
667
-    {
668
-        //style
669
-        wp_register_style(
670
-            'espresso_reg',
671
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
672
-            array('ee-admin-css'),
673
-            EVENT_ESPRESSO_VERSION
674
-        );
675
-        wp_enqueue_style('espresso_reg');
676
-        //script
677
-        wp_register_script(
678
-            'espresso_reg',
679
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
680
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
681
-            EVENT_ESPRESSO_VERSION,
682
-            true
683
-        );
684
-        wp_enqueue_script('espresso_reg');
685
-    }
686
-
687
-
688
-    public function load_scripts_styles_edit_attendee()
689
-    {
690
-        //stuff to only show up on our attendee edit details page.
691
-        $attendee_details_translations = array(
692
-            'att_publish_text' => sprintf(
693
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
694
-                $this->_cpt_model_obj->get_datetime('ATT_created')
695
-            ),
696
-        );
697
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
698
-        wp_enqueue_script('jquery-validate');
699
-    }
700
-
701
-
702
-    public function load_scripts_styles_view_registration()
703
-    {
704
-        //styles
705
-        wp_enqueue_style('espresso-ui-theme');
706
-        //scripts
707
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
708
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
709
-    }
710
-
711
-
712
-    public function load_scripts_styles_contact_list()
713
-    {
714
-        wp_deregister_style('espresso_reg');
715
-        wp_register_style(
716
-            'espresso_att',
717
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
718
-            array('ee-admin-css'),
719
-            EVENT_ESPRESSO_VERSION
720
-        );
721
-        wp_enqueue_style('espresso_att');
722
-    }
723
-
724
-
725
-    public function load_scripts_styles_new_registration()
726
-    {
727
-        wp_register_script(
728
-            'ee-spco-for-admin',
729
-            REG_ASSETS_URL . 'spco_for_admin.js',
730
-            array('underscore', 'jquery'),
731
-            EVENT_ESPRESSO_VERSION,
732
-            true
733
-        );
734
-        wp_enqueue_script('ee-spco-for-admin');
735
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
736
-        EE_Form_Section_Proper::wp_enqueue_scripts();
737
-        EED_Ticket_Selector::load_tckt_slctr_assets();
738
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
739
-    }
740
-
741
-
742
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
743
-    {
744
-        add_filter('FHEE_load_EE_messages', '__return_true');
745
-    }
746
-
747
-
748
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
749
-    {
750
-        add_filter('FHEE_load_EE_messages', '__return_true');
751
-    }
752
-
753
-
754
-    protected function _set_list_table_views_default()
755
-    {
756
-        //for notification related bulk actions we need to make sure only active messengers have an option.
757
-        EED_Messages::set_autoloaders();
758
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
759
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
760
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
761
-        //key= bulk_action_slug, value= message type.
762
-        $match_array = array(
763
-            'approve_registrations'    => 'registration',
764
-            'decline_registrations'    => 'declined_registration',
765
-            'pending_registrations'    => 'pending_approval',
766
-            'no_approve_registrations' => 'not_approved_registration',
767
-            'cancel_registrations'     => 'cancelled_registration',
768
-        );
769
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
770
-            'ee_send_message',
771
-            'batch_send_messages'
772
-        );
773
-        /** setup reg status bulk actions **/
774
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
775
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
776
-                $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
777
-                    'Approve and Notify Registrations',
778
-                    'event_espresso'
779
-                );
780
-        }
781
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
782
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
783
-                $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
784
-                    'Decline and Notify Registrations',
785
-                    'event_espresso'
786
-                );
787
-        }
788
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
789
-            'Set Registrations to Pending Payment',
790
-            'event_espresso'
791
-        );
792
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
793
-                $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
794
-                    'Set Registrations to Pending Payment and Notify',
795
-                    'event_espresso'
796
-                );
797
-        }
798
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
799
-            'Set Registrations to Not Approved',
800
-            'event_espresso'
801
-        );
802
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
803
-                $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
804
-                    'Set Registrations to Not Approved and Notify',
805
-                    'event_espresso'
806
-                );
807
-        }
808
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
809
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
810
-                $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
811
-                    'Cancel Registrations and Notify',
812
-                    'event_espresso'
813
-                );
814
-        }
815
-        $def_reg_status_actions = apply_filters(
816
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
817
-            $def_reg_status_actions,
818
-            $active_mts,
819
-            $can_send
820
-        );
821
-
822
-        $this->_views = array(
823
-            'all'   => array(
824
-                'slug'        => 'all',
825
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
826
-                'count'       => 0,
827
-                'bulk_action' => array_merge($def_reg_status_actions, array(
828
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
829
-                )),
830
-            ),
831
-            'month' => array(
832
-                'slug'        => 'month',
833
-                'label'       => esc_html__('This Month', 'event_espresso'),
834
-                'count'       => 0,
835
-                'bulk_action' => array_merge($def_reg_status_actions, array(
836
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
837
-                )),
838
-            ),
839
-            'today' => array(
840
-                'slug'        => 'today',
841
-                'label'       => sprintf(
842
-                    esc_html__('Today - %s', 'event_espresso'),
843
-                    date('M d, Y', current_time('timestamp'))
844
-                ),
845
-                'count'       => 0,
846
-                'bulk_action' => array_merge($def_reg_status_actions, array(
847
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
848
-                )),
849
-            ),
850
-        );
851
-        if (EE_Registry::instance()->CAP->current_user_can(
852
-            'ee_delete_registrations',
853
-            'espresso_registrations_delete_registration'
854
-        )) {
855
-            $this->_views['incomplete'] = array(
856
-                'slug'        => 'incomplete',
857
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
858
-                'count'       => 0,
859
-                'bulk_action' => array(
860
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
861
-                ),
862
-            );
863
-            $this->_views['trash']      = array(
864
-                'slug'        => 'trash',
865
-                'label'       => esc_html__('Trash', 'event_espresso'),
866
-                'count'       => 0,
867
-                'bulk_action' => array(
868
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
869
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
870
-                ),
871
-            );
872
-        }
873
-    }
874
-
875
-
876
-    protected function _set_list_table_views_contact_list()
877
-    {
878
-        $this->_views = array(
879
-            'in_use' => array(
880
-                'slug'        => 'in_use',
881
-                'label'       => esc_html__('In Use', 'event_espresso'),
882
-                'count'       => 0,
883
-                'bulk_action' => array(
884
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
885
-                ),
886
-            ),
887
-        );
888
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
889
-            'espresso_registrations_trash_attendees')
890
-        ) {
891
-            $this->_views['trash'] = array(
892
-                'slug'        => 'trash',
893
-                'label'       => esc_html__('Trash', 'event_espresso'),
894
-                'count'       => 0,
895
-                'bulk_action' => array(
896
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
897
-                ),
898
-            );
899
-        }
900
-    }
901
-
902
-
903
-    protected function _registration_legend_items()
904
-    {
905
-        $fc_items = array(
906
-            'star-icon'        => array(
907
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
908
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
909
-            ),
910
-            'view_details'     => array(
911
-                'class' => 'dashicons dashicons-clipboard',
912
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
913
-            ),
914
-            'edit_attendee'    => array(
915
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
916
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
917
-            ),
918
-            'view_transaction' => array(
919
-                'class' => 'dashicons dashicons-cart',
920
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
921
-            ),
922
-            'view_invoice'     => array(
923
-                'class' => 'dashicons dashicons-media-spreadsheet',
924
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
925
-            ),
926
-        );
927
-        if (EE_Registry::instance()->CAP->current_user_can(
928
-            'ee_send_message',
929
-            'espresso_registrations_resend_registration'
930
-        )) {
931
-            $fc_items['resend_registration'] = array(
932
-                'class' => 'dashicons dashicons-email-alt',
933
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
934
-            );
935
-        } else {
936
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
937
-        }
938
-        if (EE_Registry::instance()->CAP->current_user_can(
939
-            'ee_read_global_messages',
940
-            'view_filtered_messages'
941
-        )) {
942
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
943
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
944
-                $fc_items['view_related_messages'] = array(
945
-                    'class' => $related_for_icon['css_class'],
946
-                    'desc'  => $related_for_icon['label'],
947
-                );
948
-            }
949
-        }
950
-        $sc_items = array(
951
-            'approved_status'   => array(
952
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
953
-                'desc'  => EEH_Template::pretty_status(
954
-                    EEM_Registration::status_id_approved,
955
-                    false,
956
-                    'sentence'
957
-                ),
958
-            ),
959
-            'pending_status'    => array(
960
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
961
-                'desc'  => EEH_Template::pretty_status(
962
-                    EEM_Registration::status_id_pending_payment,
963
-                    false,
964
-                    'sentence'
965
-                ),
966
-            ),
967
-            'wait_list'         => array(
968
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
969
-                'desc'  => EEH_Template::pretty_status(
970
-                    EEM_Registration::status_id_wait_list,
971
-                    false,
972
-                    'sentence'
973
-                ),
974
-            ),
975
-            'incomplete_status' => array(
976
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
977
-                'desc'  => EEH_Template::pretty_status(
978
-                    EEM_Registration::status_id_incomplete,
979
-                    false,
980
-                    'sentence'
981
-                ),
982
-            ),
983
-            'not_approved'      => array(
984
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
985
-                'desc'  => EEH_Template::pretty_status(
986
-                    EEM_Registration::status_id_not_approved,
987
-                    false,
988
-                    'sentence'
989
-                ),
990
-            ),
991
-            'declined_status'   => array(
992
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
993
-                'desc'  => EEH_Template::pretty_status(
994
-                    EEM_Registration::status_id_declined,
995
-                    false,
996
-                    'sentence'
997
-                ),
998
-            ),
999
-            'cancelled_status'  => array(
1000
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1001
-                'desc'  => EEH_Template::pretty_status(
1002
-                    EEM_Registration::status_id_cancelled,
1003
-                    false,
1004
-                    'sentence'
1005
-                ),
1006
-            ),
1007
-        );
1008
-        return array_merge($fc_items, $sc_items);
1009
-    }
1010
-
1011
-
1012
-
1013
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1014
-    /**
1015
-     * @throws \EE_Error
1016
-     */
1017
-    protected function _registrations_overview_list_table()
1018
-    {
1019
-        $this->_template_args['admin_page_header'] = '';
1020
-        $EVT_ID                                    = ! empty($this->_req_data['event_id'])
1021
-            ? absint($this->_req_data['event_id'])
1022
-            : 0;
1023
-        if ($EVT_ID) {
1024
-            if (EE_Registry::instance()->CAP->current_user_can(
1025
-                'ee_edit_registrations',
1026
-                'espresso_registrations_new_registration',
1027
-                $EVT_ID
1028
-            )) {
1029
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1030
-                    'new_registration',
1031
-                    'add-registrant',
1032
-                    array('event_id' => $EVT_ID),
1033
-                    'add-new-h2'
1034
-                );
1035
-            }
1036
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1037
-            if ($event instanceof EE_Event) {
1038
-                $this->_template_args['admin_page_header'] = sprintf(
1039
-                    esc_html__(
1040
-                        '%s Viewing registrations for the event: %s%s',
1041
-                        'event_espresso'
1042
-                    ),
1043
-                    '<h3 style="line-height:1.5em;">',
1044
-                    '<br /><a href="'
1045
-                        . EE_Admin_Page::add_query_args_and_nonce(
1046
-                            array(
1047
-                                'action' => 'edit',
1048
-                                'post'   => $event->ID(),
1049
-                            ),
1050
-                            EVENTS_ADMIN_URL
1051
-                        )
1052
-                        . '">&nbsp;'
1053
-                        . $event->get('EVT_name')
1054
-                        . '&nbsp;</a>&nbsp;',
1055
-                    '</h3>'
1056
-                );
1057
-            }
1058
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1059
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1060
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1061
-                $this->_template_args['admin_page_header'] = substr(
1062
-                    $this->_template_args['admin_page_header'],
1063
-                    0,
1064
-                    -5
1065
-                );
1066
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1067
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1068
-                $this->_template_args['admin_page_header'] .= $datetime->name();
1069
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1070
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
1071
-            }
1072
-        }
1073
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1074
-        $this->display_admin_list_table_page_with_no_sidebar();
1075
-    }
1076
-
1077
-
1078
-    /**
1079
-     * This sets the _registration property for the registration details screen
1080
-     *
1081
-     * @access private
1082
-     * @return bool
1083
-     */
1084
-    private function _set_registration_object()
1085
-    {
1086
-        //get out if we've already set the object
1087
-        if ($this->_registration instanceof EE_Registration) {
1088
-            return true;
1089
-        }
1090
-        $REG    = EEM_Registration::instance();
1091
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1092
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1093
-            return true;
1094
-        } else {
1095
-            $error_msg = sprintf(
1096
-                esc_html__(
1097
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1098
-                    'event_espresso'
1099
-                ),
1100
-                $REG_ID
1101
-            );
1102
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1103
-            $this->_registration = null;
1104
-            return false;
1105
-        }
1106
-    }
1107
-
1108
-
1109
-    /**
1110
-     * Used to retrieve registrations for the list table.
1111
-     *
1112
-     * @param int  $per_page
1113
-     * @param bool $count
1114
-     * @param bool $this_month
1115
-     * @param bool $today
1116
-     * @return EE_Registration[]|int
1117
-     * @throws EE_Error
1118
-     */
1119
-    public function get_registrations(
1120
-        $per_page = 10,
1121
-        $count = false,
1122
-        $this_month = false,
1123
-        $today = false
1124
-    ) {
1125
-        if ($this_month) {
1126
-            $this->_req_data['status'] = 'month';
1127
-        }
1128
-        if ($today) {
1129
-            $this->_req_data['status'] = 'today';
1130
-        }
1131
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1132
-        /**
1133
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1134
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1135
-         * @see EEM_Base::get_all()
1136
-         */
1137
-        $query_params['group_by'] = '';
1138
-
1139
-        return $count
1140
-            ? EEM_Registration::instance()->count($query_params)
1141
-            /** @type EE_Registration[] */
1142
-            : EEM_Registration::instance()->get_all($query_params);
1143
-    }
1144
-
1145
-
1146
-
1147
-    /**
1148
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1149
-     * Note: this listens to values on the request for some of the query parameters.
1150
-     *
1151
-     * @param array $request
1152
-     * @param int    $per_page
1153
-     * @param bool   $count
1154
-     * @return array
1155
-     */
1156
-    protected function _get_registration_query_parameters(
1157
-        $request = array(),
1158
-        $per_page = 10,
1159
-        $count = false
1160
-    ) {
1161
-
1162
-        $query_params = array(
1163
-            0                          => $this->_get_where_conditions_for_registrations_query(
1164
-                $request
1165
-            ),
1166
-            'caps'                     => EEM_Registration::caps_read_admin,
1167
-            'default_where_conditions' => 'this_model_only',
1168
-        );
1169
-        if (! $count) {
1170
-            $query_params = array_merge(
1171
-                $query_params,
1172
-                $this->_get_orderby_for_registrations_query(),
1173
-                $this->_get_limit($per_page)
1174
-            );
1175
-        }
1176
-
1177
-        return $query_params;
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1183
-     *
1184
-     * @param array $request usually the same as $this->_req_data but not necessarily
1185
-     * @return array
1186
-     */
1187
-    protected function _add_event_id_to_where_conditions(array $request)
1188
-    {
1189
-        $where = array();
1190
-        if (! empty($request['event_id'])) {
1191
-            $where['EVT_ID'] = absint($request['event_id']);
1192
-        }
1193
-        return $where;
1194
-    }
1195
-
1196
-
1197
-    /**
1198
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1199
-     *
1200
-     * @param array $request usually the same as $this->_req_data but not necessarily
1201
-     * @return array
1202
-     */
1203
-    protected function _add_category_id_to_where_conditions(array $request)
1204
-    {
1205
-        $where = array();
1206
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1207
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1208
-        }
1209
-        return $where;
1210
-    }
1211
-
1212
-
1213
-    /**
1214
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1215
-     *
1216
-     * @param array $request usually the same as $this->_req_data but not necessarily
1217
-     * @return array
1218
-     */
1219
-    protected function _add_datetime_id_to_where_conditions(array $request)
1220
-    {
1221
-        $where = array();
1222
-        if (! empty($request['datetime_id'])) {
1223
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1224
-        }
1225
-        if (! empty($request['DTT_ID'])) {
1226
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1227
-        }
1228
-        return $where;
1229
-    }
1230
-
1231
-
1232
-    /**
1233
-     * Adds the correct registration status to the where conditions for the registrations query.
1234
-     *
1235
-     * @param array $request usually the same as $this->_req_data but not necessarily
1236
-     * @return array
1237
-     */
1238
-    protected function _add_registration_status_to_where_conditions(array $request)
1239
-    {
1240
-        $where = array();
1241
-        $view = EEH_Array::is_set($request, 'status', '');
1242
-        $registration_status = ! empty($request['_reg_status'])
1243
-            ? sanitize_text_field($request['_reg_status'])
1244
-            : '';
1245
-
1246
-        /*
33
+	/**
34
+	 * @var EE_Registration
35
+	 */
36
+	private $_registration;
37
+
38
+	/**
39
+	 * @var EE_Event
40
+	 */
41
+	private $_reg_event;
42
+
43
+	/**
44
+	 * @var EE_Session
45
+	 */
46
+	private $_session;
47
+
48
+	private static $_reg_status;
49
+
50
+	/**
51
+	 * Form for displaying the custom questions for this registration.
52
+	 * This gets used a few times throughout the request so its best to cache it
53
+	 *
54
+	 * @var EE_Registration_Custom_Questions_Form
55
+	 */
56
+	protected $_reg_custom_questions_form = null;
57
+
58
+
59
+	/**
60
+	 *        constructor
61
+	 *
62
+	 * @Constructor
63
+	 * @access public
64
+	 * @param bool $routing
65
+	 * @return Registrations_Admin_Page
66
+	 */
67
+	public function __construct($routing = true)
68
+	{
69
+		parent::__construct($routing);
70
+		add_action('wp_loaded', array($this, 'wp_loaded'));
71
+	}
72
+
73
+
74
+	public function wp_loaded()
75
+	{
76
+		// when adding a new registration...
77
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78
+			EE_System::do_not_cache();
79
+			if (! isset($this->_req_data['processing_registration'])
80
+				 || absint($this->_req_data['processing_registration']) !== 1
81
+			) {
82
+				// and it's NOT the attendee information reg step
83
+				// force cookie expiration by setting time to last week
84
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
85
+				// and update the global
86
+				$_COOKIE['ee_registration_added'] = 0;
87
+			}
88
+		}
89
+	}
90
+
91
+
92
+	protected function _init_page_props()
93
+	{
94
+		$this->page_slug        = REG_PG_SLUG;
95
+		$this->_admin_base_url  = REG_ADMIN_URL;
96
+		$this->_admin_base_path = REG_ADMIN;
97
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
98
+		$this->_cpt_routes      = array(
99
+			'add_new_attendee' => 'espresso_attendees',
100
+			'edit_attendee'    => 'espresso_attendees',
101
+			'insert_attendee'  => 'espresso_attendees',
102
+			'update_attendee'  => 'espresso_attendees',
103
+		);
104
+		$this->_cpt_model_names = array(
105
+			'add_new_attendee' => 'EEM_Attendee',
106
+			'edit_attendee'    => 'EEM_Attendee',
107
+		);
108
+		$this->_cpt_edit_routes = array(
109
+			'espresso_attendees' => 'edit_attendee',
110
+		);
111
+		$this->_pagenow_map     = array(
112
+			'add_new_attendee' => 'post-new.php',
113
+			'edit_attendee'    => 'post.php',
114
+			'trash'            => 'post.php',
115
+		);
116
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
117
+		//add filters so that the comment urls don't take users to a confusing 404 page
118
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
119
+	}
120
+
121
+
122
+	public function clear_comment_link($link, $comment, $args)
123
+	{
124
+		//gotta make sure this only happens on this route
125
+		$post_type = get_post_type($comment->comment_post_ID);
126
+		if ($post_type === 'espresso_attendees') {
127
+			return '#commentsdiv';
128
+		}
129
+		return $link;
130
+	}
131
+
132
+
133
+	protected function _ajax_hooks()
134
+	{
135
+		//todo: all hooks for registrations ajax goes in here
136
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
137
+	}
138
+
139
+
140
+	protected function _define_page_props()
141
+	{
142
+		$this->_admin_page_title = $this->page_label;
143
+		$this->_labels           = array(
144
+			'buttons'                      => array(
145
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
146
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
147
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
148
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
149
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
150
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
151
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
152
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
153
+			),
154
+			'publishbox'                   => array(
155
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
156
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
157
+			),
158
+			'hide_add_button_on_cpt_route' => array(
159
+				'edit_attendee' => true,
160
+			),
161
+		);
162
+	}
163
+
164
+
165
+	/**
166
+	 *        grab url requests and route them
167
+	 *
168
+	 * @access private
169
+	 * @return void
170
+	 */
171
+	public function _set_page_routes()
172
+	{
173
+		$this->_get_registration_status_array();
174
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175
+			? $this->_req_data['_REG_ID'] : 0;
176
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177
+			? $this->_req_data['reg_status_change_form']['REG_ID']
178
+			: $reg_id;
179
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
180
+			? $this->_req_data['ATT_ID'] : 0;
181
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
182
+			? $this->_req_data['post']
183
+			: $att_id;
184
+		$this->_page_routes = array(
185
+			'default'                            => array(
186
+				'func'       => '_registrations_overview_list_table',
187
+				'capability' => 'ee_read_registrations',
188
+			),
189
+			'view_registration'                  => array(
190
+				'func'       => '_registration_details',
191
+				'capability' => 'ee_read_registration',
192
+				'obj_id'     => $reg_id,
193
+			),
194
+			'edit_registration'                  => array(
195
+				'func'               => '_update_attendee_registration_form',
196
+				'noheader'           => true,
197
+				'headers_sent_route' => 'view_registration',
198
+				'capability'         => 'ee_edit_registration',
199
+				'obj_id'             => $reg_id,
200
+				'_REG_ID'            => $reg_id,
201
+			),
202
+			'trash_registrations'                => array(
203
+				'func'       => '_trash_or_restore_registrations',
204
+				'args'       => array('trash' => true),
205
+				'noheader'   => true,
206
+				'capability' => 'ee_delete_registrations',
207
+			),
208
+			'restore_registrations'              => array(
209
+				'func'       => '_trash_or_restore_registrations',
210
+				'args'       => array('trash' => false),
211
+				'noheader'   => true,
212
+				'capability' => 'ee_delete_registrations',
213
+			),
214
+			'delete_registrations'               => array(
215
+				'func'       => '_delete_registrations',
216
+				'noheader'   => true,
217
+				'capability' => 'ee_delete_registrations',
218
+			),
219
+			'new_registration'                   => array(
220
+				'func'       => 'new_registration',
221
+				'capability' => 'ee_edit_registrations',
222
+			),
223
+			'process_reg_step'                   => array(
224
+				'func'       => 'process_reg_step',
225
+				'noheader'   => true,
226
+				'capability' => 'ee_edit_registrations',
227
+			),
228
+			'redirect_to_txn'                    => array(
229
+				'func'       => 'redirect_to_txn',
230
+				'noheader'   => true,
231
+				'capability' => 'ee_edit_registrations',
232
+			),
233
+			'change_reg_status'                  => array(
234
+				'func'       => '_change_reg_status',
235
+				'noheader'   => true,
236
+				'capability' => 'ee_edit_registration',
237
+				'obj_id'     => $reg_id,
238
+			),
239
+			'approve_registration'               => array(
240
+				'func'       => 'approve_registration',
241
+				'noheader'   => true,
242
+				'capability' => 'ee_edit_registration',
243
+				'obj_id'     => $reg_id,
244
+			),
245
+			'approve_and_notify_registration'    => array(
246
+				'func'       => 'approve_registration',
247
+				'noheader'   => true,
248
+				'args'       => array(true),
249
+				'capability' => 'ee_edit_registration',
250
+				'obj_id'     => $reg_id,
251
+			),
252
+			'approve_registrations'               => array(
253
+				'func'       => 'bulk_action_on_registrations',
254
+				'noheader'   => true,
255
+				'capability' => 'ee_edit_registrations',
256
+				'args' => array('approve')
257
+			),
258
+			'approve_and_notify_registrations'               => array(
259
+				'func'       => 'bulk_action_on_registrations',
260
+				'noheader'   => true,
261
+				'capability' => 'ee_edit_registrations',
262
+				'args' => array('approve', true)
263
+			),
264
+			'decline_registration'               => array(
265
+				'func'       => 'decline_registration',
266
+				'noheader'   => true,
267
+				'capability' => 'ee_edit_registration',
268
+				'obj_id'     => $reg_id,
269
+			),
270
+			'decline_and_notify_registration'    => array(
271
+				'func'       => 'decline_registration',
272
+				'noheader'   => true,
273
+				'args'       => array(true),
274
+				'capability' => 'ee_edit_registration',
275
+				'obj_id'     => $reg_id,
276
+			),
277
+			'decline_registrations'               => array(
278
+				'func'       => 'bulk_action_on_registrations',
279
+				'noheader'   => true,
280
+				'capability' => 'ee_edit_registrations',
281
+				'args' => array('decline')
282
+			),
283
+			'decline_and_notify_registrations'    => array(
284
+				'func'       => 'bulk_action_on_registrations',
285
+				'noheader'   => true,
286
+				'capability' => 'ee_edit_registrations',
287
+				'args' => array('decline', true)
288
+			),
289
+			'pending_registration'               => array(
290
+				'func'       => 'pending_registration',
291
+				'noheader'   => true,
292
+				'capability' => 'ee_edit_registration',
293
+				'obj_id'     => $reg_id,
294
+			),
295
+			'pending_and_notify_registration'    => array(
296
+				'func'       => 'pending_registration',
297
+				'noheader'   => true,
298
+				'args'       => array(true),
299
+				'capability' => 'ee_edit_registration',
300
+				'obj_id'     => $reg_id,
301
+			),
302
+			'pending_registrations'               => array(
303
+				'func'       => 'bulk_action_on_registrations',
304
+				'noheader'   => true,
305
+				'capability' => 'ee_edit_registrations',
306
+				'args' => array('pending')
307
+			),
308
+			'pending_and_notify_registrations'    => array(
309
+				'func'       => 'bulk_action_on_registrations',
310
+				'noheader'   => true,
311
+				'capability' => 'ee_edit_registrations',
312
+				'args' => array('pending', true)
313
+			),
314
+			'no_approve_registration'            => array(
315
+				'func'       => 'not_approve_registration',
316
+				'noheader'   => true,
317
+				'capability' => 'ee_edit_registration',
318
+				'obj_id'     => $reg_id,
319
+			),
320
+			'no_approve_and_notify_registration' => array(
321
+				'func'       => 'not_approve_registration',
322
+				'noheader'   => true,
323
+				'args'       => array(true),
324
+				'capability' => 'ee_edit_registration',
325
+				'obj_id'     => $reg_id,
326
+			),
327
+			'no_approve_registrations'            => array(
328
+				'func'       => 'bulk_action_on_registrations',
329
+				'noheader'   => true,
330
+				'capability' => 'ee_edit_registrations',
331
+				'args' => array('not_approve')
332
+			),
333
+			'no_approve_and_notify_registrations' => array(
334
+				'func'       => 'bulk_action_on_registrations',
335
+				'noheader'   => true,
336
+				'capability' => 'ee_edit_registrations',
337
+				'args' => array('not_approve', true)
338
+			),
339
+			'cancel_registration'                => array(
340
+				'func'       => 'cancel_registration',
341
+				'noheader'   => true,
342
+				'capability' => 'ee_edit_registration',
343
+				'obj_id'     => $reg_id,
344
+			),
345
+			'cancel_and_notify_registration'     => array(
346
+				'func'       => 'cancel_registration',
347
+				'noheader'   => true,
348
+				'args'       => array(true),
349
+				'capability' => 'ee_edit_registration',
350
+				'obj_id'     => $reg_id,
351
+			),
352
+			'cancel_registrations'                => array(
353
+				'func'       => 'bulk_action_on_registrations',
354
+				'noheader'   => true,
355
+				'capability' => 'ee_edit_registrations',
356
+				'args' => array('cancel')
357
+			),
358
+			'cancel_and_notify_registrations'     => array(
359
+				'func'       => 'bulk_action_on_registrations',
360
+				'noheader'   => true,
361
+				'capability' => 'ee_edit_registrations',
362
+				'args' => array('cancel', true)
363
+			),
364
+			'wait_list_registration' => array(
365
+				'func'       => 'wait_list_registration',
366
+				'noheader'   => true,
367
+				'capability' => 'ee_edit_registration',
368
+				'obj_id'     => $reg_id,
369
+			),
370
+			'wait_list_and_notify_registration' => array(
371
+				'func'       => 'wait_list_registration',
372
+				'noheader'   => true,
373
+				'args'       => array(true),
374
+				'capability' => 'ee_edit_registration',
375
+				'obj_id'     => $reg_id,
376
+			),
377
+			'contact_list'                       => array(
378
+				'func'       => '_attendee_contact_list_table',
379
+				'capability' => 'ee_read_contacts',
380
+			),
381
+			'add_new_attendee'                   => array(
382
+				'func' => '_create_new_cpt_item',
383
+				'args' => array(
384
+					'new_attendee' => true,
385
+					'capability'   => 'ee_edit_contacts',
386
+				),
387
+			),
388
+			'edit_attendee'                      => array(
389
+				'func'       => '_edit_cpt_item',
390
+				'capability' => 'ee_edit_contacts',
391
+				'obj_id'     => $att_id,
392
+			),
393
+			'duplicate_attendee'                 => array(
394
+				'func'       => '_duplicate_attendee',
395
+				'noheader'   => true,
396
+				'capability' => 'ee_edit_contacts',
397
+				'obj_id'     => $att_id,
398
+			),
399
+			'insert_attendee'                    => array(
400
+				'func'       => '_insert_or_update_attendee',
401
+				'args'       => array(
402
+					'new_attendee' => true,
403
+				),
404
+				'noheader'   => true,
405
+				'capability' => 'ee_edit_contacts',
406
+			),
407
+			'update_attendee'                    => array(
408
+				'func'       => '_insert_or_update_attendee',
409
+				'args'       => array(
410
+					'new_attendee' => false,
411
+				),
412
+				'noheader'   => true,
413
+				'capability' => 'ee_edit_contacts',
414
+				'obj_id'     => $att_id,
415
+			),
416
+			'trash_attendees' => array(
417
+				'func' => '_trash_or_restore_attendees',
418
+				'args' => array(
419
+					'trash' => 'true'
420
+				),
421
+				'noheader' => true,
422
+				'capability' => 'ee_delete_contacts'
423
+			),
424
+			'trash_attendee'                    => array(
425
+				'func'       => '_trash_or_restore_attendees',
426
+				'args'       => array(
427
+					'trash' => true,
428
+				),
429
+				'noheader'   => true,
430
+				'capability' => 'ee_delete_contacts',
431
+				'obj_id'     => $att_id,
432
+			),
433
+			'restore_attendees'                  => array(
434
+				'func'       => '_trash_or_restore_attendees',
435
+				'args'       => array(
436
+					'trash' => false,
437
+				),
438
+				'noheader'   => true,
439
+				'capability' => 'ee_delete_contacts',
440
+				'obj_id'     => $att_id,
441
+			),
442
+			'resend_registration'                => array(
443
+				'func'       => '_resend_registration',
444
+				'noheader'   => true,
445
+				'capability' => 'ee_send_message',
446
+			),
447
+			'registrations_report'               => array(
448
+				'func'       => '_registrations_report',
449
+				'noheader'   => true,
450
+				'capability' => 'ee_read_registrations',
451
+			),
452
+			'contact_list_export'                => array(
453
+				'func'       => '_contact_list_export',
454
+				'noheader'   => true,
455
+				'capability' => 'export',
456
+			),
457
+			'contact_list_report'                => array(
458
+				'func'       => '_contact_list_report',
459
+				'noheader'   => true,
460
+				'capability' => 'ee_read_contacts',
461
+			),
462
+		);
463
+	}
464
+
465
+
466
+	protected function _set_page_config()
467
+	{
468
+		$this->_page_config = array(
469
+			'default'           => array(
470
+				'nav'           => array(
471
+					'label' => esc_html__('Overview', 'event_espresso'),
472
+					'order' => 5,
473
+				),
474
+				'help_tabs'     => array(
475
+					'registrations_overview_help_tab'                       => array(
476
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
477
+						'filename' => 'registrations_overview',
478
+					),
479
+					'registrations_overview_table_column_headings_help_tab' => array(
480
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
481
+						'filename' => 'registrations_overview_table_column_headings',
482
+					),
483
+					'registrations_overview_filters_help_tab'               => array(
484
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
485
+						'filename' => 'registrations_overview_filters',
486
+					),
487
+					'registrations_overview_views_help_tab'                 => array(
488
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
489
+						'filename' => 'registrations_overview_views',
490
+					),
491
+					'registrations_regoverview_other_help_tab'              => array(
492
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
493
+						'filename' => 'registrations_overview_other',
494
+					),
495
+				),
496
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
497
+				'qtips'         => array('Registration_List_Table_Tips'),
498
+				'list_table'    => 'EE_Registrations_List_Table',
499
+				'require_nonce' => false,
500
+			),
501
+			'view_registration' => array(
502
+				'nav'           => array(
503
+					'label'      => esc_html__('REG Details', 'event_espresso'),
504
+					'order'      => 15,
505
+					'url'        => isset($this->_req_data['_REG_ID'])
506
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
507
+						: $this->_admin_base_url,
508
+					'persistent' => false,
509
+				),
510
+				'help_tabs'     => array(
511
+					'registrations_details_help_tab'                    => array(
512
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
513
+						'filename' => 'registrations_details',
514
+					),
515
+					'registrations_details_table_help_tab'              => array(
516
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
517
+						'filename' => 'registrations_details_table',
518
+					),
519
+					'registrations_details_form_answers_help_tab'       => array(
520
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
521
+						'filename' => 'registrations_details_form_answers',
522
+					),
523
+					'registrations_details_registrant_details_help_tab' => array(
524
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
525
+						'filename' => 'registrations_details_registrant_details',
526
+					),
527
+				),
528
+				'help_tour'     => array('Registration_Details_Help_Tour'),
529
+				'metaboxes'     => array_merge(
530
+					$this->_default_espresso_metaboxes,
531
+					array('_registration_details_metaboxes')
532
+				),
533
+				'require_nonce' => false,
534
+			),
535
+			'new_registration'  => array(
536
+				'nav'           => array(
537
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
538
+					'url'        => '#',
539
+					'order'      => 15,
540
+					'persistent' => false,
541
+				),
542
+				'metaboxes'     => $this->_default_espresso_metaboxes,
543
+				'labels'        => array(
544
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
545
+				),
546
+				'require_nonce' => false,
547
+			),
548
+			'add_new_attendee'  => array(
549
+				'nav'           => array(
550
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
551
+					'order'      => 15,
552
+					'persistent' => false,
553
+				),
554
+				'metaboxes'     => array_merge(
555
+					$this->_default_espresso_metaboxes,
556
+					array('_publish_post_box', 'attendee_editor_metaboxes')
557
+				),
558
+				'require_nonce' => false,
559
+			),
560
+			'edit_attendee'     => array(
561
+				'nav'           => array(
562
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
563
+					'order'      => 15,
564
+					'persistent' => false,
565
+					'url'        => isset($this->_req_data['ATT_ID'])
566
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
567
+						: $this->_admin_base_url,
568
+				),
569
+				'metaboxes'     => array('attendee_editor_metaboxes'),
570
+				'require_nonce' => false,
571
+			),
572
+			'contact_list'      => array(
573
+				'nav'           => array(
574
+					'label' => esc_html__('Contact List', 'event_espresso'),
575
+					'order' => 20,
576
+				),
577
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
578
+				'help_tabs'     => array(
579
+					'registrations_contact_list_help_tab'                       => array(
580
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
581
+						'filename' => 'registrations_contact_list',
582
+					),
583
+					'registrations_contact-list_table_column_headings_help_tab' => array(
584
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
585
+						'filename' => 'registrations_contact_list_table_column_headings',
586
+					),
587
+					'registrations_contact_list_views_help_tab'                 => array(
588
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
589
+						'filename' => 'registrations_contact_list_views',
590
+					),
591
+					'registrations_contact_list_other_help_tab'                 => array(
592
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
593
+						'filename' => 'registrations_contact_list_other',
594
+					),
595
+				),
596
+				'help_tour'     => array('Contact_List_Help_Tour'),
597
+				'metaboxes'     => array(),
598
+				'require_nonce' => false,
599
+			),
600
+			//override default cpt routes
601
+			'create_new'        => '',
602
+			'edit'              => '',
603
+		);
604
+	}
605
+
606
+
607
+	/**
608
+	 * The below methods aren't used by this class currently
609
+	 */
610
+	protected function _add_screen_options()
611
+	{
612
+	}
613
+
614
+
615
+	protected function _add_feature_pointers()
616
+	{
617
+	}
618
+
619
+
620
+	public function admin_init()
621
+	{
622
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
623
+			'click "Update Registration Questions" to save your changes',
624
+			'event_espresso'
625
+		);
626
+	}
627
+
628
+
629
+	public function admin_notices()
630
+	{
631
+	}
632
+
633
+
634
+	public function admin_footer_scripts()
635
+	{
636
+	}
637
+
638
+
639
+	/**
640
+	 *        get list of registration statuses
641
+	 *
642
+	 * @access private
643
+	 * @return void
644
+	 */
645
+	private function _get_registration_status_array()
646
+	{
647
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
648
+	}
649
+
650
+
651
+	protected function _add_screen_options_default()
652
+	{
653
+		$this->_per_page_screen_option();
654
+	}
655
+
656
+
657
+	protected function _add_screen_options_contact_list()
658
+	{
659
+		$page_title              = $this->_admin_page_title;
660
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
661
+		$this->_per_page_screen_option();
662
+		$this->_admin_page_title = $page_title;
663
+	}
664
+
665
+
666
+	public function load_scripts_styles()
667
+	{
668
+		//style
669
+		wp_register_style(
670
+			'espresso_reg',
671
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
672
+			array('ee-admin-css'),
673
+			EVENT_ESPRESSO_VERSION
674
+		);
675
+		wp_enqueue_style('espresso_reg');
676
+		//script
677
+		wp_register_script(
678
+			'espresso_reg',
679
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
680
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
681
+			EVENT_ESPRESSO_VERSION,
682
+			true
683
+		);
684
+		wp_enqueue_script('espresso_reg');
685
+	}
686
+
687
+
688
+	public function load_scripts_styles_edit_attendee()
689
+	{
690
+		//stuff to only show up on our attendee edit details page.
691
+		$attendee_details_translations = array(
692
+			'att_publish_text' => sprintf(
693
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
694
+				$this->_cpt_model_obj->get_datetime('ATT_created')
695
+			),
696
+		);
697
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
698
+		wp_enqueue_script('jquery-validate');
699
+	}
700
+
701
+
702
+	public function load_scripts_styles_view_registration()
703
+	{
704
+		//styles
705
+		wp_enqueue_style('espresso-ui-theme');
706
+		//scripts
707
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
708
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
709
+	}
710
+
711
+
712
+	public function load_scripts_styles_contact_list()
713
+	{
714
+		wp_deregister_style('espresso_reg');
715
+		wp_register_style(
716
+			'espresso_att',
717
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
718
+			array('ee-admin-css'),
719
+			EVENT_ESPRESSO_VERSION
720
+		);
721
+		wp_enqueue_style('espresso_att');
722
+	}
723
+
724
+
725
+	public function load_scripts_styles_new_registration()
726
+	{
727
+		wp_register_script(
728
+			'ee-spco-for-admin',
729
+			REG_ASSETS_URL . 'spco_for_admin.js',
730
+			array('underscore', 'jquery'),
731
+			EVENT_ESPRESSO_VERSION,
732
+			true
733
+		);
734
+		wp_enqueue_script('ee-spco-for-admin');
735
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
736
+		EE_Form_Section_Proper::wp_enqueue_scripts();
737
+		EED_Ticket_Selector::load_tckt_slctr_assets();
738
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
739
+	}
740
+
741
+
742
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
743
+	{
744
+		add_filter('FHEE_load_EE_messages', '__return_true');
745
+	}
746
+
747
+
748
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
749
+	{
750
+		add_filter('FHEE_load_EE_messages', '__return_true');
751
+	}
752
+
753
+
754
+	protected function _set_list_table_views_default()
755
+	{
756
+		//for notification related bulk actions we need to make sure only active messengers have an option.
757
+		EED_Messages::set_autoloaders();
758
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
759
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
760
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
761
+		//key= bulk_action_slug, value= message type.
762
+		$match_array = array(
763
+			'approve_registrations'    => 'registration',
764
+			'decline_registrations'    => 'declined_registration',
765
+			'pending_registrations'    => 'pending_approval',
766
+			'no_approve_registrations' => 'not_approved_registration',
767
+			'cancel_registrations'     => 'cancelled_registration',
768
+		);
769
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
770
+			'ee_send_message',
771
+			'batch_send_messages'
772
+		);
773
+		/** setup reg status bulk actions **/
774
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
775
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
776
+				$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
777
+					'Approve and Notify Registrations',
778
+					'event_espresso'
779
+				);
780
+		}
781
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
782
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
783
+				$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
784
+					'Decline and Notify Registrations',
785
+					'event_espresso'
786
+				);
787
+		}
788
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
789
+			'Set Registrations to Pending Payment',
790
+			'event_espresso'
791
+		);
792
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
793
+				$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
794
+					'Set Registrations to Pending Payment and Notify',
795
+					'event_espresso'
796
+				);
797
+		}
798
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
799
+			'Set Registrations to Not Approved',
800
+			'event_espresso'
801
+		);
802
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
803
+				$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
804
+					'Set Registrations to Not Approved and Notify',
805
+					'event_espresso'
806
+				);
807
+		}
808
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
809
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
810
+				$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
811
+					'Cancel Registrations and Notify',
812
+					'event_espresso'
813
+				);
814
+		}
815
+		$def_reg_status_actions = apply_filters(
816
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
817
+			$def_reg_status_actions,
818
+			$active_mts,
819
+			$can_send
820
+		);
821
+
822
+		$this->_views = array(
823
+			'all'   => array(
824
+				'slug'        => 'all',
825
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
826
+				'count'       => 0,
827
+				'bulk_action' => array_merge($def_reg_status_actions, array(
828
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
829
+				)),
830
+			),
831
+			'month' => array(
832
+				'slug'        => 'month',
833
+				'label'       => esc_html__('This Month', 'event_espresso'),
834
+				'count'       => 0,
835
+				'bulk_action' => array_merge($def_reg_status_actions, array(
836
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
837
+				)),
838
+			),
839
+			'today' => array(
840
+				'slug'        => 'today',
841
+				'label'       => sprintf(
842
+					esc_html__('Today - %s', 'event_espresso'),
843
+					date('M d, Y', current_time('timestamp'))
844
+				),
845
+				'count'       => 0,
846
+				'bulk_action' => array_merge($def_reg_status_actions, array(
847
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
848
+				)),
849
+			),
850
+		);
851
+		if (EE_Registry::instance()->CAP->current_user_can(
852
+			'ee_delete_registrations',
853
+			'espresso_registrations_delete_registration'
854
+		)) {
855
+			$this->_views['incomplete'] = array(
856
+				'slug'        => 'incomplete',
857
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
858
+				'count'       => 0,
859
+				'bulk_action' => array(
860
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
861
+				),
862
+			);
863
+			$this->_views['trash']      = array(
864
+				'slug'        => 'trash',
865
+				'label'       => esc_html__('Trash', 'event_espresso'),
866
+				'count'       => 0,
867
+				'bulk_action' => array(
868
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
869
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
870
+				),
871
+			);
872
+		}
873
+	}
874
+
875
+
876
+	protected function _set_list_table_views_contact_list()
877
+	{
878
+		$this->_views = array(
879
+			'in_use' => array(
880
+				'slug'        => 'in_use',
881
+				'label'       => esc_html__('In Use', 'event_espresso'),
882
+				'count'       => 0,
883
+				'bulk_action' => array(
884
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
885
+				),
886
+			),
887
+		);
888
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
889
+			'espresso_registrations_trash_attendees')
890
+		) {
891
+			$this->_views['trash'] = array(
892
+				'slug'        => 'trash',
893
+				'label'       => esc_html__('Trash', 'event_espresso'),
894
+				'count'       => 0,
895
+				'bulk_action' => array(
896
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
897
+				),
898
+			);
899
+		}
900
+	}
901
+
902
+
903
+	protected function _registration_legend_items()
904
+	{
905
+		$fc_items = array(
906
+			'star-icon'        => array(
907
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
908
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
909
+			),
910
+			'view_details'     => array(
911
+				'class' => 'dashicons dashicons-clipboard',
912
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
913
+			),
914
+			'edit_attendee'    => array(
915
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
916
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
917
+			),
918
+			'view_transaction' => array(
919
+				'class' => 'dashicons dashicons-cart',
920
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
921
+			),
922
+			'view_invoice'     => array(
923
+				'class' => 'dashicons dashicons-media-spreadsheet',
924
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
925
+			),
926
+		);
927
+		if (EE_Registry::instance()->CAP->current_user_can(
928
+			'ee_send_message',
929
+			'espresso_registrations_resend_registration'
930
+		)) {
931
+			$fc_items['resend_registration'] = array(
932
+				'class' => 'dashicons dashicons-email-alt',
933
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
934
+			);
935
+		} else {
936
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
937
+		}
938
+		if (EE_Registry::instance()->CAP->current_user_can(
939
+			'ee_read_global_messages',
940
+			'view_filtered_messages'
941
+		)) {
942
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
943
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
944
+				$fc_items['view_related_messages'] = array(
945
+					'class' => $related_for_icon['css_class'],
946
+					'desc'  => $related_for_icon['label'],
947
+				);
948
+			}
949
+		}
950
+		$sc_items = array(
951
+			'approved_status'   => array(
952
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
953
+				'desc'  => EEH_Template::pretty_status(
954
+					EEM_Registration::status_id_approved,
955
+					false,
956
+					'sentence'
957
+				),
958
+			),
959
+			'pending_status'    => array(
960
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
961
+				'desc'  => EEH_Template::pretty_status(
962
+					EEM_Registration::status_id_pending_payment,
963
+					false,
964
+					'sentence'
965
+				),
966
+			),
967
+			'wait_list'         => array(
968
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
969
+				'desc'  => EEH_Template::pretty_status(
970
+					EEM_Registration::status_id_wait_list,
971
+					false,
972
+					'sentence'
973
+				),
974
+			),
975
+			'incomplete_status' => array(
976
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
977
+				'desc'  => EEH_Template::pretty_status(
978
+					EEM_Registration::status_id_incomplete,
979
+					false,
980
+					'sentence'
981
+				),
982
+			),
983
+			'not_approved'      => array(
984
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
985
+				'desc'  => EEH_Template::pretty_status(
986
+					EEM_Registration::status_id_not_approved,
987
+					false,
988
+					'sentence'
989
+				),
990
+			),
991
+			'declined_status'   => array(
992
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
993
+				'desc'  => EEH_Template::pretty_status(
994
+					EEM_Registration::status_id_declined,
995
+					false,
996
+					'sentence'
997
+				),
998
+			),
999
+			'cancelled_status'  => array(
1000
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1001
+				'desc'  => EEH_Template::pretty_status(
1002
+					EEM_Registration::status_id_cancelled,
1003
+					false,
1004
+					'sentence'
1005
+				),
1006
+			),
1007
+		);
1008
+		return array_merge($fc_items, $sc_items);
1009
+	}
1010
+
1011
+
1012
+
1013
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1014
+	/**
1015
+	 * @throws \EE_Error
1016
+	 */
1017
+	protected function _registrations_overview_list_table()
1018
+	{
1019
+		$this->_template_args['admin_page_header'] = '';
1020
+		$EVT_ID                                    = ! empty($this->_req_data['event_id'])
1021
+			? absint($this->_req_data['event_id'])
1022
+			: 0;
1023
+		if ($EVT_ID) {
1024
+			if (EE_Registry::instance()->CAP->current_user_can(
1025
+				'ee_edit_registrations',
1026
+				'espresso_registrations_new_registration',
1027
+				$EVT_ID
1028
+			)) {
1029
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1030
+					'new_registration',
1031
+					'add-registrant',
1032
+					array('event_id' => $EVT_ID),
1033
+					'add-new-h2'
1034
+				);
1035
+			}
1036
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1037
+			if ($event instanceof EE_Event) {
1038
+				$this->_template_args['admin_page_header'] = sprintf(
1039
+					esc_html__(
1040
+						'%s Viewing registrations for the event: %s%s',
1041
+						'event_espresso'
1042
+					),
1043
+					'<h3 style="line-height:1.5em;">',
1044
+					'<br /><a href="'
1045
+						. EE_Admin_Page::add_query_args_and_nonce(
1046
+							array(
1047
+								'action' => 'edit',
1048
+								'post'   => $event->ID(),
1049
+							),
1050
+							EVENTS_ADMIN_URL
1051
+						)
1052
+						. '">&nbsp;'
1053
+						. $event->get('EVT_name')
1054
+						. '&nbsp;</a>&nbsp;',
1055
+					'</h3>'
1056
+				);
1057
+			}
1058
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1059
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1060
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1061
+				$this->_template_args['admin_page_header'] = substr(
1062
+					$this->_template_args['admin_page_header'],
1063
+					0,
1064
+					-5
1065
+				);
1066
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1067
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1068
+				$this->_template_args['admin_page_header'] .= $datetime->name();
1069
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1070
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
1071
+			}
1072
+		}
1073
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1074
+		$this->display_admin_list_table_page_with_no_sidebar();
1075
+	}
1076
+
1077
+
1078
+	/**
1079
+	 * This sets the _registration property for the registration details screen
1080
+	 *
1081
+	 * @access private
1082
+	 * @return bool
1083
+	 */
1084
+	private function _set_registration_object()
1085
+	{
1086
+		//get out if we've already set the object
1087
+		if ($this->_registration instanceof EE_Registration) {
1088
+			return true;
1089
+		}
1090
+		$REG    = EEM_Registration::instance();
1091
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1092
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1093
+			return true;
1094
+		} else {
1095
+			$error_msg = sprintf(
1096
+				esc_html__(
1097
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1098
+					'event_espresso'
1099
+				),
1100
+				$REG_ID
1101
+			);
1102
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1103
+			$this->_registration = null;
1104
+			return false;
1105
+		}
1106
+	}
1107
+
1108
+
1109
+	/**
1110
+	 * Used to retrieve registrations for the list table.
1111
+	 *
1112
+	 * @param int  $per_page
1113
+	 * @param bool $count
1114
+	 * @param bool $this_month
1115
+	 * @param bool $today
1116
+	 * @return EE_Registration[]|int
1117
+	 * @throws EE_Error
1118
+	 */
1119
+	public function get_registrations(
1120
+		$per_page = 10,
1121
+		$count = false,
1122
+		$this_month = false,
1123
+		$today = false
1124
+	) {
1125
+		if ($this_month) {
1126
+			$this->_req_data['status'] = 'month';
1127
+		}
1128
+		if ($today) {
1129
+			$this->_req_data['status'] = 'today';
1130
+		}
1131
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1132
+		/**
1133
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1134
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1135
+		 * @see EEM_Base::get_all()
1136
+		 */
1137
+		$query_params['group_by'] = '';
1138
+
1139
+		return $count
1140
+			? EEM_Registration::instance()->count($query_params)
1141
+			/** @type EE_Registration[] */
1142
+			: EEM_Registration::instance()->get_all($query_params);
1143
+	}
1144
+
1145
+
1146
+
1147
+	/**
1148
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1149
+	 * Note: this listens to values on the request for some of the query parameters.
1150
+	 *
1151
+	 * @param array $request
1152
+	 * @param int    $per_page
1153
+	 * @param bool   $count
1154
+	 * @return array
1155
+	 */
1156
+	protected function _get_registration_query_parameters(
1157
+		$request = array(),
1158
+		$per_page = 10,
1159
+		$count = false
1160
+	) {
1161
+
1162
+		$query_params = array(
1163
+			0                          => $this->_get_where_conditions_for_registrations_query(
1164
+				$request
1165
+			),
1166
+			'caps'                     => EEM_Registration::caps_read_admin,
1167
+			'default_where_conditions' => 'this_model_only',
1168
+		);
1169
+		if (! $count) {
1170
+			$query_params = array_merge(
1171
+				$query_params,
1172
+				$this->_get_orderby_for_registrations_query(),
1173
+				$this->_get_limit($per_page)
1174
+			);
1175
+		}
1176
+
1177
+		return $query_params;
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1183
+	 *
1184
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1185
+	 * @return array
1186
+	 */
1187
+	protected function _add_event_id_to_where_conditions(array $request)
1188
+	{
1189
+		$where = array();
1190
+		if (! empty($request['event_id'])) {
1191
+			$where['EVT_ID'] = absint($request['event_id']);
1192
+		}
1193
+		return $where;
1194
+	}
1195
+
1196
+
1197
+	/**
1198
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1199
+	 *
1200
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1201
+	 * @return array
1202
+	 */
1203
+	protected function _add_category_id_to_where_conditions(array $request)
1204
+	{
1205
+		$where = array();
1206
+		if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1207
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1208
+		}
1209
+		return $where;
1210
+	}
1211
+
1212
+
1213
+	/**
1214
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1215
+	 *
1216
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1217
+	 * @return array
1218
+	 */
1219
+	protected function _add_datetime_id_to_where_conditions(array $request)
1220
+	{
1221
+		$where = array();
1222
+		if (! empty($request['datetime_id'])) {
1223
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1224
+		}
1225
+		if (! empty($request['DTT_ID'])) {
1226
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1227
+		}
1228
+		return $where;
1229
+	}
1230
+
1231
+
1232
+	/**
1233
+	 * Adds the correct registration status to the where conditions for the registrations query.
1234
+	 *
1235
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1236
+	 * @return array
1237
+	 */
1238
+	protected function _add_registration_status_to_where_conditions(array $request)
1239
+	{
1240
+		$where = array();
1241
+		$view = EEH_Array::is_set($request, 'status', '');
1242
+		$registration_status = ! empty($request['_reg_status'])
1243
+			? sanitize_text_field($request['_reg_status'])
1244
+			: '';
1245
+
1246
+		/*
1247 1247
          * If filtering by registration status, then we show registrations matching that status.
1248 1248
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1249 1249
          * UNLESS viewing trashed registrations.
1250 1250
          */
1251
-        if (! empty($registration_status)) {
1252
-            $where['STS_ID'] = $registration_status;
1253
-        } else {
1254
-            //make sure we exclude incomplete registrations, but only if not trashed.
1255
-            if ($view === 'trash') {
1256
-                $where['REG_deleted'] = true;
1257
-            } elseif ($view === 'incomplete') {
1258
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1259
-            } else {
1260
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1261
-            }
1262
-        }
1263
-        return $where;
1264
-    }
1265
-
1266
-
1267
-    /**
1268
-     * Adds any provided date restraints to the where conditions for the registrations query.
1269
-     *
1270
-     * @param array $request usually the same as $this->_req_data but not necessarily
1271
-     * @return array
1272
-     * @throws EE_Error
1273
-     */
1274
-    protected function _add_date_to_where_conditions(array $request)
1275
-    {
1276
-        $where = array();
1277
-        $view = EEH_Array::is_set($request, 'status', '');
1278
-        $month_range             = ! empty($request['month_range'])
1279
-            ? sanitize_text_field($request['month_range'])
1280
-            : '';
1281
-        $retrieve_for_today      = $view === 'today';
1282
-        $retrieve_for_this_month = $view === 'month';
1283
-
1284
-        if ($retrieve_for_today) {
1285
-            $now               = date('Y-m-d', current_time('timestamp'));
1286
-            $where['REG_date'] = array(
1287
-                'BETWEEN',
1288
-                array(
1289
-                    EEM_Registration::instance()->convert_datetime_for_query(
1290
-                        'REG_date',
1291
-                        $now . ' 00:00:00',
1292
-                        'Y-m-d H:i:s'
1293
-                    ),
1294
-                    EEM_Registration::instance()->convert_datetime_for_query(
1295
-                        'REG_date',
1296
-                        $now . ' 23:59:59',
1297
-                        'Y-m-d H:i:s'
1298
-                    ),
1299
-                ),
1300
-            );
1301
-        } elseif ($retrieve_for_this_month) {
1302
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1303
-            $days_this_month        = date('t', current_time('timestamp'));
1304
-            $where['REG_date']      = array(
1305
-                'BETWEEN',
1306
-                array(
1307
-                    EEM_Registration::instance()->convert_datetime_for_query(
1308
-                        'REG_date',
1309
-                        $current_year_and_month . '-01 00:00:00',
1310
-                        'Y-m-d H:i:s'
1311
-                    ),
1312
-                    EEM_Registration::instance()->convert_datetime_for_query(
1313
-                        'REG_date',
1314
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1315
-                        'Y-m-d H:i:s'
1316
-                    ),
1317
-                ),
1318
-            );
1319
-        } elseif ($month_range) {
1320
-            $pieces          = explode(' ', $month_range, 3);
1321
-            $month_requested = ! empty($pieces[0])
1322
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1323
-                : '';
1324
-            $year_requested  = ! empty($pieces[1])
1325
-                ? $pieces[1]
1326
-                : '';
1327
-            //if there is not a month or year then we can't go further
1328
-            if ($month_requested && $year_requested) {
1329
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1330
-                $where['REG_date'] = array(
1331
-                    'BETWEEN',
1332
-                    array(
1333
-                        EEM_Registration::instance()->convert_datetime_for_query(
1334
-                            'REG_date',
1335
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1336
-                            'Y-m-d H:i:s'
1337
-                        ),
1338
-                        EEM_Registration::instance()->convert_datetime_for_query(
1339
-                            'REG_date',
1340
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1341
-                            'Y-m-d H:i:s'
1342
-                        ),
1343
-                    ),
1344
-                );
1345
-            }
1346
-        }
1347
-        return $where;
1348
-    }
1349
-
1350
-
1351
-    /**
1352
-     * Adds any provided search restraints to the where conditions for the registrations query
1353
-     *
1354
-     * @param array $request usually the same as $this->_req_data but not necessarily
1355
-     * @return array
1356
-     */
1357
-    protected function _add_search_to_where_conditions(array $request)
1358
-    {
1359
-        $where = array();
1360
-        if (! empty($request['s'])) {
1361
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1362
-            $where['OR*search_conditions'] = array(
1363
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1364
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1365
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1366
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1367
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1368
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1369
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1370
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1371
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1372
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1373
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1374
-                'REG_final_price'                         => array('LIKE', $search_string),
1375
-                'REG_code'                                => array('LIKE', $search_string),
1376
-                'REG_count'                               => array('LIKE', $search_string),
1377
-                'REG_group_size'                          => array('LIKE', $search_string),
1378
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1379
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1380
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1381
-            );
1382
-        }
1383
-        return $where;
1384
-    }
1385
-
1386
-
1387
-    /**
1388
-     * Sets up the where conditions for the registrations query.
1389
-     *
1390
-     * @param array $request
1391
-     * @return array
1392
-     * @throws EE_Error
1393
-     */
1394
-    protected function _get_where_conditions_for_registrations_query($request)
1395
-    {
1396
-        return apply_filters(
1397
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1398
-            array_merge(
1399
-                $this->_add_event_id_to_where_conditions($request),
1400
-                $this->_add_category_id_to_where_conditions($request),
1401
-                $this->_add_datetime_id_to_where_conditions($request),
1402
-                $this->_add_registration_status_to_where_conditions($request),
1403
-                $this->_add_date_to_where_conditions($request),
1404
-                $this->_add_search_to_where_conditions($request)
1405
-            ),
1406
-            $request
1407
-        );
1408
-    }
1409
-
1410
-
1411
-    /**
1412
-     * Sets up the orderby for the registrations query.
1413
-     *
1414
-     * @return array
1415
-     */
1416
-    protected function _get_orderby_for_registrations_query()
1417
-    {
1418
-        $orderby_field = ! empty($this->_req_data['orderby'])
1419
-            ? sanitize_text_field($this->_req_data['orderby'])
1420
-            : '';
1421
-        switch ($orderby_field) {
1422
-            case '_REG_ID':
1423
-                $orderby_field = 'REG_ID';
1424
-                break;
1425
-            case '_Reg_status':
1426
-                $orderby_field = 'STS_ID';
1427
-                break;
1428
-            case 'ATT_fname':
1429
-                $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1430
-                break;
1431
-            case 'ATT_lname':
1432
-                $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1433
-                break;
1434
-            case 'event_name':
1435
-                $orderby_field = 'Event.EVT_name';
1436
-                break;
1437
-            case 'DTT_EVT_start':
1438
-                $orderby_field = 'Event.Datetime.DTT_EVT_start';
1439
-                break;
1440
-            default: //'REG_date'
1441
-                $orderby_field = 'REG_date';
1442
-        }
1443
-
1444
-        //order
1445
-        $order = ! empty($this->_req_data['order'])
1446
-            ? sanitize_text_field($this->_req_data['order'])
1447
-            : 'DESC';
1448
-
1449
-        //mutate orderby_field
1450
-        $orderby_field = array_combine(
1451
-            (array) $orderby_field,
1452
-            array_fill(0, count($orderby_field), $order)
1453
-        );
1454
-        //because there are many registrations with the same date, define
1455
-        //a secondary way to order them, otherwise MySQL seems to be a bit random
1456
-        if (empty($order['REG_ID'])) {
1457
-            $orderby_field['REG_ID'] = $order;
1458
-        }
1459
-        return array('order_by' => $orderby_field);
1460
-    }
1461
-
1462
-
1463
-    /**
1464
-     * Sets up the limit for the registrations query.
1465
-     *
1466
-     * @param $per_page
1467
-     * @return array
1468
-     */
1469
-    protected function _get_limit($per_page)
1470
-    {
1471
-        $current_page = ! empty($this->_req_data['paged'])
1472
-            ? absint($this->_req_data['paged'])
1473
-            : 1;
1474
-        $per_page     = ! empty($this->_req_data['perpage'])
1475
-            ? $this->_req_data['perpage']
1476
-            : $per_page;
1477
-
1478
-        //-1 means return all results so get out if that's set.
1479
-        if ((int)$per_page === -1) {
1480
-            return array();
1481
-        }
1482
-        $per_page = absint($per_page);
1483
-        $offset   = ($current_page - 1) * $per_page;
1484
-        return array('limit' => array($offset, $per_page));
1485
-    }
1486
-
1487
-
1488
-    public function get_registration_status_array()
1489
-    {
1490
-        return self::$_reg_status;
1491
-    }
1492
-
1493
-
1494
-
1495
-
1496
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1497
-    /**
1498
-     *        generates HTML for the View Registration Details Admin page
1499
-     *
1500
-     * @access protected
1501
-     * @return void
1502
-     * @throws DomainException
1503
-     * @throws EE_Error
1504
-     * @throws EntityNotFoundException
1505
-     */
1506
-    protected function _registration_details()
1507
-    {
1508
-        $this->_template_args = array();
1509
-        $this->_set_registration_object();
1510
-        if (is_object($this->_registration)) {
1511
-            $transaction                                   = $this->_registration->transaction()
1512
-                ? $this->_registration->transaction()
1513
-                : EE_Transaction::new_instance();
1514
-            $this->_session                                = $transaction->session_data();
1515
-            $event_id                                      = $this->_registration->event_ID();
1516
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1517
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1518
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1519
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1520
-            $this->_template_args['grand_total']           = $transaction->total();
1521
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1522
-            // link back to overview
1523
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1524
-            $this->_template_args['registration']                = $this->_registration;
1525
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1526
-                array(
1527
-                    'action'   => 'default',
1528
-                    'event_id' => $event_id,
1529
-                ),
1530
-                REG_ADMIN_URL
1531
-            );
1532
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1533
-                array(
1534
-                    'action' => 'default',
1535
-                    'EVT_ID' => $event_id,
1536
-                    'page'   => 'espresso_transactions',
1537
-                ),
1538
-                admin_url('admin.php')
1539
-            );
1540
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1541
-                array(
1542
-                    'page'   => 'espresso_events',
1543
-                    'action' => 'edit',
1544
-                    'post'   => $event_id,
1545
-                ),
1546
-                admin_url('admin.php')
1547
-            );
1548
-            //next and previous links
1549
-            $next_reg                                      = $this->_registration->next(
1550
-                null,
1551
-                array(),
1552
-                'REG_ID'
1553
-            );
1554
-            $this->_template_args['next_registration']     = $next_reg
1555
-                ? $this->_next_link(
1556
-                    EE_Admin_Page::add_query_args_and_nonce(
1557
-                        array(
1558
-                            'action'  => 'view_registration',
1559
-                            '_REG_ID' => $next_reg['REG_ID'],
1560
-                        ),
1561
-                        REG_ADMIN_URL
1562
-                    ),
1563
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1564
-                )
1565
-                : '';
1566
-            $previous_reg                                  = $this->_registration->previous(
1567
-                null,
1568
-                array(),
1569
-                'REG_ID'
1570
-            );
1571
-            $this->_template_args['previous_registration'] = $previous_reg
1572
-                ? $this->_previous_link(
1573
-                    EE_Admin_Page::add_query_args_and_nonce(
1574
-                        array(
1575
-                            'action'  => 'view_registration',
1576
-                            '_REG_ID' => $previous_reg['REG_ID'],
1577
-                        ),
1578
-                        REG_ADMIN_URL
1579
-                    ),
1580
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1581
-                )
1582
-                : '';
1583
-            // grab header
1584
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1585
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1586
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1587
-                $template_path,
1588
-                $this->_template_args,
1589
-                true
1590
-            );
1591
-        } else {
1592
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1593
-        }
1594
-        // the details template wrapper
1595
-        $this->display_admin_page_with_sidebar();
1596
-    }
1597
-
1598
-
1599
-    protected function _registration_details_metaboxes()
1600
-    {
1601
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1602
-        $this->_set_registration_object();
1603
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1604
-        add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1605
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1606
-        add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1607
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1608
-        if ($attendee instanceof EE_Attendee
1609
-            && EE_Registry::instance()->CAP->current_user_can(
1610
-                'ee_edit_registration',
1611
-                'edit-reg-questions-mbox',
1612
-                $this->_registration->ID()
1613
-            )
1614
-        ) {
1615
-            add_meta_box(
1616
-                'edit-reg-questions-mbox',
1617
-                esc_html__('Registration Form Answers', 'event_espresso'),
1618
-                array($this, '_reg_questions_meta_box'),
1619
-                $this->wp_page_slug,
1620
-                'normal',
1621
-                'high'
1622
-            );
1623
-        }
1624
-        add_meta_box(
1625
-            'edit-reg-registrant-mbox',
1626
-            esc_html__('Contact Details', 'event_espresso'),
1627
-            array($this, '_reg_registrant_side_meta_box'),
1628
-            $this->wp_page_slug,
1629
-            'side',
1630
-            'high'
1631
-        );
1632
-        if ($this->_registration->group_size() > 1) {
1633
-            add_meta_box(
1634
-                'edit-reg-attendees-mbox',
1635
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1636
-                array($this, '_reg_attendees_meta_box'),
1637
-                $this->wp_page_slug,
1638
-                'normal',
1639
-                'high'
1640
-            );
1641
-        }
1642
-    }
1643
-
1644
-
1645
-    /**
1646
-     * set_reg_status_buttons_metabox
1647
-     *
1648
-     * @access protected
1649
-     * @return string
1650
-     * @throws \EE_Error
1651
-     */
1652
-    public function set_reg_status_buttons_metabox()
1653
-    {
1654
-        $this->_set_registration_object();
1655
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1656
-        echo $change_reg_status_form->form_open(
1657
-            self::add_query_args_and_nonce(
1658
-                array(
1659
-                    'action' => 'change_reg_status',
1660
-                ),
1661
-                REG_ADMIN_URL
1662
-            )
1663
-        );
1664
-        echo $change_reg_status_form->get_html();
1665
-        echo $change_reg_status_form->form_close();
1666
-    }
1667
-
1668
-
1669
-
1670
-    /**
1671
-     * @return EE_Form_Section_Proper
1672
-     * @throws EE_Error
1673
-     */
1674
-    protected function _generate_reg_status_change_form()
1675
-    {
1676
-        return new EE_Form_Section_Proper(array(
1677
-            'name'            => 'reg_status_change_form',
1678
-            'html_id'         => 'reg-status-change-form',
1679
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1680
-            'subsections'     => array(
1681
-                'return'             => new EE_Hidden_Input(array(
1682
-                    'name'    => 'return',
1683
-                    'default' => 'view_registration',
1684
-                )),
1685
-                'REG_ID'             => new EE_Hidden_Input(array(
1686
-                    'name'    => 'REG_ID',
1687
-                    'default' => $this->_registration->ID(),
1688
-                )),
1689
-                'current_status'     => new EE_Form_Section_HTML(
1690
-                    EEH_HTML::tr(
1691
-                        EEH_HTML::th(
1692
-                            EEH_HTML::label(
1693
-                                EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1694
-                                )
1695
-                            )
1696
-                        )
1697
-                        . EEH_HTML::td(
1698
-                            EEH_HTML::strong(
1699
-                                $this->_registration->pretty_status(),
1700
-                                '',
1701
-                                'status-' . $this->_registration->status_ID(),
1702
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1703
-                            )
1704
-                        )
1705
-                    )
1706
-                ),
1707
-                'reg_status'         => new EE_Select_Input(
1708
-                    $this->_get_reg_statuses(),
1709
-                    array(
1710
-                        'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1711
-                        'default'         => $this->_registration->status_ID(),
1712
-                    )
1713
-                ),
1714
-                'send_notifications' => new EE_Yes_No_Input(
1715
-                    array(
1716
-                        'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1717
-                        'default'         => false,
1718
-                        'html_help_text'  => esc_html__(
1719
-                            'If set to "Yes", then the related messages will be sent to the registrant.',
1720
-                            'event_espresso'
1721
-                        ),
1722
-                    )
1723
-                ),
1724
-                'submit'             => new EE_Submit_Input(
1725
-                    array(
1726
-                        'html_class'      => 'button-primary',
1727
-                        'html_label_text' => '&nbsp;',
1728
-                        'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1729
-                    )
1730
-                ),
1731
-            ),
1732
-        ));
1733
-    }
1734
-
1735
-
1736
-    /**
1737
-     * Returns an array of all the buttons for the various statuses and switch status actions
1738
-     *
1739
-     * @return array
1740
-     * @throws EE_Error
1741
-     * @throws EntityNotFoundException
1742
-     */
1743
-    protected function _get_reg_statuses()
1744
-    {
1745
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1746
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1747
-        // get current reg status
1748
-        $current_status = $this->_registration->status_ID();
1749
-        // is registration for free event? This will determine whether to display the pending payment option
1750
-        if (
1751
-            $current_status !== EEM_Registration::status_id_pending_payment
1752
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1753
-        ) {
1754
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1755
-        }
1756
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1757
-    }
1758
-
1759
-
1760
-    /**
1761
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1762
-     *
1763
-     * @param bool $status REG status given for changing registrations to.
1764
-     * @param bool $notify Whether to send messages notifications or not.
1765
-     * @return array (array with reg_id(s) updated and whether update was successful.
1766
-     * @throws EE_Error
1767
-     * @throws InvalidArgumentException
1768
-     * @throws InvalidDataTypeException
1769
-     * @throws InvalidInterfaceException
1770
-     * @throws ReflectionException
1771
-     * @throws RuntimeException
1772
-     * @throws EntityNotFoundException
1773
-     */
1774
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1775
-    {
1776
-        if (isset($this->_req_data['reg_status_change_form'])) {
1777
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1778
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1779
-                : array();
1780
-        } else {
1781
-            $REG_IDs = isset($this->_req_data['_REG_ID'])
1782
-                ? (array)$this->_req_data['_REG_ID']
1783
-                : array();
1784
-        }
1785
-        // sanitize $REG_IDs
1786
-        $REG_IDs = array_map('absint', $REG_IDs);
1787
-        // and remove empty entries
1788
-        $REG_IDs = array_filter($REG_IDs);
1789
-
1790
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1791
-
1792
-        /**
1793
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1794
-         * Currently this value is used downstream by the _process_resend_registration method.
1795
-         *
1796
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1797
-         * @param bool                     $status           The status registrations were changed to.
1798
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1799
-         * @param Registrations_Admin_Page $admin_page_object
1800
-         */
1801
-        $this->_req_data['_REG_ID'] = apply_filters(
1802
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1803
-            $result['REG_ID'],
1804
-            $status,
1805
-            $result['success'],
1806
-            $this
1807
-        );
1808
-
1809
-        //notify?
1810
-        if ($notify
1811
-            && $result['success']
1812
-            && ! empty($this->_req_data['_REG_ID'])
1813
-            && EE_Registry::instance()->CAP->current_user_can(
1814
-                'ee_send_message',
1815
-                'espresso_registrations_resend_registration'
1816
-            )
1817
-        ) {
1818
-            $this->_process_resend_registration();
1819
-        }
1820
-        return $result;
1821
-    }
1822
-
1823
-
1824
-    /**
1825
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1826
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1827
-     *
1828
-     * @param array  $REG_IDs
1829
-     * @param string $status
1830
-     * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1831
-     *                        slug sent with setting the registration status.
1832
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1833
-     * @throws EE_Error
1834
-     * @throws InvalidArgumentException
1835
-     * @throws InvalidDataTypeException
1836
-     * @throws InvalidInterfaceException
1837
-     * @throws ReflectionException
1838
-     * @throws RuntimeException
1839
-     * @throws EntityNotFoundException
1840
-     */
1841
-    protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1842
-    {
1843
-        $success = false;
1844
-        // typecast $REG_IDs
1845
-        $REG_IDs = (array)$REG_IDs;
1846
-        if ( ! empty($REG_IDs)) {
1847
-            $success = true;
1848
-            // set default status if none is passed
1849
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1850
-            $status_context = $notify
1851
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1852
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1853
-            //loop through REG_ID's and change status
1854
-            foreach ($REG_IDs as $REG_ID) {
1855
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1856
-                if ($registration instanceof EE_Registration) {
1857
-                    $registration->set_status(
1858
-                        $status,
1859
-                        false,
1860
-                        new Context(
1861
-                            $status_context,
1862
-                            esc_html__(
1863
-                                'Manually triggered status change on a Registration Admin Page route.',
1864
-                                'event_espresso'
1865
-                            )
1866
-                        )
1867
-                    );
1868
-                    $result = $registration->save();
1869
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1870
-                    $success = $result !== false ? $success : false;
1871
-                }
1872
-            }
1873
-        }
1874
-
1875
-        //return $success and processed registrations
1876
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1877
-    }
1878
-
1879
-
1880
-    /**
1881
-     * Common logic for setting up success message and redirecting to appropriate route
1882
-     *
1883
-     * @param  string $STS_ID status id for the registration changed to
1884
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1885
-     * @return void
1886
-     */
1887
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1888
-    {
1889
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1890
-            : array('success' => false);
1891
-        $success = isset($result['success']) && $result['success'];
1892
-        //setup success message
1893
-        if ($success) {
1894
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1895
-                $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1896
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1897
-            } else {
1898
-                $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1899
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1900
-            }
1901
-            EE_Error::add_success($msg);
1902
-        } else {
1903
-            EE_Error::add_error(
1904
-                esc_html__(
1905
-                    'Something went wrong, and the status was not changed',
1906
-                    'event_espresso'
1907
-                ), __FILE__, __LINE__, __FUNCTION__
1908
-            );
1909
-        }
1910
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1911
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1912
-        } else {
1913
-            $route = array('action' => 'default');
1914
-        }
1915
-        //unset nonces
1916
-        foreach ($this->_req_data as $ref => $value) {
1917
-            if (strpos($ref, 'nonce') !== false) {
1918
-                unset($this->_req_data[$ref]);
1919
-                continue;
1920
-            }
1921
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1922
-            $this->_req_data[$ref] = $value;
1923
-        }
1924
-        //merge request vars so that the reloaded list table contains any existing filter query params
1925
-        $route = array_merge($this->_req_data, $route);
1926
-        $this->_redirect_after_action($success, '', '', $route, true);
1927
-    }
1928
-
1929
-
1930
-    /**
1931
-     * incoming reg status change from reg details page.
1932
-     *
1933
-     * @return void
1934
-     */
1935
-    protected function _change_reg_status()
1936
-    {
1937
-        $this->_req_data['return'] = 'view_registration';
1938
-        //set notify based on whether the send notifications toggle is set or not
1939
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1940
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1941
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1942
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1943
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1944
-            case EEM_Registration::status_id_approved :
1945
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1946
-                $this->approve_registration($notify);
1947
-                break;
1948
-            case EEM_Registration::status_id_pending_payment :
1949
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1950
-                $this->pending_registration($notify);
1951
-                break;
1952
-            case EEM_Registration::status_id_not_approved :
1953
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1954
-                $this->not_approve_registration($notify);
1955
-                break;
1956
-            case EEM_Registration::status_id_declined :
1957
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1958
-                $this->decline_registration($notify);
1959
-                break;
1960
-            case EEM_Registration::status_id_cancelled :
1961
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1962
-                $this->cancel_registration($notify);
1963
-                break;
1964
-            case EEM_Registration::status_id_wait_list :
1965
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1966
-                $this->wait_list_registration($notify);
1967
-                break;
1968
-            case EEM_Registration::status_id_incomplete :
1969
-            default :
1970
-                $result['success'] = false;
1971
-                unset($this->_req_data['return']);
1972
-                $this->_reg_status_change_return('', false);
1973
-                break;
1974
-        }
1975
-    }
1976
-
1977
-
1978
-    /**
1979
-     * Callback for bulk action routes.
1980
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1981
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1982
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1983
-     * when an action is happening on just a single registration).
1984
-     * @param      $action
1985
-     * @param bool $notify
1986
-     */
1987
-    protected function bulk_action_on_registrations($action, $notify = false) {
1988
-        do_action(
1989
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1990
-            $this,
1991
-            $action,
1992
-            $notify
1993
-        );
1994
-        $method = $action . '_registration';
1995
-        if (method_exists($this, $method)) {
1996
-            $this->$method($notify);
1997
-        }
1998
-    }
1999
-
2000
-
2001
-    /**
2002
-     * approve_registration
2003
-     *
2004
-     * @access protected
2005
-     * @param bool $notify whether or not to notify the registrant about their approval.
2006
-     * @return void
2007
-     */
2008
-    protected function approve_registration($notify = false)
2009
-    {
2010
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2011
-    }
2012
-
2013
-
2014
-    /**
2015
-     *        decline_registration
2016
-     *
2017
-     * @access protected
2018
-     * @param bool $notify whether or not to notify the registrant about their status change.
2019
-     * @return void
2020
-     */
2021
-    protected function decline_registration($notify = false)
2022
-    {
2023
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2024
-    }
2025
-
2026
-
2027
-    /**
2028
-     *        cancel_registration
2029
-     *
2030
-     * @access protected
2031
-     * @param bool $notify whether or not to notify the registrant about their status change.
2032
-     * @return void
2033
-     */
2034
-    protected function cancel_registration($notify = false)
2035
-    {
2036
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2037
-    }
2038
-
2039
-
2040
-    /**
2041
-     *        not_approve_registration
2042
-     *
2043
-     * @access protected
2044
-     * @param bool $notify whether or not to notify the registrant about their status change.
2045
-     * @return void
2046
-     */
2047
-    protected function not_approve_registration($notify = false)
2048
-    {
2049
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2050
-    }
2051
-
2052
-
2053
-    /**
2054
-     *        decline_registration
2055
-     *
2056
-     * @access protected
2057
-     * @param bool $notify whether or not to notify the registrant about their status change.
2058
-     * @return void
2059
-     */
2060
-    protected function pending_registration($notify = false)
2061
-    {
2062
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2063
-    }
2064
-
2065
-
2066
-    /**
2067
-     * waitlist_registration
2068
-     *
2069
-     * @access protected
2070
-     * @param bool $notify whether or not to notify the registrant about their status change.
2071
-     * @return void
2072
-     */
2073
-    protected function wait_list_registration($notify = false)
2074
-    {
2075
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2076
-    }
2077
-
2078
-
2079
-    /**
2080
-     *        generates HTML for the Registration main meta box
2081
-     *
2082
-     * @access public
2083
-     * @return void
2084
-     * @throws DomainException
2085
-     * @throws EE_Error
2086
-     * @throws EntityNotFoundException
2087
-     */
2088
-    public function _reg_details_meta_box()
2089
-    {
2090
-        EEH_Autoloader::register_line_item_display_autoloaders();
2091
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2092
-        EE_Registry::instance()->load_helper('Line_Item');
2093
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2094
-            : EE_Transaction::new_instance();
2095
-        $this->_session = $transaction->session_data();
2096
-        $filters        = new EE_Line_Item_Filter_Collection();
2097
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2098
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2099
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2100
-            $transaction->total_line_item());
2101
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2102
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2103
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2104
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2105
-            $filtered_line_item_tree,
2106
-            array('EE_Registration' => $this->_registration)
2107
-        );
2108
-        $attendee                                = $this->_registration->attendee();
2109
-        if (EE_Registry::instance()->CAP->current_user_can(
2110
-            'ee_read_transaction',
2111
-            'espresso_transactions_view_transaction'
2112
-        )) {
2113
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2114
-                EE_Admin_Page::add_query_args_and_nonce(
2115
-                    array(
2116
-                        'action' => 'view_transaction',
2117
-                        'TXN_ID' => $transaction->ID(),
2118
-                    ),
2119
-                    TXN_ADMIN_URL
2120
-                ),
2121
-                esc_html__(' View Transaction', 'event_espresso'),
2122
-                'button secondary-button right',
2123
-                'dashicons dashicons-cart'
2124
-            );
2125
-        } else {
2126
-            $this->_template_args['view_transaction_button'] = '';
2127
-        }
2128
-        if ($attendee instanceof EE_Attendee
2129
-            && EE_Registry::instance()->CAP->current_user_can(
2130
-                'ee_send_message',
2131
-                'espresso_registrations_resend_registration'
2132
-            )
2133
-        ) {
2134
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2135
-                EE_Admin_Page::add_query_args_and_nonce(
2136
-                    array(
2137
-                        'action'      => 'resend_registration',
2138
-                        '_REG_ID'     => $this->_registration->ID(),
2139
-                        'redirect_to' => 'view_registration',
2140
-                    ),
2141
-                    REG_ADMIN_URL
2142
-                ),
2143
-                esc_html__(' Resend Registration', 'event_espresso'),
2144
-                'button secondary-button right',
2145
-                'dashicons dashicons-email-alt'
2146
-            );
2147
-        } else {
2148
-            $this->_template_args['resend_registration_button'] = '';
2149
-        }
2150
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2151
-        $payment                               = $transaction->get_first_related('Payment');
2152
-        $payment                               = ! $payment instanceof EE_Payment
2153
-            ? EE_Payment::new_instance()
2154
-            : $payment;
2155
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2156
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2157
-            ? EE_Payment_Method::new_instance()
2158
-            : $payment_method;
2159
-        $reg_details                           = array(
2160
-            'payment_method'       => $payment_method->name(),
2161
-            'response_msg'         => $payment->gateway_response(),
2162
-            'registration_id'      => $this->_registration->get('REG_code'),
2163
-            'registration_session' => $this->_registration->session_ID(),
2164
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2165
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2166
-        );
2167
-        if (isset($reg_details['registration_id'])) {
2168
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2169
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2170
-                'Registration ID',
2171
-                'event_espresso'
2172
-            );
2173
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2174
-        }
2175
-        if (isset($reg_details['payment_method'])) {
2176
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2177
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2178
-                'Most Recent Payment Method',
2179
-                'event_espresso'
2180
-            );
2181
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2182
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2183
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2184
-                'Payment method response',
2185
-                'event_espresso'
2186
-            );
2187
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2188
-        }
2189
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2190
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2191
-            'Registration Session',
2192
-            'event_espresso'
2193
-        );
2194
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2195
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2196
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2197
-            'Registration placed from IP',
2198
-            'event_espresso'
2199
-        );
2200
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2201
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2202
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2203
-            'event_espresso');
2204
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2205
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2206
-            array(
2207
-                'action'   => 'default',
2208
-                'event_id' => $this->_registration->event_ID(),
2209
-            ),
2210
-            REG_ADMIN_URL
2211
-        );
2212
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2213
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2214
-        $template_path                                                        =
2215
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2216
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2217
-    }
2218
-
2219
-
2220
-    /**
2221
-     * generates HTML for the Registration Questions meta box.
2222
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2223
-     * otherwise uses new forms system
2224
-     *
2225
-     * @access public
2226
-     * @return void
2227
-     * @throws DomainException
2228
-     * @throws EE_Error
2229
-     */
2230
-    public function _reg_questions_meta_box()
2231
-    {
2232
-        //allow someone to override this method entirely
2233
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2234
-            $this->_registration)) {
2235
-            $form                                              = $this->_get_reg_custom_questions_form(
2236
-                $this->_registration->ID()
2237
-            );
2238
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2239
-                ? $form->get_html_and_js()
2240
-                : '';
2241
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2242
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2243
-            $template_path                                     =
2244
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2245
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2246
-        }
2247
-    }
2248
-
2249
-
2250
-    /**
2251
-     * form_before_question_group
2252
-     *
2253
-     * @deprecated    as of 4.8.32.rc.000
2254
-     * @access        public
2255
-     * @param        string $output
2256
-     * @return        string
2257
-     */
2258
-    public function form_before_question_group($output)
2259
-    {
2260
-        EE_Error::doing_it_wrong(
2261
-            __CLASS__ . '::' . __FUNCTION__,
2262
-            esc_html__(
2263
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2264
-                'event_espresso'
2265
-            ),
2266
-            '4.8.32.rc.000'
2267
-        );
2268
-        return '
1251
+		if (! empty($registration_status)) {
1252
+			$where['STS_ID'] = $registration_status;
1253
+		} else {
1254
+			//make sure we exclude incomplete registrations, but only if not trashed.
1255
+			if ($view === 'trash') {
1256
+				$where['REG_deleted'] = true;
1257
+			} elseif ($view === 'incomplete') {
1258
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1259
+			} else {
1260
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1261
+			}
1262
+		}
1263
+		return $where;
1264
+	}
1265
+
1266
+
1267
+	/**
1268
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1269
+	 *
1270
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1271
+	 * @return array
1272
+	 * @throws EE_Error
1273
+	 */
1274
+	protected function _add_date_to_where_conditions(array $request)
1275
+	{
1276
+		$where = array();
1277
+		$view = EEH_Array::is_set($request, 'status', '');
1278
+		$month_range             = ! empty($request['month_range'])
1279
+			? sanitize_text_field($request['month_range'])
1280
+			: '';
1281
+		$retrieve_for_today      = $view === 'today';
1282
+		$retrieve_for_this_month = $view === 'month';
1283
+
1284
+		if ($retrieve_for_today) {
1285
+			$now               = date('Y-m-d', current_time('timestamp'));
1286
+			$where['REG_date'] = array(
1287
+				'BETWEEN',
1288
+				array(
1289
+					EEM_Registration::instance()->convert_datetime_for_query(
1290
+						'REG_date',
1291
+						$now . ' 00:00:00',
1292
+						'Y-m-d H:i:s'
1293
+					),
1294
+					EEM_Registration::instance()->convert_datetime_for_query(
1295
+						'REG_date',
1296
+						$now . ' 23:59:59',
1297
+						'Y-m-d H:i:s'
1298
+					),
1299
+				),
1300
+			);
1301
+		} elseif ($retrieve_for_this_month) {
1302
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1303
+			$days_this_month        = date('t', current_time('timestamp'));
1304
+			$where['REG_date']      = array(
1305
+				'BETWEEN',
1306
+				array(
1307
+					EEM_Registration::instance()->convert_datetime_for_query(
1308
+						'REG_date',
1309
+						$current_year_and_month . '-01 00:00:00',
1310
+						'Y-m-d H:i:s'
1311
+					),
1312
+					EEM_Registration::instance()->convert_datetime_for_query(
1313
+						'REG_date',
1314
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1315
+						'Y-m-d H:i:s'
1316
+					),
1317
+				),
1318
+			);
1319
+		} elseif ($month_range) {
1320
+			$pieces          = explode(' ', $month_range, 3);
1321
+			$month_requested = ! empty($pieces[0])
1322
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1323
+				: '';
1324
+			$year_requested  = ! empty($pieces[1])
1325
+				? $pieces[1]
1326
+				: '';
1327
+			//if there is not a month or year then we can't go further
1328
+			if ($month_requested && $year_requested) {
1329
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1330
+				$where['REG_date'] = array(
1331
+					'BETWEEN',
1332
+					array(
1333
+						EEM_Registration::instance()->convert_datetime_for_query(
1334
+							'REG_date',
1335
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1336
+							'Y-m-d H:i:s'
1337
+						),
1338
+						EEM_Registration::instance()->convert_datetime_for_query(
1339
+							'REG_date',
1340
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1341
+							'Y-m-d H:i:s'
1342
+						),
1343
+					),
1344
+				);
1345
+			}
1346
+		}
1347
+		return $where;
1348
+	}
1349
+
1350
+
1351
+	/**
1352
+	 * Adds any provided search restraints to the where conditions for the registrations query
1353
+	 *
1354
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1355
+	 * @return array
1356
+	 */
1357
+	protected function _add_search_to_where_conditions(array $request)
1358
+	{
1359
+		$where = array();
1360
+		if (! empty($request['s'])) {
1361
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1362
+			$where['OR*search_conditions'] = array(
1363
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1364
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1365
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1366
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1367
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1368
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1369
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1370
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1371
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1372
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1373
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1374
+				'REG_final_price'                         => array('LIKE', $search_string),
1375
+				'REG_code'                                => array('LIKE', $search_string),
1376
+				'REG_count'                               => array('LIKE', $search_string),
1377
+				'REG_group_size'                          => array('LIKE', $search_string),
1378
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1379
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1380
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1381
+			);
1382
+		}
1383
+		return $where;
1384
+	}
1385
+
1386
+
1387
+	/**
1388
+	 * Sets up the where conditions for the registrations query.
1389
+	 *
1390
+	 * @param array $request
1391
+	 * @return array
1392
+	 * @throws EE_Error
1393
+	 */
1394
+	protected function _get_where_conditions_for_registrations_query($request)
1395
+	{
1396
+		return apply_filters(
1397
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1398
+			array_merge(
1399
+				$this->_add_event_id_to_where_conditions($request),
1400
+				$this->_add_category_id_to_where_conditions($request),
1401
+				$this->_add_datetime_id_to_where_conditions($request),
1402
+				$this->_add_registration_status_to_where_conditions($request),
1403
+				$this->_add_date_to_where_conditions($request),
1404
+				$this->_add_search_to_where_conditions($request)
1405
+			),
1406
+			$request
1407
+		);
1408
+	}
1409
+
1410
+
1411
+	/**
1412
+	 * Sets up the orderby for the registrations query.
1413
+	 *
1414
+	 * @return array
1415
+	 */
1416
+	protected function _get_orderby_for_registrations_query()
1417
+	{
1418
+		$orderby_field = ! empty($this->_req_data['orderby'])
1419
+			? sanitize_text_field($this->_req_data['orderby'])
1420
+			: '';
1421
+		switch ($orderby_field) {
1422
+			case '_REG_ID':
1423
+				$orderby_field = 'REG_ID';
1424
+				break;
1425
+			case '_Reg_status':
1426
+				$orderby_field = 'STS_ID';
1427
+				break;
1428
+			case 'ATT_fname':
1429
+				$orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1430
+				break;
1431
+			case 'ATT_lname':
1432
+				$orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1433
+				break;
1434
+			case 'event_name':
1435
+				$orderby_field = 'Event.EVT_name';
1436
+				break;
1437
+			case 'DTT_EVT_start':
1438
+				$orderby_field = 'Event.Datetime.DTT_EVT_start';
1439
+				break;
1440
+			default: //'REG_date'
1441
+				$orderby_field = 'REG_date';
1442
+		}
1443
+
1444
+		//order
1445
+		$order = ! empty($this->_req_data['order'])
1446
+			? sanitize_text_field($this->_req_data['order'])
1447
+			: 'DESC';
1448
+
1449
+		//mutate orderby_field
1450
+		$orderby_field = array_combine(
1451
+			(array) $orderby_field,
1452
+			array_fill(0, count($orderby_field), $order)
1453
+		);
1454
+		//because there are many registrations with the same date, define
1455
+		//a secondary way to order them, otherwise MySQL seems to be a bit random
1456
+		if (empty($order['REG_ID'])) {
1457
+			$orderby_field['REG_ID'] = $order;
1458
+		}
1459
+		return array('order_by' => $orderby_field);
1460
+	}
1461
+
1462
+
1463
+	/**
1464
+	 * Sets up the limit for the registrations query.
1465
+	 *
1466
+	 * @param $per_page
1467
+	 * @return array
1468
+	 */
1469
+	protected function _get_limit($per_page)
1470
+	{
1471
+		$current_page = ! empty($this->_req_data['paged'])
1472
+			? absint($this->_req_data['paged'])
1473
+			: 1;
1474
+		$per_page     = ! empty($this->_req_data['perpage'])
1475
+			? $this->_req_data['perpage']
1476
+			: $per_page;
1477
+
1478
+		//-1 means return all results so get out if that's set.
1479
+		if ((int)$per_page === -1) {
1480
+			return array();
1481
+		}
1482
+		$per_page = absint($per_page);
1483
+		$offset   = ($current_page - 1) * $per_page;
1484
+		return array('limit' => array($offset, $per_page));
1485
+	}
1486
+
1487
+
1488
+	public function get_registration_status_array()
1489
+	{
1490
+		return self::$_reg_status;
1491
+	}
1492
+
1493
+
1494
+
1495
+
1496
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1497
+	/**
1498
+	 *        generates HTML for the View Registration Details Admin page
1499
+	 *
1500
+	 * @access protected
1501
+	 * @return void
1502
+	 * @throws DomainException
1503
+	 * @throws EE_Error
1504
+	 * @throws EntityNotFoundException
1505
+	 */
1506
+	protected function _registration_details()
1507
+	{
1508
+		$this->_template_args = array();
1509
+		$this->_set_registration_object();
1510
+		if (is_object($this->_registration)) {
1511
+			$transaction                                   = $this->_registration->transaction()
1512
+				? $this->_registration->transaction()
1513
+				: EE_Transaction::new_instance();
1514
+			$this->_session                                = $transaction->session_data();
1515
+			$event_id                                      = $this->_registration->event_ID();
1516
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1517
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1518
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1519
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1520
+			$this->_template_args['grand_total']           = $transaction->total();
1521
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1522
+			// link back to overview
1523
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1524
+			$this->_template_args['registration']                = $this->_registration;
1525
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1526
+				array(
1527
+					'action'   => 'default',
1528
+					'event_id' => $event_id,
1529
+				),
1530
+				REG_ADMIN_URL
1531
+			);
1532
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1533
+				array(
1534
+					'action' => 'default',
1535
+					'EVT_ID' => $event_id,
1536
+					'page'   => 'espresso_transactions',
1537
+				),
1538
+				admin_url('admin.php')
1539
+			);
1540
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1541
+				array(
1542
+					'page'   => 'espresso_events',
1543
+					'action' => 'edit',
1544
+					'post'   => $event_id,
1545
+				),
1546
+				admin_url('admin.php')
1547
+			);
1548
+			//next and previous links
1549
+			$next_reg                                      = $this->_registration->next(
1550
+				null,
1551
+				array(),
1552
+				'REG_ID'
1553
+			);
1554
+			$this->_template_args['next_registration']     = $next_reg
1555
+				? $this->_next_link(
1556
+					EE_Admin_Page::add_query_args_and_nonce(
1557
+						array(
1558
+							'action'  => 'view_registration',
1559
+							'_REG_ID' => $next_reg['REG_ID'],
1560
+						),
1561
+						REG_ADMIN_URL
1562
+					),
1563
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1564
+				)
1565
+				: '';
1566
+			$previous_reg                                  = $this->_registration->previous(
1567
+				null,
1568
+				array(),
1569
+				'REG_ID'
1570
+			);
1571
+			$this->_template_args['previous_registration'] = $previous_reg
1572
+				? $this->_previous_link(
1573
+					EE_Admin_Page::add_query_args_and_nonce(
1574
+						array(
1575
+							'action'  => 'view_registration',
1576
+							'_REG_ID' => $previous_reg['REG_ID'],
1577
+						),
1578
+						REG_ADMIN_URL
1579
+					),
1580
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1581
+				)
1582
+				: '';
1583
+			// grab header
1584
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1585
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1586
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1587
+				$template_path,
1588
+				$this->_template_args,
1589
+				true
1590
+			);
1591
+		} else {
1592
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1593
+		}
1594
+		// the details template wrapper
1595
+		$this->display_admin_page_with_sidebar();
1596
+	}
1597
+
1598
+
1599
+	protected function _registration_details_metaboxes()
1600
+	{
1601
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1602
+		$this->_set_registration_object();
1603
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1604
+		add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1605
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1606
+		add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1607
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1608
+		if ($attendee instanceof EE_Attendee
1609
+			&& EE_Registry::instance()->CAP->current_user_can(
1610
+				'ee_edit_registration',
1611
+				'edit-reg-questions-mbox',
1612
+				$this->_registration->ID()
1613
+			)
1614
+		) {
1615
+			add_meta_box(
1616
+				'edit-reg-questions-mbox',
1617
+				esc_html__('Registration Form Answers', 'event_espresso'),
1618
+				array($this, '_reg_questions_meta_box'),
1619
+				$this->wp_page_slug,
1620
+				'normal',
1621
+				'high'
1622
+			);
1623
+		}
1624
+		add_meta_box(
1625
+			'edit-reg-registrant-mbox',
1626
+			esc_html__('Contact Details', 'event_espresso'),
1627
+			array($this, '_reg_registrant_side_meta_box'),
1628
+			$this->wp_page_slug,
1629
+			'side',
1630
+			'high'
1631
+		);
1632
+		if ($this->_registration->group_size() > 1) {
1633
+			add_meta_box(
1634
+				'edit-reg-attendees-mbox',
1635
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1636
+				array($this, '_reg_attendees_meta_box'),
1637
+				$this->wp_page_slug,
1638
+				'normal',
1639
+				'high'
1640
+			);
1641
+		}
1642
+	}
1643
+
1644
+
1645
+	/**
1646
+	 * set_reg_status_buttons_metabox
1647
+	 *
1648
+	 * @access protected
1649
+	 * @return string
1650
+	 * @throws \EE_Error
1651
+	 */
1652
+	public function set_reg_status_buttons_metabox()
1653
+	{
1654
+		$this->_set_registration_object();
1655
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1656
+		echo $change_reg_status_form->form_open(
1657
+			self::add_query_args_and_nonce(
1658
+				array(
1659
+					'action' => 'change_reg_status',
1660
+				),
1661
+				REG_ADMIN_URL
1662
+			)
1663
+		);
1664
+		echo $change_reg_status_form->get_html();
1665
+		echo $change_reg_status_form->form_close();
1666
+	}
1667
+
1668
+
1669
+
1670
+	/**
1671
+	 * @return EE_Form_Section_Proper
1672
+	 * @throws EE_Error
1673
+	 */
1674
+	protected function _generate_reg_status_change_form()
1675
+	{
1676
+		return new EE_Form_Section_Proper(array(
1677
+			'name'            => 'reg_status_change_form',
1678
+			'html_id'         => 'reg-status-change-form',
1679
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1680
+			'subsections'     => array(
1681
+				'return'             => new EE_Hidden_Input(array(
1682
+					'name'    => 'return',
1683
+					'default' => 'view_registration',
1684
+				)),
1685
+				'REG_ID'             => new EE_Hidden_Input(array(
1686
+					'name'    => 'REG_ID',
1687
+					'default' => $this->_registration->ID(),
1688
+				)),
1689
+				'current_status'     => new EE_Form_Section_HTML(
1690
+					EEH_HTML::tr(
1691
+						EEH_HTML::th(
1692
+							EEH_HTML::label(
1693
+								EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1694
+								)
1695
+							)
1696
+						)
1697
+						. EEH_HTML::td(
1698
+							EEH_HTML::strong(
1699
+								$this->_registration->pretty_status(),
1700
+								'',
1701
+								'status-' . $this->_registration->status_ID(),
1702
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1703
+							)
1704
+						)
1705
+					)
1706
+				),
1707
+				'reg_status'         => new EE_Select_Input(
1708
+					$this->_get_reg_statuses(),
1709
+					array(
1710
+						'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1711
+						'default'         => $this->_registration->status_ID(),
1712
+					)
1713
+				),
1714
+				'send_notifications' => new EE_Yes_No_Input(
1715
+					array(
1716
+						'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1717
+						'default'         => false,
1718
+						'html_help_text'  => esc_html__(
1719
+							'If set to "Yes", then the related messages will be sent to the registrant.',
1720
+							'event_espresso'
1721
+						),
1722
+					)
1723
+				),
1724
+				'submit'             => new EE_Submit_Input(
1725
+					array(
1726
+						'html_class'      => 'button-primary',
1727
+						'html_label_text' => '&nbsp;',
1728
+						'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1729
+					)
1730
+				),
1731
+			),
1732
+		));
1733
+	}
1734
+
1735
+
1736
+	/**
1737
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1738
+	 *
1739
+	 * @return array
1740
+	 * @throws EE_Error
1741
+	 * @throws EntityNotFoundException
1742
+	 */
1743
+	protected function _get_reg_statuses()
1744
+	{
1745
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1746
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1747
+		// get current reg status
1748
+		$current_status = $this->_registration->status_ID();
1749
+		// is registration for free event? This will determine whether to display the pending payment option
1750
+		if (
1751
+			$current_status !== EEM_Registration::status_id_pending_payment
1752
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1753
+		) {
1754
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1755
+		}
1756
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1757
+	}
1758
+
1759
+
1760
+	/**
1761
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1762
+	 *
1763
+	 * @param bool $status REG status given for changing registrations to.
1764
+	 * @param bool $notify Whether to send messages notifications or not.
1765
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1766
+	 * @throws EE_Error
1767
+	 * @throws InvalidArgumentException
1768
+	 * @throws InvalidDataTypeException
1769
+	 * @throws InvalidInterfaceException
1770
+	 * @throws ReflectionException
1771
+	 * @throws RuntimeException
1772
+	 * @throws EntityNotFoundException
1773
+	 */
1774
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1775
+	{
1776
+		if (isset($this->_req_data['reg_status_change_form'])) {
1777
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1778
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1779
+				: array();
1780
+		} else {
1781
+			$REG_IDs = isset($this->_req_data['_REG_ID'])
1782
+				? (array)$this->_req_data['_REG_ID']
1783
+				: array();
1784
+		}
1785
+		// sanitize $REG_IDs
1786
+		$REG_IDs = array_map('absint', $REG_IDs);
1787
+		// and remove empty entries
1788
+		$REG_IDs = array_filter($REG_IDs);
1789
+
1790
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1791
+
1792
+		/**
1793
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1794
+		 * Currently this value is used downstream by the _process_resend_registration method.
1795
+		 *
1796
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1797
+		 * @param bool                     $status           The status registrations were changed to.
1798
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1799
+		 * @param Registrations_Admin_Page $admin_page_object
1800
+		 */
1801
+		$this->_req_data['_REG_ID'] = apply_filters(
1802
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1803
+			$result['REG_ID'],
1804
+			$status,
1805
+			$result['success'],
1806
+			$this
1807
+		);
1808
+
1809
+		//notify?
1810
+		if ($notify
1811
+			&& $result['success']
1812
+			&& ! empty($this->_req_data['_REG_ID'])
1813
+			&& EE_Registry::instance()->CAP->current_user_can(
1814
+				'ee_send_message',
1815
+				'espresso_registrations_resend_registration'
1816
+			)
1817
+		) {
1818
+			$this->_process_resend_registration();
1819
+		}
1820
+		return $result;
1821
+	}
1822
+
1823
+
1824
+	/**
1825
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1826
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1827
+	 *
1828
+	 * @param array  $REG_IDs
1829
+	 * @param string $status
1830
+	 * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1831
+	 *                        slug sent with setting the registration status.
1832
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1833
+	 * @throws EE_Error
1834
+	 * @throws InvalidArgumentException
1835
+	 * @throws InvalidDataTypeException
1836
+	 * @throws InvalidInterfaceException
1837
+	 * @throws ReflectionException
1838
+	 * @throws RuntimeException
1839
+	 * @throws EntityNotFoundException
1840
+	 */
1841
+	protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1842
+	{
1843
+		$success = false;
1844
+		// typecast $REG_IDs
1845
+		$REG_IDs = (array)$REG_IDs;
1846
+		if ( ! empty($REG_IDs)) {
1847
+			$success = true;
1848
+			// set default status if none is passed
1849
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1850
+			$status_context = $notify
1851
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1852
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1853
+			//loop through REG_ID's and change status
1854
+			foreach ($REG_IDs as $REG_ID) {
1855
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1856
+				if ($registration instanceof EE_Registration) {
1857
+					$registration->set_status(
1858
+						$status,
1859
+						false,
1860
+						new Context(
1861
+							$status_context,
1862
+							esc_html__(
1863
+								'Manually triggered status change on a Registration Admin Page route.',
1864
+								'event_espresso'
1865
+							)
1866
+						)
1867
+					);
1868
+					$result = $registration->save();
1869
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1870
+					$success = $result !== false ? $success : false;
1871
+				}
1872
+			}
1873
+		}
1874
+
1875
+		//return $success and processed registrations
1876
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1877
+	}
1878
+
1879
+
1880
+	/**
1881
+	 * Common logic for setting up success message and redirecting to appropriate route
1882
+	 *
1883
+	 * @param  string $STS_ID status id for the registration changed to
1884
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1885
+	 * @return void
1886
+	 */
1887
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1888
+	{
1889
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1890
+			: array('success' => false);
1891
+		$success = isset($result['success']) && $result['success'];
1892
+		//setup success message
1893
+		if ($success) {
1894
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1895
+				$msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1896
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1897
+			} else {
1898
+				$msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1899
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1900
+			}
1901
+			EE_Error::add_success($msg);
1902
+		} else {
1903
+			EE_Error::add_error(
1904
+				esc_html__(
1905
+					'Something went wrong, and the status was not changed',
1906
+					'event_espresso'
1907
+				), __FILE__, __LINE__, __FUNCTION__
1908
+			);
1909
+		}
1910
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1911
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1912
+		} else {
1913
+			$route = array('action' => 'default');
1914
+		}
1915
+		//unset nonces
1916
+		foreach ($this->_req_data as $ref => $value) {
1917
+			if (strpos($ref, 'nonce') !== false) {
1918
+				unset($this->_req_data[$ref]);
1919
+				continue;
1920
+			}
1921
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1922
+			$this->_req_data[$ref] = $value;
1923
+		}
1924
+		//merge request vars so that the reloaded list table contains any existing filter query params
1925
+		$route = array_merge($this->_req_data, $route);
1926
+		$this->_redirect_after_action($success, '', '', $route, true);
1927
+	}
1928
+
1929
+
1930
+	/**
1931
+	 * incoming reg status change from reg details page.
1932
+	 *
1933
+	 * @return void
1934
+	 */
1935
+	protected function _change_reg_status()
1936
+	{
1937
+		$this->_req_data['return'] = 'view_registration';
1938
+		//set notify based on whether the send notifications toggle is set or not
1939
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1940
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1941
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1942
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1943
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1944
+			case EEM_Registration::status_id_approved :
1945
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1946
+				$this->approve_registration($notify);
1947
+				break;
1948
+			case EEM_Registration::status_id_pending_payment :
1949
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1950
+				$this->pending_registration($notify);
1951
+				break;
1952
+			case EEM_Registration::status_id_not_approved :
1953
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1954
+				$this->not_approve_registration($notify);
1955
+				break;
1956
+			case EEM_Registration::status_id_declined :
1957
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1958
+				$this->decline_registration($notify);
1959
+				break;
1960
+			case EEM_Registration::status_id_cancelled :
1961
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1962
+				$this->cancel_registration($notify);
1963
+				break;
1964
+			case EEM_Registration::status_id_wait_list :
1965
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1966
+				$this->wait_list_registration($notify);
1967
+				break;
1968
+			case EEM_Registration::status_id_incomplete :
1969
+			default :
1970
+				$result['success'] = false;
1971
+				unset($this->_req_data['return']);
1972
+				$this->_reg_status_change_return('', false);
1973
+				break;
1974
+		}
1975
+	}
1976
+
1977
+
1978
+	/**
1979
+	 * Callback for bulk action routes.
1980
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1981
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1982
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1983
+	 * when an action is happening on just a single registration).
1984
+	 * @param      $action
1985
+	 * @param bool $notify
1986
+	 */
1987
+	protected function bulk_action_on_registrations($action, $notify = false) {
1988
+		do_action(
1989
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1990
+			$this,
1991
+			$action,
1992
+			$notify
1993
+		);
1994
+		$method = $action . '_registration';
1995
+		if (method_exists($this, $method)) {
1996
+			$this->$method($notify);
1997
+		}
1998
+	}
1999
+
2000
+
2001
+	/**
2002
+	 * approve_registration
2003
+	 *
2004
+	 * @access protected
2005
+	 * @param bool $notify whether or not to notify the registrant about their approval.
2006
+	 * @return void
2007
+	 */
2008
+	protected function approve_registration($notify = false)
2009
+	{
2010
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2011
+	}
2012
+
2013
+
2014
+	/**
2015
+	 *        decline_registration
2016
+	 *
2017
+	 * @access protected
2018
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2019
+	 * @return void
2020
+	 */
2021
+	protected function decline_registration($notify = false)
2022
+	{
2023
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2024
+	}
2025
+
2026
+
2027
+	/**
2028
+	 *        cancel_registration
2029
+	 *
2030
+	 * @access protected
2031
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2032
+	 * @return void
2033
+	 */
2034
+	protected function cancel_registration($notify = false)
2035
+	{
2036
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2037
+	}
2038
+
2039
+
2040
+	/**
2041
+	 *        not_approve_registration
2042
+	 *
2043
+	 * @access protected
2044
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2045
+	 * @return void
2046
+	 */
2047
+	protected function not_approve_registration($notify = false)
2048
+	{
2049
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2050
+	}
2051
+
2052
+
2053
+	/**
2054
+	 *        decline_registration
2055
+	 *
2056
+	 * @access protected
2057
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2058
+	 * @return void
2059
+	 */
2060
+	protected function pending_registration($notify = false)
2061
+	{
2062
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2063
+	}
2064
+
2065
+
2066
+	/**
2067
+	 * waitlist_registration
2068
+	 *
2069
+	 * @access protected
2070
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2071
+	 * @return void
2072
+	 */
2073
+	protected function wait_list_registration($notify = false)
2074
+	{
2075
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2076
+	}
2077
+
2078
+
2079
+	/**
2080
+	 *        generates HTML for the Registration main meta box
2081
+	 *
2082
+	 * @access public
2083
+	 * @return void
2084
+	 * @throws DomainException
2085
+	 * @throws EE_Error
2086
+	 * @throws EntityNotFoundException
2087
+	 */
2088
+	public function _reg_details_meta_box()
2089
+	{
2090
+		EEH_Autoloader::register_line_item_display_autoloaders();
2091
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2092
+		EE_Registry::instance()->load_helper('Line_Item');
2093
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2094
+			: EE_Transaction::new_instance();
2095
+		$this->_session = $transaction->session_data();
2096
+		$filters        = new EE_Line_Item_Filter_Collection();
2097
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2098
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2099
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2100
+			$transaction->total_line_item());
2101
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2102
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2103
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2104
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2105
+			$filtered_line_item_tree,
2106
+			array('EE_Registration' => $this->_registration)
2107
+		);
2108
+		$attendee                                = $this->_registration->attendee();
2109
+		if (EE_Registry::instance()->CAP->current_user_can(
2110
+			'ee_read_transaction',
2111
+			'espresso_transactions_view_transaction'
2112
+		)) {
2113
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2114
+				EE_Admin_Page::add_query_args_and_nonce(
2115
+					array(
2116
+						'action' => 'view_transaction',
2117
+						'TXN_ID' => $transaction->ID(),
2118
+					),
2119
+					TXN_ADMIN_URL
2120
+				),
2121
+				esc_html__(' View Transaction', 'event_espresso'),
2122
+				'button secondary-button right',
2123
+				'dashicons dashicons-cart'
2124
+			);
2125
+		} else {
2126
+			$this->_template_args['view_transaction_button'] = '';
2127
+		}
2128
+		if ($attendee instanceof EE_Attendee
2129
+			&& EE_Registry::instance()->CAP->current_user_can(
2130
+				'ee_send_message',
2131
+				'espresso_registrations_resend_registration'
2132
+			)
2133
+		) {
2134
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2135
+				EE_Admin_Page::add_query_args_and_nonce(
2136
+					array(
2137
+						'action'      => 'resend_registration',
2138
+						'_REG_ID'     => $this->_registration->ID(),
2139
+						'redirect_to' => 'view_registration',
2140
+					),
2141
+					REG_ADMIN_URL
2142
+				),
2143
+				esc_html__(' Resend Registration', 'event_espresso'),
2144
+				'button secondary-button right',
2145
+				'dashicons dashicons-email-alt'
2146
+			);
2147
+		} else {
2148
+			$this->_template_args['resend_registration_button'] = '';
2149
+		}
2150
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2151
+		$payment                               = $transaction->get_first_related('Payment');
2152
+		$payment                               = ! $payment instanceof EE_Payment
2153
+			? EE_Payment::new_instance()
2154
+			: $payment;
2155
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2156
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2157
+			? EE_Payment_Method::new_instance()
2158
+			: $payment_method;
2159
+		$reg_details                           = array(
2160
+			'payment_method'       => $payment_method->name(),
2161
+			'response_msg'         => $payment->gateway_response(),
2162
+			'registration_id'      => $this->_registration->get('REG_code'),
2163
+			'registration_session' => $this->_registration->session_ID(),
2164
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2165
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2166
+		);
2167
+		if (isset($reg_details['registration_id'])) {
2168
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2169
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2170
+				'Registration ID',
2171
+				'event_espresso'
2172
+			);
2173
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2174
+		}
2175
+		if (isset($reg_details['payment_method'])) {
2176
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2177
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2178
+				'Most Recent Payment Method',
2179
+				'event_espresso'
2180
+			);
2181
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2182
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2183
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2184
+				'Payment method response',
2185
+				'event_espresso'
2186
+			);
2187
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2188
+		}
2189
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2190
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2191
+			'Registration Session',
2192
+			'event_espresso'
2193
+		);
2194
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2195
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2196
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2197
+			'Registration placed from IP',
2198
+			'event_espresso'
2199
+		);
2200
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2201
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2202
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2203
+			'event_espresso');
2204
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2205
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2206
+			array(
2207
+				'action'   => 'default',
2208
+				'event_id' => $this->_registration->event_ID(),
2209
+			),
2210
+			REG_ADMIN_URL
2211
+		);
2212
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2213
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2214
+		$template_path                                                        =
2215
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2216
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2217
+	}
2218
+
2219
+
2220
+	/**
2221
+	 * generates HTML for the Registration Questions meta box.
2222
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2223
+	 * otherwise uses new forms system
2224
+	 *
2225
+	 * @access public
2226
+	 * @return void
2227
+	 * @throws DomainException
2228
+	 * @throws EE_Error
2229
+	 */
2230
+	public function _reg_questions_meta_box()
2231
+	{
2232
+		//allow someone to override this method entirely
2233
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2234
+			$this->_registration)) {
2235
+			$form                                              = $this->_get_reg_custom_questions_form(
2236
+				$this->_registration->ID()
2237
+			);
2238
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2239
+				? $form->get_html_and_js()
2240
+				: '';
2241
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2242
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2243
+			$template_path                                     =
2244
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2245
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2246
+		}
2247
+	}
2248
+
2249
+
2250
+	/**
2251
+	 * form_before_question_group
2252
+	 *
2253
+	 * @deprecated    as of 4.8.32.rc.000
2254
+	 * @access        public
2255
+	 * @param        string $output
2256
+	 * @return        string
2257
+	 */
2258
+	public function form_before_question_group($output)
2259
+	{
2260
+		EE_Error::doing_it_wrong(
2261
+			__CLASS__ . '::' . __FUNCTION__,
2262
+			esc_html__(
2263
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2264
+				'event_espresso'
2265
+			),
2266
+			'4.8.32.rc.000'
2267
+		);
2268
+		return '
2269 2269
 	<table class="form-table ee-width-100">
2270 2270
 		<tbody>
2271 2271
 			';
2272
-    }
2273
-
2274
-
2275
-    /**
2276
-     * form_after_question_group
2277
-     *
2278
-     * @deprecated    as of 4.8.32.rc.000
2279
-     * @access        public
2280
-     * @param        string $output
2281
-     * @return        string
2282
-     */
2283
-    public function form_after_question_group($output)
2284
-    {
2285
-        EE_Error::doing_it_wrong(
2286
-            __CLASS__ . '::' . __FUNCTION__,
2287
-            esc_html__(
2288
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2289
-                'event_espresso'
2290
-            ),
2291
-            '4.8.32.rc.000'
2292
-        );
2293
-        return '
2272
+	}
2273
+
2274
+
2275
+	/**
2276
+	 * form_after_question_group
2277
+	 *
2278
+	 * @deprecated    as of 4.8.32.rc.000
2279
+	 * @access        public
2280
+	 * @param        string $output
2281
+	 * @return        string
2282
+	 */
2283
+	public function form_after_question_group($output)
2284
+	{
2285
+		EE_Error::doing_it_wrong(
2286
+			__CLASS__ . '::' . __FUNCTION__,
2287
+			esc_html__(
2288
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2289
+				'event_espresso'
2290
+			),
2291
+			'4.8.32.rc.000'
2292
+		);
2293
+		return '
2294 2294
 			<tr class="hide-if-no-js">
2295 2295
 				<th> </th>
2296 2296
 				<td class="reg-admin-edit-attendee-question-td">
2297 2297
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2298
-               . esc_attr__('click to edit question', 'event_espresso')
2299
-               . '">
2298
+			   . esc_attr__('click to edit question', 'event_espresso')
2299
+			   . '">
2300 2300
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2301
-               . esc_html__('edit the above question group', 'event_espresso')
2302
-               . '</span>
2301
+			   . esc_html__('edit the above question group', 'event_espresso')
2302
+			   . '</span>
2303 2303
 						<div class="dashicons dashicons-edit"></div>
2304 2304
 					</a>
2305 2305
 				</td>
@@ -2307,558 +2307,558 @@  discard block
 block discarded – undo
2307 2307
 		</tbody>
2308 2308
 	</table>
2309 2309
 ';
2310
-    }
2311
-
2312
-
2313
-    /**
2314
-     * form_form_field_label_wrap
2315
-     *
2316
-     * @deprecated    as of 4.8.32.rc.000
2317
-     * @access        public
2318
-     * @param        string $label
2319
-     * @return        string
2320
-     */
2321
-    public function form_form_field_label_wrap($label)
2322
-    {
2323
-        EE_Error::doing_it_wrong(
2324
-            __CLASS__ . '::' . __FUNCTION__,
2325
-            esc_html__(
2326
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2327
-                'event_espresso'
2328
-            ),
2329
-            '4.8.32.rc.000'
2330
-        );
2331
-        return '
2310
+	}
2311
+
2312
+
2313
+	/**
2314
+	 * form_form_field_label_wrap
2315
+	 *
2316
+	 * @deprecated    as of 4.8.32.rc.000
2317
+	 * @access        public
2318
+	 * @param        string $label
2319
+	 * @return        string
2320
+	 */
2321
+	public function form_form_field_label_wrap($label)
2322
+	{
2323
+		EE_Error::doing_it_wrong(
2324
+			__CLASS__ . '::' . __FUNCTION__,
2325
+			esc_html__(
2326
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2327
+				'event_espresso'
2328
+			),
2329
+			'4.8.32.rc.000'
2330
+		);
2331
+		return '
2332 2332
 			<tr>
2333 2333
 				<th>
2334 2334
 					' . $label . '
2335 2335
 				</th>';
2336
-    }
2337
-
2338
-
2339
-    /**
2340
-     * form_form_field_input__wrap
2341
-     *
2342
-     * @deprecated    as of 4.8.32.rc.000
2343
-     * @access        public
2344
-     * @param        string $input
2345
-     * @return        string
2346
-     */
2347
-    public function form_form_field_input__wrap($input)
2348
-    {
2349
-        EE_Error::doing_it_wrong(
2350
-            __CLASS__ . '::' . __FUNCTION__,
2351
-            esc_html__(
2352
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2353
-                'event_espresso'
2354
-            ),
2355
-            '4.8.32.rc.000'
2356
-        );
2357
-        return '
2336
+	}
2337
+
2338
+
2339
+	/**
2340
+	 * form_form_field_input__wrap
2341
+	 *
2342
+	 * @deprecated    as of 4.8.32.rc.000
2343
+	 * @access        public
2344
+	 * @param        string $input
2345
+	 * @return        string
2346
+	 */
2347
+	public function form_form_field_input__wrap($input)
2348
+	{
2349
+		EE_Error::doing_it_wrong(
2350
+			__CLASS__ . '::' . __FUNCTION__,
2351
+			esc_html__(
2352
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2353
+				'event_espresso'
2354
+			),
2355
+			'4.8.32.rc.000'
2356
+		);
2357
+		return '
2358 2358
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2359 2359
 					' . $input . '
2360 2360
 				</td>
2361 2361
 			</tr>';
2362
-    }
2363
-
2364
-
2365
-    /**
2366
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2367
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2368
-     * to display the page
2369
-     *
2370
-     * @access protected
2371
-     * @return void
2372
-     * @throws EE_Error
2373
-     */
2374
-    protected function _update_attendee_registration_form()
2375
-    {
2376
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2377
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2378
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2379
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2380
-            if ($success) {
2381
-                $what  = esc_html__('Registration Form', 'event_espresso');
2382
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2383
-                    : array('action' => 'default');
2384
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2385
-            }
2386
-        }
2387
-    }
2388
-
2389
-
2390
-    /**
2391
-     * Gets the form for saving registrations custom questions (if done
2392
-     * previously retrieves the cached form object, which may have validation errors in it)
2393
-     *
2394
-     * @param int $REG_ID
2395
-     * @return EE_Registration_Custom_Questions_Form
2396
-     * @throws EE_Error
2397
-     */
2398
-    protected function _get_reg_custom_questions_form($REG_ID)
2399
-    {
2400
-        if ( ! $this->_reg_custom_questions_form) {
2401
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2402
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2403
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2404
-            );
2405
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2406
-        }
2407
-        return $this->_reg_custom_questions_form;
2408
-    }
2409
-
2410
-
2411
-    /**
2412
-     * Saves
2413
-     *
2414
-     * @access private
2415
-     * @param bool $REG_ID
2416
-     * @return bool
2417
-     * @throws EE_Error
2418
-     */
2419
-    private function _save_reg_custom_questions_form($REG_ID = false)
2420
-    {
2421
-        if ( ! $REG_ID) {
2422
-            EE_Error::add_error(
2423
-                esc_html__(
2424
-                    'An error occurred. No registration ID was received.', 'event_espresso'),
2425
-                __FILE__, __FUNCTION__, __LINE__
2426
-            );
2427
-        }
2428
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2429
-        $form->receive_form_submission($this->_req_data);
2430
-        $success = false;
2431
-        if ($form->is_valid()) {
2432
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2433
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2434
-                    $where_conditions    = array(
2435
-                        'QST_ID' => $question_id,
2436
-                        'REG_ID' => $REG_ID,
2437
-                    );
2438
-                    $possibly_new_values = array(
2439
-                        'ANS_value' => $input->normalized_value(),
2440
-                    );
2441
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2442
-                    if ($answer instanceof EE_Answer) {
2443
-                        $success = $answer->save($possibly_new_values);
2444
-                    } else {
2445
-                        //insert it then
2446
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2447
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2448
-                        $success     = $answer->save();
2449
-                    }
2450
-                }
2451
-            }
2452
-        } else {
2453
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2454
-        }
2455
-        return $success;
2456
-    }
2457
-
2458
-
2459
-    /**
2460
-     *        generates HTML for the Registration main meta box
2461
-     *
2462
-     * @access public
2463
-     * @return void
2464
-     * @throws DomainException
2465
-     * @throws EE_Error
2466
-     */
2467
-    public function _reg_attendees_meta_box()
2468
-    {
2469
-        $REG = EEM_Registration::instance();
2470
-        //get all other registrations on this transaction, and cache
2471
-        //the attendees for them so we don't have to run another query using force_join
2472
-        $registrations                           = $REG->get_all(array(
2473
-            array(
2474
-                'TXN_ID' => $this->_registration->transaction_ID(),
2475
-                'REG_ID' => array('!=', $this->_registration->ID()),
2476
-            ),
2477
-            'force_join' => array('Attendee'),
2478
-        ));
2479
-        $this->_template_args['attendees']       = array();
2480
-        $this->_template_args['attendee_notice'] = '';
2481
-        if (empty($registrations)
2482
-            || (is_array($registrations)
2483
-                && ! EEH_Array::get_one_item_from_array($registrations))
2484
-        ) {
2485
-            EE_Error::add_error(
2486
-                esc_html__(
2487
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2488
-                    'event_espresso'
2489
-                ), __FILE__, __FUNCTION__, __LINE__
2490
-            );
2491
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2492
-        } else {
2493
-            $att_nmbr = 1;
2494
-            foreach ($registrations as $registration) {
2495
-                /* @var $registration EE_Registration */
2496
-                $attendee                                                    = $registration->attendee()
2497
-                    ? $registration->attendee()
2498
-                    : EEM_Attendee::instance()
2499
-                                  ->create_default_object();
2500
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2501
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2502
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2503
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2504
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2505
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2506
-                    ', ',
2507
-                    $attendee->full_address_as_array()
2508
-                );
2509
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2510
-                    array(
2511
-                        'action' => 'edit_attendee',
2512
-                        'post'   => $attendee->ID(),
2513
-                    ),
2514
-                    REG_ADMIN_URL
2515
-                );
2516
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2517
-                $att_nmbr++;
2518
-            }
2519
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2520
-        }
2521
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2522
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2523
-    }
2524
-
2525
-
2526
-    /**
2527
-     *        generates HTML for the Edit Registration side meta box
2528
-     *
2529
-     * @access public
2530
-     * @return void
2531
-     * @throws DomainException
2532
-     * @throws EE_Error
2533
-     */
2534
-    public function _reg_registrant_side_meta_box()
2535
-    {
2536
-        /*@var $attendee EE_Attendee */
2537
-        $att_check = $this->_registration->attendee();
2538
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2539
-        //now let's determine if this is not the primary registration.  If it isn't then we set the
2540
-        //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2541
-        //primary registration object (that way we know if we need to show create button or not)
2542
-        if ( ! $this->_registration->is_primary_registrant()) {
2543
-            $primary_registration = $this->_registration->get_primary_registration();
2544
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2545
-                : null;
2546
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2547
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2548
-                //custom attendee object so let's not worry about the primary reg.
2549
-                $primary_registration = null;
2550
-            }
2551
-        } else {
2552
-            $primary_registration = null;
2553
-        }
2554
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2555
-        $this->_template_args['fname']             = $attendee->fname();
2556
-        $this->_template_args['lname']             = $attendee->lname();
2557
-        $this->_template_args['email']             = $attendee->email();
2558
-        $this->_template_args['phone']             = $attendee->phone();
2559
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2560
-        //edit link
2561
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2562
-            'action' => 'edit_attendee',
2563
-            'post'   => $attendee->ID(),
2564
-        ), REG_ADMIN_URL);
2565
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2566
-        //create link
2567
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2568
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2569
-                'action'  => 'duplicate_attendee',
2570
-                '_REG_ID' => $this->_registration->ID(),
2571
-            ), REG_ADMIN_URL) : '';
2572
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2573
-        $this->_template_args['att_check']    = $att_check;
2574
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2575
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2576
-    }
2577
-
2578
-
2579
-    /**
2580
-     * trash or restore registrations
2581
-     *
2582
-     * @param  boolean $trash whether to archive or restore
2583
-     * @return void
2584
-     * @throws EE_Error
2585
-     * @throws RuntimeException
2586
-     * @access protected
2587
-     */
2588
-    protected function _trash_or_restore_registrations($trash = true)
2589
-    {
2590
-        //if empty _REG_ID then get out because there's nothing to do
2591
-        if (empty($this->_req_data['_REG_ID'])) {
2592
-            EE_Error::add_error(
2593
-                sprintf(
2594
-                    esc_html__(
2595
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2596
-                        'event_espresso'
2597
-                    ),
2598
-                    $trash ? 'trash' : 'restore'
2599
-                ),
2600
-                __FILE__, __LINE__, __FUNCTION__
2601
-            );
2602
-            $this->_redirect_after_action(false, '', '', array(), true);
2603
-        }
2604
-        $success = 0;
2605
-        $overwrite_msgs = false;
2606
-        //Checkboxes
2607
-        if ( ! is_array($this->_req_data['_REG_ID'])) {
2608
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2609
-        }
2610
-        $reg_count = count($this->_req_data['_REG_ID']);
2611
-        // cycle thru checkboxes
2612
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2613
-            /** @var EE_Registration $REG */
2614
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2615
-            $payments = $REG->registration_payments();
2616
-            if (! empty($payments)) {
2617
-                $name = $REG->attendee() instanceof EE_Attendee
2618
-                    ? $REG->attendee()->full_name()
2619
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2620
-                $overwrite_msgs = true;
2621
-                EE_Error::add_error(
2622
-                    sprintf(
2623
-                        esc_html__(
2624
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2625
-                            'event_espresso'
2626
-                        ),
2627
-                        $name
2628
-                    ),
2629
-                    __FILE__, __FUNCTION__, __LINE__
2630
-                );
2631
-                //can't trash this registration because it has payments.
2632
-                continue;
2633
-            }
2634
-            $updated = $trash ? $REG->delete() : $REG->restore();
2635
-            if ($updated) {
2636
-                $success++;
2637
-            }
2638
-        }
2639
-        $this->_redirect_after_action(
2640
-            $success === $reg_count, // were ALL registrations affected?
2641
-            $success > 1
2642
-                ? esc_html__('Registrations', 'event_espresso')
2643
-                : esc_html__('Registration', 'event_espresso'),
2644
-            $trash
2645
-                ? esc_html__('moved to the trash', 'event_espresso')
2646
-                : esc_html__('restored', 'event_espresso'),
2647
-            array('action' => 'default'),
2648
-            $overwrite_msgs
2649
-        );
2650
-    }
2651
-
2652
-
2653
-    /**
2654
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2655
-     * registration but also.
2656
-     * 1. Removing relations to EE_Attendee
2657
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2658
-     * ALSO trashed.
2659
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2660
-     * 4. Removing relationships between all tickets and the related registrations
2661
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2662
-     * 6. Deleting permanently any related Checkins.
2663
-     *
2664
-     * @return void
2665
-     * @throws EE_Error
2666
-     */
2667
-    protected function _delete_registrations()
2668
-    {
2669
-        $REG_MDL = EEM_Registration::instance();
2670
-        $success = 1;
2671
-        //Checkboxes
2672
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2673
-            // if array has more than one element than success message should be plural
2674
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2675
-            // cycle thru checkboxes
2676
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2677
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2678
-                if ( ! $REG instanceof EE_Registration) {
2679
-                    continue;
2680
-                }
2681
-                $deleted = $this->_delete_registration($REG);
2682
-                if ( ! $deleted) {
2683
-                    $success = 0;
2684
-                }
2685
-            }
2686
-        } else {
2687
-            // grab single id and delete
2688
-            $REG_ID  = $this->_req_data['_REG_ID'];
2689
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2690
-            $deleted = $this->_delete_registration($REG);
2691
-            if ( ! $deleted) {
2692
-                $success = 0;
2693
-            }
2694
-        }
2695
-        $what        = $success > 1
2696
-            ? esc_html__('Registrations', 'event_espresso')
2697
-            : esc_html__('Registration', 'event_espresso');
2698
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2699
-        $this->_redirect_after_action(
2700
-            $success,
2701
-            $what,
2702
-            $action_desc,
2703
-            array('action' => 'default'),
2704
-            true
2705
-        );
2706
-    }
2707
-
2708
-
2709
-    /**
2710
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2711
-     * models get affected.
2712
-     *
2713
-     * @param  EE_Registration $REG registration to be deleted permenantly
2714
-     * @return bool true = successful deletion, false = fail.
2715
-     * @throws EE_Error
2716
-     */
2717
-    protected function _delete_registration(EE_Registration $REG)
2718
-    {
2719
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2720
-        //registrations on the transaction that are NOT trashed.
2721
-        $TXN         = $REG->get_first_related('Transaction');
2722
-        $REGS        = $TXN->get_many_related('Registration');
2723
-        $all_trashed = true;
2724
-        foreach ($REGS as $registration) {
2725
-            if ( ! $registration->get('REG_deleted')) {
2726
-                $all_trashed = false;
2727
-            }
2728
-        }
2729
-        if ( ! $all_trashed) {
2730
-            EE_Error::add_error(
2731
-                esc_html__(
2732
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2733
-                    'event_espresso'
2734
-                ),
2735
-                __FILE__, __FUNCTION__, __LINE__
2736
-            );
2737
-            return false;
2738
-        }
2739
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them
2740
-        //separately from THIS one).
2741
-        foreach ($REGS as $registration) {
2742
-            //delete related answers
2743
-            $registration->delete_related_permanently('Answer');
2744
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2745
-            $attendee = $registration->get_first_related('Attendee');
2746
-            if ($attendee instanceof EE_Attendee) {
2747
-                $registration->_remove_relation_to($attendee, 'Attendee');
2748
-            }
2749
-            //now remove relationships to tickets on this registration.
2750
-            $registration->_remove_relations('Ticket');
2751
-            //now delete permanently the checkins related to this registration.
2752
-            $registration->delete_related_permanently('Checkin');
2753
-            if ($registration->ID() === $REG->ID()) {
2754
-                continue;
2755
-            } //we don't want to delete permanently the existing registration just yet.
2756
-            //remove relation to transaction for these registrations if NOT the existing registrations
2757
-            $registration->_remove_relations('Transaction');
2758
-            //delete permanently any related messages.
2759
-            $registration->delete_related_permanently('Message');
2760
-            //now delete this registration permanently
2761
-            $registration->delete_permanently();
2762
-        }
2763
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself
2764
-        // (the transaction and line items should be all that's left).
2765
-        // delete the line items related to the transaction for this registration.
2766
-        $TXN->delete_related_permanently('Line_Item');
2767
-        //we need to remove all the relationships on the transaction
2768
-        $TXN->delete_related_permanently('Payment');
2769
-        $TXN->delete_related_permanently('Extra_Meta');
2770
-        $TXN->delete_related_permanently('Message');
2771
-        //now we can delete this REG permanently (and the transaction of course)
2772
-        $REG->delete_related_permanently('Transaction');
2773
-        return $REG->delete_permanently();
2774
-    }
2775
-
2776
-
2777
-    /**
2778
-     *    generates HTML for the Register New Attendee Admin page
2779
-     *
2780
-     * @access private
2781
-     * @throws DomainException
2782
-     * @throws EE_Error
2783
-     */
2784
-    public function new_registration()
2785
-    {
2786
-        if ( ! $this->_set_reg_event()) {
2787
-            throw new EE_Error(
2788
-                esc_html__(
2789
-                    'Unable to continue with registering because there is no Event ID in the request',
2790
-                    'event_espresso'
2791
-                )
2792
-            );
2793
-        }
2794
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2795
-        // gotta start with a clean slate if we're not coming here via ajax
2796
-        if ( ! defined('DOING_AJAX')
2797
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2798
-        ) {
2799
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2800
-        }
2801
-        $this->_template_args['event_name'] = '';
2802
-        // event name
2803
-        if ($this->_reg_event) {
2804
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2805
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2806
-                'action' => 'edit',
2807
-                'post'   => $this->_reg_event->ID(),
2808
-            ), EVENTS_ADMIN_URL);
2809
-            $edit_event_lnk                     = '<a href="'
2810
-                                                  . $edit_event_url
2811
-                                                  . '" title="'
2812
-                                                  . esc_attr__('Edit ', 'event_espresso')
2813
-                                                  . $this->_reg_event->name()
2814
-                                                  . '">'
2815
-                                                  . esc_html__('Edit Event', 'event_espresso')
2816
-                                                  . '</a>';
2817
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2818
-                                                   . $edit_event_lnk
2819
-                                                   . '</span>';
2820
-        }
2821
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2822
-        if (defined('DOING_AJAX')) {
2823
-            $this->_return_json();
2824
-        }
2825
-        // grab header
2826
-        $template_path                              =
2827
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2828
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2829
-            $this->_template_args, true);
2830
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2831
-        // the details template wrapper
2832
-        $this->display_admin_page_with_sidebar();
2833
-    }
2834
-
2835
-
2836
-    /**
2837
-     * This returns the content for a registration step
2838
-     *
2839
-     * @access protected
2840
-     * @return string html
2841
-     * @throws DomainException
2842
-     * @throws EE_Error
2843
-     */
2844
-    protected function _get_registration_step_content()
2845
-    {
2846
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2847
-            $warning_msg = sprintf(
2848
-                esc_html__(
2849
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2850
-                    'event_espresso'
2851
-                ),
2852
-                '<br />',
2853
-                '<h3 class="important-notice">',
2854
-                '</h3>',
2855
-                '<div class="float-right">',
2856
-                '<span id="redirect_timer" class="important-notice">30</span>',
2857
-                '</div>',
2858
-                '<b>',
2859
-                '</b>'
2860
-            );
2861
-            return '
2362
+	}
2363
+
2364
+
2365
+	/**
2366
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2367
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2368
+	 * to display the page
2369
+	 *
2370
+	 * @access protected
2371
+	 * @return void
2372
+	 * @throws EE_Error
2373
+	 */
2374
+	protected function _update_attendee_registration_form()
2375
+	{
2376
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2377
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2378
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2379
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2380
+			if ($success) {
2381
+				$what  = esc_html__('Registration Form', 'event_espresso');
2382
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2383
+					: array('action' => 'default');
2384
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2385
+			}
2386
+		}
2387
+	}
2388
+
2389
+
2390
+	/**
2391
+	 * Gets the form for saving registrations custom questions (if done
2392
+	 * previously retrieves the cached form object, which may have validation errors in it)
2393
+	 *
2394
+	 * @param int $REG_ID
2395
+	 * @return EE_Registration_Custom_Questions_Form
2396
+	 * @throws EE_Error
2397
+	 */
2398
+	protected function _get_reg_custom_questions_form($REG_ID)
2399
+	{
2400
+		if ( ! $this->_reg_custom_questions_form) {
2401
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2402
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2403
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2404
+			);
2405
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2406
+		}
2407
+		return $this->_reg_custom_questions_form;
2408
+	}
2409
+
2410
+
2411
+	/**
2412
+	 * Saves
2413
+	 *
2414
+	 * @access private
2415
+	 * @param bool $REG_ID
2416
+	 * @return bool
2417
+	 * @throws EE_Error
2418
+	 */
2419
+	private function _save_reg_custom_questions_form($REG_ID = false)
2420
+	{
2421
+		if ( ! $REG_ID) {
2422
+			EE_Error::add_error(
2423
+				esc_html__(
2424
+					'An error occurred. No registration ID was received.', 'event_espresso'),
2425
+				__FILE__, __FUNCTION__, __LINE__
2426
+			);
2427
+		}
2428
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2429
+		$form->receive_form_submission($this->_req_data);
2430
+		$success = false;
2431
+		if ($form->is_valid()) {
2432
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2433
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2434
+					$where_conditions    = array(
2435
+						'QST_ID' => $question_id,
2436
+						'REG_ID' => $REG_ID,
2437
+					);
2438
+					$possibly_new_values = array(
2439
+						'ANS_value' => $input->normalized_value(),
2440
+					);
2441
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2442
+					if ($answer instanceof EE_Answer) {
2443
+						$success = $answer->save($possibly_new_values);
2444
+					} else {
2445
+						//insert it then
2446
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2447
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2448
+						$success     = $answer->save();
2449
+					}
2450
+				}
2451
+			}
2452
+		} else {
2453
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2454
+		}
2455
+		return $success;
2456
+	}
2457
+
2458
+
2459
+	/**
2460
+	 *        generates HTML for the Registration main meta box
2461
+	 *
2462
+	 * @access public
2463
+	 * @return void
2464
+	 * @throws DomainException
2465
+	 * @throws EE_Error
2466
+	 */
2467
+	public function _reg_attendees_meta_box()
2468
+	{
2469
+		$REG = EEM_Registration::instance();
2470
+		//get all other registrations on this transaction, and cache
2471
+		//the attendees for them so we don't have to run another query using force_join
2472
+		$registrations                           = $REG->get_all(array(
2473
+			array(
2474
+				'TXN_ID' => $this->_registration->transaction_ID(),
2475
+				'REG_ID' => array('!=', $this->_registration->ID()),
2476
+			),
2477
+			'force_join' => array('Attendee'),
2478
+		));
2479
+		$this->_template_args['attendees']       = array();
2480
+		$this->_template_args['attendee_notice'] = '';
2481
+		if (empty($registrations)
2482
+			|| (is_array($registrations)
2483
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2484
+		) {
2485
+			EE_Error::add_error(
2486
+				esc_html__(
2487
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2488
+					'event_espresso'
2489
+				), __FILE__, __FUNCTION__, __LINE__
2490
+			);
2491
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2492
+		} else {
2493
+			$att_nmbr = 1;
2494
+			foreach ($registrations as $registration) {
2495
+				/* @var $registration EE_Registration */
2496
+				$attendee                                                    = $registration->attendee()
2497
+					? $registration->attendee()
2498
+					: EEM_Attendee::instance()
2499
+								  ->create_default_object();
2500
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2501
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2502
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2503
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2504
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2505
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2506
+					', ',
2507
+					$attendee->full_address_as_array()
2508
+				);
2509
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2510
+					array(
2511
+						'action' => 'edit_attendee',
2512
+						'post'   => $attendee->ID(),
2513
+					),
2514
+					REG_ADMIN_URL
2515
+				);
2516
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2517
+				$att_nmbr++;
2518
+			}
2519
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2520
+		}
2521
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2522
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2523
+	}
2524
+
2525
+
2526
+	/**
2527
+	 *        generates HTML for the Edit Registration side meta box
2528
+	 *
2529
+	 * @access public
2530
+	 * @return void
2531
+	 * @throws DomainException
2532
+	 * @throws EE_Error
2533
+	 */
2534
+	public function _reg_registrant_side_meta_box()
2535
+	{
2536
+		/*@var $attendee EE_Attendee */
2537
+		$att_check = $this->_registration->attendee();
2538
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2539
+		//now let's determine if this is not the primary registration.  If it isn't then we set the
2540
+		//primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2541
+		//primary registration object (that way we know if we need to show create button or not)
2542
+		if ( ! $this->_registration->is_primary_registrant()) {
2543
+			$primary_registration = $this->_registration->get_primary_registration();
2544
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2545
+				: null;
2546
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2547
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2548
+				//custom attendee object so let's not worry about the primary reg.
2549
+				$primary_registration = null;
2550
+			}
2551
+		} else {
2552
+			$primary_registration = null;
2553
+		}
2554
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2555
+		$this->_template_args['fname']             = $attendee->fname();
2556
+		$this->_template_args['lname']             = $attendee->lname();
2557
+		$this->_template_args['email']             = $attendee->email();
2558
+		$this->_template_args['phone']             = $attendee->phone();
2559
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2560
+		//edit link
2561
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2562
+			'action' => 'edit_attendee',
2563
+			'post'   => $attendee->ID(),
2564
+		), REG_ADMIN_URL);
2565
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2566
+		//create link
2567
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2568
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2569
+				'action'  => 'duplicate_attendee',
2570
+				'_REG_ID' => $this->_registration->ID(),
2571
+			), REG_ADMIN_URL) : '';
2572
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2573
+		$this->_template_args['att_check']    = $att_check;
2574
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2575
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2576
+	}
2577
+
2578
+
2579
+	/**
2580
+	 * trash or restore registrations
2581
+	 *
2582
+	 * @param  boolean $trash whether to archive or restore
2583
+	 * @return void
2584
+	 * @throws EE_Error
2585
+	 * @throws RuntimeException
2586
+	 * @access protected
2587
+	 */
2588
+	protected function _trash_or_restore_registrations($trash = true)
2589
+	{
2590
+		//if empty _REG_ID then get out because there's nothing to do
2591
+		if (empty($this->_req_data['_REG_ID'])) {
2592
+			EE_Error::add_error(
2593
+				sprintf(
2594
+					esc_html__(
2595
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2596
+						'event_espresso'
2597
+					),
2598
+					$trash ? 'trash' : 'restore'
2599
+				),
2600
+				__FILE__, __LINE__, __FUNCTION__
2601
+			);
2602
+			$this->_redirect_after_action(false, '', '', array(), true);
2603
+		}
2604
+		$success = 0;
2605
+		$overwrite_msgs = false;
2606
+		//Checkboxes
2607
+		if ( ! is_array($this->_req_data['_REG_ID'])) {
2608
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2609
+		}
2610
+		$reg_count = count($this->_req_data['_REG_ID']);
2611
+		// cycle thru checkboxes
2612
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2613
+			/** @var EE_Registration $REG */
2614
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2615
+			$payments = $REG->registration_payments();
2616
+			if (! empty($payments)) {
2617
+				$name = $REG->attendee() instanceof EE_Attendee
2618
+					? $REG->attendee()->full_name()
2619
+					: esc_html__('Unknown Attendee', 'event_espresso');
2620
+				$overwrite_msgs = true;
2621
+				EE_Error::add_error(
2622
+					sprintf(
2623
+						esc_html__(
2624
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2625
+							'event_espresso'
2626
+						),
2627
+						$name
2628
+					),
2629
+					__FILE__, __FUNCTION__, __LINE__
2630
+				);
2631
+				//can't trash this registration because it has payments.
2632
+				continue;
2633
+			}
2634
+			$updated = $trash ? $REG->delete() : $REG->restore();
2635
+			if ($updated) {
2636
+				$success++;
2637
+			}
2638
+		}
2639
+		$this->_redirect_after_action(
2640
+			$success === $reg_count, // were ALL registrations affected?
2641
+			$success > 1
2642
+				? esc_html__('Registrations', 'event_espresso')
2643
+				: esc_html__('Registration', 'event_espresso'),
2644
+			$trash
2645
+				? esc_html__('moved to the trash', 'event_espresso')
2646
+				: esc_html__('restored', 'event_espresso'),
2647
+			array('action' => 'default'),
2648
+			$overwrite_msgs
2649
+		);
2650
+	}
2651
+
2652
+
2653
+	/**
2654
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2655
+	 * registration but also.
2656
+	 * 1. Removing relations to EE_Attendee
2657
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2658
+	 * ALSO trashed.
2659
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2660
+	 * 4. Removing relationships between all tickets and the related registrations
2661
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2662
+	 * 6. Deleting permanently any related Checkins.
2663
+	 *
2664
+	 * @return void
2665
+	 * @throws EE_Error
2666
+	 */
2667
+	protected function _delete_registrations()
2668
+	{
2669
+		$REG_MDL = EEM_Registration::instance();
2670
+		$success = 1;
2671
+		//Checkboxes
2672
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2673
+			// if array has more than one element than success message should be plural
2674
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2675
+			// cycle thru checkboxes
2676
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2677
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2678
+				if ( ! $REG instanceof EE_Registration) {
2679
+					continue;
2680
+				}
2681
+				$deleted = $this->_delete_registration($REG);
2682
+				if ( ! $deleted) {
2683
+					$success = 0;
2684
+				}
2685
+			}
2686
+		} else {
2687
+			// grab single id and delete
2688
+			$REG_ID  = $this->_req_data['_REG_ID'];
2689
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2690
+			$deleted = $this->_delete_registration($REG);
2691
+			if ( ! $deleted) {
2692
+				$success = 0;
2693
+			}
2694
+		}
2695
+		$what        = $success > 1
2696
+			? esc_html__('Registrations', 'event_espresso')
2697
+			: esc_html__('Registration', 'event_espresso');
2698
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2699
+		$this->_redirect_after_action(
2700
+			$success,
2701
+			$what,
2702
+			$action_desc,
2703
+			array('action' => 'default'),
2704
+			true
2705
+		);
2706
+	}
2707
+
2708
+
2709
+	/**
2710
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2711
+	 * models get affected.
2712
+	 *
2713
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2714
+	 * @return bool true = successful deletion, false = fail.
2715
+	 * @throws EE_Error
2716
+	 */
2717
+	protected function _delete_registration(EE_Registration $REG)
2718
+	{
2719
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2720
+		//registrations on the transaction that are NOT trashed.
2721
+		$TXN         = $REG->get_first_related('Transaction');
2722
+		$REGS        = $TXN->get_many_related('Registration');
2723
+		$all_trashed = true;
2724
+		foreach ($REGS as $registration) {
2725
+			if ( ! $registration->get('REG_deleted')) {
2726
+				$all_trashed = false;
2727
+			}
2728
+		}
2729
+		if ( ! $all_trashed) {
2730
+			EE_Error::add_error(
2731
+				esc_html__(
2732
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2733
+					'event_espresso'
2734
+				),
2735
+				__FILE__, __FUNCTION__, __LINE__
2736
+			);
2737
+			return false;
2738
+		}
2739
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them
2740
+		//separately from THIS one).
2741
+		foreach ($REGS as $registration) {
2742
+			//delete related answers
2743
+			$registration->delete_related_permanently('Answer');
2744
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2745
+			$attendee = $registration->get_first_related('Attendee');
2746
+			if ($attendee instanceof EE_Attendee) {
2747
+				$registration->_remove_relation_to($attendee, 'Attendee');
2748
+			}
2749
+			//now remove relationships to tickets on this registration.
2750
+			$registration->_remove_relations('Ticket');
2751
+			//now delete permanently the checkins related to this registration.
2752
+			$registration->delete_related_permanently('Checkin');
2753
+			if ($registration->ID() === $REG->ID()) {
2754
+				continue;
2755
+			} //we don't want to delete permanently the existing registration just yet.
2756
+			//remove relation to transaction for these registrations if NOT the existing registrations
2757
+			$registration->_remove_relations('Transaction');
2758
+			//delete permanently any related messages.
2759
+			$registration->delete_related_permanently('Message');
2760
+			//now delete this registration permanently
2761
+			$registration->delete_permanently();
2762
+		}
2763
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself
2764
+		// (the transaction and line items should be all that's left).
2765
+		// delete the line items related to the transaction for this registration.
2766
+		$TXN->delete_related_permanently('Line_Item');
2767
+		//we need to remove all the relationships on the transaction
2768
+		$TXN->delete_related_permanently('Payment');
2769
+		$TXN->delete_related_permanently('Extra_Meta');
2770
+		$TXN->delete_related_permanently('Message');
2771
+		//now we can delete this REG permanently (and the transaction of course)
2772
+		$REG->delete_related_permanently('Transaction');
2773
+		return $REG->delete_permanently();
2774
+	}
2775
+
2776
+
2777
+	/**
2778
+	 *    generates HTML for the Register New Attendee Admin page
2779
+	 *
2780
+	 * @access private
2781
+	 * @throws DomainException
2782
+	 * @throws EE_Error
2783
+	 */
2784
+	public function new_registration()
2785
+	{
2786
+		if ( ! $this->_set_reg_event()) {
2787
+			throw new EE_Error(
2788
+				esc_html__(
2789
+					'Unable to continue with registering because there is no Event ID in the request',
2790
+					'event_espresso'
2791
+				)
2792
+			);
2793
+		}
2794
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2795
+		// gotta start with a clean slate if we're not coming here via ajax
2796
+		if ( ! defined('DOING_AJAX')
2797
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2798
+		) {
2799
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2800
+		}
2801
+		$this->_template_args['event_name'] = '';
2802
+		// event name
2803
+		if ($this->_reg_event) {
2804
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2805
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2806
+				'action' => 'edit',
2807
+				'post'   => $this->_reg_event->ID(),
2808
+			), EVENTS_ADMIN_URL);
2809
+			$edit_event_lnk                     = '<a href="'
2810
+												  . $edit_event_url
2811
+												  . '" title="'
2812
+												  . esc_attr__('Edit ', 'event_espresso')
2813
+												  . $this->_reg_event->name()
2814
+												  . '">'
2815
+												  . esc_html__('Edit Event', 'event_espresso')
2816
+												  . '</a>';
2817
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2818
+												   . $edit_event_lnk
2819
+												   . '</span>';
2820
+		}
2821
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2822
+		if (defined('DOING_AJAX')) {
2823
+			$this->_return_json();
2824
+		}
2825
+		// grab header
2826
+		$template_path                              =
2827
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2828
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2829
+			$this->_template_args, true);
2830
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2831
+		// the details template wrapper
2832
+		$this->display_admin_page_with_sidebar();
2833
+	}
2834
+
2835
+
2836
+	/**
2837
+	 * This returns the content for a registration step
2838
+	 *
2839
+	 * @access protected
2840
+	 * @return string html
2841
+	 * @throws DomainException
2842
+	 * @throws EE_Error
2843
+	 */
2844
+	protected function _get_registration_step_content()
2845
+	{
2846
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2847
+			$warning_msg = sprintf(
2848
+				esc_html__(
2849
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2850
+					'event_espresso'
2851
+				),
2852
+				'<br />',
2853
+				'<h3 class="important-notice">',
2854
+				'</h3>',
2855
+				'<div class="float-right">',
2856
+				'<span id="redirect_timer" class="important-notice">30</span>',
2857
+				'</div>',
2858
+				'<b>',
2859
+				'</b>'
2860
+			);
2861
+			return '
2862 2862
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2863 2863
 	<script >
2864 2864
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2871,792 +2871,792 @@  discard block
 block discarded – undo
2871 2871
 	        }
2872 2872
 	    }, 800 );
2873 2873
 	</script >';
2874
-        }
2875
-        $template_args = array(
2876
-            'title'                    => '',
2877
-            'content'                  => '',
2878
-            'step_button_text'         => '',
2879
-            'show_notification_toggle' => false,
2880
-        );
2881
-        //to indicate we're processing a new registration
2882
-        $hidden_fields = array(
2883
-            'processing_registration' => array(
2884
-                'type'  => 'hidden',
2885
-                'value' => 0,
2886
-            ),
2887
-            'event_id'                => array(
2888
-                'type'  => 'hidden',
2889
-                'value' => $this->_reg_event->ID(),
2890
-            ),
2891
-        );
2892
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2893
-        $cart = EE_Registry::instance()->SSN->cart();
2894
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2895
-        switch ($step) {
2896
-            case 'ticket' :
2897
-                $hidden_fields['processing_registration']['value'] = 1;
2898
-                $template_args['title']                            = esc_html__(
2899
-                    'Step One: Select the Ticket for this registration',
2900
-                    'event_espresso'
2901
-                );
2902
-                $template_args['content']                          =
2903
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2904
-                $template_args['step_button_text']                 = esc_html__(
2905
-                    'Add Tickets and Continue to Registrant Details',
2906
-                    'event_espresso'
2907
-                );
2908
-                $template_args['show_notification_toggle']         = false;
2909
-                break;
2910
-            case 'questions' :
2911
-                $hidden_fields['processing_registration']['value'] = 2;
2912
-                $template_args['title']                            = esc_html__(
2913
-                    'Step Two: Add Registrant Details for this Registration',
2914
-                    'event_espresso'
2915
-                );
2916
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2917
-                // properly by the first process_reg_step run.
2918
-                $template_args['content']                  =
2919
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2920
-                $template_args['step_button_text']         = esc_html__(
2921
-                    'Save Registration and Continue to Details',
2922
-                    'event_espresso'
2923
-                );
2924
-                $template_args['show_notification_toggle'] = true;
2925
-                break;
2926
-        }
2927
-        //we come back to the process_registration_step route.
2928
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2929
-        return EEH_Template::display_template(
2930
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2931
-            $template_args,
2932
-            true
2933
-        );
2934
-    }
2935
-
2936
-
2937
-    /**
2938
-     *        set_reg_event
2939
-     *
2940
-     * @access private
2941
-     * @return bool
2942
-     * @throws EE_Error
2943
-     */
2944
-    private function _set_reg_event()
2945
-    {
2946
-        if (is_object($this->_reg_event)) {
2947
-            return true;
2948
-        }
2949
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2950
-        if ( ! $EVT_ID) {
2951
-            return false;
2952
-        }
2953
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2954
-        return true;
2955
-    }
2956
-
2957
-
2958
-    /**
2959
-     * process_reg_step
2960
-     *
2961
-     * @access        public
2962
-     * @return string
2963
-     * @throws DomainException
2964
-     * @throws EE_Error
2965
-     * @throws RuntimeException
2966
-     */
2967
-    public function process_reg_step()
2968
-    {
2969
-        EE_System::do_not_cache();
2970
-        $this->_set_reg_event();
2971
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2972
-        EE_Registry::instance()->REQ->set('uts', time());
2973
-        //what step are we on?
2974
-        $cart = EE_Registry::instance()->SSN->cart();
2975
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2976
-        //if doing ajax then we need to verify the nonce
2977
-        if (defined('DOING_AJAX')) {
2978
-            $nonce = isset($this->_req_data[$this->_req_nonce])
2979
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2980
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2981
-        }
2982
-        switch ($step) {
2983
-            case 'ticket' :
2984
-                //process ticket selection
2985
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2986
-                if ($success) {
2987
-                    EE_Error::add_success(
2988
-                        esc_html__(
2989
-                            'Tickets Selected. Now complete the registration.',
2990
-                            'event_espresso'
2991
-                        )
2992
-                    );
2993
-                } else {
2994
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
2995
-                }
2996
-                if (defined('DOING_AJAX')) {
2997
-                    $this->new_registration(); //display next step
2998
-                } else {
2999
-                    $query_args = array(
3000
-                        'action'                  => 'new_registration',
3001
-                        'processing_registration' => 1,
3002
-                        'event_id'                => $this->_reg_event->ID(),
3003
-                        'uts'                     => time(),
3004
-                    );
3005
-                    $this->_redirect_after_action(
3006
-                        false,
3007
-                        '',
3008
-                        '',
3009
-                        $query_args,
3010
-                        true
3011
-                    );
3012
-                }
3013
-                break;
3014
-            case 'questions' :
3015
-                if (! isset(
3016
-                    $this->_req_data['txn_reg_status_change'],
3017
-                    $this->_req_data['txn_reg_status_change']['send_notifications'])
3018
-                ) {
3019
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3020
-                }
3021
-                //process registration
3022
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3023
-                if ($cart instanceof EE_Cart) {
3024
-                    $grand_total = $cart->get_cart_grand_total();
3025
-                    if ($grand_total instanceof EE_Line_Item) {
3026
-                        $grand_total->save_this_and_descendants_to_txn();
3027
-                    }
3028
-                }
3029
-                if ( ! $transaction instanceof EE_Transaction) {
3030
-                    $query_args = array(
3031
-                        'action'                  => 'new_registration',
3032
-                        'processing_registration' => 2,
3033
-                        'event_id'                => $this->_reg_event->ID(),
3034
-                        'uts'                     => time(),
3035
-                    );
3036
-                    if (defined('DOING_AJAX')) {
3037
-                        //display registration form again because there are errors (maybe validation?)
3038
-                        $this->new_registration();
3039
-                        return;
3040
-                    } else {
3041
-                        $this->_redirect_after_action(
3042
-                            false,
3043
-                            '',
3044
-                            '',
3045
-                            $query_args,
3046
-                            true
3047
-                        );
3048
-                        return;
3049
-                    }
3050
-                }
3051
-                // maybe update status, and make sure to save transaction if not done already
3052
-                if ( ! $transaction->update_status_based_on_total_paid()) {
3053
-                    $transaction->save();
3054
-                }
3055
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3056
-                $this->_req_data = array();
3057
-                $query_args      = array(
3058
-                    'action'        => 'redirect_to_txn',
3059
-                    'TXN_ID'        => $transaction->ID(),
3060
-                    'EVT_ID'        => $this->_reg_event->ID(),
3061
-                    'event_name'    => urlencode($this->_reg_event->name()),
3062
-                    'redirect_from' => 'new_registration',
3063
-                );
3064
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3065
-                break;
3066
-        }
3067
-        //what are you looking here for?  Should be nothing to do at this point.
3068
-    }
3069
-
3070
-
3071
-    /**
3072
-     * redirect_to_txn
3073
-     *
3074
-     * @access public
3075
-     * @return void
3076
-     * @throws EE_Error
3077
-     */
3078
-    public function redirect_to_txn()
3079
-    {
3080
-        EE_System::do_not_cache();
3081
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3082
-        $query_args = array(
3083
-            'action' => 'view_transaction',
3084
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3085
-            'page'   => 'espresso_transactions',
3086
-        );
3087
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3088
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3089
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
3090
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3091
-        }
3092
-        EE_Error::add_success(
3093
-            esc_html__(
3094
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3095
-                'event_espresso'
3096
-            )
3097
-        );
3098
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3099
-    }
3100
-
3101
-
3102
-    /**
3103
-     *        generates HTML for the Attendee Contact List
3104
-     *
3105
-     * @access protected
3106
-     * @return void
3107
-     */
3108
-    protected function _attendee_contact_list_table()
3109
-    {
3110
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3111
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3112
-        $this->display_admin_list_table_page_with_no_sidebar();
3113
-    }
3114
-
3115
-
3116
-    /**
3117
-     *        get_attendees
3118
-     *
3119
-     * @param      $per_page
3120
-     * @param bool $count whether to return count or data.
3121
-     * @param bool $trash
3122
-     * @return array
3123
-     * @throws EE_Error
3124
-     * @access public
3125
-     */
3126
-    public function get_attendees($per_page, $count = false, $trash = false)
3127
-    {
3128
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3129
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3130
-        $ATT_MDL                    = EEM_Attendee::instance();
3131
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3132
-        switch ($this->_req_data['orderby']) {
3133
-            case 'ATT_ID':
3134
-                $orderby = 'ATT_ID';
3135
-                break;
3136
-            case 'ATT_fname':
3137
-                $orderby = 'ATT_fname';
3138
-                break;
3139
-            case 'ATT_email':
3140
-                $orderby = 'ATT_email';
3141
-                break;
3142
-            case 'ATT_city':
3143
-                $orderby = 'ATT_city';
3144
-                break;
3145
-            case 'STA_ID':
3146
-                $orderby = 'STA_ID';
3147
-                break;
3148
-            case 'CNT_ID':
3149
-                $orderby = 'CNT_ID';
3150
-                break;
3151
-            default:
3152
-                $orderby = 'ATT_lname';
3153
-        }
3154
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3155
-            ? $this->_req_data['order']
3156
-            : 'ASC';
3157
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3158
-            ? $this->_req_data['paged']
3159
-            : 1;
3160
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3161
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3162
-            ? $this->_req_data['perpage']
3163
-            : $per_page;
3164
-        $_where       = array();
3165
-        if ( ! empty($this->_req_data['s'])) {
3166
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3167
-            $_where['OR'] = array(
3168
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3169
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3170
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3171
-                'ATT_fname'                         => array('LIKE', $sstr),
3172
-                'ATT_lname'                         => array('LIKE', $sstr),
3173
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3174
-                'ATT_email'                         => array('LIKE', $sstr),
3175
-                'ATT_address'                       => array('LIKE', $sstr),
3176
-                'ATT_address2'                      => array('LIKE', $sstr),
3177
-                'ATT_city'                          => array('LIKE', $sstr),
3178
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3179
-                'State.STA_name'                    => array('LIKE', $sstr),
3180
-                'ATT_phone'                         => array('LIKE', $sstr),
3181
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3182
-                'Registration.REG_code'             => array('LIKE', $sstr),
3183
-                'Registration.REG_count'            => array('LIKE', $sstr),
3184
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3185
-            );
3186
-        }
3187
-        $offset = ($current_page - 1) * $per_page;
3188
-        $limit  = $count ? null : array($offset, $per_page);
3189
-        if ($trash) {
3190
-            $_where['status'] = array('!=', 'publish');
3191
-            $all_attendees    = $count
3192
-                ? $ATT_MDL->count(array(
3193
-                    $_where,
3194
-                    'order_by' => array($orderby => $sort),
3195
-                    'limit'    => $limit,
3196
-                ), 'ATT_ID', true)
3197
-                : $ATT_MDL->get_all(array(
3198
-                    $_where,
3199
-                    'order_by' => array($orderby => $sort),
3200
-                    'limit'    => $limit,
3201
-                ));
3202
-        } else {
3203
-            $_where['status'] = array('IN', array('publish'));
3204
-            $all_attendees    = $count
3205
-                ? $ATT_MDL->count(array(
3206
-                    $_where,
3207
-                    'order_by' => array($orderby => $sort),
3208
-                    'limit'    => $limit,
3209
-                ), 'ATT_ID', true)
3210
-                : $ATT_MDL->get_all(array(
3211
-                    $_where,
3212
-                    'order_by' => array($orderby => $sort),
3213
-                    'limit'    => $limit,
3214
-                ));
3215
-        }
3216
-        return $all_attendees;
3217
-    }
3218
-
3219
-
3220
-    /**
3221
-     * This is just taking care of resending the registration confirmation
3222
-     *
3223
-     * @access protected
3224
-     * @return void
3225
-     */
3226
-    protected function _resend_registration()
3227
-    {
3228
-        $this->_process_resend_registration();
3229
-        $query_args = isset($this->_req_data['redirect_to'])
3230
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3231
-            : array('action' => 'default');
3232
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3233
-    }
3234
-
3235
-    /**
3236
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3237
-     * to use when selecting registrations
3238
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3239
-     *                                                     the query parameters from the request
3240
-     * @return void ends the request with a redirect or download
3241
-     */
3242
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3243
-    {
3244
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3245
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3246
-                array(
3247
-                    'page'        => 'espresso_batch',
3248
-                    'batch'       => 'file',
3249
-                    'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3250
-                    'filters'     => urlencode(
3251
-                        serialize(
3252
-                            call_user_func(
3253
-                                array( $this, $method_name_for_getting_query_params ),
3254
-                                EEH_Array::is_set(
3255
-                                    $this->_req_data,
3256
-                                    'filters',
3257
-                                    array()
3258
-                                )
3259
-                            )
3260
-                        )
3261
-                ),
3262
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3263
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3264
-                'return_url'  => urlencode($this->_req_data['return_url']),
3265
-            )));
3266
-        } else {
3267
-            $new_request_args = array(
3268
-                'export' => 'report',
3269
-                'action' => 'registrations_report_for_event',
3270
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3271
-            );
3272
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3273
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3274
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3275
-                $EE_Export = EE_Export::instance($this->_req_data);
3276
-                $EE_Export->export();
3277
-            }
3278
-        }
3279
-    }
3280
-
3281
-
3282
-
3283
-    /**
3284
-     * Creates a registration report using only query parameters in the request
3285
-     * @return void
3286
-     */
3287
-    public function _registrations_report()
3288
-    {
3289
-        $this->_registrations_report_base('_get_registration_query_parameters');
3290
-    }
3291
-
3292
-
3293
-    public function _contact_list_export()
3294
-    {
3295
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3296
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3297
-            $EE_Export = EE_Export::instance($this->_req_data);
3298
-            $EE_Export->export_attendees();
3299
-        }
3300
-    }
3301
-
3302
-
3303
-    public function _contact_list_report()
3304
-    {
3305
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3306
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3307
-                'page'        => 'espresso_batch',
3308
-                'batch'       => 'file',
3309
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3310
-                'return_url'  => urlencode($this->_req_data['return_url']),
3311
-            )));
3312
-        } else {
3313
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3314
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3315
-                $EE_Export = EE_Export::instance($this->_req_data);
3316
-                $EE_Export->report_attendees();
3317
-            }
3318
-        }
3319
-    }
3320
-
3321
-
3322
-
3323
-
3324
-
3325
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3326
-    /**
3327
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3328
-     *
3329
-     * @return void
3330
-     * @throws EE_Error
3331
-     */
3332
-    protected function _duplicate_attendee()
3333
-    {
3334
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3335
-        //verify we have necessary info
3336
-        if (empty($this->_req_data['_REG_ID'])) {
3337
-            EE_Error::add_error(
3338
-                esc_html__(
3339
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3340
-                    'event_espresso'
3341
-                ), __FILE__, __LINE__, __FUNCTION__
3342
-            );
3343
-            $query_args = array('action' => $action);
3344
-            $this->_redirect_after_action('', '', '', $query_args, true);
3345
-        }
3346
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3347
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3348
-        $attendee     = $registration->attendee();
3349
-        //remove relation of existing attendee on registration
3350
-        $registration->_remove_relation_to($attendee, 'Attendee');
3351
-        //new attendee
3352
-        $new_attendee = clone $attendee;
3353
-        $new_attendee->set('ATT_ID', 0);
3354
-        $new_attendee->save();
3355
-        //add new attendee to reg
3356
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3357
-        EE_Error::add_success(
3358
-            esc_html__(
3359
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3360
-                'event_espresso'
3361
-            )
3362
-        );
3363
-        //redirect to edit page for attendee
3364
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3365
-        $this->_redirect_after_action('', '', '', $query_args, true);
3366
-    }
3367
-
3368
-
3369
-    //related to cpt routes
3370
-    protected function _insert_update_cpt_item($post_id, $post)
3371
-    {
3372
-        $success  = true;
3373
-        $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3374
-        //for attendee updates
3375
-        if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3376
-            //note we should only be UPDATING attendees at this point.
3377
-            $updated_fields = array(
3378
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3379
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3380
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3381
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3382
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3383
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3384
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3385
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3386
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3387
-                'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3388
-                'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3389
-            );
3390
-            foreach ($updated_fields as $field => $value) {
3391
-                $attendee->set($field, $value);
3392
-            }
3393
-            $success                   = $attendee->save();
3394
-            $attendee_update_callbacks = apply_filters(
3395
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3396
-                array()
3397
-            );
3398
-            foreach ($attendee_update_callbacks as $a_callback) {
3399
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3400
-                    throw new EE_Error(
3401
-                        sprintf(
3402
-                            esc_html__(
3403
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3404
-                                'event_espresso'
3405
-                            ),
3406
-                            $a_callback
3407
-                        )
3408
-                    );
3409
-                }
3410
-            }
3411
-        }
3412
-        if ($success === false) {
3413
-            EE_Error::add_error(
3414
-                esc_html__(
3415
-                    'Something went wrong with updating the meta table data for the registration.',
3416
-                    'event_espresso'
3417
-                ),
3418
-                __FILE__, __FUNCTION__, __LINE__
3419
-            );
3420
-        }
3421
-    }
3422
-
3423
-
3424
-    public function trash_cpt_item($post_id)
3425
-    {
3426
-    }
3427
-
3428
-
3429
-    public function delete_cpt_item($post_id)
3430
-    {
3431
-    }
3432
-
3433
-
3434
-    public function restore_cpt_item($post_id)
3435
-    {
3436
-    }
3437
-
3438
-
3439
-    protected function _restore_cpt_item($post_id, $revision_id)
3440
-    {
3441
-    }
3442
-
3443
-
3444
-    public function attendee_editor_metaboxes()
3445
-    {
3446
-        $this->verify_cpt_object();
3447
-        remove_meta_box(
3448
-            'postexcerpt',
3449
-            esc_html__('Excerpt', 'event_espresso'),
3450
-            'post_excerpt_meta_box',
3451
-            $this->_cpt_routes[$this->_req_action],
3452
-            'normal',
3453
-            'core'
3454
-        );
3455
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3456
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3457
-            add_meta_box(
3458
-                'postexcerpt',
3459
-                esc_html__('Short Biography', 'event_espresso'),
3460
-                'post_excerpt_meta_box',
3461
-                $this->_cpt_routes[$this->_req_action],
3462
-                'normal'
3463
-            );
3464
-        }
3465
-        if (post_type_supports('espresso_attendees', 'comments')) {
3466
-            add_meta_box(
3467
-                'commentsdiv',
3468
-                esc_html__('Notes on the Contact', 'event_espresso'),
3469
-                'post_comment_meta_box',
3470
-                $this->_cpt_routes[$this->_req_action],
3471
-                'normal',
3472
-                'core'
3473
-            );
3474
-        }
3475
-        add_meta_box(
3476
-            'attendee_contact_info',
3477
-            esc_html__('Contact Info', 'event_espresso'),
3478
-            array($this, 'attendee_contact_info'),
3479
-            $this->_cpt_routes[$this->_req_action],
3480
-            'side',
3481
-            'core'
3482
-        );
3483
-        add_meta_box(
3484
-            'attendee_details_address',
3485
-            esc_html__('Address Details', 'event_espresso'),
3486
-            array($this, 'attendee_address_details'),
3487
-            $this->_cpt_routes[$this->_req_action],
3488
-            'normal',
3489
-            'core'
3490
-        );
3491
-        add_meta_box(
3492
-            'attendee_registrations',
3493
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3494
-            array($this, 'attendee_registrations_meta_box'),
3495
-            $this->_cpt_routes[$this->_req_action],
3496
-            'normal',
3497
-            'high'
3498
-        );
3499
-    }
3500
-
3501
-
3502
-    /**
3503
-     * Metabox for attendee contact info
3504
-     *
3505
-     * @param  WP_Post $post wp post object
3506
-     * @return string attendee contact info ( and form )
3507
-     * @throws DomainException
3508
-     */
3509
-    public function attendee_contact_info($post)
3510
-    {
3511
-        //get attendee object ( should already have it )
3512
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3513
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3514
-        EEH_Template::display_template($template, $this->_template_args);
3515
-    }
3516
-
3517
-
3518
-    /**
3519
-     * Metabox for attendee details
3520
-     *
3521
-     * @param  WP_Post $post wp post object
3522
-     * @return string attendee address details (and form)
3523
-     * @throws DomainException
3524
-     */
3525
-    public function attendee_address_details($post)
3526
-    {
3527
-        //get attendee object (should already have it)
3528
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3529
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3530
-            new EE_Question_Form_Input(
3531
-                EE_Question::new_instance(
3532
-                    array(
3533
-                        'QST_ID'           => 0,
3534
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3535
-                        'QST_system'       => 'admin-state',
3536
-                    )
3537
-                ),
3538
-                EE_Answer::new_instance(
3539
-                    array(
3540
-                        'ANS_ID'    => 0,
3541
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3542
-                    )
3543
-                ),
3544
-                array(
3545
-                    'input_id'       => 'STA_ID',
3546
-                    'input_name'     => 'STA_ID',
3547
-                    'input_prefix'   => '',
3548
-                    'append_qstn_id' => false,
3549
-                )
3550
-            )
3551
-        );
3552
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3553
-            new EE_Question_Form_Input(
3554
-                EE_Question::new_instance(
3555
-                    array(
3556
-                        'QST_ID'           => 0,
3557
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3558
-                        'QST_system'       => 'admin-country',
3559
-                    )
3560
-                ),
3561
-                EE_Answer::new_instance(
3562
-                    array(
3563
-                        'ANS_ID'    => 0,
3564
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3565
-                    )
3566
-                ),
3567
-                array(
3568
-                    'input_id'       => 'CNT_ISO',
3569
-                    'input_name'     => 'CNT_ISO',
3570
-                    'input_prefix'   => '',
3571
-                    'append_qstn_id' => false,
3572
-                )
3573
-            )
3574
-        );
3575
-        $template                             =
3576
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3577
-        EEH_Template::display_template($template, $this->_template_args);
3578
-    }
3579
-
3580
-
3581
-    /**
3582
-     *        _attendee_details
3583
-     *
3584
-     * @access protected
3585
-     * @param $post
3586
-     * @return void
3587
-     * @throws DomainException
3588
-     * @throws EE_Error
3589
-     */
3590
-    public function attendee_registrations_meta_box($post)
3591
-    {
3592
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3593
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3594
-        $template                              =
3595
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3596
-        EEH_Template::display_template($template, $this->_template_args);
3597
-    }
3598
-
3599
-
3600
-    /**
3601
-     * add in the form fields for the attendee edit
3602
-     *
3603
-     * @param  WP_Post $post wp post object
3604
-     * @return string html for new form.
3605
-     * @throws DomainException
3606
-     */
3607
-    public function after_title_form_fields($post)
3608
-    {
3609
-        if ($post->post_type == 'espresso_attendees') {
3610
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3611
-            $template_args['attendee'] = $this->_cpt_model_obj;
3612
-            EEH_Template::display_template($template, $template_args);
3613
-        }
3614
-    }
3615
-
3616
-
3617
-    /**
3618
-     *        _trash_or_restore_attendee
3619
-     *
3620
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3621
-     * @return void
3622
-     * @throws EE_Error
3623
-     * @access protected
3624
-     */
3625
-    protected function _trash_or_restore_attendees($trash = true)
3626
-    {
3627
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3628
-        $ATT_MDL = EEM_Attendee::instance();
3629
-        $success = 1;
3630
-        //Checkboxes
3631
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3632
-            // if array has more than one element than success message should be plural
3633
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3634
-            // cycle thru checkboxes
3635
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3636
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3637
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3638
-                if ( ! $updated) {
3639
-                    $success = 0;
3640
-                }
3641
-            }
3642
-        } else {
3643
-            // grab single id and delete
3644
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3645
-            //get attendee
3646
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3647
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3648
-            $updated = $att->save();
3649
-            if ( ! $updated) {
3650
-                $success = 0;
3651
-            }
3652
-        }
3653
-        $what        = $success > 1
3654
-            ? esc_html__('Contacts', 'event_espresso')
3655
-            : esc_html__('Contact', 'event_espresso');
3656
-        $action_desc = $trash
3657
-            ? esc_html__('moved to the trash', 'event_espresso')
3658
-            : esc_html__('restored', 'event_espresso');
3659
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3660
-    }
2874
+		}
2875
+		$template_args = array(
2876
+			'title'                    => '',
2877
+			'content'                  => '',
2878
+			'step_button_text'         => '',
2879
+			'show_notification_toggle' => false,
2880
+		);
2881
+		//to indicate we're processing a new registration
2882
+		$hidden_fields = array(
2883
+			'processing_registration' => array(
2884
+				'type'  => 'hidden',
2885
+				'value' => 0,
2886
+			),
2887
+			'event_id'                => array(
2888
+				'type'  => 'hidden',
2889
+				'value' => $this->_reg_event->ID(),
2890
+			),
2891
+		);
2892
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2893
+		$cart = EE_Registry::instance()->SSN->cart();
2894
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2895
+		switch ($step) {
2896
+			case 'ticket' :
2897
+				$hidden_fields['processing_registration']['value'] = 1;
2898
+				$template_args['title']                            = esc_html__(
2899
+					'Step One: Select the Ticket for this registration',
2900
+					'event_espresso'
2901
+				);
2902
+				$template_args['content']                          =
2903
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2904
+				$template_args['step_button_text']                 = esc_html__(
2905
+					'Add Tickets and Continue to Registrant Details',
2906
+					'event_espresso'
2907
+				);
2908
+				$template_args['show_notification_toggle']         = false;
2909
+				break;
2910
+			case 'questions' :
2911
+				$hidden_fields['processing_registration']['value'] = 2;
2912
+				$template_args['title']                            = esc_html__(
2913
+					'Step Two: Add Registrant Details for this Registration',
2914
+					'event_espresso'
2915
+				);
2916
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2917
+				// properly by the first process_reg_step run.
2918
+				$template_args['content']                  =
2919
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2920
+				$template_args['step_button_text']         = esc_html__(
2921
+					'Save Registration and Continue to Details',
2922
+					'event_espresso'
2923
+				);
2924
+				$template_args['show_notification_toggle'] = true;
2925
+				break;
2926
+		}
2927
+		//we come back to the process_registration_step route.
2928
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2929
+		return EEH_Template::display_template(
2930
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2931
+			$template_args,
2932
+			true
2933
+		);
2934
+	}
2935
+
2936
+
2937
+	/**
2938
+	 *        set_reg_event
2939
+	 *
2940
+	 * @access private
2941
+	 * @return bool
2942
+	 * @throws EE_Error
2943
+	 */
2944
+	private function _set_reg_event()
2945
+	{
2946
+		if (is_object($this->_reg_event)) {
2947
+			return true;
2948
+		}
2949
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2950
+		if ( ! $EVT_ID) {
2951
+			return false;
2952
+		}
2953
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2954
+		return true;
2955
+	}
2956
+
2957
+
2958
+	/**
2959
+	 * process_reg_step
2960
+	 *
2961
+	 * @access        public
2962
+	 * @return string
2963
+	 * @throws DomainException
2964
+	 * @throws EE_Error
2965
+	 * @throws RuntimeException
2966
+	 */
2967
+	public function process_reg_step()
2968
+	{
2969
+		EE_System::do_not_cache();
2970
+		$this->_set_reg_event();
2971
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2972
+		EE_Registry::instance()->REQ->set('uts', time());
2973
+		//what step are we on?
2974
+		$cart = EE_Registry::instance()->SSN->cart();
2975
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2976
+		//if doing ajax then we need to verify the nonce
2977
+		if (defined('DOING_AJAX')) {
2978
+			$nonce = isset($this->_req_data[$this->_req_nonce])
2979
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2980
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2981
+		}
2982
+		switch ($step) {
2983
+			case 'ticket' :
2984
+				//process ticket selection
2985
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2986
+				if ($success) {
2987
+					EE_Error::add_success(
2988
+						esc_html__(
2989
+							'Tickets Selected. Now complete the registration.',
2990
+							'event_espresso'
2991
+						)
2992
+					);
2993
+				} else {
2994
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
2995
+				}
2996
+				if (defined('DOING_AJAX')) {
2997
+					$this->new_registration(); //display next step
2998
+				} else {
2999
+					$query_args = array(
3000
+						'action'                  => 'new_registration',
3001
+						'processing_registration' => 1,
3002
+						'event_id'                => $this->_reg_event->ID(),
3003
+						'uts'                     => time(),
3004
+					);
3005
+					$this->_redirect_after_action(
3006
+						false,
3007
+						'',
3008
+						'',
3009
+						$query_args,
3010
+						true
3011
+					);
3012
+				}
3013
+				break;
3014
+			case 'questions' :
3015
+				if (! isset(
3016
+					$this->_req_data['txn_reg_status_change'],
3017
+					$this->_req_data['txn_reg_status_change']['send_notifications'])
3018
+				) {
3019
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3020
+				}
3021
+				//process registration
3022
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3023
+				if ($cart instanceof EE_Cart) {
3024
+					$grand_total = $cart->get_cart_grand_total();
3025
+					if ($grand_total instanceof EE_Line_Item) {
3026
+						$grand_total->save_this_and_descendants_to_txn();
3027
+					}
3028
+				}
3029
+				if ( ! $transaction instanceof EE_Transaction) {
3030
+					$query_args = array(
3031
+						'action'                  => 'new_registration',
3032
+						'processing_registration' => 2,
3033
+						'event_id'                => $this->_reg_event->ID(),
3034
+						'uts'                     => time(),
3035
+					);
3036
+					if (defined('DOING_AJAX')) {
3037
+						//display registration form again because there are errors (maybe validation?)
3038
+						$this->new_registration();
3039
+						return;
3040
+					} else {
3041
+						$this->_redirect_after_action(
3042
+							false,
3043
+							'',
3044
+							'',
3045
+							$query_args,
3046
+							true
3047
+						);
3048
+						return;
3049
+					}
3050
+				}
3051
+				// maybe update status, and make sure to save transaction if not done already
3052
+				if ( ! $transaction->update_status_based_on_total_paid()) {
3053
+					$transaction->save();
3054
+				}
3055
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3056
+				$this->_req_data = array();
3057
+				$query_args      = array(
3058
+					'action'        => 'redirect_to_txn',
3059
+					'TXN_ID'        => $transaction->ID(),
3060
+					'EVT_ID'        => $this->_reg_event->ID(),
3061
+					'event_name'    => urlencode($this->_reg_event->name()),
3062
+					'redirect_from' => 'new_registration',
3063
+				);
3064
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3065
+				break;
3066
+		}
3067
+		//what are you looking here for?  Should be nothing to do at this point.
3068
+	}
3069
+
3070
+
3071
+	/**
3072
+	 * redirect_to_txn
3073
+	 *
3074
+	 * @access public
3075
+	 * @return void
3076
+	 * @throws EE_Error
3077
+	 */
3078
+	public function redirect_to_txn()
3079
+	{
3080
+		EE_System::do_not_cache();
3081
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3082
+		$query_args = array(
3083
+			'action' => 'view_transaction',
3084
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3085
+			'page'   => 'espresso_transactions',
3086
+		);
3087
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3088
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3089
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
3090
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3091
+		}
3092
+		EE_Error::add_success(
3093
+			esc_html__(
3094
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3095
+				'event_espresso'
3096
+			)
3097
+		);
3098
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3099
+	}
3100
+
3101
+
3102
+	/**
3103
+	 *        generates HTML for the Attendee Contact List
3104
+	 *
3105
+	 * @access protected
3106
+	 * @return void
3107
+	 */
3108
+	protected function _attendee_contact_list_table()
3109
+	{
3110
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3111
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3112
+		$this->display_admin_list_table_page_with_no_sidebar();
3113
+	}
3114
+
3115
+
3116
+	/**
3117
+	 *        get_attendees
3118
+	 *
3119
+	 * @param      $per_page
3120
+	 * @param bool $count whether to return count or data.
3121
+	 * @param bool $trash
3122
+	 * @return array
3123
+	 * @throws EE_Error
3124
+	 * @access public
3125
+	 */
3126
+	public function get_attendees($per_page, $count = false, $trash = false)
3127
+	{
3128
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3129
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3130
+		$ATT_MDL                    = EEM_Attendee::instance();
3131
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3132
+		switch ($this->_req_data['orderby']) {
3133
+			case 'ATT_ID':
3134
+				$orderby = 'ATT_ID';
3135
+				break;
3136
+			case 'ATT_fname':
3137
+				$orderby = 'ATT_fname';
3138
+				break;
3139
+			case 'ATT_email':
3140
+				$orderby = 'ATT_email';
3141
+				break;
3142
+			case 'ATT_city':
3143
+				$orderby = 'ATT_city';
3144
+				break;
3145
+			case 'STA_ID':
3146
+				$orderby = 'STA_ID';
3147
+				break;
3148
+			case 'CNT_ID':
3149
+				$orderby = 'CNT_ID';
3150
+				break;
3151
+			default:
3152
+				$orderby = 'ATT_lname';
3153
+		}
3154
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3155
+			? $this->_req_data['order']
3156
+			: 'ASC';
3157
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3158
+			? $this->_req_data['paged']
3159
+			: 1;
3160
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3161
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3162
+			? $this->_req_data['perpage']
3163
+			: $per_page;
3164
+		$_where       = array();
3165
+		if ( ! empty($this->_req_data['s'])) {
3166
+			$sstr         = '%' . $this->_req_data['s'] . '%';
3167
+			$_where['OR'] = array(
3168
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3169
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3170
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3171
+				'ATT_fname'                         => array('LIKE', $sstr),
3172
+				'ATT_lname'                         => array('LIKE', $sstr),
3173
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3174
+				'ATT_email'                         => array('LIKE', $sstr),
3175
+				'ATT_address'                       => array('LIKE', $sstr),
3176
+				'ATT_address2'                      => array('LIKE', $sstr),
3177
+				'ATT_city'                          => array('LIKE', $sstr),
3178
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3179
+				'State.STA_name'                    => array('LIKE', $sstr),
3180
+				'ATT_phone'                         => array('LIKE', $sstr),
3181
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3182
+				'Registration.REG_code'             => array('LIKE', $sstr),
3183
+				'Registration.REG_count'            => array('LIKE', $sstr),
3184
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3185
+			);
3186
+		}
3187
+		$offset = ($current_page - 1) * $per_page;
3188
+		$limit  = $count ? null : array($offset, $per_page);
3189
+		if ($trash) {
3190
+			$_where['status'] = array('!=', 'publish');
3191
+			$all_attendees    = $count
3192
+				? $ATT_MDL->count(array(
3193
+					$_where,
3194
+					'order_by' => array($orderby => $sort),
3195
+					'limit'    => $limit,
3196
+				), 'ATT_ID', true)
3197
+				: $ATT_MDL->get_all(array(
3198
+					$_where,
3199
+					'order_by' => array($orderby => $sort),
3200
+					'limit'    => $limit,
3201
+				));
3202
+		} else {
3203
+			$_where['status'] = array('IN', array('publish'));
3204
+			$all_attendees    = $count
3205
+				? $ATT_MDL->count(array(
3206
+					$_where,
3207
+					'order_by' => array($orderby => $sort),
3208
+					'limit'    => $limit,
3209
+				), 'ATT_ID', true)
3210
+				: $ATT_MDL->get_all(array(
3211
+					$_where,
3212
+					'order_by' => array($orderby => $sort),
3213
+					'limit'    => $limit,
3214
+				));
3215
+		}
3216
+		return $all_attendees;
3217
+	}
3218
+
3219
+
3220
+	/**
3221
+	 * This is just taking care of resending the registration confirmation
3222
+	 *
3223
+	 * @access protected
3224
+	 * @return void
3225
+	 */
3226
+	protected function _resend_registration()
3227
+	{
3228
+		$this->_process_resend_registration();
3229
+		$query_args = isset($this->_req_data['redirect_to'])
3230
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3231
+			: array('action' => 'default');
3232
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3233
+	}
3234
+
3235
+	/**
3236
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3237
+	 * to use when selecting registrations
3238
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3239
+	 *                                                     the query parameters from the request
3240
+	 * @return void ends the request with a redirect or download
3241
+	 */
3242
+	public function _registrations_report_base( $method_name_for_getting_query_params )
3243
+	{
3244
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3245
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3246
+				array(
3247
+					'page'        => 'espresso_batch',
3248
+					'batch'       => 'file',
3249
+					'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3250
+					'filters'     => urlencode(
3251
+						serialize(
3252
+							call_user_func(
3253
+								array( $this, $method_name_for_getting_query_params ),
3254
+								EEH_Array::is_set(
3255
+									$this->_req_data,
3256
+									'filters',
3257
+									array()
3258
+								)
3259
+							)
3260
+						)
3261
+				),
3262
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3263
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3264
+				'return_url'  => urlencode($this->_req_data['return_url']),
3265
+			)));
3266
+		} else {
3267
+			$new_request_args = array(
3268
+				'export' => 'report',
3269
+				'action' => 'registrations_report_for_event',
3270
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3271
+			);
3272
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3273
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3274
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3275
+				$EE_Export = EE_Export::instance($this->_req_data);
3276
+				$EE_Export->export();
3277
+			}
3278
+		}
3279
+	}
3280
+
3281
+
3282
+
3283
+	/**
3284
+	 * Creates a registration report using only query parameters in the request
3285
+	 * @return void
3286
+	 */
3287
+	public function _registrations_report()
3288
+	{
3289
+		$this->_registrations_report_base('_get_registration_query_parameters');
3290
+	}
3291
+
3292
+
3293
+	public function _contact_list_export()
3294
+	{
3295
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3296
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3297
+			$EE_Export = EE_Export::instance($this->_req_data);
3298
+			$EE_Export->export_attendees();
3299
+		}
3300
+	}
3301
+
3302
+
3303
+	public function _contact_list_report()
3304
+	{
3305
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3306
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3307
+				'page'        => 'espresso_batch',
3308
+				'batch'       => 'file',
3309
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3310
+				'return_url'  => urlencode($this->_req_data['return_url']),
3311
+			)));
3312
+		} else {
3313
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3314
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3315
+				$EE_Export = EE_Export::instance($this->_req_data);
3316
+				$EE_Export->report_attendees();
3317
+			}
3318
+		}
3319
+	}
3320
+
3321
+
3322
+
3323
+
3324
+
3325
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3326
+	/**
3327
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3328
+	 *
3329
+	 * @return void
3330
+	 * @throws EE_Error
3331
+	 */
3332
+	protected function _duplicate_attendee()
3333
+	{
3334
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3335
+		//verify we have necessary info
3336
+		if (empty($this->_req_data['_REG_ID'])) {
3337
+			EE_Error::add_error(
3338
+				esc_html__(
3339
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3340
+					'event_espresso'
3341
+				), __FILE__, __LINE__, __FUNCTION__
3342
+			);
3343
+			$query_args = array('action' => $action);
3344
+			$this->_redirect_after_action('', '', '', $query_args, true);
3345
+		}
3346
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3347
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3348
+		$attendee     = $registration->attendee();
3349
+		//remove relation of existing attendee on registration
3350
+		$registration->_remove_relation_to($attendee, 'Attendee');
3351
+		//new attendee
3352
+		$new_attendee = clone $attendee;
3353
+		$new_attendee->set('ATT_ID', 0);
3354
+		$new_attendee->save();
3355
+		//add new attendee to reg
3356
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3357
+		EE_Error::add_success(
3358
+			esc_html__(
3359
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3360
+				'event_espresso'
3361
+			)
3362
+		);
3363
+		//redirect to edit page for attendee
3364
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3365
+		$this->_redirect_after_action('', '', '', $query_args, true);
3366
+	}
3367
+
3368
+
3369
+	//related to cpt routes
3370
+	protected function _insert_update_cpt_item($post_id, $post)
3371
+	{
3372
+		$success  = true;
3373
+		$attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3374
+		//for attendee updates
3375
+		if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3376
+			//note we should only be UPDATING attendees at this point.
3377
+			$updated_fields = array(
3378
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3379
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3380
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3381
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3382
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3383
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3384
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3385
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3386
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3387
+				'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3388
+				'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3389
+			);
3390
+			foreach ($updated_fields as $field => $value) {
3391
+				$attendee->set($field, $value);
3392
+			}
3393
+			$success                   = $attendee->save();
3394
+			$attendee_update_callbacks = apply_filters(
3395
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3396
+				array()
3397
+			);
3398
+			foreach ($attendee_update_callbacks as $a_callback) {
3399
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3400
+					throw new EE_Error(
3401
+						sprintf(
3402
+							esc_html__(
3403
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3404
+								'event_espresso'
3405
+							),
3406
+							$a_callback
3407
+						)
3408
+					);
3409
+				}
3410
+			}
3411
+		}
3412
+		if ($success === false) {
3413
+			EE_Error::add_error(
3414
+				esc_html__(
3415
+					'Something went wrong with updating the meta table data for the registration.',
3416
+					'event_espresso'
3417
+				),
3418
+				__FILE__, __FUNCTION__, __LINE__
3419
+			);
3420
+		}
3421
+	}
3422
+
3423
+
3424
+	public function trash_cpt_item($post_id)
3425
+	{
3426
+	}
3427
+
3428
+
3429
+	public function delete_cpt_item($post_id)
3430
+	{
3431
+	}
3432
+
3433
+
3434
+	public function restore_cpt_item($post_id)
3435
+	{
3436
+	}
3437
+
3438
+
3439
+	protected function _restore_cpt_item($post_id, $revision_id)
3440
+	{
3441
+	}
3442
+
3443
+
3444
+	public function attendee_editor_metaboxes()
3445
+	{
3446
+		$this->verify_cpt_object();
3447
+		remove_meta_box(
3448
+			'postexcerpt',
3449
+			esc_html__('Excerpt', 'event_espresso'),
3450
+			'post_excerpt_meta_box',
3451
+			$this->_cpt_routes[$this->_req_action],
3452
+			'normal',
3453
+			'core'
3454
+		);
3455
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3456
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3457
+			add_meta_box(
3458
+				'postexcerpt',
3459
+				esc_html__('Short Biography', 'event_espresso'),
3460
+				'post_excerpt_meta_box',
3461
+				$this->_cpt_routes[$this->_req_action],
3462
+				'normal'
3463
+			);
3464
+		}
3465
+		if (post_type_supports('espresso_attendees', 'comments')) {
3466
+			add_meta_box(
3467
+				'commentsdiv',
3468
+				esc_html__('Notes on the Contact', 'event_espresso'),
3469
+				'post_comment_meta_box',
3470
+				$this->_cpt_routes[$this->_req_action],
3471
+				'normal',
3472
+				'core'
3473
+			);
3474
+		}
3475
+		add_meta_box(
3476
+			'attendee_contact_info',
3477
+			esc_html__('Contact Info', 'event_espresso'),
3478
+			array($this, 'attendee_contact_info'),
3479
+			$this->_cpt_routes[$this->_req_action],
3480
+			'side',
3481
+			'core'
3482
+		);
3483
+		add_meta_box(
3484
+			'attendee_details_address',
3485
+			esc_html__('Address Details', 'event_espresso'),
3486
+			array($this, 'attendee_address_details'),
3487
+			$this->_cpt_routes[$this->_req_action],
3488
+			'normal',
3489
+			'core'
3490
+		);
3491
+		add_meta_box(
3492
+			'attendee_registrations',
3493
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3494
+			array($this, 'attendee_registrations_meta_box'),
3495
+			$this->_cpt_routes[$this->_req_action],
3496
+			'normal',
3497
+			'high'
3498
+		);
3499
+	}
3500
+
3501
+
3502
+	/**
3503
+	 * Metabox for attendee contact info
3504
+	 *
3505
+	 * @param  WP_Post $post wp post object
3506
+	 * @return string attendee contact info ( and form )
3507
+	 * @throws DomainException
3508
+	 */
3509
+	public function attendee_contact_info($post)
3510
+	{
3511
+		//get attendee object ( should already have it )
3512
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3513
+		$template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3514
+		EEH_Template::display_template($template, $this->_template_args);
3515
+	}
3516
+
3517
+
3518
+	/**
3519
+	 * Metabox for attendee details
3520
+	 *
3521
+	 * @param  WP_Post $post wp post object
3522
+	 * @return string attendee address details (and form)
3523
+	 * @throws DomainException
3524
+	 */
3525
+	public function attendee_address_details($post)
3526
+	{
3527
+		//get attendee object (should already have it)
3528
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3529
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3530
+			new EE_Question_Form_Input(
3531
+				EE_Question::new_instance(
3532
+					array(
3533
+						'QST_ID'           => 0,
3534
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3535
+						'QST_system'       => 'admin-state',
3536
+					)
3537
+				),
3538
+				EE_Answer::new_instance(
3539
+					array(
3540
+						'ANS_ID'    => 0,
3541
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3542
+					)
3543
+				),
3544
+				array(
3545
+					'input_id'       => 'STA_ID',
3546
+					'input_name'     => 'STA_ID',
3547
+					'input_prefix'   => '',
3548
+					'append_qstn_id' => false,
3549
+				)
3550
+			)
3551
+		);
3552
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3553
+			new EE_Question_Form_Input(
3554
+				EE_Question::new_instance(
3555
+					array(
3556
+						'QST_ID'           => 0,
3557
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3558
+						'QST_system'       => 'admin-country',
3559
+					)
3560
+				),
3561
+				EE_Answer::new_instance(
3562
+					array(
3563
+						'ANS_ID'    => 0,
3564
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3565
+					)
3566
+				),
3567
+				array(
3568
+					'input_id'       => 'CNT_ISO',
3569
+					'input_name'     => 'CNT_ISO',
3570
+					'input_prefix'   => '',
3571
+					'append_qstn_id' => false,
3572
+				)
3573
+			)
3574
+		);
3575
+		$template                             =
3576
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3577
+		EEH_Template::display_template($template, $this->_template_args);
3578
+	}
3579
+
3580
+
3581
+	/**
3582
+	 *        _attendee_details
3583
+	 *
3584
+	 * @access protected
3585
+	 * @param $post
3586
+	 * @return void
3587
+	 * @throws DomainException
3588
+	 * @throws EE_Error
3589
+	 */
3590
+	public function attendee_registrations_meta_box($post)
3591
+	{
3592
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3593
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3594
+		$template                              =
3595
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3596
+		EEH_Template::display_template($template, $this->_template_args);
3597
+	}
3598
+
3599
+
3600
+	/**
3601
+	 * add in the form fields for the attendee edit
3602
+	 *
3603
+	 * @param  WP_Post $post wp post object
3604
+	 * @return string html for new form.
3605
+	 * @throws DomainException
3606
+	 */
3607
+	public function after_title_form_fields($post)
3608
+	{
3609
+		if ($post->post_type == 'espresso_attendees') {
3610
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3611
+			$template_args['attendee'] = $this->_cpt_model_obj;
3612
+			EEH_Template::display_template($template, $template_args);
3613
+		}
3614
+	}
3615
+
3616
+
3617
+	/**
3618
+	 *        _trash_or_restore_attendee
3619
+	 *
3620
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3621
+	 * @return void
3622
+	 * @throws EE_Error
3623
+	 * @access protected
3624
+	 */
3625
+	protected function _trash_or_restore_attendees($trash = true)
3626
+	{
3627
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3628
+		$ATT_MDL = EEM_Attendee::instance();
3629
+		$success = 1;
3630
+		//Checkboxes
3631
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3632
+			// if array has more than one element than success message should be plural
3633
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3634
+			// cycle thru checkboxes
3635
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3636
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3637
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3638
+				if ( ! $updated) {
3639
+					$success = 0;
3640
+				}
3641
+			}
3642
+		} else {
3643
+			// grab single id and delete
3644
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3645
+			//get attendee
3646
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3647
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3648
+			$updated = $att->save();
3649
+			if ( ! $updated) {
3650
+				$success = 0;
3651
+			}
3652
+		}
3653
+		$what        = $success > 1
3654
+			? esc_html__('Contacts', 'event_espresso')
3655
+			: esc_html__('Contact', 'event_espresso');
3656
+		$action_desc = $trash
3657
+			? esc_html__('moved to the trash', 'event_espresso')
3658
+			: esc_html__('restored', 'event_espresso');
3659
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3660
+	}
3661 3661
 
3662 3662
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Message.class.php 1 patch
Indentation   +860 added lines, -860 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -12,869 +12,869 @@  discard block
 block discarded – undo
12 12
 class EE_Message extends EE_Base_Class implements EEI_Admin_Links
13 13
 {
14 14
 
15
-    /**
16
-     * @deprecated 4.9.0  Added for backward compat with add-on's
17
-     * @type null
18
-     */
19
-    public $template_pack;
20
-
21
-    /**
22
-     * @deprecated 4.9.0 Added for backward compat with add-on's
23
-     * @type null
24
-     */
25
-    public $template_variation;
26
-
27
-    /**
28
-     * @deprecated 4.9.0 Added for backward compat with add-on's
29
-     * @type string
30
-     */
31
-    public $content = '';
32
-
33
-
34
-    /**
35
-     * @type EE_messenger $_messenger
36
-     */
37
-    protected $_messenger = null;
38
-
39
-    /**
40
-     * @type EE_message_type $_message_type
41
-     */
42
-    protected $_message_type = null;
43
-
44
-
45
-    /**
46
-     * @param array  $props_n_values
47
-     * @param string $timezone
48
-     * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
49
-     *                             format.
50
-     * @return EE_Message
51
-     */
52
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
53
-    {
54
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
55
-        //if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
56
-        if ( ! $has_object) {
57
-            EE_Registry::instance()->load_helper('URL');
58
-            $props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
59
-        }
60
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
61
-    }
62
-
63
-
64
-    /**
65
-     * @param array  $props_n_values
66
-     * @param string $timezone
67
-     * @return EE_Message
68
-     */
69
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
70
-    {
71
-        return new self($props_n_values, true, $timezone);
72
-    }
73
-
74
-
75
-    /**
76
-     * Gets MSG_token
77
-     *
78
-     * @return int
79
-     */
80
-    public function MSG_token()
81
-    {
82
-        return $this->get('MSG_token');
83
-    }
84
-
85
-
86
-    /**
87
-     * Sets MSG_token
88
-     *
89
-     * @param int $MSG_token
90
-     */
91
-    public function set_MSG_token($MSG_token)
92
-    {
93
-        $this->set('MSG_token', $MSG_token);
94
-    }
95
-
96
-
97
-    /**
98
-     * Gets GRP_ID
99
-     *
100
-     * @return int
101
-     */
102
-    public function GRP_ID()
103
-    {
104
-        return $this->get('GRP_ID');
105
-    }
106
-
107
-
108
-    /**
109
-     * Sets GRP_ID
110
-     *
111
-     * @param int $GRP_ID
112
-     */
113
-    public function set_GRP_ID($GRP_ID)
114
-    {
115
-        $this->set('GRP_ID', $GRP_ID);
116
-    }
117
-
118
-
119
-    /**
120
-     * Gets TXN_ID
121
-     *
122
-     * @return int
123
-     */
124
-    public function TXN_ID()
125
-    {
126
-        return $this->get('TXN_ID');
127
-    }
128
-
129
-
130
-    /**
131
-     * Sets TXN_ID
132
-     *
133
-     * @param int $TXN_ID
134
-     */
135
-    public function set_TXN_ID($TXN_ID)
136
-    {
137
-        $this->set('TXN_ID', $TXN_ID);
138
-    }
139
-
140
-
141
-    /**
142
-     * Gets messenger
143
-     *
144
-     * @return string
145
-     */
146
-    public function messenger()
147
-    {
148
-        return $this->get('MSG_messenger');
149
-    }
150
-
151
-
152
-    /**
153
-     * Sets messenger
154
-     *
155
-     * @param string $messenger
156
-     */
157
-    public function set_messenger($messenger)
158
-    {
159
-        $this->set('MSG_messenger', $messenger);
160
-    }
161
-
162
-
163
-    /**
164
-     * Returns corresponding messenger object for the set messenger on this message
165
-     *
166
-     * @return EE_messenger | null
167
-     */
168
-    public function messenger_object()
169
-    {
170
-        return $this->_messenger;
171
-    }
172
-
173
-
174
-    /**
175
-     * Sets messenger
176
-     *
177
-     * @param EE_messenger $messenger
178
-     */
179
-    public function set_messenger_object(EE_messenger $messenger)
180
-    {
181
-        $this->_messenger = $messenger;
182
-    }
183
-
184
-
185
-    /**
186
-     * validates messenger
187
-     *
188
-     * @param bool $throw_exceptions
189
-     * @return bool
190
-     * @throws \EE_Error
191
-     */
192
-    public function valid_messenger($throw_exceptions = false)
193
-    {
194
-        if ($this->_messenger instanceof EE_messenger) {
195
-            return true;
196
-        }
197
-        if ($throw_exceptions) {
198
-            throw new EE_Error(
199
-                sprintf(
200
-                    __(
201
-                        'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
202
-                        'event_espresso'
203
-                    ),
204
-                    $this->messenger()
205
-                )
206
-            );
207
-        }
208
-        return false;
209
-    }
210
-
211
-
212
-    /**
213
-     * This returns the set localized label for the messenger on this message.
214
-     * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
215
-     * with this message.
216
-     *
217
-     * @param   bool $plural whether to return the plural label or not.
218
-     * @return string
219
-     */
220
-    public function messenger_label($plural = false)
221
-    {
222
-        $label_type = $plural ? 'plural' : 'singular';
223
-        $messenger  = $this->messenger_object();
224
-        return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger();
225
-    }
226
-
227
-
228
-    /**
229
-     * Gets message_type
230
-     *
231
-     * @return string
232
-     */
233
-    public function message_type()
234
-    {
235
-        return $this->get('MSG_message_type');
236
-    }
237
-
238
-
239
-    /**
240
-     * Sets message_type
241
-     *
242
-     * @param string $message_type
243
-     */
244
-    public function set_message_type($message_type)
245
-    {
246
-        $this->set('MSG_message_type', $message_type);
247
-    }
248
-
249
-
250
-    /**
251
-     * Returns the message type object for the set message type on this message
252
-     *
253
-     * @return EE_message_type | null
254
-     */
255
-    public function message_type_object()
256
-    {
257
-        return $this->_message_type;
258
-    }
259
-
260
-
261
-    /**
262
-     * Sets message_type
263
-     *
264
-     * @param EE_message_type $message_type
265
-     * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
266
-     *                                        the message type or not.
267
-     */
268
-    public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
269
-    {
270
-        $this->_message_type = $message_type;
271
-        if ($set_priority) {
272
-            $this->set_priority($this->_message_type->get_priority());
273
-        }
274
-    }
275
-
276
-
277
-    /**
278
-     * validates message_type
279
-     *
280
-     * @param bool $throw_exceptions
281
-     * @return bool
282
-     * @throws \EE_Error
283
-     */
284
-    public function valid_message_type($throw_exceptions = false)
285
-    {
286
-        if ($this->_message_type instanceof EE_message_type) {
287
-            return true;
288
-        }
289
-        if ($throw_exceptions) {
290
-            throw new EE_Error(
291
-                sprintf(
292
-                    __(
293
-                        'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
294
-                        'event_espresso'
295
-                    ),
296
-                    $this->message_type()
297
-                )
298
-            );
299
-        }
300
-        return false;
301
-    }
302
-
303
-
304
-    /**
305
-     * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
306
-     *
307
-     * @param bool $throw_exceptions
308
-     * @return bool
309
-     * @throws \EE_Error
310
-     */
311
-    public function is_valid($throw_exceptions = false)
312
-    {
313
-        if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
314
-            return true;
315
-        }
316
-        return false;
317
-    }
318
-
319
-
320
-    /**
321
-     * This validates whether the internal messenger and message type objects are valid for sending.
322
-     * Three checks are done:
323
-     * 1. There is a valid messenger object.
324
-     * 2. There is a valid message type object.
325
-     * 3. The message type object is active for the messenger.
326
-     *
327
-     * @throws EE_Error  But only if $throw_exceptions is set to true.
328
-     * @param bool $throw_exceptions
329
-     * @return bool
330
-     */
331
-    public function is_valid_for_sending_or_generation($throw_exceptions = false)
332
-    {
333
-        $valid = false;
334
-        if ($this->is_valid($throw_exceptions)) {
335
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
336
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
337
-            $valid                    = $message_resource_manager->is_message_type_active_for_messenger($this->messenger(),
338
-                $this->message_type());
339
-            if ( ! $valid && $throw_exceptions) {
340
-                throw new EE_Error(
341
-                    sprintf(
342
-                        __('The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
343
-                            'event_espresso'),
344
-                        $this->message_type(),
345
-                        $this->messenger()
346
-                    )
347
-                );
348
-            }
349
-        }
350
-        return $valid;
351
-    }
352
-
353
-
354
-    /**
355
-     * This returns the set localized label for the message type on this message.
356
-     * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
357
-     * with this message.
358
-     *
359
-     * @param   bool $plural whether to return the plural label or not.
360
-     * @return string
361
-     */
362
-    public function message_type_label($plural = false)
363
-    {
364
-        $label_type   = $plural ? 'plural' : 'singular';
365
-        $message_type = $this->message_type_object();
366
-        return $message_type instanceof EE_message_type ? $message_type->label[$label_type] : str_replace(
367
-            '_',
368
-            ' ',
369
-            $this->message_type()
370
-        );
371
-    }
372
-
373
-
374
-    /**
375
-     * Gets context
376
-     *
377
-     * @return string
378
-     */
379
-    public function context()
380
-    {
381
-        return $this->get('MSG_context');
382
-    }
383
-
384
-
385
-    /**
386
-     * This returns the corresponding localized label for the given context slug, if possible from installed message
387
-     * types. Otherwise, this will just return the set context slug on this object.
388
-     *
389
-     * @return string
390
-     */
391
-    public function context_label()
392
-    {
393
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
394
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
395
-        $contexts                 = $message_resource_manager->get_all_contexts();
396
-        return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context();
397
-    }
398
-
399
-
400
-    /**
401
-     * Sets context
402
-     *
403
-     * @param string $context
404
-     */
405
-    public function set_context($context)
406
-    {
407
-        $this->set('MSG_context', $context);
408
-    }
409
-
410
-
411
-    /**
412
-     * Gets recipient_ID
413
-     *
414
-     * @return int
415
-     */
416
-    public function recipient_ID()
417
-    {
418
-        return $this->get('MSG_recipient_ID');
419
-    }
420
-
421
-
422
-    /**
423
-     * Sets recipient_ID
424
-     *
425
-     * @param string $recipient_ID
426
-     */
427
-    public function set_recipient_ID($recipient_ID)
428
-    {
429
-        $this->set('MSG_recipient_ID', $recipient_ID);
430
-    }
431
-
432
-
433
-    /**
434
-     * Gets recipient_type
435
-     *
436
-     * @return string
437
-     */
438
-    public function recipient_type()
439
-    {
440
-        return $this->get('MSG_recipient_type');
441
-    }
442
-
443
-
444
-    /**
445
-     * Return the related object matching the recipient type and ID.
446
-     *
447
-     * @return EE_Base_Class | null
448
-     */
449
-    public function recipient_object()
450
-    {
451
-        if ( ! $this->recipient_type() || ! $this->recipient_ID()) {
452
-            return null;
453
-        }
454
-
455
-        return $this->get_first_related($this->recipient_type());
456
-    }
457
-
458
-
459
-    /**
460
-     * Sets recipient_type
461
-     *
462
-     * @param string $recipient_type
463
-     */
464
-    public function set_recipient_type($recipient_type)
465
-    {
466
-        $this->set('MSG_recipient_type', $recipient_type);
467
-    }
468
-
469
-
470
-    /**
471
-     * Gets content
472
-     *
473
-     * @return string
474
-     */
475
-    public function content()
476
-    {
477
-        return $this->get('MSG_content');
478
-    }
479
-
480
-
481
-    /**
482
-     * Sets content
483
-     *
484
-     * @param string $content
485
-     */
486
-    public function set_content($content)
487
-    {
488
-        $this->set('MSG_content', $content);
489
-    }
490
-
491
-
492
-    /**
493
-     * Gets subject
494
-     *
495
-     * @return string
496
-     */
497
-    public function subject()
498
-    {
499
-        return $this->get('MSG_subject');
500
-    }
501
-
502
-
503
-    /**
504
-     * Sets subject
505
-     *
506
-     * @param string $subject
507
-     */
508
-    public function set_subject($subject)
509
-    {
510
-        $this->set('MSG_subject', $subject);
511
-    }
512
-
513
-
514
-    /**
515
-     * Gets to
516
-     *
517
-     * @return string
518
-     */
519
-    public function to()
520
-    {
521
-        $to = $this->get('MSG_to');
522
-        return empty($to) ? __('No recipient', 'event_espresso') : $to;
523
-    }
524
-
525
-
526
-    /**
527
-     * Sets to
528
-     *
529
-     * @param string $to
530
-     */
531
-    public function set_to($to)
532
-    {
533
-        $this->set('MSG_to', $to);
534
-    }
535
-
536
-
537
-    /**
538
-     * Gets from
539
-     *
540
-     * @return string
541
-     */
542
-    public function from()
543
-    {
544
-        return $this->get('MSG_from');
545
-    }
546
-
547
-
548
-    /**
549
-     * Sets from
550
-     *
551
-     * @param string $from
552
-     */
553
-    public function set_from($from)
554
-    {
555
-        $this->set('MSG_from', $from);
556
-    }
557
-
558
-
559
-    /**
560
-     * Gets priority
561
-     *
562
-     * @return int
563
-     */
564
-    public function priority()
565
-    {
566
-        return $this->get('MSG_priority');
567
-    }
568
-
569
-
570
-    /**
571
-     * Sets priority
572
-     * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
573
-     * this method calls the send_now method to verify that.
574
-     *
575
-     * @param int $priority
576
-     */
577
-    public function set_priority($priority)
578
-    {
579
-        $priority = $this->send_now() ? EEM_Message::priority_high : $priority;
580
-        parent::set('MSG_priority', $priority);
581
-    }
582
-
583
-
584
-    /**
585
-     * Overrides parent::set method so we can capture any sets for priority.
586
-     *
587
-     * @see parent::set() for phpdocs
588
-     * @param string $field_name
589
-     * @param mixed  $field_value
590
-     * @param bool   $use_default
591
-     * @throws EE_Error
592
-     */
593
-    public function set($field_name, $field_value, $use_default = false)
594
-    {
595
-        if ($field_name === 'MSG_priority') {
596
-            $this->set_priority($field_value);
597
-        }
598
-        parent::set($field_name, $field_value, $use_default);
599
-    }
600
-
601
-
602
-    /**
603
-     * @return bool
604
-     * @throws \EE_Error
605
-     */
606
-    public function send_now()
607
-    {
608
-        $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high : $this->priority();
609
-        return $send_now === EEM_Message::priority_high ? true : false;
610
-    }
611
-
612
-
613
-    /**
614
-     * Gets STS_ID
615
-     *
616
-     * @return string
617
-     */
618
-    public function STS_ID()
619
-    {
620
-        return $this->get('STS_ID');
621
-    }
622
-
623
-
624
-    /**
625
-     * Sets STS_ID
626
-     *
627
-     * @param string $STS_ID
628
-     */
629
-    public function set_STS_ID($STS_ID)
630
-    {
631
-        $this->set('STS_ID', $STS_ID);
632
-    }
633
-
634
-
635
-    /**
636
-     * Gets created
637
-     *
638
-     * @return string
639
-     */
640
-    public function created()
641
-    {
642
-        return $this->get('MSG_created');
643
-    }
644
-
645
-
646
-    /**
647
-     * Sets created
648
-     *
649
-     * @param string $created
650
-     */
651
-    public function set_created($created)
652
-    {
653
-        $this->set('MSG_created', $created);
654
-    }
655
-
656
-
657
-    /**
658
-     * Gets modified
659
-     *
660
-     * @return string
661
-     */
662
-    public function modified()
663
-    {
664
-        return $this->get('MSG_modified');
665
-    }
666
-
667
-
668
-    /**
669
-     * Sets modified
670
-     *
671
-     * @param string $modified
672
-     */
673
-    public function set_modified($modified)
674
-    {
675
-        $this->set('MSG_modified', $modified);
676
-    }
677
-
678
-
679
-    /**
680
-     * Sets generation data for this message.
681
-     *
682
-     * @param mixed $data
683
-     */
684
-    public function set_generation_data($data)
685
-    {
686
-        $this->set_field_or_extra_meta('MSG_generation_data', $data);
687
-    }
688
-
689
-
690
-    /**
691
-     * Returns any set generation data for this message.
692
-     *
693
-     * @return mixed|null
694
-     */
695
-    public function get_generation_data()
696
-    {
697
-        return $this->get_field_or_extra_meta('MSG_generation_data');
698
-    }
699
-
700
-
701
-    /**
702
-     * Gets any error message.
703
-     *
704
-     * @return mixed|null
705
-     */
706
-    public function error_message()
707
-    {
708
-        return $this->get_field_or_extra_meta('MSG_error');
709
-    }
710
-
711
-
712
-    /**
713
-     * Sets an error message.
714
-     *
715
-     * @param $message
716
-     * @return bool|int
717
-     */
718
-    public function set_error_message($message)
719
-    {
720
-        return $this->set_field_or_extra_meta('MSG_error', $message);
721
-    }
722
-
723
-
724
-    /**
725
-     * This retrieves the associated template pack with this message.
726
-     *
727
-     * @return EE_Messages_Template_Pack | null
728
-     */
729
-    public function get_template_pack()
730
-    {
731
-        /**
732
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
733
-         */
734
-        if ( ! empty($this->template_pack)) {
735
-            return $this->template_pack;
736
-        }
737
-        /** @type EE_Message_Template_Group $grp */
738
-        $grp = $this->get_first_related('Message_Template_Group');
739
-        //if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
740
-        if ( ! $grp instanceof EE_Message_Template_Group) {
741
-            $grp = EEM_Message_Template_Group::instance()->get_one(
742
-                array(
743
-                    array(
744
-                        'MTP_messenger'    => $this->messenger(),
745
-                        'MTP_message_type' => $this->message_type(),
746
-                        'MTP_is_global'    => true,
747
-                    ),
748
-                )
749
-            );
750
-        }
751
-
752
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
753
-    }
754
-
755
-
756
-    /**
757
-     * Retrieves the variation used for generating this message.
758
-     *
759
-     * @return string
760
-     */
761
-    public function get_template_pack_variation()
762
-    {
763
-        /**
764
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
765
-         */
766
-        if ( ! empty($this->template_variation)) {
767
-            return $this->template_variation;
768
-        }
769
-
770
-        /** @type EE_Message_Template_Group $grp */
771
-        $grp = $this->get_first_related('Message_Template_Group');
772
-
773
-        //if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
774
-        if ( ! $grp instanceof EE_Message_Template_Group) {
775
-            $grp = EEM_Message_Template_Group::instance()->get_one(
776
-                array(
777
-                    array(
778
-                        'MTP_messenger'    => $this->messenger(),
779
-                        'MTP_message_type' => $this->message_type(),
780
-                        'MTP_is_global'    => true,
781
-                    ),
782
-                )
783
-            );
784
-        }
785
-
786
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
787
-    }
788
-
789
-    /**
790
-     * Return the link to the admin details for the object.
791
-     *
792
-     * @return string
793
-     */
794
-    public function get_admin_details_link()
795
-    {
796
-        EE_Registry::instance()->load_helper('URL');
797
-        EE_Registry::instance()->load_helper('MSG_Template');
798
-        switch ($this->STS_ID()) {
799
-            case EEM_Message::status_failed :
800
-            case EEM_Message::status_debug_only :
801
-                return EEH_MSG_Template::generate_error_display_trigger($this);
802
-                break;
803
-
804
-            case EEM_Message::status_sent :
805
-                return EEH_MSG_Template::generate_browser_trigger($this);
806
-                break;
807
-
808
-            default :
809
-                return '';
810
-        }
811
-    }
812
-
813
-    /**
814
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
815
-     *
816
-     * @return string
817
-     */
818
-    public function get_admin_edit_link()
819
-    {
820
-        return $this->get_admin_details_link();
821
-    }
822
-
823
-    /**
824
-     * Returns the link to a settings page for the object.
825
-     *
826
-     * @return string
827
-     */
828
-    public function get_admin_settings_link()
829
-    {
830
-        EE_Registry::instance()->load_helper('URL');
831
-        return EEH_URL::add_query_args_and_nonce(
832
-            array(
833
-                'page'   => 'espresso_messages',
834
-                'action' => 'settings',
835
-            ),
836
-            admin_url('admin.php')
837
-        );
838
-    }
839
-
840
-    /**
841
-     * Returns the link to the "overview" for the object (typically the "list table" view).
842
-     *
843
-     * @return string
844
-     */
845
-    public function get_admin_overview_link()
846
-    {
847
-        EE_Registry::instance()->load_helper('URL');
848
-        return EEH_URL::add_query_args_and_nonce(
849
-            array(
850
-                'page'   => 'espresso_messages',
851
-                'action' => 'default',
852
-            ),
853
-            admin_url('admin.php')
854
-        );
855
-    }
856
-
857
-
858
-    /**
859
-     * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for
860
-     * it.
861
-     * Note this also SAVES the current message object to the db because it adds an error message to accompany the status.
862
-     *
863
-     */
864
-    public function set_messenger_is_executing()
865
-    {
866
-        $this->set_STS_ID( EEM_Message::status_messenger_executing );
867
-        $this->set_error_message(
868
-            esc_html__(
869
-                'A message with this status indicates that there was a problem that occurred while the message was being
15
+	/**
16
+	 * @deprecated 4.9.0  Added for backward compat with add-on's
17
+	 * @type null
18
+	 */
19
+	public $template_pack;
20
+
21
+	/**
22
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
23
+	 * @type null
24
+	 */
25
+	public $template_variation;
26
+
27
+	/**
28
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
29
+	 * @type string
30
+	 */
31
+	public $content = '';
32
+
33
+
34
+	/**
35
+	 * @type EE_messenger $_messenger
36
+	 */
37
+	protected $_messenger = null;
38
+
39
+	/**
40
+	 * @type EE_message_type $_message_type
41
+	 */
42
+	protected $_message_type = null;
43
+
44
+
45
+	/**
46
+	 * @param array  $props_n_values
47
+	 * @param string $timezone
48
+	 * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
49
+	 *                             format.
50
+	 * @return EE_Message
51
+	 */
52
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
53
+	{
54
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
55
+		//if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
56
+		if ( ! $has_object) {
57
+			EE_Registry::instance()->load_helper('URL');
58
+			$props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
59
+		}
60
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
61
+	}
62
+
63
+
64
+	/**
65
+	 * @param array  $props_n_values
66
+	 * @param string $timezone
67
+	 * @return EE_Message
68
+	 */
69
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
70
+	{
71
+		return new self($props_n_values, true, $timezone);
72
+	}
73
+
74
+
75
+	/**
76
+	 * Gets MSG_token
77
+	 *
78
+	 * @return int
79
+	 */
80
+	public function MSG_token()
81
+	{
82
+		return $this->get('MSG_token');
83
+	}
84
+
85
+
86
+	/**
87
+	 * Sets MSG_token
88
+	 *
89
+	 * @param int $MSG_token
90
+	 */
91
+	public function set_MSG_token($MSG_token)
92
+	{
93
+		$this->set('MSG_token', $MSG_token);
94
+	}
95
+
96
+
97
+	/**
98
+	 * Gets GRP_ID
99
+	 *
100
+	 * @return int
101
+	 */
102
+	public function GRP_ID()
103
+	{
104
+		return $this->get('GRP_ID');
105
+	}
106
+
107
+
108
+	/**
109
+	 * Sets GRP_ID
110
+	 *
111
+	 * @param int $GRP_ID
112
+	 */
113
+	public function set_GRP_ID($GRP_ID)
114
+	{
115
+		$this->set('GRP_ID', $GRP_ID);
116
+	}
117
+
118
+
119
+	/**
120
+	 * Gets TXN_ID
121
+	 *
122
+	 * @return int
123
+	 */
124
+	public function TXN_ID()
125
+	{
126
+		return $this->get('TXN_ID');
127
+	}
128
+
129
+
130
+	/**
131
+	 * Sets TXN_ID
132
+	 *
133
+	 * @param int $TXN_ID
134
+	 */
135
+	public function set_TXN_ID($TXN_ID)
136
+	{
137
+		$this->set('TXN_ID', $TXN_ID);
138
+	}
139
+
140
+
141
+	/**
142
+	 * Gets messenger
143
+	 *
144
+	 * @return string
145
+	 */
146
+	public function messenger()
147
+	{
148
+		return $this->get('MSG_messenger');
149
+	}
150
+
151
+
152
+	/**
153
+	 * Sets messenger
154
+	 *
155
+	 * @param string $messenger
156
+	 */
157
+	public function set_messenger($messenger)
158
+	{
159
+		$this->set('MSG_messenger', $messenger);
160
+	}
161
+
162
+
163
+	/**
164
+	 * Returns corresponding messenger object for the set messenger on this message
165
+	 *
166
+	 * @return EE_messenger | null
167
+	 */
168
+	public function messenger_object()
169
+	{
170
+		return $this->_messenger;
171
+	}
172
+
173
+
174
+	/**
175
+	 * Sets messenger
176
+	 *
177
+	 * @param EE_messenger $messenger
178
+	 */
179
+	public function set_messenger_object(EE_messenger $messenger)
180
+	{
181
+		$this->_messenger = $messenger;
182
+	}
183
+
184
+
185
+	/**
186
+	 * validates messenger
187
+	 *
188
+	 * @param bool $throw_exceptions
189
+	 * @return bool
190
+	 * @throws \EE_Error
191
+	 */
192
+	public function valid_messenger($throw_exceptions = false)
193
+	{
194
+		if ($this->_messenger instanceof EE_messenger) {
195
+			return true;
196
+		}
197
+		if ($throw_exceptions) {
198
+			throw new EE_Error(
199
+				sprintf(
200
+					__(
201
+						'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
202
+						'event_espresso'
203
+					),
204
+					$this->messenger()
205
+				)
206
+			);
207
+		}
208
+		return false;
209
+	}
210
+
211
+
212
+	/**
213
+	 * This returns the set localized label for the messenger on this message.
214
+	 * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
215
+	 * with this message.
216
+	 *
217
+	 * @param   bool $plural whether to return the plural label or not.
218
+	 * @return string
219
+	 */
220
+	public function messenger_label($plural = false)
221
+	{
222
+		$label_type = $plural ? 'plural' : 'singular';
223
+		$messenger  = $this->messenger_object();
224
+		return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger();
225
+	}
226
+
227
+
228
+	/**
229
+	 * Gets message_type
230
+	 *
231
+	 * @return string
232
+	 */
233
+	public function message_type()
234
+	{
235
+		return $this->get('MSG_message_type');
236
+	}
237
+
238
+
239
+	/**
240
+	 * Sets message_type
241
+	 *
242
+	 * @param string $message_type
243
+	 */
244
+	public function set_message_type($message_type)
245
+	{
246
+		$this->set('MSG_message_type', $message_type);
247
+	}
248
+
249
+
250
+	/**
251
+	 * Returns the message type object for the set message type on this message
252
+	 *
253
+	 * @return EE_message_type | null
254
+	 */
255
+	public function message_type_object()
256
+	{
257
+		return $this->_message_type;
258
+	}
259
+
260
+
261
+	/**
262
+	 * Sets message_type
263
+	 *
264
+	 * @param EE_message_type $message_type
265
+	 * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
266
+	 *                                        the message type or not.
267
+	 */
268
+	public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
269
+	{
270
+		$this->_message_type = $message_type;
271
+		if ($set_priority) {
272
+			$this->set_priority($this->_message_type->get_priority());
273
+		}
274
+	}
275
+
276
+
277
+	/**
278
+	 * validates message_type
279
+	 *
280
+	 * @param bool $throw_exceptions
281
+	 * @return bool
282
+	 * @throws \EE_Error
283
+	 */
284
+	public function valid_message_type($throw_exceptions = false)
285
+	{
286
+		if ($this->_message_type instanceof EE_message_type) {
287
+			return true;
288
+		}
289
+		if ($throw_exceptions) {
290
+			throw new EE_Error(
291
+				sprintf(
292
+					__(
293
+						'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
294
+						'event_espresso'
295
+					),
296
+					$this->message_type()
297
+				)
298
+			);
299
+		}
300
+		return false;
301
+	}
302
+
303
+
304
+	/**
305
+	 * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
306
+	 *
307
+	 * @param bool $throw_exceptions
308
+	 * @return bool
309
+	 * @throws \EE_Error
310
+	 */
311
+	public function is_valid($throw_exceptions = false)
312
+	{
313
+		if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
314
+			return true;
315
+		}
316
+		return false;
317
+	}
318
+
319
+
320
+	/**
321
+	 * This validates whether the internal messenger and message type objects are valid for sending.
322
+	 * Three checks are done:
323
+	 * 1. There is a valid messenger object.
324
+	 * 2. There is a valid message type object.
325
+	 * 3. The message type object is active for the messenger.
326
+	 *
327
+	 * @throws EE_Error  But only if $throw_exceptions is set to true.
328
+	 * @param bool $throw_exceptions
329
+	 * @return bool
330
+	 */
331
+	public function is_valid_for_sending_or_generation($throw_exceptions = false)
332
+	{
333
+		$valid = false;
334
+		if ($this->is_valid($throw_exceptions)) {
335
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
336
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
337
+			$valid                    = $message_resource_manager->is_message_type_active_for_messenger($this->messenger(),
338
+				$this->message_type());
339
+			if ( ! $valid && $throw_exceptions) {
340
+				throw new EE_Error(
341
+					sprintf(
342
+						__('The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
343
+							'event_espresso'),
344
+						$this->message_type(),
345
+						$this->messenger()
346
+					)
347
+				);
348
+			}
349
+		}
350
+		return $valid;
351
+	}
352
+
353
+
354
+	/**
355
+	 * This returns the set localized label for the message type on this message.
356
+	 * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
357
+	 * with this message.
358
+	 *
359
+	 * @param   bool $plural whether to return the plural label or not.
360
+	 * @return string
361
+	 */
362
+	public function message_type_label($plural = false)
363
+	{
364
+		$label_type   = $plural ? 'plural' : 'singular';
365
+		$message_type = $this->message_type_object();
366
+		return $message_type instanceof EE_message_type ? $message_type->label[$label_type] : str_replace(
367
+			'_',
368
+			' ',
369
+			$this->message_type()
370
+		);
371
+	}
372
+
373
+
374
+	/**
375
+	 * Gets context
376
+	 *
377
+	 * @return string
378
+	 */
379
+	public function context()
380
+	{
381
+		return $this->get('MSG_context');
382
+	}
383
+
384
+
385
+	/**
386
+	 * This returns the corresponding localized label for the given context slug, if possible from installed message
387
+	 * types. Otherwise, this will just return the set context slug on this object.
388
+	 *
389
+	 * @return string
390
+	 */
391
+	public function context_label()
392
+	{
393
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
394
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
395
+		$contexts                 = $message_resource_manager->get_all_contexts();
396
+		return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context();
397
+	}
398
+
399
+
400
+	/**
401
+	 * Sets context
402
+	 *
403
+	 * @param string $context
404
+	 */
405
+	public function set_context($context)
406
+	{
407
+		$this->set('MSG_context', $context);
408
+	}
409
+
410
+
411
+	/**
412
+	 * Gets recipient_ID
413
+	 *
414
+	 * @return int
415
+	 */
416
+	public function recipient_ID()
417
+	{
418
+		return $this->get('MSG_recipient_ID');
419
+	}
420
+
421
+
422
+	/**
423
+	 * Sets recipient_ID
424
+	 *
425
+	 * @param string $recipient_ID
426
+	 */
427
+	public function set_recipient_ID($recipient_ID)
428
+	{
429
+		$this->set('MSG_recipient_ID', $recipient_ID);
430
+	}
431
+
432
+
433
+	/**
434
+	 * Gets recipient_type
435
+	 *
436
+	 * @return string
437
+	 */
438
+	public function recipient_type()
439
+	{
440
+		return $this->get('MSG_recipient_type');
441
+	}
442
+
443
+
444
+	/**
445
+	 * Return the related object matching the recipient type and ID.
446
+	 *
447
+	 * @return EE_Base_Class | null
448
+	 */
449
+	public function recipient_object()
450
+	{
451
+		if ( ! $this->recipient_type() || ! $this->recipient_ID()) {
452
+			return null;
453
+		}
454
+
455
+		return $this->get_first_related($this->recipient_type());
456
+	}
457
+
458
+
459
+	/**
460
+	 * Sets recipient_type
461
+	 *
462
+	 * @param string $recipient_type
463
+	 */
464
+	public function set_recipient_type($recipient_type)
465
+	{
466
+		$this->set('MSG_recipient_type', $recipient_type);
467
+	}
468
+
469
+
470
+	/**
471
+	 * Gets content
472
+	 *
473
+	 * @return string
474
+	 */
475
+	public function content()
476
+	{
477
+		return $this->get('MSG_content');
478
+	}
479
+
480
+
481
+	/**
482
+	 * Sets content
483
+	 *
484
+	 * @param string $content
485
+	 */
486
+	public function set_content($content)
487
+	{
488
+		$this->set('MSG_content', $content);
489
+	}
490
+
491
+
492
+	/**
493
+	 * Gets subject
494
+	 *
495
+	 * @return string
496
+	 */
497
+	public function subject()
498
+	{
499
+		return $this->get('MSG_subject');
500
+	}
501
+
502
+
503
+	/**
504
+	 * Sets subject
505
+	 *
506
+	 * @param string $subject
507
+	 */
508
+	public function set_subject($subject)
509
+	{
510
+		$this->set('MSG_subject', $subject);
511
+	}
512
+
513
+
514
+	/**
515
+	 * Gets to
516
+	 *
517
+	 * @return string
518
+	 */
519
+	public function to()
520
+	{
521
+		$to = $this->get('MSG_to');
522
+		return empty($to) ? __('No recipient', 'event_espresso') : $to;
523
+	}
524
+
525
+
526
+	/**
527
+	 * Sets to
528
+	 *
529
+	 * @param string $to
530
+	 */
531
+	public function set_to($to)
532
+	{
533
+		$this->set('MSG_to', $to);
534
+	}
535
+
536
+
537
+	/**
538
+	 * Gets from
539
+	 *
540
+	 * @return string
541
+	 */
542
+	public function from()
543
+	{
544
+		return $this->get('MSG_from');
545
+	}
546
+
547
+
548
+	/**
549
+	 * Sets from
550
+	 *
551
+	 * @param string $from
552
+	 */
553
+	public function set_from($from)
554
+	{
555
+		$this->set('MSG_from', $from);
556
+	}
557
+
558
+
559
+	/**
560
+	 * Gets priority
561
+	 *
562
+	 * @return int
563
+	 */
564
+	public function priority()
565
+	{
566
+		return $this->get('MSG_priority');
567
+	}
568
+
569
+
570
+	/**
571
+	 * Sets priority
572
+	 * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
573
+	 * this method calls the send_now method to verify that.
574
+	 *
575
+	 * @param int $priority
576
+	 */
577
+	public function set_priority($priority)
578
+	{
579
+		$priority = $this->send_now() ? EEM_Message::priority_high : $priority;
580
+		parent::set('MSG_priority', $priority);
581
+	}
582
+
583
+
584
+	/**
585
+	 * Overrides parent::set method so we can capture any sets for priority.
586
+	 *
587
+	 * @see parent::set() for phpdocs
588
+	 * @param string $field_name
589
+	 * @param mixed  $field_value
590
+	 * @param bool   $use_default
591
+	 * @throws EE_Error
592
+	 */
593
+	public function set($field_name, $field_value, $use_default = false)
594
+	{
595
+		if ($field_name === 'MSG_priority') {
596
+			$this->set_priority($field_value);
597
+		}
598
+		parent::set($field_name, $field_value, $use_default);
599
+	}
600
+
601
+
602
+	/**
603
+	 * @return bool
604
+	 * @throws \EE_Error
605
+	 */
606
+	public function send_now()
607
+	{
608
+		$send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high : $this->priority();
609
+		return $send_now === EEM_Message::priority_high ? true : false;
610
+	}
611
+
612
+
613
+	/**
614
+	 * Gets STS_ID
615
+	 *
616
+	 * @return string
617
+	 */
618
+	public function STS_ID()
619
+	{
620
+		return $this->get('STS_ID');
621
+	}
622
+
623
+
624
+	/**
625
+	 * Sets STS_ID
626
+	 *
627
+	 * @param string $STS_ID
628
+	 */
629
+	public function set_STS_ID($STS_ID)
630
+	{
631
+		$this->set('STS_ID', $STS_ID);
632
+	}
633
+
634
+
635
+	/**
636
+	 * Gets created
637
+	 *
638
+	 * @return string
639
+	 */
640
+	public function created()
641
+	{
642
+		return $this->get('MSG_created');
643
+	}
644
+
645
+
646
+	/**
647
+	 * Sets created
648
+	 *
649
+	 * @param string $created
650
+	 */
651
+	public function set_created($created)
652
+	{
653
+		$this->set('MSG_created', $created);
654
+	}
655
+
656
+
657
+	/**
658
+	 * Gets modified
659
+	 *
660
+	 * @return string
661
+	 */
662
+	public function modified()
663
+	{
664
+		return $this->get('MSG_modified');
665
+	}
666
+
667
+
668
+	/**
669
+	 * Sets modified
670
+	 *
671
+	 * @param string $modified
672
+	 */
673
+	public function set_modified($modified)
674
+	{
675
+		$this->set('MSG_modified', $modified);
676
+	}
677
+
678
+
679
+	/**
680
+	 * Sets generation data for this message.
681
+	 *
682
+	 * @param mixed $data
683
+	 */
684
+	public function set_generation_data($data)
685
+	{
686
+		$this->set_field_or_extra_meta('MSG_generation_data', $data);
687
+	}
688
+
689
+
690
+	/**
691
+	 * Returns any set generation data for this message.
692
+	 *
693
+	 * @return mixed|null
694
+	 */
695
+	public function get_generation_data()
696
+	{
697
+		return $this->get_field_or_extra_meta('MSG_generation_data');
698
+	}
699
+
700
+
701
+	/**
702
+	 * Gets any error message.
703
+	 *
704
+	 * @return mixed|null
705
+	 */
706
+	public function error_message()
707
+	{
708
+		return $this->get_field_or_extra_meta('MSG_error');
709
+	}
710
+
711
+
712
+	/**
713
+	 * Sets an error message.
714
+	 *
715
+	 * @param $message
716
+	 * @return bool|int
717
+	 */
718
+	public function set_error_message($message)
719
+	{
720
+		return $this->set_field_or_extra_meta('MSG_error', $message);
721
+	}
722
+
723
+
724
+	/**
725
+	 * This retrieves the associated template pack with this message.
726
+	 *
727
+	 * @return EE_Messages_Template_Pack | null
728
+	 */
729
+	public function get_template_pack()
730
+	{
731
+		/**
732
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
733
+		 */
734
+		if ( ! empty($this->template_pack)) {
735
+			return $this->template_pack;
736
+		}
737
+		/** @type EE_Message_Template_Group $grp */
738
+		$grp = $this->get_first_related('Message_Template_Group');
739
+		//if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
740
+		if ( ! $grp instanceof EE_Message_Template_Group) {
741
+			$grp = EEM_Message_Template_Group::instance()->get_one(
742
+				array(
743
+					array(
744
+						'MTP_messenger'    => $this->messenger(),
745
+						'MTP_message_type' => $this->message_type(),
746
+						'MTP_is_global'    => true,
747
+					),
748
+				)
749
+			);
750
+		}
751
+
752
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
753
+	}
754
+
755
+
756
+	/**
757
+	 * Retrieves the variation used for generating this message.
758
+	 *
759
+	 * @return string
760
+	 */
761
+	public function get_template_pack_variation()
762
+	{
763
+		/**
764
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
765
+		 */
766
+		if ( ! empty($this->template_variation)) {
767
+			return $this->template_variation;
768
+		}
769
+
770
+		/** @type EE_Message_Template_Group $grp */
771
+		$grp = $this->get_first_related('Message_Template_Group');
772
+
773
+		//if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
774
+		if ( ! $grp instanceof EE_Message_Template_Group) {
775
+			$grp = EEM_Message_Template_Group::instance()->get_one(
776
+				array(
777
+					array(
778
+						'MTP_messenger'    => $this->messenger(),
779
+						'MTP_message_type' => $this->message_type(),
780
+						'MTP_is_global'    => true,
781
+					),
782
+				)
783
+			);
784
+		}
785
+
786
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
787
+	}
788
+
789
+	/**
790
+	 * Return the link to the admin details for the object.
791
+	 *
792
+	 * @return string
793
+	 */
794
+	public function get_admin_details_link()
795
+	{
796
+		EE_Registry::instance()->load_helper('URL');
797
+		EE_Registry::instance()->load_helper('MSG_Template');
798
+		switch ($this->STS_ID()) {
799
+			case EEM_Message::status_failed :
800
+			case EEM_Message::status_debug_only :
801
+				return EEH_MSG_Template::generate_error_display_trigger($this);
802
+				break;
803
+
804
+			case EEM_Message::status_sent :
805
+				return EEH_MSG_Template::generate_browser_trigger($this);
806
+				break;
807
+
808
+			default :
809
+				return '';
810
+		}
811
+	}
812
+
813
+	/**
814
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
815
+	 *
816
+	 * @return string
817
+	 */
818
+	public function get_admin_edit_link()
819
+	{
820
+		return $this->get_admin_details_link();
821
+	}
822
+
823
+	/**
824
+	 * Returns the link to a settings page for the object.
825
+	 *
826
+	 * @return string
827
+	 */
828
+	public function get_admin_settings_link()
829
+	{
830
+		EE_Registry::instance()->load_helper('URL');
831
+		return EEH_URL::add_query_args_and_nonce(
832
+			array(
833
+				'page'   => 'espresso_messages',
834
+				'action' => 'settings',
835
+			),
836
+			admin_url('admin.php')
837
+		);
838
+	}
839
+
840
+	/**
841
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
842
+	 *
843
+	 * @return string
844
+	 */
845
+	public function get_admin_overview_link()
846
+	{
847
+		EE_Registry::instance()->load_helper('URL');
848
+		return EEH_URL::add_query_args_and_nonce(
849
+			array(
850
+				'page'   => 'espresso_messages',
851
+				'action' => 'default',
852
+			),
853
+			admin_url('admin.php')
854
+		);
855
+	}
856
+
857
+
858
+	/**
859
+	 * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for
860
+	 * it.
861
+	 * Note this also SAVES the current message object to the db because it adds an error message to accompany the status.
862
+	 *
863
+	 */
864
+	public function set_messenger_is_executing()
865
+	{
866
+		$this->set_STS_ID( EEM_Message::status_messenger_executing );
867
+		$this->set_error_message(
868
+			esc_html__(
869
+				'A message with this status indicates that there was a problem that occurred while the message was being
870 870
                 processed by the messenger.  It is still possible that the message was sent successfully, but at some
871 871
                 point during the processing there was a failure.  This usually is indicative of a timeout issue with PHP 
872 872
                 or memory limits being reached.  If you see this repeatedly you may want to consider upgrading the memory 
873 873
                 available to PHP on your server.',
874
-                'event_espresso'
875
-            )
876
-        );
877
-    }
874
+				'event_espresso'
875
+			)
876
+		);
877
+	}
878 878
 }
879 879
 /* End of file EE_Message.class.php */
880 880
 /* Location: /core/db_classes/EE_Message.class.php */
881 881
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/Helpers/BaseCoreAdmin.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -13,72 +13,72 @@
 block discarded – undo
13 13
 trait BaseCoreAdmin
14 14
 {
15 15
 
16
-    /**
17
-     * Core method for going to an Event Espresso Admin page.
18
-     * @param string $page
19
-     * @param string $action
20
-     * @param string $additional_params
21
-     */
22
-    public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '')
23
-    {
24
-        $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params));
25
-    }
16
+	/**
17
+	 * Core method for going to an Event Espresso Admin page.
18
+	 * @param string $page
19
+	 * @param string $action
20
+	 * @param string $additional_params
21
+	 */
22
+	public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '')
23
+	{
24
+		$this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params));
25
+	}
26 26
 
27 27
 
28
-    /**
29
-     * Helper method for returning an instance of the Actor.  Intended to help with IDE fill out of methods.
30
-     * @return \EventEspressoAcceptanceTester;
31
-     */
32
-    protected function actor()
33
-    {
34
-        /** @var \EventEspressoAcceptanceTester $this */
35
-        return $this;
36
-    }
28
+	/**
29
+	 * Helper method for returning an instance of the Actor.  Intended to help with IDE fill out of methods.
30
+	 * @return \EventEspressoAcceptanceTester;
31
+	 */
32
+	protected function actor()
33
+	{
34
+		/** @var \EventEspressoAcceptanceTester $this */
35
+		return $this;
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * Use this to set the per page option for a list table page.
41
-     * Assumes you are on a page that has this field exposed.
42
-     *
43
-     * @param int|string $per_page_value
44
-     * @throws \Codeception\Exception\TestRuntimeException
45
-     */
46
-    public function setPerPageOptionForScreen($per_page_value)
47
-    {
48
-        $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR);
49
-        $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value);
50
-        $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR);
51
-        $this->actor()->wait(8);
52
-    }
39
+	/**
40
+	 * Use this to set the per page option for a list table page.
41
+	 * Assumes you are on a page that has this field exposed.
42
+	 *
43
+	 * @param int|string $per_page_value
44
+	 * @throws \Codeception\Exception\TestRuntimeException
45
+	 */
46
+	public function setPerPageOptionForScreen($per_page_value)
47
+	{
48
+		$this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR);
49
+		$this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value);
50
+		$this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR);
51
+		$this->actor()->wait(8);
52
+	}
53 53
 
54 54
 
55 55
 
56
-    /**
57
-     * Use this to append a given value to a wpEditor instance.
58
-     * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and
59
-     * the value is added to the text area.
60
-     *
61
-     * @param $field_reference
62
-     * @param $value
63
-     * @throws \Codeception\Exception\ElementNotFound
64
-     */
65
-    public function appendToWPEditorField($field_reference, $value)
66
-    {
67
-        $this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference));
68
-        $this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value);
69
-    }
56
+	/**
57
+	 * Use this to append a given value to a wpEditor instance.
58
+	 * How it works is it first switched the instance to the text (or html) view so that the textarea is exposed and
59
+	 * the value is added to the text area.
60
+	 *
61
+	 * @param $field_reference
62
+	 * @param $value
63
+	 * @throws \Codeception\Exception\ElementNotFound
64
+	 */
65
+	public function appendToWPEditorField($field_reference, $value)
66
+	{
67
+		$this->actor()->click(CoreAdmin::wpEditorTextTabSelector($field_reference));
68
+		$this->actor()->appendField(CoreAdmin::wpEditorTextAreaSelector($field_reference), $value);
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     * Use to select and submit the given bulk action.
74
-     * @param string $bulk_action_option
75
-     */
76
-    public function submitBulkActionOnListTable($bulk_action_option)
77
-    {
78
-        $this->actor()->selectOption(
79
-            CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTION_FIELD,
80
-            $bulk_action_option
81
-        );
82
-        $this->actor()->click(CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY);
83
-    }
72
+	/**
73
+	 * Use to select and submit the given bulk action.
74
+	 * @param string $bulk_action_option
75
+	 */
76
+	public function submitBulkActionOnListTable($bulk_action_option)
77
+	{
78
+		$this->actor()->selectOption(
79
+			CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTION_FIELD,
80
+			$bulk_action_option
81
+		);
82
+		$this->actor()->click(CoreAdmin::SELECTOR_LIST_TABLE_BULK_ACTTION_APPLY);
83
+	}
84 84
 }
Please login to merge, or discard this patch.
acceptance_tests/Helpers/RegistrationsAdmin.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -13,30 +13,30 @@
 block discarded – undo
13 13
 trait RegistrationsAdmin
14 14
 {
15 15
 
16
-    /**
17
-     * This will select all checkboxes on a registration list table for the given array of
18
-     * registration ids.
19
-     * Assumes the actor is on a list table page for registrations.
20
-     * @param $registration_ids
21
-     */
22
-    public function selectBulkActionCheckboxesForRegistrationIds(array $registration_ids)
23
-    {
24
-        foreach ($registration_ids as $registration_id) {
25
-            $this->actor()->checkOption(
26
-                RegistrationsAdminPage::listTableCheckBoxSelectorForRegistrationId($registration_id)
27
-            );
28
-        }
29
-    }
16
+	/**
17
+	 * This will select all checkboxes on a registration list table for the given array of
18
+	 * registration ids.
19
+	 * Assumes the actor is on a list table page for registrations.
20
+	 * @param $registration_ids
21
+	 */
22
+	public function selectBulkActionCheckboxesForRegistrationIds(array $registration_ids)
23
+	{
24
+		foreach ($registration_ids as $registration_id) {
25
+			$this->actor()->checkOption(
26
+				RegistrationsAdminPage::listTableCheckBoxSelectorForRegistrationId($registration_id)
27
+			);
28
+		}
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     * Navigates the actor to the default registration list table page.
34
-     * @param string $additional_params
35
-     */
36
-    public function amOnDefaultRegistrationsListTableAdminPage($additional_params = '')
37
-    {
38
-        $this->actor()->amOnAdminPage(
39
-            RegistrationsAdminPage::registrationsDefaultAdminListTableUrl($additional_params)
40
-        );
41
-    }
32
+	/**
33
+	 * Navigates the actor to the default registration list table page.
34
+	 * @param string $additional_params
35
+	 */
36
+	public function amOnDefaultRegistrationsListTableAdminPage($additional_params = '')
37
+	{
38
+		$this->actor()->amOnAdminPage(
39
+			RegistrationsAdminPage::registrationsDefaultAdminListTableUrl($additional_params)
40
+		);
41
+	}
42 42
 }
43 43
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/Helpers/Checkout.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -13,70 +13,70 @@
 block discarded – undo
13 13
  */
14 14
 trait Checkout
15 15
 {
16
-    /**
17
-     * @param     $value
18
-     * @param int $attendee_number
19
-     */
20
-    public function fillOutFirstNameFieldForAttendee($value, $attendee_number = 1)
21
-    {
22
-        $this->actor()->fillField(CheckoutPage::firstNameFieldSelectorForAttendeeNumber($attendee_number), $value);
23
-    }
16
+	/**
17
+	 * @param     $value
18
+	 * @param int $attendee_number
19
+	 */
20
+	public function fillOutFirstNameFieldForAttendee($value, $attendee_number = 1)
21
+	{
22
+		$this->actor()->fillField(CheckoutPage::firstNameFieldSelectorForAttendeeNumber($attendee_number), $value);
23
+	}
24 24
 
25
-    /**
26
-     * @param     $value
27
-     * @param int $attendee_number
28
-     */
29
-    public function fillOutLastNameFieldForAttendee($value, $attendee_number = 1)
30
-    {
31
-        $this->actor()->fillField(CheckoutPage::lastNameFieldSelectorForAttendeeNumber($attendee_number), $value);
32
-    }
25
+	/**
26
+	 * @param     $value
27
+	 * @param int $attendee_number
28
+	 */
29
+	public function fillOutLastNameFieldForAttendee($value, $attendee_number = 1)
30
+	{
31
+		$this->actor()->fillField(CheckoutPage::lastNameFieldSelectorForAttendeeNumber($attendee_number), $value);
32
+	}
33 33
 
34
-    /**
35
-     * @param     $value
36
-     * @param int $attendee_number
37
-     */
38
-    public function fillOutEmailFieldForAttendee($value, $attendee_number = 1)
39
-    {
40
-        $this->actor()->fillField(CheckoutPage::emailFieldSelectorForAttendeeNumber($attendee_number), $value);
41
-    }
34
+	/**
35
+	 * @param     $value
36
+	 * @param int $attendee_number
37
+	 */
38
+	public function fillOutEmailFieldForAttendee($value, $attendee_number = 1)
39
+	{
40
+		$this->actor()->fillField(CheckoutPage::emailFieldSelectorForAttendeeNumber($attendee_number), $value);
41
+	}
42 42
 
43 43
 
44
-    /**
45
-     * Clicks the next registration step button.
46
-     */
47
-    public function goToNextRegistrationStep()
48
-    {
49
-        $this->actor()->click(CheckoutPage::NEXT_STEP_BUTTON_SELECTOR);
50
-    }
44
+	/**
45
+	 * Clicks the next registration step button.
46
+	 */
47
+	public function goToNextRegistrationStep()
48
+	{
49
+		$this->actor()->click(CheckoutPage::NEXT_STEP_BUTTON_SELECTOR);
50
+	}
51 51
 
52 52
 
53
-    /**
54
-     * Selects the payment option for the given payment method slug.
55
-     *
56
-     * @param string $payment_method_slug
57
-     * @param bool   $verify_selected      If true, this will wait for the "Important Information" info box after the
58
-     *                                     payment option select box is complete.  Otherwise its up to calling code to
59
-     *                                     wait for whatever is needed after selecting the payment method.
60
-     */
61
-    public function selectPaymentOptionFor($payment_method_slug = 'invoice', $verify_selected = true)
62
-    {
63
-        $this->actor()->selectOption(
64
-            CheckoutPage::PAYMENT_METHOD_STEP_FORM,
65
-            $payment_method_slug
66
-        );
67
-        if ($verify_selected) {
68
-            $this->actor()->waitForText('Important information regarding your payment');
69
-        }
70
-    }
53
+	/**
54
+	 * Selects the payment option for the given payment method slug.
55
+	 *
56
+	 * @param string $payment_method_slug
57
+	 * @param bool   $verify_selected      If true, this will wait for the "Important Information" info box after the
58
+	 *                                     payment option select box is complete.  Otherwise its up to calling code to
59
+	 *                                     wait for whatever is needed after selecting the payment method.
60
+	 */
61
+	public function selectPaymentOptionFor($payment_method_slug = 'invoice', $verify_selected = true)
62
+	{
63
+		$this->actor()->selectOption(
64
+			CheckoutPage::PAYMENT_METHOD_STEP_FORM,
65
+			$payment_method_slug
66
+		);
67
+		if ($verify_selected) {
68
+			$this->actor()->waitForText('Important information regarding your payment');
69
+		}
70
+	}
71 71
 
72 72
 
73
-    /**
74
-     * Submits the payment options step form.
75
-     * Assumes the actor is in the context of the payment options SPCO step.
76
-     */
77
-    public function submitPaymentOptionsRegistrationStepForm()
78
-    {
79
-        $this->actor()->submitForm(CheckoutPage::PAYMENT_METHOD_STEP_FORM, array());
80
-    }
73
+	/**
74
+	 * Submits the payment options step form.
75
+	 * Assumes the actor is in the context of the payment options SPCO step.
76
+	 */
77
+	public function submitPaymentOptionsRegistrationStepForm()
78
+	{
79
+		$this->actor()->submitForm(CheckoutPage::PAYMENT_METHOD_STEP_FORM, array());
80
+	}
81 81
 
82 82
 }
83 83
\ No newline at end of file
Please login to merge, or discard this patch.