Completed
Branch BUG/delete-event (f1829b)
by
unknown
04:31 queued 02:39
created
core/db_models/EEM_Event.model.php 1 patch
Indentation   +951 added lines, -951 removed lines patch added patch discarded remove patch
@@ -15,955 +15,955 @@
 block discarded – undo
15 15
 class EEM_Event extends EEM_CPT_Base
16 16
 {
17 17
 
18
-    /**
19
-     * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
20
-     * event
21
-     */
22
-    const sold_out = 'sold_out';
23
-
24
-    /**
25
-     * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
26
-     * date)
27
-     */
28
-    const postponed = 'postponed';
29
-
30
-    /**
31
-     * constant used by status(), indicating that the event will no longer occur
32
-     */
33
-    const cancelled = 'cancelled';
34
-
35
-
36
-    /**
37
-     * @var string
38
-     */
39
-    protected static $_default_reg_status;
40
-
41
-
42
-    /**
43
-     * This is the default for the additional limit field.
44
-     * @var int
45
-     */
46
-    protected static $_default_additional_limit = 10;
47
-
48
-
49
-    /**
50
-     * private instance of the Event object
51
-     *
52
-     * @var EEM_Event
53
-     */
54
-    protected static $_instance;
55
-
56
-
57
-
58
-
59
-    /**
60
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
61
-     *
62
-     * @param string $timezone
63
-     * @throws \EE_Error
64
-     */
65
-    protected function __construct($timezone = null)
66
-    {
67
-        EE_Registry::instance()->load_model('Registration');
68
-        $this->singular_item = esc_html__('Event', 'event_espresso');
69
-        $this->plural_item = esc_html__('Events', 'event_espresso');
70
-        // to remove Cancelled events from the frontend, copy the following filter to your functions.php file
71
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
72
-        // to remove Postponed events from the frontend, copy the following filter to your functions.php file
73
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
74
-        // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
75
-        //  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
76
-        $this->_custom_stati = apply_filters(
77
-            'AFEE__EEM_Event__construct___custom_stati',
78
-            array(
79
-                EEM_Event::cancelled => array(
80
-                    'label'  => esc_html__('Cancelled', 'event_espresso'),
81
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
82
-                ),
83
-                EEM_Event::postponed => array(
84
-                    'label'  => esc_html__('Postponed', 'event_espresso'),
85
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
86
-                ),
87
-                EEM_Event::sold_out  => array(
88
-                    'label'  => esc_html__('Sold Out', 'event_espresso'),
89
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
90
-                ),
91
-            )
92
-        );
93
-        self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
94
-            : self::$_default_reg_status;
95
-        $this->_tables = array(
96
-            'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
97
-            'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
98
-        );
99
-        $this->_fields = array(
100
-            'Event_CPT'  => array(
101
-                'EVT_ID'         => new EE_Primary_Key_Int_Field(
102
-                    'ID',
103
-                    esc_html__('Post ID for Event', 'event_espresso')
104
-                ),
105
-                'EVT_name'       => new EE_Plain_Text_Field(
106
-                    'post_title',
107
-                    esc_html__('Event Name', 'event_espresso'),
108
-                    false,
109
-                    ''
110
-                ),
111
-                'EVT_desc'       => new EE_Post_Content_Field(
112
-                    'post_content',
113
-                    esc_html__('Event Description', 'event_espresso'),
114
-                    false,
115
-                    ''
116
-                ),
117
-                'EVT_slug'       => new EE_Slug_Field(
118
-                    'post_name',
119
-                    esc_html__('Event Slug', 'event_espresso'),
120
-                    false,
121
-                    ''
122
-                ),
123
-                'EVT_created'    => new EE_Datetime_Field(
124
-                    'post_date',
125
-                    esc_html__('Date/Time Event Created', 'event_espresso'),
126
-                    false,
127
-                    EE_Datetime_Field::now
128
-                ),
129
-                'EVT_short_desc' => new EE_Simple_HTML_Field(
130
-                    'post_excerpt',
131
-                    esc_html__('Event Short Description', 'event_espresso'),
132
-                    false,
133
-                    ''
134
-                ),
135
-                'EVT_modified'   => new EE_Datetime_Field(
136
-                    'post_modified',
137
-                    esc_html__('Date/Time Event Modified', 'event_espresso'),
138
-                    false,
139
-                    EE_Datetime_Field::now
140
-                ),
141
-                'EVT_wp_user'    => new EE_WP_User_Field(
142
-                    'post_author',
143
-                    esc_html__('Event Creator ID', 'event_espresso'),
144
-                    false
145
-                ),
146
-                'parent'         => new EE_Integer_Field(
147
-                    'post_parent',
148
-                    esc_html__('Event Parent ID', 'event_espresso'),
149
-                    false,
150
-                    0
151
-                ),
152
-                'EVT_order'      => new EE_Integer_Field(
153
-                    'menu_order',
154
-                    esc_html__('Event Menu Order', 'event_espresso'),
155
-                    false,
156
-                    1
157
-                ),
158
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
159
-                // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
160
-                'status'         => new EE_WP_Post_Status_Field(
161
-                    'post_status',
162
-                    esc_html__('Event Status', 'event_espresso'),
163
-                    false,
164
-                    'draft',
165
-                    $this->_custom_stati
166
-                ),
167
-                'password' => new EE_Password_Field(
168
-                    'post_password',
169
-                    esc_html__('Password', 'event_espresso'),
170
-                    false,
171
-                    '',
172
-                    array(
173
-                        'EVT_desc',
174
-                        'EVT_short_desc',
175
-                        'EVT_display_desc',
176
-                        'EVT_display_ticket_selector',
177
-                        'EVT_visible_on',
178
-                        'EVT_additional_limit',
179
-                        'EVT_default_registration_status',
180
-                        'EVT_member_only',
181
-                        'EVT_phone',
182
-                        'EVT_allow_overflow',
183
-                        'EVT_timezone_string',
184
-                        'EVT_external_URL',
185
-                        'EVT_donations'
186
-                    )
187
-                )
188
-            ),
189
-            'Event_Meta' => array(
190
-                'EVTM_ID'                         => new EE_DB_Only_Float_Field(
191
-                    'EVTM_ID',
192
-                    esc_html__('Event Meta Row ID', 'event_espresso'),
193
-                    false
194
-                ),
195
-                'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
196
-                    'EVT_ID',
197
-                    esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
198
-                    false
199
-                ),
200
-                'EVT_display_desc'                => new EE_Boolean_Field(
201
-                    'EVT_display_desc',
202
-                    esc_html__('Display Description Flag', 'event_espresso'),
203
-                    false,
204
-                    true
205
-                ),
206
-                'EVT_display_ticket_selector'     => new EE_Boolean_Field(
207
-                    'EVT_display_ticket_selector',
208
-                    esc_html__('Display Ticket Selector Flag', 'event_espresso'),
209
-                    false,
210
-                    true
211
-                ),
212
-                'EVT_visible_on'                  => new EE_Datetime_Field(
213
-                    'EVT_visible_on',
214
-                    esc_html__('Event Visible Date', 'event_espresso'),
215
-                    true,
216
-                    EE_Datetime_Field::now
217
-                ),
218
-                'EVT_additional_limit'            => new EE_Integer_Field(
219
-                    'EVT_additional_limit',
220
-                    esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
221
-                    true,
222
-                    self::$_default_additional_limit
223
-                ),
224
-                'EVT_default_registration_status' => new EE_Enum_Text_Field(
225
-                    'EVT_default_registration_status',
226
-                    esc_html__('Default Registration Status on this Event', 'event_espresso'),
227
-                    false,
228
-                    EEM_Event::$_default_reg_status,
229
-                    EEM_Registration::reg_status_array()
230
-                ),
231
-                'EVT_member_only'                 => new EE_Boolean_Field(
232
-                    'EVT_member_only',
233
-                    esc_html__('Member-Only Event Flag', 'event_espresso'),
234
-                    false,
235
-                    false
236
-                ),
237
-                'EVT_phone'                       => new EE_Plain_Text_Field(
238
-                    'EVT_phone',
239
-                    esc_html__('Event Phone Number', 'event_espresso'),
240
-                    false,
241
-                    ''
242
-                ),
243
-                'EVT_allow_overflow'              => new EE_Boolean_Field(
244
-                    'EVT_allow_overflow',
245
-                    esc_html__('Allow Overflow on Event', 'event_espresso'),
246
-                    false,
247
-                    false
248
-                ),
249
-                'EVT_timezone_string'             => new EE_Plain_Text_Field(
250
-                    'EVT_timezone_string',
251
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'),
252
-                    false,
253
-                    ''
254
-                ),
255
-                'EVT_external_URL'                => new EE_Plain_Text_Field(
256
-                    'EVT_external_URL',
257
-                    esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
258
-                    true
259
-                ),
260
-                'EVT_donations'                   => new EE_Boolean_Field(
261
-                    'EVT_donations',
262
-                    esc_html__('Accept Donations?', 'event_espresso'),
263
-                    false,
264
-                    false
265
-                ),
266
-            ),
267
-        );
268
-        $this->_model_relations = array(
269
-            'Registration'           => new EE_Has_Many_Relation(),
270
-            'Datetime'               => new EE_Has_Many_Relation(),
271
-            'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
272
-            'Event_Question_Group'   => new EE_Has_Many_Relation(),
273
-            'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
274
-            'Term_Relationship'      => new EE_Has_Many_Relation(),
275
-            'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
276
-            'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
277
-            'Attendee'               => new EE_HABTM_Relation('Registration'),
278
-            'WP_User'                => new EE_Belongs_To_Relation(),
279
-        );
280
-        // this model is generally available for reading
281
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
282
-        $this->model_chain_to_password = '';
283
-        parent::__construct($timezone);
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     * @param string $default_reg_status
290
-     */
291
-    public static function set_default_reg_status($default_reg_status)
292
-    {
293
-        self::$_default_reg_status = $default_reg_status;
294
-        // if EEM_Event has already been instantiated,
295
-        // then we need to reset the `EVT_default_reg_status` field to use the new default.
296
-        if (self::$_instance instanceof EEM_Event) {
297
-            $default_reg_status = new EE_Enum_Text_Field(
298
-                'EVT_default_registration_status',
299
-                esc_html__('Default Registration Status on this Event', 'event_espresso'),
300
-                false,
301
-                $default_reg_status,
302
-                EEM_Registration::reg_status_array()
303
-            );
304
-            $default_reg_status->_construct_finalize(
305
-                'Event_Meta',
306
-                'EVT_default_registration_status',
307
-                'EEM_Event'
308
-            );
309
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
310
-        }
311
-    }
312
-
313
-
314
-    /**
315
-     * Used to override the default for the additional limit field.
316
-     * @param $additional_limit
317
-     */
318
-    public static function set_default_additional_limit($additional_limit)
319
-    {
320
-        self::$_default_additional_limit = (int) $additional_limit;
321
-        if (self::$_instance instanceof EEM_Event) {
322
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
323
-                'EVT_additional_limit',
324
-                esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
325
-                true,
326
-                self::$_default_additional_limit
327
-            );
328
-            self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
329
-                'Event_Meta',
330
-                'EVT_additional_limit',
331
-                'EEM_Event'
332
-            );
333
-        }
334
-    }
335
-
336
-
337
-    /**
338
-     * Return what is currently set as the default additional limit for the event.
339
-     * @return int
340
-     */
341
-    public static function get_default_additional_limit()
342
-    {
343
-        return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
344
-    }
345
-
346
-
347
-    /**
348
-     * get_question_groups
349
-     *
350
-     * @return array
351
-     * @throws \EE_Error
352
-     */
353
-    public function get_all_question_groups()
354
-    {
355
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
356
-            array(
357
-                array('QSG_deleted' => false),
358
-                'order_by' => array('QSG_order' => 'ASC'),
359
-            )
360
-        );
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     * get_question_groups
367
-     *
368
-     * @param int $EVT_ID
369
-     * @return array|bool
370
-     * @throws \EE_Error
371
-     */
372
-    public function get_all_event_question_groups($EVT_ID = 0)
373
-    {
374
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
375
-            EE_Error::add_error(
376
-                esc_html__(
377
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
378
-                    'event_espresso'
379
-                ),
380
-                __FILE__,
381
-                __FUNCTION__,
382
-                __LINE__
383
-            );
384
-            return false;
385
-        }
386
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
387
-            array(
388
-                array('EVT_ID' => $EVT_ID),
389
-            )
390
-        );
391
-    }
392
-
393
-
394
-    /**
395
-     * get_question_groups
396
-     *
397
-     * @param int $EVT_ID
398
-     * @param boolean $for_primary_attendee
399
-     * @return array|bool
400
-     * @throws EE_Error
401
-     * @throws InvalidArgumentException
402
-     * @throws ReflectionException
403
-     * @throws InvalidDataTypeException
404
-     * @throws InvalidInterfaceException
405
-     */
406
-    public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
407
-    {
408
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
409
-            EE_Error::add_error(
410
-                esc_html__(
411
-                    // @codingStandardsIgnoreStart
412
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
413
-                    // @codingStandardsIgnoreEnd
414
-                    'event_espresso'
415
-                ),
416
-                __FILE__,
417
-                __FUNCTION__,
418
-                __LINE__
419
-            );
420
-            return false;
421
-        }
422
-        $query_params = [
423
-            [
424
-                'EVT_ID' => $EVT_ID,
425
-                EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true
426
-            ]
427
-        ];
428
-        if ($for_primary_attendee) {
429
-            $query_params[0]['EQG_primary'] = true;
430
-        } else {
431
-            $query_params[0]['EQG_additional'] = true;
432
-        }
433
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params);
434
-    }
435
-
436
-
437
-    /**
438
-     * get_question_groups
439
-     *
440
-     * @param int $EVT_ID
441
-     * @param EE_Registration $registration
442
-     * @return array|bool
443
-     * @throws EE_Error
444
-     * @throws InvalidArgumentException
445
-     * @throws InvalidDataTypeException
446
-     * @throws InvalidInterfaceException
447
-     * @throws ReflectionException
448
-     */
449
-    public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
450
-    {
451
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
452
-            EE_Error::add_error(
453
-                esc_html__(
454
-                    'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
455
-                    'event_espresso'
456
-                ),
457
-                __FILE__,
458
-                __FUNCTION__,
459
-                __LINE__
460
-            );
461
-            return false;
462
-        }
463
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
464
-            [
465
-                [
466
-                    'Event_Question_Group.EVT_ID'      => $EVT_ID,
467
-                    'Event_Question_Group.'
468
-                        . EEM_Event_Question_Group::instance()->fieldNameForContext(
469
-                            $registration->is_primary_registrant()
470
-                        ) => true
471
-                ],
472
-                'order_by' => ['QSG_order' => 'ASC'],
473
-            ]
474
-        );
475
-    }
476
-
477
-
478
-
479
-    /**
480
-     * get_question_target_db_column
481
-     *
482
-     * @param string $QSG_IDs csv list of $QSG IDs
483
-     * @return array|bool
484
-     * @throws \EE_Error
485
-     */
486
-    public function get_questions_in_groups($QSG_IDs = '')
487
-    {
488
-        if (empty($QSG_IDs)) {
489
-            EE_Error::add_error(
490
-                esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
491
-                __FILE__,
492
-                __FUNCTION__,
493
-                __LINE__
494
-            );
495
-            return false;
496
-        }
497
-        return EE_Registry::instance()->load_model('Question')->get_all(
498
-            array(
499
-                array(
500
-                    'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
501
-                    'QST_deleted'           => false,
502
-                    'QST_admin_only'        => is_admin(),
503
-                ),
504
-                'order_by' => 'QST_order',
505
-            )
506
-        );
507
-    }
508
-
509
-
510
-
511
-    /**
512
-     * get_options_for_question
513
-     *
514
-     * @param string $QST_IDs csv list of $QST IDs
515
-     * @return array|bool
516
-     * @throws \EE_Error
517
-     */
518
-    public function get_options_for_question($QST_IDs)
519
-    {
520
-        if (empty($QST_IDs)) {
521
-            EE_Error::add_error(
522
-                esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
523
-                __FILE__,
524
-                __FUNCTION__,
525
-                __LINE__
526
-            );
527
-            return false;
528
-        }
529
-        return EE_Registry::instance()->load_model('Question_Option')->get_all(
530
-            array(
531
-                array(
532
-                    'Question.QST_ID' => array('IN', $QST_IDs),
533
-                    'QSO_deleted'     => false,
534
-                ),
535
-                'order_by' => 'QSO_ID',
536
-            )
537
-        );
538
-    }
539
-
540
-
541
-
542
-
543
-
544
-
545
-
546
-    /**
547
-     * Gets all events that are published
548
-     * and have event start time earlier than now and an event end time later than now
549
-     *
550
-     * @param  array $query_params An array of query params to further filter on
551
-     *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
552
-     * @param bool   $count        whether to return the count or not (default FALSE)
553
-     * @return EE_Event[]|int
554
-     * @throws \EE_Error
555
-     */
556
-    public function get_active_events($query_params, $count = false)
557
-    {
558
-        if (array_key_exists(0, $query_params)) {
559
-            $where_params = $query_params[0];
560
-            unset($query_params[0]);
561
-        } else {
562
-            $where_params = array();
563
-        }
564
-        // if we have count make sure we don't include group by
565
-        if ($count && isset($query_params['group_by'])) {
566
-            unset($query_params['group_by']);
567
-        }
568
-        // let's add specific query_params for active_events
569
-        // keep in mind this will override any sent status in the query AND any date queries.
570
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
571
-        // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
572
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
573
-            $where_params['Datetime.DTT_EVT_start******'] = array(
574
-                '<',
575
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
576
-            );
577
-        } else {
578
-            $where_params['Datetime.DTT_EVT_start'] = array(
579
-                '<',
580
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
581
-            );
582
-        }
583
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
584
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
585
-                '>',
586
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
587
-            );
588
-        } else {
589
-            $where_params['Datetime.DTT_EVT_end'] = array(
590
-                '>',
591
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
592
-            );
593
-        }
594
-        $query_params[0] = $where_params;
595
-        // don't use $query_params with count()
596
-        // because we don't want to include additional query clauses like "GROUP BY"
597
-        return $count
598
-            ? $this->count(array($where_params), 'EVT_ID', true)
599
-            : $this->get_all($query_params);
600
-    }
601
-
602
-
603
-
604
-    /**
605
-     * get all events that are published and have an event start time later than now
606
-     *
607
-     * @param  array $query_params An array of query params to further filter on
608
-     *                             (Note that status and DTT_EVT_start will be overridden)
609
-     * @param bool   $count        whether to return the count or not (default FALSE)
610
-     * @return EE_Event[]|int
611
-     * @throws \EE_Error
612
-     */
613
-    public function get_upcoming_events($query_params, $count = false)
614
-    {
615
-        if (array_key_exists(0, $query_params)) {
616
-            $where_params = $query_params[0];
617
-            unset($query_params[0]);
618
-        } else {
619
-            $where_params = array();
620
-        }
621
-        // if we have count make sure we don't include group by
622
-        if ($count && isset($query_params['group_by'])) {
623
-            unset($query_params['group_by']);
624
-        }
625
-        // let's add specific query_params for active_events
626
-        // keep in mind this will override any sent status in the query AND any date queries.
627
-        // we need to pull events with a status of publish and sold_out
628
-        $event_status = array('publish', EEM_Event::sold_out);
629
-        // check if the user can read private events and if so add the 'private status to the were params'
630
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) {
631
-            $event_status[] = 'private';
632
-        }
633
-        $where_params['status'] = array('IN', $event_status);
634
-        // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
635
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
636
-            $where_params['Datetime.DTT_EVT_start*****'] = array(
637
-                '>',
638
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
639
-            );
640
-        } else {
641
-            $where_params['Datetime.DTT_EVT_start'] = array(
642
-                '>',
643
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
644
-            );
645
-        }
646
-        $query_params[0] = $where_params;
647
-        // don't use $query_params with count()
648
-        // because we don't want to include additional query clauses like "GROUP BY"
649
-        return $count
650
-            ? $this->count(array($where_params), 'EVT_ID', true)
651
-            : $this->get_all($query_params);
652
-    }
653
-
654
-
655
-
656
-    /**
657
-     * Gets all events that are published
658
-     * and have an event end time later than now
659
-     *
660
-     * @param  array $query_params An array of query params to further filter on
661
-     *                             (note that status and DTT_EVT_end will be overridden)
662
-     * @param bool   $count        whether to return the count or not (default FALSE)
663
-     * @return EE_Event[]|int
664
-     * @throws \EE_Error
665
-     */
666
-    public function get_active_and_upcoming_events($query_params, $count = false)
667
-    {
668
-        if (array_key_exists(0, $query_params)) {
669
-            $where_params = $query_params[0];
670
-            unset($query_params[0]);
671
-        } else {
672
-            $where_params = array();
673
-        }
674
-        // if we have count make sure we don't include group by
675
-        if ($count && isset($query_params['group_by'])) {
676
-            unset($query_params['group_by']);
677
-        }
678
-        // let's add specific query_params for active_events
679
-        // keep in mind this will override any sent status in the query AND any date queries.
680
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
681
-        // add where params for DTT_EVT_end
682
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
683
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
684
-                '>',
685
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
686
-            );
687
-        } else {
688
-            $where_params['Datetime.DTT_EVT_end'] = array(
689
-                '>',
690
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
691
-            );
692
-        }
693
-        $query_params[0] = $where_params;
694
-        // don't use $query_params with count()
695
-        // because we don't want to include additional query clauses like "GROUP BY"
696
-        return $count
697
-            ? $this->count(array($where_params), 'EVT_ID', true)
698
-            : $this->get_all($query_params);
699
-    }
700
-
701
-
702
-
703
-    /**
704
-     * This only returns events that are expired.
705
-     * They may still be published but all their datetimes have expired.
706
-     *
707
-     * @param  array $query_params An array of query params to further filter on
708
-     *                             (note that status and DTT_EVT_end will be overridden)
709
-     * @param bool   $count        whether to return the count or not (default FALSE)
710
-     * @return EE_Event[]|int
711
-     * @throws \EE_Error
712
-     */
713
-    public function get_expired_events($query_params, $count = false)
714
-    {
715
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
716
-        // if we have count make sure we don't include group by
717
-        if ($count && isset($query_params['group_by'])) {
718
-            unset($query_params['group_by']);
719
-        }
720
-        // let's add specific query_params for active_events
721
-        // keep in mind this will override any sent status in the query AND any date queries.
722
-        if (isset($where_params['status'])) {
723
-            unset($where_params['status']);
724
-        }
725
-        $exclude_query = $query_params;
726
-        if (isset($exclude_query[0])) {
727
-            unset($exclude_query[0]);
728
-        }
729
-        $exclude_query[0] = array(
730
-            'Datetime.DTT_EVT_end' => array(
731
-                '>',
732
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
733
-            ),
734
-        );
735
-        // first get all events that have datetimes where its not expired.
736
-        $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
737
-        $event_ids = array_keys($event_ids);
738
-        // if we have any additional query_params, let's add them to the 'AND' condition
739
-        $and_condition = array(
740
-            'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
741
-            'EVT_ID'               => array('NOT IN', $event_ids),
742
-        );
743
-        if (isset($where_params['OR'])) {
744
-            $and_condition['OR'] = $where_params['OR'];
745
-            unset($where_params['OR']);
746
-        }
747
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
748
-            $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
749
-            unset($where_params['Datetime.DTT_EVT_end']);
750
-        }
751
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
752
-            $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
753
-            unset($where_params['Datetime.DTT_EVT_start']);
754
-        }
755
-        // merge remaining $where params with the and conditions.
756
-        $where_params['AND'] = array_merge($and_condition, $where_params);
757
-        $query_params[0] = $where_params;
758
-        // don't use $query_params with count()
759
-        // because we don't want to include additional query clauses like "GROUP BY"
760
-        return $count
761
-            ? $this->count(array($where_params), 'EVT_ID', true)
762
-            : $this->get_all($query_params);
763
-    }
764
-
765
-
766
-
767
-    /**
768
-     * This basically just returns the events that do not have the publish status.
769
-     *
770
-     * @param  array   $query_params An array of query params to further filter on
771
-     *                               (note that status will be overwritten)
772
-     * @param  boolean $count        whether to return the count or not (default FALSE)
773
-     * @return EE_Event[]|int
774
-     * @throws \EE_Error
775
-     */
776
-    public function get_inactive_events($query_params, $count = false)
777
-    {
778
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
779
-        // let's add in specific query_params for inactive events.
780
-        if (isset($where_params['status'])) {
781
-            unset($where_params['status']);
782
-        }
783
-        // if we have count make sure we don't include group by
784
-        if ($count && isset($query_params['group_by'])) {
785
-            unset($query_params['group_by']);
786
-        }
787
-        // if we have any additional query_params, let's add them to the 'AND' condition
788
-        $where_params['AND']['status'] = array('!=', 'publish');
789
-        if (isset($where_params['OR'])) {
790
-            $where_params['AND']['OR'] = $where_params['OR'];
791
-            unset($where_params['OR']);
792
-        }
793
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
794
-            $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
795
-            unset($where_params['Datetime.DTT_EVT_end']);
796
-        }
797
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
798
-            $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
799
-            unset($where_params['Datetime.DTT_EVT_start']);
800
-        }
801
-        $query_params[0] = $where_params;
802
-        // don't use $query_params with count()
803
-        // because we don't want to include additional query clauses like "GROUP BY"
804
-        return $count
805
-            ? $this->count(array($where_params), 'EVT_ID', true)
806
-            : $this->get_all($query_params);
807
-    }
808
-
809
-
810
-
811
-    /**
812
-     * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
813
-     * because we don't want to override any existing global default prices but instead insert NEW prices that get
814
-     * attached to the event. See parent for param descriptions
815
-     *
816
-     * @param        $id_or_obj
817
-     * @param        $other_model_id_or_obj
818
-     * @param string $relationName
819
-     * @param array  $where_query
820
-     * @return EE_Base_Class
821
-     * @throws EE_Error
822
-     */
823
-    public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
824
-    {
825
-        if ($relationName === 'Price') {
826
-            // let's get the PRC object for the given ID to make sure that we aren't dealing with a default
827
-            $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
828
-            // if EVT_ID = 0, then this is a default
829
-            if ((int) $prc_chk->get('EVT_ID') === 0) {
830
-                // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
831
-                $prc_chk->set('PRC_ID', 0);
832
-            }
833
-            // run parent
834
-            return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
835
-        }
836
-        // otherwise carry on as normal
837
-        return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
838
-    }
839
-
840
-
841
-
842
-    /******************** DEPRECATED METHODS ********************/
843
-
844
-
845
-
846
-    /**
847
-     * _get_question_target_db_column
848
-     *
849
-     * @deprecated as of 4.8.32.rc.001. Instead consider using
850
-     *             EE_Registration_Custom_Questions_Form located in
851
-     *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
852
-     * @access     public
853
-     * @param    EE_Registration $registration (so existing answers for registration are included)
854
-     * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
855
-     *                                         registration).
856
-     * @throws EE_Error
857
-     * @return    array
858
-     */
859
-    public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
860
-    {
861
-        if (empty($EVT_ID)) {
862
-            throw new EE_Error(esc_html__(
863
-                'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
864
-                'event_espresso'
865
-            ));
866
-        }
867
-        $questions = array();
868
-        // get all question groups for event
869
-        $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
870
-        if (! empty($qgs)) {
871
-            foreach ($qgs as $qg) {
872
-                $qsts = $qg->questions();
873
-                $questions[ $qg->ID() ] = $qg->model_field_array();
874
-                $questions[ $qg->ID() ]['QSG_questions'] = array();
875
-                foreach ($qsts as $qst) {
876
-                    if ($qst->is_system_question()) {
877
-                        continue;
878
-                    }
879
-                    $answer = EEM_Answer::instance()->get_one(array(
880
-                        array(
881
-                            'QST_ID' => $qst->ID(),
882
-                            'REG_ID' => $registration->ID(),
883
-                        ),
884
-                    ));
885
-                    $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
886
-                    $qst_name = $qstn_id = $qst->ID();
887
-                    $ans_id = $answer->ID();
888
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
889
-                    $input_name = '';
890
-                    $input_id = sanitize_key($qst->display_text());
891
-                    $input_class = '';
892
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
893
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
894
-                                                                                           . $input_name
895
-                                                                                           . $qst_name;
896
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
897
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
898
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
899
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
900
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
901
-                    // leave responses as-is, don't convert stuff into html entities please!
902
-                    $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
903
-                    if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
904
-                        $QSOs = $qst->options(true, $answer->value());
905
-                        if (is_array($QSOs)) {
906
-                            foreach ($QSOs as $QSO_ID => $QSO) {
907
-                                $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
908
-                            }
909
-                        }
910
-                    }
911
-                }
912
-            }
913
-        }
914
-        return $questions;
915
-    }
916
-
917
-
918
-    /**
919
-     * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
920
-     *                             or an stdClass where each property is the name of a column,
921
-     * @return EE_Base_Class
922
-     * @throws \EE_Error
923
-     */
924
-    public function instantiate_class_from_array_or_object($cols_n_values)
925
-    {
926
-        $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
927
-        if ($classInstance instanceof EE_Event) {
928
-            // events have their timezone defined in the DB, so use it immediately
929
-            $this->set_timezone($classInstance->get_timezone());
930
-        }
931
-        return $classInstance;
932
-    }
933
-
934
-
935
-    /**
936
-     * Deletes the model objects that meet the query params. Note: this method is overridden
937
-     * in EEM_Soft_Delete_Base so that soft-deleted model objects are instead only flagged
938
-     * as archived, not actually deleted
939
-     *
940
-     * @param array   $query_params   @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
941
-     * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
942
-     *                                that blocks it (ie, there' sno other data that depends on this data); if false,
943
-     *                                deletes regardless of other objects which may depend on it. Its generally
944
-     *                                advisable to always leave this as TRUE, otherwise you could easily corrupt your
945
-     *                                DB
946
-     * @return int                    number of rows deleted
947
-     * @throws EE_Error
948
-     */
949
-    public function delete_permanently($query_params, $allow_blocking = true)
950
-    {
951
-        $deleted = parent::delete_permanently($query_params, $allow_blocking);
952
-        if ($deleted) {
953
-            // get list of events with no prices
954
-            $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []);
955
-            $where = isset($query_params[0]) ? $query_params[0] : [];
956
-            $where_event = isset($where['EVT_ID']) ? $where['EVT_ID'] : ['', ''];
957
-            $where_event_ids = isset($where_event[1]) ? $where_event[1] : '';
958
-            $event_ids = is_string($where_event_ids)
959
-                ? explode(',', $where_event_ids)
960
-                : (array) $where_event_ids;
961
-            array_walk($event_ids, 'trim');
962
-            $event_ids = array_filter($event_ids);
963
-            // remove events from list of events with no prices
964
-            $espresso_no_ticket_prices = array_diff($espresso_no_ticket_prices, $event_ids);
965
-            update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
966
-        }
967
-        return $deleted;
968
-    }
18
+	/**
19
+	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
20
+	 * event
21
+	 */
22
+	const sold_out = 'sold_out';
23
+
24
+	/**
25
+	 * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
26
+	 * date)
27
+	 */
28
+	const postponed = 'postponed';
29
+
30
+	/**
31
+	 * constant used by status(), indicating that the event will no longer occur
32
+	 */
33
+	const cancelled = 'cancelled';
34
+
35
+
36
+	/**
37
+	 * @var string
38
+	 */
39
+	protected static $_default_reg_status;
40
+
41
+
42
+	/**
43
+	 * This is the default for the additional limit field.
44
+	 * @var int
45
+	 */
46
+	protected static $_default_additional_limit = 10;
47
+
48
+
49
+	/**
50
+	 * private instance of the Event object
51
+	 *
52
+	 * @var EEM_Event
53
+	 */
54
+	protected static $_instance;
55
+
56
+
57
+
58
+
59
+	/**
60
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
61
+	 *
62
+	 * @param string $timezone
63
+	 * @throws \EE_Error
64
+	 */
65
+	protected function __construct($timezone = null)
66
+	{
67
+		EE_Registry::instance()->load_model('Registration');
68
+		$this->singular_item = esc_html__('Event', 'event_espresso');
69
+		$this->plural_item = esc_html__('Events', 'event_espresso');
70
+		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
71
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
72
+		// to remove Postponed events from the frontend, copy the following filter to your functions.php file
73
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
74
+		// to remove Sold Out events from the frontend, copy the following filter to your functions.php file
75
+		//  add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
76
+		$this->_custom_stati = apply_filters(
77
+			'AFEE__EEM_Event__construct___custom_stati',
78
+			array(
79
+				EEM_Event::cancelled => array(
80
+					'label'  => esc_html__('Cancelled', 'event_espresso'),
81
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
82
+				),
83
+				EEM_Event::postponed => array(
84
+					'label'  => esc_html__('Postponed', 'event_espresso'),
85
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
86
+				),
87
+				EEM_Event::sold_out  => array(
88
+					'label'  => esc_html__('Sold Out', 'event_espresso'),
89
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
90
+				),
91
+			)
92
+		);
93
+		self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
94
+			: self::$_default_reg_status;
95
+		$this->_tables = array(
96
+			'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
97
+			'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
98
+		);
99
+		$this->_fields = array(
100
+			'Event_CPT'  => array(
101
+				'EVT_ID'         => new EE_Primary_Key_Int_Field(
102
+					'ID',
103
+					esc_html__('Post ID for Event', 'event_espresso')
104
+				),
105
+				'EVT_name'       => new EE_Plain_Text_Field(
106
+					'post_title',
107
+					esc_html__('Event Name', 'event_espresso'),
108
+					false,
109
+					''
110
+				),
111
+				'EVT_desc'       => new EE_Post_Content_Field(
112
+					'post_content',
113
+					esc_html__('Event Description', 'event_espresso'),
114
+					false,
115
+					''
116
+				),
117
+				'EVT_slug'       => new EE_Slug_Field(
118
+					'post_name',
119
+					esc_html__('Event Slug', 'event_espresso'),
120
+					false,
121
+					''
122
+				),
123
+				'EVT_created'    => new EE_Datetime_Field(
124
+					'post_date',
125
+					esc_html__('Date/Time Event Created', 'event_espresso'),
126
+					false,
127
+					EE_Datetime_Field::now
128
+				),
129
+				'EVT_short_desc' => new EE_Simple_HTML_Field(
130
+					'post_excerpt',
131
+					esc_html__('Event Short Description', 'event_espresso'),
132
+					false,
133
+					''
134
+				),
135
+				'EVT_modified'   => new EE_Datetime_Field(
136
+					'post_modified',
137
+					esc_html__('Date/Time Event Modified', 'event_espresso'),
138
+					false,
139
+					EE_Datetime_Field::now
140
+				),
141
+				'EVT_wp_user'    => new EE_WP_User_Field(
142
+					'post_author',
143
+					esc_html__('Event Creator ID', 'event_espresso'),
144
+					false
145
+				),
146
+				'parent'         => new EE_Integer_Field(
147
+					'post_parent',
148
+					esc_html__('Event Parent ID', 'event_espresso'),
149
+					false,
150
+					0
151
+				),
152
+				'EVT_order'      => new EE_Integer_Field(
153
+					'menu_order',
154
+					esc_html__('Event Menu Order', 'event_espresso'),
155
+					false,
156
+					1
157
+				),
158
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
159
+				// EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
160
+				'status'         => new EE_WP_Post_Status_Field(
161
+					'post_status',
162
+					esc_html__('Event Status', 'event_espresso'),
163
+					false,
164
+					'draft',
165
+					$this->_custom_stati
166
+				),
167
+				'password' => new EE_Password_Field(
168
+					'post_password',
169
+					esc_html__('Password', 'event_espresso'),
170
+					false,
171
+					'',
172
+					array(
173
+						'EVT_desc',
174
+						'EVT_short_desc',
175
+						'EVT_display_desc',
176
+						'EVT_display_ticket_selector',
177
+						'EVT_visible_on',
178
+						'EVT_additional_limit',
179
+						'EVT_default_registration_status',
180
+						'EVT_member_only',
181
+						'EVT_phone',
182
+						'EVT_allow_overflow',
183
+						'EVT_timezone_string',
184
+						'EVT_external_URL',
185
+						'EVT_donations'
186
+					)
187
+				)
188
+			),
189
+			'Event_Meta' => array(
190
+				'EVTM_ID'                         => new EE_DB_Only_Float_Field(
191
+					'EVTM_ID',
192
+					esc_html__('Event Meta Row ID', 'event_espresso'),
193
+					false
194
+				),
195
+				'EVT_ID_fk'                       => new EE_DB_Only_Int_Field(
196
+					'EVT_ID',
197
+					esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'),
198
+					false
199
+				),
200
+				'EVT_display_desc'                => new EE_Boolean_Field(
201
+					'EVT_display_desc',
202
+					esc_html__('Display Description Flag', 'event_espresso'),
203
+					false,
204
+					true
205
+				),
206
+				'EVT_display_ticket_selector'     => new EE_Boolean_Field(
207
+					'EVT_display_ticket_selector',
208
+					esc_html__('Display Ticket Selector Flag', 'event_espresso'),
209
+					false,
210
+					true
211
+				),
212
+				'EVT_visible_on'                  => new EE_Datetime_Field(
213
+					'EVT_visible_on',
214
+					esc_html__('Event Visible Date', 'event_espresso'),
215
+					true,
216
+					EE_Datetime_Field::now
217
+				),
218
+				'EVT_additional_limit'            => new EE_Integer_Field(
219
+					'EVT_additional_limit',
220
+					esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
221
+					true,
222
+					self::$_default_additional_limit
223
+				),
224
+				'EVT_default_registration_status' => new EE_Enum_Text_Field(
225
+					'EVT_default_registration_status',
226
+					esc_html__('Default Registration Status on this Event', 'event_espresso'),
227
+					false,
228
+					EEM_Event::$_default_reg_status,
229
+					EEM_Registration::reg_status_array()
230
+				),
231
+				'EVT_member_only'                 => new EE_Boolean_Field(
232
+					'EVT_member_only',
233
+					esc_html__('Member-Only Event Flag', 'event_espresso'),
234
+					false,
235
+					false
236
+				),
237
+				'EVT_phone'                       => new EE_Plain_Text_Field(
238
+					'EVT_phone',
239
+					esc_html__('Event Phone Number', 'event_espresso'),
240
+					false,
241
+					''
242
+				),
243
+				'EVT_allow_overflow'              => new EE_Boolean_Field(
244
+					'EVT_allow_overflow',
245
+					esc_html__('Allow Overflow on Event', 'event_espresso'),
246
+					false,
247
+					false
248
+				),
249
+				'EVT_timezone_string'             => new EE_Plain_Text_Field(
250
+					'EVT_timezone_string',
251
+					esc_html__('Timezone (name) for Event times', 'event_espresso'),
252
+					false,
253
+					''
254
+				),
255
+				'EVT_external_URL'                => new EE_Plain_Text_Field(
256
+					'EVT_external_URL',
257
+					esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'),
258
+					true
259
+				),
260
+				'EVT_donations'                   => new EE_Boolean_Field(
261
+					'EVT_donations',
262
+					esc_html__('Accept Donations?', 'event_espresso'),
263
+					false,
264
+					false
265
+				),
266
+			),
267
+		);
268
+		$this->_model_relations = array(
269
+			'Registration'           => new EE_Has_Many_Relation(),
270
+			'Datetime'               => new EE_Has_Many_Relation(),
271
+			'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
272
+			'Event_Question_Group'   => new EE_Has_Many_Relation(),
273
+			'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
274
+			'Term_Relationship'      => new EE_Has_Many_Relation(),
275
+			'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
276
+			'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
277
+			'Attendee'               => new EE_HABTM_Relation('Registration'),
278
+			'WP_User'                => new EE_Belongs_To_Relation(),
279
+		);
280
+		// this model is generally available for reading
281
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
282
+		$this->model_chain_to_password = '';
283
+		parent::__construct($timezone);
284
+	}
285
+
286
+
287
+
288
+	/**
289
+	 * @param string $default_reg_status
290
+	 */
291
+	public static function set_default_reg_status($default_reg_status)
292
+	{
293
+		self::$_default_reg_status = $default_reg_status;
294
+		// if EEM_Event has already been instantiated,
295
+		// then we need to reset the `EVT_default_reg_status` field to use the new default.
296
+		if (self::$_instance instanceof EEM_Event) {
297
+			$default_reg_status = new EE_Enum_Text_Field(
298
+				'EVT_default_registration_status',
299
+				esc_html__('Default Registration Status on this Event', 'event_espresso'),
300
+				false,
301
+				$default_reg_status,
302
+				EEM_Registration::reg_status_array()
303
+			);
304
+			$default_reg_status->_construct_finalize(
305
+				'Event_Meta',
306
+				'EVT_default_registration_status',
307
+				'EEM_Event'
308
+			);
309
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
310
+		}
311
+	}
312
+
313
+
314
+	/**
315
+	 * Used to override the default for the additional limit field.
316
+	 * @param $additional_limit
317
+	 */
318
+	public static function set_default_additional_limit($additional_limit)
319
+	{
320
+		self::$_default_additional_limit = (int) $additional_limit;
321
+		if (self::$_instance instanceof EEM_Event) {
322
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field(
323
+				'EVT_additional_limit',
324
+				esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'),
325
+				true,
326
+				self::$_default_additional_limit
327
+			);
328
+			self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize(
329
+				'Event_Meta',
330
+				'EVT_additional_limit',
331
+				'EEM_Event'
332
+			);
333
+		}
334
+	}
335
+
336
+
337
+	/**
338
+	 * Return what is currently set as the default additional limit for the event.
339
+	 * @return int
340
+	 */
341
+	public static function get_default_additional_limit()
342
+	{
343
+		return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit);
344
+	}
345
+
346
+
347
+	/**
348
+	 * get_question_groups
349
+	 *
350
+	 * @return array
351
+	 * @throws \EE_Error
352
+	 */
353
+	public function get_all_question_groups()
354
+	{
355
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
356
+			array(
357
+				array('QSG_deleted' => false),
358
+				'order_by' => array('QSG_order' => 'ASC'),
359
+			)
360
+		);
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 * get_question_groups
367
+	 *
368
+	 * @param int $EVT_ID
369
+	 * @return array|bool
370
+	 * @throws \EE_Error
371
+	 */
372
+	public function get_all_event_question_groups($EVT_ID = 0)
373
+	{
374
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
375
+			EE_Error::add_error(
376
+				esc_html__(
377
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
378
+					'event_espresso'
379
+				),
380
+				__FILE__,
381
+				__FUNCTION__,
382
+				__LINE__
383
+			);
384
+			return false;
385
+		}
386
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
387
+			array(
388
+				array('EVT_ID' => $EVT_ID),
389
+			)
390
+		);
391
+	}
392
+
393
+
394
+	/**
395
+	 * get_question_groups
396
+	 *
397
+	 * @param int $EVT_ID
398
+	 * @param boolean $for_primary_attendee
399
+	 * @return array|bool
400
+	 * @throws EE_Error
401
+	 * @throws InvalidArgumentException
402
+	 * @throws ReflectionException
403
+	 * @throws InvalidDataTypeException
404
+	 * @throws InvalidInterfaceException
405
+	 */
406
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
407
+	{
408
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
409
+			EE_Error::add_error(
410
+				esc_html__(
411
+					// @codingStandardsIgnoreStart
412
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
413
+					// @codingStandardsIgnoreEnd
414
+					'event_espresso'
415
+				),
416
+				__FILE__,
417
+				__FUNCTION__,
418
+				__LINE__
419
+			);
420
+			return false;
421
+		}
422
+		$query_params = [
423
+			[
424
+				'EVT_ID' => $EVT_ID,
425
+				EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true
426
+			]
427
+		];
428
+		if ($for_primary_attendee) {
429
+			$query_params[0]['EQG_primary'] = true;
430
+		} else {
431
+			$query_params[0]['EQG_additional'] = true;
432
+		}
433
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params);
434
+	}
435
+
436
+
437
+	/**
438
+	 * get_question_groups
439
+	 *
440
+	 * @param int $EVT_ID
441
+	 * @param EE_Registration $registration
442
+	 * @return array|bool
443
+	 * @throws EE_Error
444
+	 * @throws InvalidArgumentException
445
+	 * @throws InvalidDataTypeException
446
+	 * @throws InvalidInterfaceException
447
+	 * @throws ReflectionException
448
+	 */
449
+	public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
450
+	{
451
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
452
+			EE_Error::add_error(
453
+				esc_html__(
454
+					'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
455
+					'event_espresso'
456
+				),
457
+				__FILE__,
458
+				__FUNCTION__,
459
+				__LINE__
460
+			);
461
+			return false;
462
+		}
463
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
464
+			[
465
+				[
466
+					'Event_Question_Group.EVT_ID'      => $EVT_ID,
467
+					'Event_Question_Group.'
468
+						. EEM_Event_Question_Group::instance()->fieldNameForContext(
469
+							$registration->is_primary_registrant()
470
+						) => true
471
+				],
472
+				'order_by' => ['QSG_order' => 'ASC'],
473
+			]
474
+		);
475
+	}
476
+
477
+
478
+
479
+	/**
480
+	 * get_question_target_db_column
481
+	 *
482
+	 * @param string $QSG_IDs csv list of $QSG IDs
483
+	 * @return array|bool
484
+	 * @throws \EE_Error
485
+	 */
486
+	public function get_questions_in_groups($QSG_IDs = '')
487
+	{
488
+		if (empty($QSG_IDs)) {
489
+			EE_Error::add_error(
490
+				esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
491
+				__FILE__,
492
+				__FUNCTION__,
493
+				__LINE__
494
+			);
495
+			return false;
496
+		}
497
+		return EE_Registry::instance()->load_model('Question')->get_all(
498
+			array(
499
+				array(
500
+					'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
501
+					'QST_deleted'           => false,
502
+					'QST_admin_only'        => is_admin(),
503
+				),
504
+				'order_by' => 'QST_order',
505
+			)
506
+		);
507
+	}
508
+
509
+
510
+
511
+	/**
512
+	 * get_options_for_question
513
+	 *
514
+	 * @param string $QST_IDs csv list of $QST IDs
515
+	 * @return array|bool
516
+	 * @throws \EE_Error
517
+	 */
518
+	public function get_options_for_question($QST_IDs)
519
+	{
520
+		if (empty($QST_IDs)) {
521
+			EE_Error::add_error(
522
+				esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
523
+				__FILE__,
524
+				__FUNCTION__,
525
+				__LINE__
526
+			);
527
+			return false;
528
+		}
529
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(
530
+			array(
531
+				array(
532
+					'Question.QST_ID' => array('IN', $QST_IDs),
533
+					'QSO_deleted'     => false,
534
+				),
535
+				'order_by' => 'QSO_ID',
536
+			)
537
+		);
538
+	}
539
+
540
+
541
+
542
+
543
+
544
+
545
+
546
+	/**
547
+	 * Gets all events that are published
548
+	 * and have event start time earlier than now and an event end time later than now
549
+	 *
550
+	 * @param  array $query_params An array of query params to further filter on
551
+	 *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
552
+	 * @param bool   $count        whether to return the count or not (default FALSE)
553
+	 * @return EE_Event[]|int
554
+	 * @throws \EE_Error
555
+	 */
556
+	public function get_active_events($query_params, $count = false)
557
+	{
558
+		if (array_key_exists(0, $query_params)) {
559
+			$where_params = $query_params[0];
560
+			unset($query_params[0]);
561
+		} else {
562
+			$where_params = array();
563
+		}
564
+		// if we have count make sure we don't include group by
565
+		if ($count && isset($query_params['group_by'])) {
566
+			unset($query_params['group_by']);
567
+		}
568
+		// let's add specific query_params for active_events
569
+		// keep in mind this will override any sent status in the query AND any date queries.
570
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
571
+		// if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
572
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
573
+			$where_params['Datetime.DTT_EVT_start******'] = array(
574
+				'<',
575
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
576
+			);
577
+		} else {
578
+			$where_params['Datetime.DTT_EVT_start'] = array(
579
+				'<',
580
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
581
+			);
582
+		}
583
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
584
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
585
+				'>',
586
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
587
+			);
588
+		} else {
589
+			$where_params['Datetime.DTT_EVT_end'] = array(
590
+				'>',
591
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
592
+			);
593
+		}
594
+		$query_params[0] = $where_params;
595
+		// don't use $query_params with count()
596
+		// because we don't want to include additional query clauses like "GROUP BY"
597
+		return $count
598
+			? $this->count(array($where_params), 'EVT_ID', true)
599
+			: $this->get_all($query_params);
600
+	}
601
+
602
+
603
+
604
+	/**
605
+	 * get all events that are published and have an event start time later than now
606
+	 *
607
+	 * @param  array $query_params An array of query params to further filter on
608
+	 *                             (Note that status and DTT_EVT_start will be overridden)
609
+	 * @param bool   $count        whether to return the count or not (default FALSE)
610
+	 * @return EE_Event[]|int
611
+	 * @throws \EE_Error
612
+	 */
613
+	public function get_upcoming_events($query_params, $count = false)
614
+	{
615
+		if (array_key_exists(0, $query_params)) {
616
+			$where_params = $query_params[0];
617
+			unset($query_params[0]);
618
+		} else {
619
+			$where_params = array();
620
+		}
621
+		// if we have count make sure we don't include group by
622
+		if ($count && isset($query_params['group_by'])) {
623
+			unset($query_params['group_by']);
624
+		}
625
+		// let's add specific query_params for active_events
626
+		// keep in mind this will override any sent status in the query AND any date queries.
627
+		// we need to pull events with a status of publish and sold_out
628
+		$event_status = array('publish', EEM_Event::sold_out);
629
+		// check if the user can read private events and if so add the 'private status to the were params'
630
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) {
631
+			$event_status[] = 'private';
632
+		}
633
+		$where_params['status'] = array('IN', $event_status);
634
+		// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
635
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
636
+			$where_params['Datetime.DTT_EVT_start*****'] = array(
637
+				'>',
638
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
639
+			);
640
+		} else {
641
+			$where_params['Datetime.DTT_EVT_start'] = array(
642
+				'>',
643
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
644
+			);
645
+		}
646
+		$query_params[0] = $where_params;
647
+		// don't use $query_params with count()
648
+		// because we don't want to include additional query clauses like "GROUP BY"
649
+		return $count
650
+			? $this->count(array($where_params), 'EVT_ID', true)
651
+			: $this->get_all($query_params);
652
+	}
653
+
654
+
655
+
656
+	/**
657
+	 * Gets all events that are published
658
+	 * and have an event end time later than now
659
+	 *
660
+	 * @param  array $query_params An array of query params to further filter on
661
+	 *                             (note that status and DTT_EVT_end will be overridden)
662
+	 * @param bool   $count        whether to return the count or not (default FALSE)
663
+	 * @return EE_Event[]|int
664
+	 * @throws \EE_Error
665
+	 */
666
+	public function get_active_and_upcoming_events($query_params, $count = false)
667
+	{
668
+		if (array_key_exists(0, $query_params)) {
669
+			$where_params = $query_params[0];
670
+			unset($query_params[0]);
671
+		} else {
672
+			$where_params = array();
673
+		}
674
+		// if we have count make sure we don't include group by
675
+		if ($count && isset($query_params['group_by'])) {
676
+			unset($query_params['group_by']);
677
+		}
678
+		// let's add specific query_params for active_events
679
+		// keep in mind this will override any sent status in the query AND any date queries.
680
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
681
+		// add where params for DTT_EVT_end
682
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
683
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
684
+				'>',
685
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
686
+			);
687
+		} else {
688
+			$where_params['Datetime.DTT_EVT_end'] = array(
689
+				'>',
690
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
691
+			);
692
+		}
693
+		$query_params[0] = $where_params;
694
+		// don't use $query_params with count()
695
+		// because we don't want to include additional query clauses like "GROUP BY"
696
+		return $count
697
+			? $this->count(array($where_params), 'EVT_ID', true)
698
+			: $this->get_all($query_params);
699
+	}
700
+
701
+
702
+
703
+	/**
704
+	 * This only returns events that are expired.
705
+	 * They may still be published but all their datetimes have expired.
706
+	 *
707
+	 * @param  array $query_params An array of query params to further filter on
708
+	 *                             (note that status and DTT_EVT_end will be overridden)
709
+	 * @param bool   $count        whether to return the count or not (default FALSE)
710
+	 * @return EE_Event[]|int
711
+	 * @throws \EE_Error
712
+	 */
713
+	public function get_expired_events($query_params, $count = false)
714
+	{
715
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
716
+		// if we have count make sure we don't include group by
717
+		if ($count && isset($query_params['group_by'])) {
718
+			unset($query_params['group_by']);
719
+		}
720
+		// let's add specific query_params for active_events
721
+		// keep in mind this will override any sent status in the query AND any date queries.
722
+		if (isset($where_params['status'])) {
723
+			unset($where_params['status']);
724
+		}
725
+		$exclude_query = $query_params;
726
+		if (isset($exclude_query[0])) {
727
+			unset($exclude_query[0]);
728
+		}
729
+		$exclude_query[0] = array(
730
+			'Datetime.DTT_EVT_end' => array(
731
+				'>',
732
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
733
+			),
734
+		);
735
+		// first get all events that have datetimes where its not expired.
736
+		$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
737
+		$event_ids = array_keys($event_ids);
738
+		// if we have any additional query_params, let's add them to the 'AND' condition
739
+		$and_condition = array(
740
+			'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
741
+			'EVT_ID'               => array('NOT IN', $event_ids),
742
+		);
743
+		if (isset($where_params['OR'])) {
744
+			$and_condition['OR'] = $where_params['OR'];
745
+			unset($where_params['OR']);
746
+		}
747
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
748
+			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
749
+			unset($where_params['Datetime.DTT_EVT_end']);
750
+		}
751
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
752
+			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
753
+			unset($where_params['Datetime.DTT_EVT_start']);
754
+		}
755
+		// merge remaining $where params with the and conditions.
756
+		$where_params['AND'] = array_merge($and_condition, $where_params);
757
+		$query_params[0] = $where_params;
758
+		// don't use $query_params with count()
759
+		// because we don't want to include additional query clauses like "GROUP BY"
760
+		return $count
761
+			? $this->count(array($where_params), 'EVT_ID', true)
762
+			: $this->get_all($query_params);
763
+	}
764
+
765
+
766
+
767
+	/**
768
+	 * This basically just returns the events that do not have the publish status.
769
+	 *
770
+	 * @param  array   $query_params An array of query params to further filter on
771
+	 *                               (note that status will be overwritten)
772
+	 * @param  boolean $count        whether to return the count or not (default FALSE)
773
+	 * @return EE_Event[]|int
774
+	 * @throws \EE_Error
775
+	 */
776
+	public function get_inactive_events($query_params, $count = false)
777
+	{
778
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
779
+		// let's add in specific query_params for inactive events.
780
+		if (isset($where_params['status'])) {
781
+			unset($where_params['status']);
782
+		}
783
+		// if we have count make sure we don't include group by
784
+		if ($count && isset($query_params['group_by'])) {
785
+			unset($query_params['group_by']);
786
+		}
787
+		// if we have any additional query_params, let's add them to the 'AND' condition
788
+		$where_params['AND']['status'] = array('!=', 'publish');
789
+		if (isset($where_params['OR'])) {
790
+			$where_params['AND']['OR'] = $where_params['OR'];
791
+			unset($where_params['OR']);
792
+		}
793
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
794
+			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
795
+			unset($where_params['Datetime.DTT_EVT_end']);
796
+		}
797
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
798
+			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
799
+			unset($where_params['Datetime.DTT_EVT_start']);
800
+		}
801
+		$query_params[0] = $where_params;
802
+		// don't use $query_params with count()
803
+		// because we don't want to include additional query clauses like "GROUP BY"
804
+		return $count
805
+			? $this->count(array($where_params), 'EVT_ID', true)
806
+			: $this->get_all($query_params);
807
+	}
808
+
809
+
810
+
811
+	/**
812
+	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
813
+	 * because we don't want to override any existing global default prices but instead insert NEW prices that get
814
+	 * attached to the event. See parent for param descriptions
815
+	 *
816
+	 * @param        $id_or_obj
817
+	 * @param        $other_model_id_or_obj
818
+	 * @param string $relationName
819
+	 * @param array  $where_query
820
+	 * @return EE_Base_Class
821
+	 * @throws EE_Error
822
+	 */
823
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
824
+	{
825
+		if ($relationName === 'Price') {
826
+			// let's get the PRC object for the given ID to make sure that we aren't dealing with a default
827
+			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
828
+			// if EVT_ID = 0, then this is a default
829
+			if ((int) $prc_chk->get('EVT_ID') === 0) {
830
+				// let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
831
+				$prc_chk->set('PRC_ID', 0);
832
+			}
833
+			// run parent
834
+			return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
835
+		}
836
+		// otherwise carry on as normal
837
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
838
+	}
839
+
840
+
841
+
842
+	/******************** DEPRECATED METHODS ********************/
843
+
844
+
845
+
846
+	/**
847
+	 * _get_question_target_db_column
848
+	 *
849
+	 * @deprecated as of 4.8.32.rc.001. Instead consider using
850
+	 *             EE_Registration_Custom_Questions_Form located in
851
+	 *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
852
+	 * @access     public
853
+	 * @param    EE_Registration $registration (so existing answers for registration are included)
854
+	 * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
855
+	 *                                         registration).
856
+	 * @throws EE_Error
857
+	 * @return    array
858
+	 */
859
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
860
+	{
861
+		if (empty($EVT_ID)) {
862
+			throw new EE_Error(esc_html__(
863
+				'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
864
+				'event_espresso'
865
+			));
866
+		}
867
+		$questions = array();
868
+		// get all question groups for event
869
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
870
+		if (! empty($qgs)) {
871
+			foreach ($qgs as $qg) {
872
+				$qsts = $qg->questions();
873
+				$questions[ $qg->ID() ] = $qg->model_field_array();
874
+				$questions[ $qg->ID() ]['QSG_questions'] = array();
875
+				foreach ($qsts as $qst) {
876
+					if ($qst->is_system_question()) {
877
+						continue;
878
+					}
879
+					$answer = EEM_Answer::instance()->get_one(array(
880
+						array(
881
+							'QST_ID' => $qst->ID(),
882
+							'REG_ID' => $registration->ID(),
883
+						),
884
+					));
885
+					$answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
886
+					$qst_name = $qstn_id = $qst->ID();
887
+					$ans_id = $answer->ID();
888
+					$qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
889
+					$input_name = '';
890
+					$input_id = sanitize_key($qst->display_text());
891
+					$input_class = '';
892
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array();
893
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn'
894
+																						   . $input_name
895
+																						   . $qst_name;
896
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
897
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
898
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
899
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
900
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
901
+					// leave responses as-is, don't convert stuff into html entities please!
902
+					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false;
903
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
904
+						$QSOs = $qst->options(true, $answer->value());
905
+						if (is_array($QSOs)) {
906
+							foreach ($QSOs as $QSO_ID => $QSO) {
907
+								$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
908
+							}
909
+						}
910
+					}
911
+				}
912
+			}
913
+		}
914
+		return $questions;
915
+	}
916
+
917
+
918
+	/**
919
+	 * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value
920
+	 *                             or an stdClass where each property is the name of a column,
921
+	 * @return EE_Base_Class
922
+	 * @throws \EE_Error
923
+	 */
924
+	public function instantiate_class_from_array_or_object($cols_n_values)
925
+	{
926
+		$classInstance = parent::instantiate_class_from_array_or_object($cols_n_values);
927
+		if ($classInstance instanceof EE_Event) {
928
+			// events have their timezone defined in the DB, so use it immediately
929
+			$this->set_timezone($classInstance->get_timezone());
930
+		}
931
+		return $classInstance;
932
+	}
933
+
934
+
935
+	/**
936
+	 * Deletes the model objects that meet the query params. Note: this method is overridden
937
+	 * in EEM_Soft_Delete_Base so that soft-deleted model objects are instead only flagged
938
+	 * as archived, not actually deleted
939
+	 *
940
+	 * @param array   $query_params   @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
941
+	 * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
942
+	 *                                that blocks it (ie, there' sno other data that depends on this data); if false,
943
+	 *                                deletes regardless of other objects which may depend on it. Its generally
944
+	 *                                advisable to always leave this as TRUE, otherwise you could easily corrupt your
945
+	 *                                DB
946
+	 * @return int                    number of rows deleted
947
+	 * @throws EE_Error
948
+	 */
949
+	public function delete_permanently($query_params, $allow_blocking = true)
950
+	{
951
+		$deleted = parent::delete_permanently($query_params, $allow_blocking);
952
+		if ($deleted) {
953
+			// get list of events with no prices
954
+			$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', []);
955
+			$where = isset($query_params[0]) ? $query_params[0] : [];
956
+			$where_event = isset($where['EVT_ID']) ? $where['EVT_ID'] : ['', ''];
957
+			$where_event_ids = isset($where_event[1]) ? $where_event[1] : '';
958
+			$event_ids = is_string($where_event_ids)
959
+				? explode(',', $where_event_ids)
960
+				: (array) $where_event_ids;
961
+			array_walk($event_ids, 'trim');
962
+			$event_ids = array_filter($event_ids);
963
+			// remove events from list of events with no prices
964
+			$espresso_no_ticket_prices = array_diff($espresso_no_ticket_prices, $event_ids);
965
+			update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
966
+		}
967
+		return $deleted;
968
+	}
969 969
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Soft_Delete_Base.model.php 1 patch
Indentation   +361 added lines, -361 removed lines patch added patch discarded remove patch
@@ -27,365 +27,365 @@
 block discarded – undo
27 27
 abstract class EEM_Soft_Delete_Base extends EEM_Base
28 28
 {
29 29
 
30
-    /**
31
-     * @param null $timezone
32
-     */
33
-    protected function __construct($timezone = null)
34
-    {
35
-        if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
36
-            $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
37
-        }
38
-        parent::__construct($timezone);
39
-    }
40
-
41
-
42
-
43
-    /**
44
-     * Searches for field on this model of type 'deleted_flag'. if it is found,
45
-     * returns it's name.
46
-     *
47
-     * @return string
48
-     * @throws EE_Error
49
-     */
50
-    public function deleted_field_name()
51
-    {
52
-        $field = $this->get_a_field_of_type('EE_Trashed_Flag_Field');
53
-        if ($field) {
54
-            return $field->get_name();
55
-        } else {
56
-            throw new EE_Error(sprintf(esc_html__(
57
-                'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
58
-                'event_espresso'
59
-            ), get_class($this), get_class($this)));
60
-        }
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * Gets one item that's been deleted, according to $query_params
67
-     *
68
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
69
-     * @return EE_Soft_Delete_Base_Class
70
-     */
71
-    public function get_one_deleted($query_params = array())
72
-    {
73
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
74
-        return parent::get_one($query_params);
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * Gets one item from the DB, regardless of whether it's been soft-deleted or not
81
-     *
82
-     * @param array $query_params like EEM_base::get_all's $query_params
83
-     * @return EE_Soft_Delete_Base_Class
84
-     */
85
-    public function get_one_deleted_or_undeleted($query_params = array())
86
-    {
87
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
88
-        return parent::get_one($query_params);
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist.
95
-     *
96
-     * @param int|string $id
97
-     * @return EE_Soft_Delete_Base_Class
98
-     */
99
-    public function get_one_by_ID_but_ignore_deleted($id)
100
-    {
101
-        return $this->get_one(
102
-            $this->alter_query_params_to_restrict_by_ID(
103
-                $id,
104
-                array('default_where_conditions' => 'default')
105
-            )
106
-        );
107
-    }
108
-
109
-
110
-
111
-    /**
112
-     * Counts all the deleted/trashed items
113
-     *
114
-     * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
115
-     * @param string $field_to_count
116
-     * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
117
-     * @return int
118
-     */
119
-    public function count_deleted($query_params = null, $field_to_count = null, $distinct = false)
120
-    {
121
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
122
-        return parent::count($query_params, $field_to_count, $distinct);
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * Alters the query params so that only trashed/soft-deleted items are considered
129
-     *
130
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
131
-     * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
132
-     */
133
-    protected function _alter_query_params_so_only_trashed_items_included($query_params)
134
-    {
135
-        $deletedFlagFieldName = $this->deleted_field_name();
136
-        $query_params[0][ $deletedFlagFieldName ] = true;
137
-        return $query_params;
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * Alters the query params so that only trashed/soft-deleted items are considered
144
-     *
145
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
146
-     * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
147
-     */
148
-    public function alter_query_params_so_only_trashed_items_included($query_params)
149
-    {
150
-        return $this->_alter_query_params_so_only_trashed_items_included($query_params);
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Alters the query params so each item's deleted status is ignored.
157
-     *
158
-     * @param array $query_params
159
-     * @return array
160
-     */
161
-    public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = array())
162
-    {
163
-        return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * Alters the query params so each item's deleted status is ignored.
170
-     *
171
-     * @param array $query_params
172
-     * @return array
173
-     */
174
-    protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
175
-    {
176
-        if (! isset($query_params['default_where_conditions'])) {
177
-            $query_params['default_where_conditions'] = 'minimum';
178
-        }
179
-        return $query_params;
180
-    }
181
-
182
-
183
-
184
-    /**
185
-     * Counts all deleted and undeleted items
186
-     *
187
-     * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
188
-     * @param string $field_to_count
189
-     * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
190
-     * @return int
191
-     */
192
-    public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = false)
193
-    {
194
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
195
-        return parent::count($query_params, $field_to_count, $distinct);
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * Sum all the deleted items.
202
-     *
203
-     * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
204
-     * @param string $field_to_sum
205
-     * @return int
206
-     */
207
-    public function sum_deleted($query_params = null, $field_to_sum = null)
208
-    {
209
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
210
-        return parent::sum($query_params, $field_to_sum);
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * Sums all the deleted and undeleted items.
217
-     *
218
-     * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
219
-     * @param string $field_to_sum
220
-     * @return int
221
-     */
222
-    public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null)
223
-    {
224
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
225
-        parent::sum($query_params, $field_to_sum);
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of
232
-     * whether they've been soft-deleted or not
233
-     *
234
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
235
-     * @return EE_Soft_Delete_Base_Class[]
236
-     */
237
-    public function get_all_deleted_and_undeleted($query_params = array())
238
-    {
239
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
240
-        return parent::get_all($query_params);
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params.
247
-     *
248
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
249
-     * @return EE_Soft_Delete_Base_Class[]
250
-     */
251
-    public function get_all_deleted($query_params = array())
252
-    {
253
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
254
-        return parent::get_all($query_params);
255
-    }
256
-
257
-
258
-
259
-    /**
260
-     * Permanently deletes the selected rows. When selecting rows for deletion, ignores
261
-     * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects
262
-     * before you can permanently delete them).
263
-     * Because this will cause a real deletion, related models may block this deletion (ie, add an error
264
-     * and abort the delete)
265
-     *
266
-     * @param array   $query_params   @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
267
-     * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
268
-     *                                that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
269
-     *                                which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
270
-     * @return int                    number of rows deleted
271
-     * @throws EE_Error
272
-     */
273
-    public function delete_permanently($query_params, $allow_blocking = true)
274
-    {
275
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
276
-        return parent::delete_permanently($query_params, $allow_blocking);
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * Restores a particular item by its ID (primary key). Ignores the fact whether the item
283
-     * has been soft-deleted or not.
284
-     *
285
-     * @param mixed $ID int if primary key is an int, string otherwise
286
-     * @return boolean success
287
-     */
288
-    public function restore_by_ID($ID = false)
289
-    {
290
-        return $this->delete_or_restore_by_ID(false, $ID);
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However,
297
-     * this function will ignore whether the items have been soft-deleted or not.
298
-     *
299
-     * @param boolean $delete true for delete, false for restore
300
-     * @param mixed   $ID     int if primary key is an int, string otherwise
301
-     * @return boolean
302
-     */
303
-    public function delete_or_restore_by_ID($delete = true, $ID = false)
304
-    {
305
-        if (! $ID) {
306
-            return false;
307
-        }
308
-        if (
309
-            $this->delete_or_restore(
310
-                $delete,
311
-                $this->alter_query_params_to_restrict_by_ID($ID)
312
-            )
313
-        ) {
314
-            return true;
315
-        } else {
316
-            return false;
317
-        }
318
-    }
319
-
320
-
321
-
322
-    /**
323
-     * Overrides parent's 'delete' method to instead do a soft delete on all rows that
324
-     * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been soft-deleted or not.
325
-     * Note: because this item will be soft-deleted only,
326
-     * doesn't block because of model dependencies
327
-     *
328
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
329
-     * @param bool  $block_deletes
330
-     * @return boolean
331
-     */
332
-    public function delete($query_params = array(), $block_deletes = false)
333
-    {
334
-        // no matter what, we WON'T block soft deletes.
335
-        return $this->delete_or_restore(true, $query_params);
336
-    }
337
-
338
-
339
-
340
-    /**
341
-     * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default, trashed/soft-deleted
342
-     * items are ignored in queries. However, this particular function ignores whether the items have been soft-deleted or not.
343
-     *
344
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
345
-     * @return boolean
346
-     */
347
-    public function restore($query_params = array())
348
-    {
349
-        return $this->delete_or_restore(false, $query_params);
350
-    }
351
-
352
-
353
-
354
-    /**
355
-     * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
356
-     *
357
-     * @param boolean $delete       true to indicate deletion, false to indicate restoration
358
-     * @param array   $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
359
-     * @return boolean
360
-     */
361
-    public function delete_or_restore($delete = true, $query_params = array())
362
-    {
363
-        $deletedFlagFieldName = $this->deleted_field_name();
364
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
365
-        if ($this->update(array($deletedFlagFieldName => $delete), $query_params)) {
366
-            return true;
367
-        } else {
368
-            return false;
369
-        }
370
-    }
371
-
372
-
373
-
374
-    /**
375
-     * Updates all the items of this model which match the $query params, regardless of whether
376
-     * they've been soft-deleted or not
377
-     *
378
-     * @param array   $fields_n_values         like EEM_Base::update's $fields_n_value
379
-     * @param array   $query_params            like EEM_base::get_all's $query_params
380
-     * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
381
-     *                                         in this model's entity map according to $fields_n_values that match $query_params. This
382
-     *                                         obviously has some overhead, so you can disable it by setting this to FALSE, but
383
-     *                                         be aware that model objects being used could get out-of-sync with the database
384
-     * @return int number of items updated
385
-     */
386
-    public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
387
-    {
388
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
389
-        return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync);
390
-    }
30
+	/**
31
+	 * @param null $timezone
32
+	 */
33
+	protected function __construct($timezone = null)
34
+	{
35
+		if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
36
+			$this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
37
+		}
38
+		parent::__construct($timezone);
39
+	}
40
+
41
+
42
+
43
+	/**
44
+	 * Searches for field on this model of type 'deleted_flag'. if it is found,
45
+	 * returns it's name.
46
+	 *
47
+	 * @return string
48
+	 * @throws EE_Error
49
+	 */
50
+	public function deleted_field_name()
51
+	{
52
+		$field = $this->get_a_field_of_type('EE_Trashed_Flag_Field');
53
+		if ($field) {
54
+			return $field->get_name();
55
+		} else {
56
+			throw new EE_Error(sprintf(esc_html__(
57
+				'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
58
+				'event_espresso'
59
+			), get_class($this), get_class($this)));
60
+		}
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * Gets one item that's been deleted, according to $query_params
67
+	 *
68
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
69
+	 * @return EE_Soft_Delete_Base_Class
70
+	 */
71
+	public function get_one_deleted($query_params = array())
72
+	{
73
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
74
+		return parent::get_one($query_params);
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * Gets one item from the DB, regardless of whether it's been soft-deleted or not
81
+	 *
82
+	 * @param array $query_params like EEM_base::get_all's $query_params
83
+	 * @return EE_Soft_Delete_Base_Class
84
+	 */
85
+	public function get_one_deleted_or_undeleted($query_params = array())
86
+	{
87
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
88
+		return parent::get_one($query_params);
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist.
95
+	 *
96
+	 * @param int|string $id
97
+	 * @return EE_Soft_Delete_Base_Class
98
+	 */
99
+	public function get_one_by_ID_but_ignore_deleted($id)
100
+	{
101
+		return $this->get_one(
102
+			$this->alter_query_params_to_restrict_by_ID(
103
+				$id,
104
+				array('default_where_conditions' => 'default')
105
+			)
106
+		);
107
+	}
108
+
109
+
110
+
111
+	/**
112
+	 * Counts all the deleted/trashed items
113
+	 *
114
+	 * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
115
+	 * @param string $field_to_count
116
+	 * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
117
+	 * @return int
118
+	 */
119
+	public function count_deleted($query_params = null, $field_to_count = null, $distinct = false)
120
+	{
121
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
122
+		return parent::count($query_params, $field_to_count, $distinct);
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * Alters the query params so that only trashed/soft-deleted items are considered
129
+	 *
130
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
131
+	 * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
132
+	 */
133
+	protected function _alter_query_params_so_only_trashed_items_included($query_params)
134
+	{
135
+		$deletedFlagFieldName = $this->deleted_field_name();
136
+		$query_params[0][ $deletedFlagFieldName ] = true;
137
+		return $query_params;
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * Alters the query params so that only trashed/soft-deleted items are considered
144
+	 *
145
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
146
+	 * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
147
+	 */
148
+	public function alter_query_params_so_only_trashed_items_included($query_params)
149
+	{
150
+		return $this->_alter_query_params_so_only_trashed_items_included($query_params);
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Alters the query params so each item's deleted status is ignored.
157
+	 *
158
+	 * @param array $query_params
159
+	 * @return array
160
+	 */
161
+	public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = array())
162
+	{
163
+		return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * Alters the query params so each item's deleted status is ignored.
170
+	 *
171
+	 * @param array $query_params
172
+	 * @return array
173
+	 */
174
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
175
+	{
176
+		if (! isset($query_params['default_where_conditions'])) {
177
+			$query_params['default_where_conditions'] = 'minimum';
178
+		}
179
+		return $query_params;
180
+	}
181
+
182
+
183
+
184
+	/**
185
+	 * Counts all deleted and undeleted items
186
+	 *
187
+	 * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
188
+	 * @param string $field_to_count
189
+	 * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
190
+	 * @return int
191
+	 */
192
+	public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = false)
193
+	{
194
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
195
+		return parent::count($query_params, $field_to_count, $distinct);
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * Sum all the deleted items.
202
+	 *
203
+	 * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
204
+	 * @param string $field_to_sum
205
+	 * @return int
206
+	 */
207
+	public function sum_deleted($query_params = null, $field_to_sum = null)
208
+	{
209
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
210
+		return parent::sum($query_params, $field_to_sum);
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * Sums all the deleted and undeleted items.
217
+	 *
218
+	 * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
219
+	 * @param string $field_to_sum
220
+	 * @return int
221
+	 */
222
+	public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null)
223
+	{
224
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
225
+		parent::sum($query_params, $field_to_sum);
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of
232
+	 * whether they've been soft-deleted or not
233
+	 *
234
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
235
+	 * @return EE_Soft_Delete_Base_Class[]
236
+	 */
237
+	public function get_all_deleted_and_undeleted($query_params = array())
238
+	{
239
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
240
+		return parent::get_all($query_params);
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params.
247
+	 *
248
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
249
+	 * @return EE_Soft_Delete_Base_Class[]
250
+	 */
251
+	public function get_all_deleted($query_params = array())
252
+	{
253
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
254
+		return parent::get_all($query_params);
255
+	}
256
+
257
+
258
+
259
+	/**
260
+	 * Permanently deletes the selected rows. When selecting rows for deletion, ignores
261
+	 * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects
262
+	 * before you can permanently delete them).
263
+	 * Because this will cause a real deletion, related models may block this deletion (ie, add an error
264
+	 * and abort the delete)
265
+	 *
266
+	 * @param array   $query_params   @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
267
+	 * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
268
+	 *                                that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
269
+	 *                                which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
270
+	 * @return int                    number of rows deleted
271
+	 * @throws EE_Error
272
+	 */
273
+	public function delete_permanently($query_params, $allow_blocking = true)
274
+	{
275
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
276
+		return parent::delete_permanently($query_params, $allow_blocking);
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * Restores a particular item by its ID (primary key). Ignores the fact whether the item
283
+	 * has been soft-deleted or not.
284
+	 *
285
+	 * @param mixed $ID int if primary key is an int, string otherwise
286
+	 * @return boolean success
287
+	 */
288
+	public function restore_by_ID($ID = false)
289
+	{
290
+		return $this->delete_or_restore_by_ID(false, $ID);
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However,
297
+	 * this function will ignore whether the items have been soft-deleted or not.
298
+	 *
299
+	 * @param boolean $delete true for delete, false for restore
300
+	 * @param mixed   $ID     int if primary key is an int, string otherwise
301
+	 * @return boolean
302
+	 */
303
+	public function delete_or_restore_by_ID($delete = true, $ID = false)
304
+	{
305
+		if (! $ID) {
306
+			return false;
307
+		}
308
+		if (
309
+			$this->delete_or_restore(
310
+				$delete,
311
+				$this->alter_query_params_to_restrict_by_ID($ID)
312
+			)
313
+		) {
314
+			return true;
315
+		} else {
316
+			return false;
317
+		}
318
+	}
319
+
320
+
321
+
322
+	/**
323
+	 * Overrides parent's 'delete' method to instead do a soft delete on all rows that
324
+	 * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been soft-deleted or not.
325
+	 * Note: because this item will be soft-deleted only,
326
+	 * doesn't block because of model dependencies
327
+	 *
328
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
329
+	 * @param bool  $block_deletes
330
+	 * @return boolean
331
+	 */
332
+	public function delete($query_params = array(), $block_deletes = false)
333
+	{
334
+		// no matter what, we WON'T block soft deletes.
335
+		return $this->delete_or_restore(true, $query_params);
336
+	}
337
+
338
+
339
+
340
+	/**
341
+	 * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default, trashed/soft-deleted
342
+	 * items are ignored in queries. However, this particular function ignores whether the items have been soft-deleted or not.
343
+	 *
344
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
345
+	 * @return boolean
346
+	 */
347
+	public function restore($query_params = array())
348
+	{
349
+		return $this->delete_or_restore(false, $query_params);
350
+	}
351
+
352
+
353
+
354
+	/**
355
+	 * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
356
+	 *
357
+	 * @param boolean $delete       true to indicate deletion, false to indicate restoration
358
+	 * @param array   $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
359
+	 * @return boolean
360
+	 */
361
+	public function delete_or_restore($delete = true, $query_params = array())
362
+	{
363
+		$deletedFlagFieldName = $this->deleted_field_name();
364
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
365
+		if ($this->update(array($deletedFlagFieldName => $delete), $query_params)) {
366
+			return true;
367
+		} else {
368
+			return false;
369
+		}
370
+	}
371
+
372
+
373
+
374
+	/**
375
+	 * Updates all the items of this model which match the $query params, regardless of whether
376
+	 * they've been soft-deleted or not
377
+	 *
378
+	 * @param array   $fields_n_values         like EEM_Base::update's $fields_n_value
379
+	 * @param array   $query_params            like EEM_base::get_all's $query_params
380
+	 * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
381
+	 *                                         in this model's entity map according to $fields_n_values that match $query_params. This
382
+	 *                                         obviously has some overhead, so you can disable it by setting this to FALSE, but
383
+	 *                                         be aware that model objects being used could get out-of-sync with the database
384
+	 * @return int number of items updated
385
+	 */
386
+	public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
387
+	{
388
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
389
+		return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync);
390
+	}
391 391
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 2 patches
Indentation   +2674 added lines, -2674 removed lines patch added patch discarded remove patch
@@ -19,2678 +19,2678 @@
 block discarded – undo
19 19
 class Events_Admin_Page extends EE_Admin_Page_CPT
20 20
 {
21 21
 
22
-    /**
23
-     * This will hold the event object for event_details screen.
24
-     *
25
-     * @var EE_Event $_event
26
-     */
27
-    protected $_event;
28
-
29
-
30
-    /**
31
-     * This will hold the category object for category_details screen.
32
-     *
33
-     * @var stdClass $_category
34
-     */
35
-    protected $_category;
36
-
37
-
38
-    /**
39
-     * This will hold the event model instance
40
-     *
41
-     * @var EEM_Event $_event_model
42
-     */
43
-    protected $_event_model;
44
-
45
-
46
-    /**
47
-     * @var EE_Event
48
-     */
49
-    protected $_cpt_model_obj = false;
50
-
51
-
52
-    /**
53
-     * @var NodeGroupDao
54
-     */
55
-    protected $model_obj_node_group_persister;
56
-
57
-    /**
58
-     * Initialize page props for this admin page group.
59
-     */
60
-    protected function _init_page_props()
61
-    {
62
-        $this->page_slug = EVENTS_PG_SLUG;
63
-        $this->page_label = EVENTS_LABEL;
64
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
65
-        $this->_admin_base_path = EVENTS_ADMIN;
66
-        $this->_cpt_model_names = array(
67
-            'create_new' => 'EEM_Event',
68
-            'edit'       => 'EEM_Event',
69
-        );
70
-        $this->_cpt_edit_routes = array(
71
-            'espresso_events' => 'edit',
72
-        );
73
-        add_action(
74
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
75
-            array($this, 'verify_event_edit'),
76
-            10,
77
-            2
78
-        );
79
-    }
80
-
81
-
82
-    /**
83
-     * Sets the ajax hooks used for this admin page group.
84
-     */
85
-    protected function _ajax_hooks()
86
-    {
87
-        add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
88
-    }
89
-
90
-
91
-    /**
92
-     * Sets the page properties for this admin page group.
93
-     */
94
-    protected function _define_page_props()
95
-    {
96
-        $this->_admin_page_title = EVENTS_LABEL;
97
-        $this->_labels = array(
98
-            'buttons'      => array(
99
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
100
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
101
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
102
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
103
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
104
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
105
-            ),
106
-            'editor_title' => array(
107
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
108
-            ),
109
-            'publishbox'   => array(
110
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
111
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
112
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
113
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
114
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
115
-            ),
116
-        );
117
-    }
118
-
119
-
120
-    /**
121
-     * Sets the page routes property for this admin page group.
122
-     */
123
-    protected function _set_page_routes()
124
-    {
125
-        // load formatter helper
126
-        // load field generator helper
127
-        // is there a evt_id in the request?
128
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
129
-            ? $this->_req_data['EVT_ID']
130
-            : 0;
131
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
132
-        $this->_page_routes = array(
133
-            'default'                       => array(
134
-                'func'       => '_events_overview_list_table',
135
-                'capability' => 'ee_read_events',
136
-            ),
137
-            'create_new'                    => array(
138
-                'func'       => '_create_new_cpt_item',
139
-                'capability' => 'ee_edit_events',
140
-            ),
141
-            'edit'                          => array(
142
-                'func'       => '_edit_cpt_item',
143
-                'capability' => 'ee_edit_event',
144
-                'obj_id'     => $evt_id,
145
-            ),
146
-            'copy_event'                    => array(
147
-                'func'       => '_copy_events',
148
-                'capability' => 'ee_edit_event',
149
-                'obj_id'     => $evt_id,
150
-                'noheader'   => true,
151
-            ),
152
-            'trash_event'                   => array(
153
-                'func'       => '_trash_or_restore_event',
154
-                'args'       => array('event_status' => 'trash'),
155
-                'capability' => 'ee_delete_event',
156
-                'obj_id'     => $evt_id,
157
-                'noheader'   => true,
158
-            ),
159
-            'trash_events'                  => array(
160
-                'func'       => '_trash_or_restore_events',
161
-                'args'       => array('event_status' => 'trash'),
162
-                'capability' => 'ee_delete_events',
163
-                'noheader'   => true,
164
-            ),
165
-            'restore_event'                 => array(
166
-                'func'       => '_trash_or_restore_event',
167
-                'args'       => array('event_status' => 'draft'),
168
-                'capability' => 'ee_delete_event',
169
-                'obj_id'     => $evt_id,
170
-                'noheader'   => true,
171
-            ),
172
-            'restore_events'                => array(
173
-                'func'       => '_trash_or_restore_events',
174
-                'args'       => array('event_status' => 'draft'),
175
-                'capability' => 'ee_delete_events',
176
-                'noheader'   => true,
177
-            ),
178
-            'delete_event'                  => array(
179
-                'func'       => '_delete_event',
180
-                'capability' => 'ee_delete_event',
181
-                'obj_id'     => $evt_id,
182
-                'noheader'   => true,
183
-            ),
184
-            'delete_events'                 => array(
185
-                'func'       => '_delete_events',
186
-                'capability' => 'ee_delete_events',
187
-                'noheader'   => true,
188
-            ),
189
-            'view_report'                   => array(
190
-                'func'      => '_view_report',
191
-                'capablity' => 'ee_edit_events',
192
-            ),
193
-            'default_event_settings'        => array(
194
-                'func'       => '_default_event_settings',
195
-                'capability' => 'manage_options',
196
-            ),
197
-            'update_default_event_settings' => array(
198
-                'func'       => '_update_default_event_settings',
199
-                'capability' => 'manage_options',
200
-                'noheader'   => true,
201
-            ),
202
-            'template_settings'             => array(
203
-                'func'       => '_template_settings',
204
-                'capability' => 'manage_options',
205
-            ),
206
-            // event category tab related
207
-            'add_category'                  => array(
208
-                'func'       => '_category_details',
209
-                'capability' => 'ee_edit_event_category',
210
-                'args'       => array('add'),
211
-            ),
212
-            'edit_category'                 => array(
213
-                'func'       => '_category_details',
214
-                'capability' => 'ee_edit_event_category',
215
-                'args'       => array('edit'),
216
-            ),
217
-            'delete_categories'             => array(
218
-                'func'       => '_delete_categories',
219
-                'capability' => 'ee_delete_event_category',
220
-                'noheader'   => true,
221
-            ),
222
-            'delete_category'               => array(
223
-                'func'       => '_delete_categories',
224
-                'capability' => 'ee_delete_event_category',
225
-                'noheader'   => true,
226
-            ),
227
-            'insert_category'               => array(
228
-                'func'       => '_insert_or_update_category',
229
-                'args'       => array('new_category' => true),
230
-                'capability' => 'ee_edit_event_category',
231
-                'noheader'   => true,
232
-            ),
233
-            'update_category'               => array(
234
-                'func'       => '_insert_or_update_category',
235
-                'args'       => array('new_category' => false),
236
-                'capability' => 'ee_edit_event_category',
237
-                'noheader'   => true,
238
-            ),
239
-            'category_list'                 => array(
240
-                'func'       => '_category_list_table',
241
-                'capability' => 'ee_manage_event_categories',
242
-            ),
243
-            'preview_deletion' => [
244
-                'func' => 'previewDeletion',
245
-                'capability' => 'ee_delete_events',
246
-            ],
247
-            'confirm_deletion' => [
248
-                'func' => 'confirmDeletion',
249
-                'capability' => 'ee_delete_events',
250
-                'noheader' => true,
251
-            ]
252
-        );
253
-    }
254
-
255
-
256
-    /**
257
-     * Set the _page_config property for this admin page group.
258
-     */
259
-    protected function _set_page_config()
260
-    {
261
-        $this->_page_config = array(
262
-            'default'                => array(
263
-                'nav'           => array(
264
-                    'label' => esc_html__('Overview', 'event_espresso'),
265
-                    'order' => 10,
266
-                ),
267
-                'list_table'    => 'Events_Admin_List_Table',
268
-                'help_tabs'     => array(
269
-                    'events_overview_help_tab'                       => array(
270
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
271
-                        'filename' => 'events_overview',
272
-                    ),
273
-                    'events_overview_table_column_headings_help_tab' => array(
274
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
275
-                        'filename' => 'events_overview_table_column_headings',
276
-                    ),
277
-                    'events_overview_filters_help_tab'               => array(
278
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
279
-                        'filename' => 'events_overview_filters',
280
-                    ),
281
-                    'events_overview_view_help_tab'                  => array(
282
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
283
-                        'filename' => 'events_overview_views',
284
-                    ),
285
-                    'events_overview_other_help_tab'                 => array(
286
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
287
-                        'filename' => 'events_overview_other',
288
-                    ),
289
-                ),
290
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
291
-                // 'help_tour'     => array(
292
-                //     'Event_Overview_Help_Tour',
293
-                //     // 'New_Features_Test_Help_Tour' for testing multiple help tour
294
-                // ),
295
-                'qtips'         => array(
296
-                    'EE_Event_List_Table_Tips',
297
-                ),
298
-                'require_nonce' => false,
299
-            ),
300
-            'create_new'             => array(
301
-                'nav'           => array(
302
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
303
-                    'order'      => 5,
304
-                    'persistent' => false,
305
-                ),
306
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
307
-                'help_tabs'     => array(
308
-                    'event_editor_help_tab'                            => array(
309
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
310
-                        'filename' => 'event_editor',
311
-                    ),
312
-                    'event_editor_title_richtexteditor_help_tab'       => array(
313
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
314
-                        'filename' => 'event_editor_title_richtexteditor',
315
-                    ),
316
-                    'event_editor_venue_details_help_tab'              => array(
317
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
318
-                        'filename' => 'event_editor_venue_details',
319
-                    ),
320
-                    'event_editor_event_datetimes_help_tab'            => array(
321
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
322
-                        'filename' => 'event_editor_event_datetimes',
323
-                    ),
324
-                    'event_editor_event_tickets_help_tab'              => array(
325
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
326
-                        'filename' => 'event_editor_event_tickets',
327
-                    ),
328
-                    'event_editor_event_registration_options_help_tab' => array(
329
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
330
-                        'filename' => 'event_editor_event_registration_options',
331
-                    ),
332
-                    'event_editor_tags_categories_help_tab'            => array(
333
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
334
-                        'filename' => 'event_editor_tags_categories',
335
-                    ),
336
-                    'event_editor_questions_registrants_help_tab'      => array(
337
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
338
-                        'filename' => 'event_editor_questions_registrants',
339
-                    ),
340
-                    'event_editor_save_new_event_help_tab'             => array(
341
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
342
-                        'filename' => 'event_editor_save_new_event',
343
-                    ),
344
-                    'event_editor_other_help_tab'                      => array(
345
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
346
-                        'filename' => 'event_editor_other',
347
-                    ),
348
-                ),
349
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
350
-                // 'help_tour'     => array(
351
-                //     'Event_Editor_Help_Tour',
352
-                // ),
353
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
354
-                'require_nonce' => false,
355
-            ),
356
-            'edit'                   => array(
357
-                'nav'           => array(
358
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
359
-                    'order'      => 5,
360
-                    'persistent' => false,
361
-                    'url'        => isset($this->_req_data['post'])
362
-                        ? EE_Admin_Page::add_query_args_and_nonce(
363
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
364
-                            $this->_current_page_view_url
365
-                        )
366
-                        : $this->_admin_base_url,
367
-                ),
368
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
369
-                'help_tabs'     => array(
370
-                    'event_editor_help_tab'                            => array(
371
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
372
-                        'filename' => 'event_editor',
373
-                    ),
374
-                    'event_editor_title_richtexteditor_help_tab'       => array(
375
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
376
-                        'filename' => 'event_editor_title_richtexteditor',
377
-                    ),
378
-                    'event_editor_venue_details_help_tab'              => array(
379
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
380
-                        'filename' => 'event_editor_venue_details',
381
-                    ),
382
-                    'event_editor_event_datetimes_help_tab'            => array(
383
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
384
-                        'filename' => 'event_editor_event_datetimes',
385
-                    ),
386
-                    'event_editor_event_tickets_help_tab'              => array(
387
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
388
-                        'filename' => 'event_editor_event_tickets',
389
-                    ),
390
-                    'event_editor_event_registration_options_help_tab' => array(
391
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
392
-                        'filename' => 'event_editor_event_registration_options',
393
-                    ),
394
-                    'event_editor_tags_categories_help_tab'            => array(
395
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
396
-                        'filename' => 'event_editor_tags_categories',
397
-                    ),
398
-                    'event_editor_questions_registrants_help_tab'      => array(
399
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
400
-                        'filename' => 'event_editor_questions_registrants',
401
-                    ),
402
-                    'event_editor_save_new_event_help_tab'             => array(
403
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
404
-                        'filename' => 'event_editor_save_new_event',
405
-                    ),
406
-                    'event_editor_other_help_tab'                      => array(
407
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
408
-                        'filename' => 'event_editor_other',
409
-                    ),
410
-                ),
411
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
412
-                'require_nonce' => false,
413
-            ),
414
-            'default_event_settings' => array(
415
-                'nav'           => array(
416
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
417
-                    'order' => 40,
418
-                ),
419
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
420
-                'labels'        => array(
421
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
422
-                ),
423
-                'help_tabs'     => array(
424
-                    'default_settings_help_tab'        => array(
425
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
426
-                        'filename' => 'events_default_settings',
427
-                    ),
428
-                    'default_settings_status_help_tab' => array(
429
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
430
-                        'filename' => 'events_default_settings_status',
431
-                    ),
432
-                    'default_maximum_tickets_help_tab' => array(
433
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
434
-                        'filename' => 'events_default_settings_max_tickets',
435
-                    ),
436
-                ),
437
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
438
-                // 'help_tour'     => array('Event_Default_Settings_Help_Tour'),
439
-                'require_nonce' => false,
440
-            ),
441
-            // template settings
442
-            'template_settings'      => array(
443
-                'nav'           => array(
444
-                    'label' => esc_html__('Templates', 'event_espresso'),
445
-                    'order' => 30,
446
-                ),
447
-                'metaboxes'     => $this->_default_espresso_metaboxes,
448
-                'help_tabs'     => array(
449
-                    'general_settings_templates_help_tab' => array(
450
-                        'title'    => esc_html__('Templates', 'event_espresso'),
451
-                        'filename' => 'general_settings_templates',
452
-                    ),
453
-                ),
454
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
455
-                // 'help_tour'     => array('Templates_Help_Tour'),
456
-                'require_nonce' => false,
457
-            ),
458
-            // event category stuff
459
-            'add_category'           => array(
460
-                'nav'           => array(
461
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
462
-                    'order'      => 15,
463
-                    'persistent' => false,
464
-                ),
465
-                'help_tabs'     => array(
466
-                    'add_category_help_tab' => array(
467
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
468
-                        'filename' => 'events_add_category',
469
-                    ),
470
-                ),
471
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
472
-                // 'help_tour'     => array('Event_Add_Category_Help_Tour'),
473
-                'metaboxes'     => array('_publish_post_box'),
474
-                'require_nonce' => false,
475
-            ),
476
-            'edit_category'          => array(
477
-                'nav'           => array(
478
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
479
-                    'order'      => 15,
480
-                    'persistent' => false,
481
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
482
-                        ? add_query_arg(
483
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
484
-                            $this->_current_page_view_url
485
-                        )
486
-                        : $this->_admin_base_url,
487
-                ),
488
-                'help_tabs'     => array(
489
-                    'edit_category_help_tab' => array(
490
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
491
-                        'filename' => 'events_edit_category',
492
-                    ),
493
-                ),
494
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
495
-                'metaboxes'     => array('_publish_post_box'),
496
-                'require_nonce' => false,
497
-            ),
498
-            'category_list'          => array(
499
-                'nav'           => array(
500
-                    'label' => esc_html__('Categories', 'event_espresso'),
501
-                    'order' => 20,
502
-                ),
503
-                'list_table'    => 'Event_Categories_Admin_List_Table',
504
-                'help_tabs'     => array(
505
-                    'events_categories_help_tab'                       => array(
506
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
507
-                        'filename' => 'events_categories',
508
-                    ),
509
-                    'events_categories_table_column_headings_help_tab' => array(
510
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
511
-                        'filename' => 'events_categories_table_column_headings',
512
-                    ),
513
-                    'events_categories_view_help_tab'                  => array(
514
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
515
-                        'filename' => 'events_categories_views',
516
-                    ),
517
-                    'events_categories_other_help_tab'                 => array(
518
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
519
-                        'filename' => 'events_categories_other',
520
-                    ),
521
-                ),
522
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
523
-                // 'help_tour'     => array(
524
-                //     'Event_Categories_Help_Tour',
525
-                // ),
526
-                'metaboxes'     => $this->_default_espresso_metaboxes,
527
-                'require_nonce' => false,
528
-            ),
529
-            'preview_deletion'           => array(
530
-                'nav'           => array(
531
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
532
-                    'order'      => 15,
533
-                    'persistent' => false,
534
-                    'url'        => '',
535
-                ),
536
-                'require_nonce' => false
537
-            )
538
-        );
539
-    }
540
-
541
-
542
-    /**
543
-     * Used to register any global screen options if necessary for every route in this admin page group.
544
-     */
545
-    protected function _add_screen_options()
546
-    {
547
-    }
548
-
549
-
550
-    /**
551
-     * Implementing the screen options for the 'default' route.
552
-     */
553
-    protected function _add_screen_options_default()
554
-    {
555
-        $this->_per_page_screen_option();
556
-    }
557
-
558
-
559
-    /**
560
-     * Implementing screen options for the category list route.
561
-     */
562
-    protected function _add_screen_options_category_list()
563
-    {
564
-        $page_title = $this->_admin_page_title;
565
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
566
-        $this->_per_page_screen_option();
567
-        $this->_admin_page_title = $page_title;
568
-    }
569
-
570
-
571
-    /**
572
-     * Used to register any global feature pointers for the admin page group.
573
-     */
574
-    protected function _add_feature_pointers()
575
-    {
576
-    }
577
-
578
-
579
-    /**
580
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
581
-     */
582
-    public function load_scripts_styles()
583
-    {
584
-        wp_register_style(
585
-            'events-admin-css',
586
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
587
-            array(),
588
-            EVENT_ESPRESSO_VERSION
589
-        );
590
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
591
-        wp_enqueue_style('events-admin-css');
592
-        wp_enqueue_style('ee-cat-admin');
593
-        // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
594
-        // registers for all views
595
-        // scripts
596
-        wp_register_script(
597
-            'event_editor_js',
598
-            EVENTS_ASSETS_URL . 'event_editor.js',
599
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
600
-            EVENT_ESPRESSO_VERSION,
601
-            true
602
-        );
603
-    }
604
-
605
-
606
-    /**
607
-     * Enqueuing scripts and styles specific to this view
608
-     */
609
-    public function load_scripts_styles_create_new()
610
-    {
611
-        $this->load_scripts_styles_edit();
612
-    }
613
-
614
-
615
-    /**
616
-     * Enqueuing scripts and styles specific to this view
617
-     */
618
-    public function load_scripts_styles_edit()
619
-    {
620
-        // styles
621
-        wp_enqueue_style('espresso-ui-theme');
622
-        wp_register_style(
623
-            'event-editor-css',
624
-            EVENTS_ASSETS_URL . 'event-editor.css',
625
-            array('ee-admin-css'),
626
-            EVENT_ESPRESSO_VERSION
627
-        );
628
-        wp_enqueue_style('event-editor-css');
629
-        // scripts
630
-        wp_register_script(
631
-            'event-datetime-metabox',
632
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
633
-            array('event_editor_js', 'ee-datepicker'),
634
-            EVENT_ESPRESSO_VERSION
635
-        );
636
-        wp_enqueue_script('event-datetime-metabox');
637
-    }
638
-
639
-
640
-    /**
641
-     * Populating the _views property for the category list table view.
642
-     */
643
-    protected function _set_list_table_views_category_list()
644
-    {
645
-        $this->_views = array(
646
-            'all' => array(
647
-                'slug'        => 'all',
648
-                'label'       => esc_html__('All', 'event_espresso'),
649
-                'count'       => 0,
650
-                'bulk_action' => array(
651
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
652
-                ),
653
-            ),
654
-        );
655
-    }
656
-
657
-
658
-    /**
659
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
660
-     */
661
-    public function admin_init()
662
-    {
663
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
664
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
665
-            'event_espresso'
666
-        );
667
-    }
668
-
669
-
670
-    /**
671
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
672
-     * group.
673
-     */
674
-    public function admin_notices()
675
-    {
676
-    }
677
-
678
-
679
-    /**
680
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
681
-     * this admin page group.
682
-     */
683
-    public function admin_footer_scripts()
684
-    {
685
-    }
686
-
687
-
688
-    /**
689
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
690
-     * warning (via EE_Error::add_error());
691
-     *
692
-     * @param  EE_Event $event Event object
693
-     * @param string    $req_type
694
-     * @return void
695
-     * @throws EE_Error
696
-     * @access public
697
-     */
698
-    public function verify_event_edit($event = null, $req_type = '')
699
-    {
700
-        // don't need to do this when processing
701
-        if (! empty($req_type)) {
702
-            return;
703
-        }
704
-        // no event?
705
-        if (empty($event)) {
706
-            // set event
707
-            $event = $this->_cpt_model_obj;
708
-        }
709
-        // STILL no event?
710
-        if (! $event instanceof EE_Event) {
711
-            return;
712
-        }
713
-        $orig_status = $event->status();
714
-        // first check if event is active.
715
-        if (
716
-            $orig_status === EEM_Event::cancelled
717
-            || $orig_status === EEM_Event::postponed
718
-            || $event->is_expired()
719
-            || $event->is_inactive()
720
-        ) {
721
-            return;
722
-        }
723
-        // made it here so it IS active... next check that any of the tickets are sold.
724
-        if ($event->is_sold_out(true)) {
725
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
726
-                EE_Error::add_attention(
727
-                    sprintf(
728
-                        esc_html__(
729
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
730
-                            'event_espresso'
731
-                        ),
732
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
733
-                    )
734
-                );
735
-            }
736
-            return;
737
-        } elseif ($orig_status === EEM_Event::sold_out) {
738
-            EE_Error::add_attention(
739
-                sprintf(
740
-                    esc_html__(
741
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
742
-                        'event_espresso'
743
-                    ),
744
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
745
-                )
746
-            );
747
-        }
748
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
749
-        if (! $event->tickets_on_sale()) {
750
-            return;
751
-        }
752
-        // made it here so show warning
753
-        $this->_edit_event_warning();
754
-    }
755
-
756
-
757
-    /**
758
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
759
-     * When needed, hook this into a EE_Error::add_error() notice.
760
-     *
761
-     * @access protected
762
-     * @return void
763
-     */
764
-    protected function _edit_event_warning()
765
-    {
766
-        // we don't want to add warnings during these requests
767
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
768
-            return;
769
-        }
770
-        EE_Error::add_attention(
771
-            sprintf(
772
-                esc_html__(
773
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
774
-                    'event_espresso'
775
-                ),
776
-                '<a class="espresso-help-tab-lnk">',
777
-                '</a>'
778
-            )
779
-        );
780
-    }
781
-
782
-
783
-    /**
784
-     * When a user is creating a new event, notify them if they haven't set their timezone.
785
-     * Otherwise, do the normal logic
786
-     *
787
-     * @return string
788
-     * @throws \EE_Error
789
-     */
790
-    protected function _create_new_cpt_item()
791
-    {
792
-        $has_timezone_string = get_option('timezone_string');
793
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
794
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
795
-            EE_Error::add_attention(
796
-                sprintf(
797
-                    esc_html__(
798
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
799
-                        'event_espresso'
800
-                    ),
801
-                    '<br>',
802
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
803
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
804
-                    . '</select>',
805
-                    '<button class="button button-secondary timezone-submit">',
806
-                    '</button><span class="spinner"></span>'
807
-                ),
808
-                __FILE__,
809
-                __FUNCTION__,
810
-                __LINE__
811
-            );
812
-        }
813
-        return parent::_create_new_cpt_item();
814
-    }
815
-
816
-
817
-    /**
818
-     * Sets the _views property for the default route in this admin page group.
819
-     */
820
-    protected function _set_list_table_views_default()
821
-    {
822
-        $this->_views = array(
823
-            'all'   => array(
824
-                'slug'        => 'all',
825
-                'label'       => esc_html__('View All Events', 'event_espresso'),
826
-                'count'       => 0,
827
-                'bulk_action' => array(
828
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
829
-                ),
830
-            ),
831
-            'draft' => array(
832
-                'slug'        => 'draft',
833
-                'label'       => esc_html__('Draft', 'event_espresso'),
834
-                'count'       => 0,
835
-                'bulk_action' => array(
836
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
837
-                ),
838
-            ),
839
-        );
840
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
841
-            $this->_views['trash'] = array(
842
-                'slug'        => 'trash',
843
-                'label'       => esc_html__('Trash', 'event_espresso'),
844
-                'count'       => 0,
845
-                'bulk_action' => array(
846
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
847
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
848
-                ),
849
-            );
850
-        }
851
-    }
852
-
853
-
854
-    /**
855
-     * Provides the legend item array for the default list table view.
856
-     *
857
-     * @return array
858
-     */
859
-    protected function _event_legend_items()
860
-    {
861
-        $items = array(
862
-            'view_details'   => array(
863
-                'class' => 'dashicons dashicons-search',
864
-                'desc'  => esc_html__('View Event', 'event_espresso'),
865
-            ),
866
-            'edit_event'     => array(
867
-                'class' => 'ee-icon ee-icon-calendar-edit',
868
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
869
-            ),
870
-            'view_attendees' => array(
871
-                'class' => 'dashicons dashicons-groups',
872
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
873
-            ),
874
-        );
875
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
876
-        $statuses = array(
877
-            'sold_out_status'  => array(
878
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
879
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
880
-            ),
881
-            'active_status'    => array(
882
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
883
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
884
-            ),
885
-            'upcoming_status'  => array(
886
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
887
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
888
-            ),
889
-            'postponed_status' => array(
890
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
891
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
892
-            ),
893
-            'cancelled_status' => array(
894
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
895
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
896
-            ),
897
-            'expired_status'   => array(
898
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
899
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
900
-            ),
901
-            'inactive_status'  => array(
902
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
903
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
904
-            ),
905
-        );
906
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
907
-        return array_merge($items, $statuses);
908
-    }
909
-
910
-
911
-    /**
912
-     * @return EEM_Event
913
-     */
914
-    private function _event_model()
915
-    {
916
-        if (! $this->_event_model instanceof EEM_Event) {
917
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
918
-        }
919
-        return $this->_event_model;
920
-    }
921
-
922
-
923
-    /**
924
-     * Adds extra buttons to the WP CPT permalink field row.
925
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
926
-     *
927
-     * @param  string $return    the current html
928
-     * @param  int    $id        the post id for the page
929
-     * @param  string $new_title What the title is
930
-     * @param  string $new_slug  what the slug is
931
-     * @return string            The new html string for the permalink area
932
-     */
933
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
934
-    {
935
-        // make sure this is only when editing
936
-        if (! empty($id)) {
937
-            $post = get_post($id);
938
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
939
-                       . esc_html__('Shortcode', 'event_espresso')
940
-                       . '</a> ';
941
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
942
-                       . $post->ID
943
-                       . ']">';
944
-        }
945
-        return $return;
946
-    }
947
-
948
-
949
-    /**
950
-     * _events_overview_list_table
951
-     * This contains the logic for showing the events_overview list
952
-     *
953
-     * @access protected
954
-     * @return void
955
-     * @throws \EE_Error
956
-     */
957
-    protected function _events_overview_list_table()
958
-    {
959
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
960
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
961
-            ? (array) $this->_template_args['after_list_table']
962
-            : array();
963
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
964
-                . EEH_Template::get_button_or_link(
965
-                    get_post_type_archive_link('espresso_events'),
966
-                    esc_html__("View Event Archive Page", "event_espresso"),
967
-                    'button'
968
-                );
969
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
970
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
971
-            'create_new',
972
-            'add',
973
-            array(),
974
-            'add-new-h2'
975
-        );
976
-        $this->display_admin_list_table_page_with_no_sidebar();
977
-    }
978
-
979
-
980
-    /**
981
-     * this allows for extra misc actions in the default WP publish box
982
-     *
983
-     * @return void
984
-     */
985
-    public function extra_misc_actions_publish_box()
986
-    {
987
-        $this->_generate_publish_box_extra_content();
988
-    }
989
-
990
-
991
-    /**
992
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
993
-     * saved.
994
-     * Typically you would use this to save any additional data.
995
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
996
-     * ALSO very important.  When a post transitions from scheduled to published,
997
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
998
-     * other meta saves. So MAKE sure that you handle this accordingly.
999
-     *
1000
-     * @access protected
1001
-     * @abstract
1002
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
1003
-     * @param  object $post    The post object of the cpt that was saved.
1004
-     * @return void
1005
-     * @throws \EE_Error
1006
-     */
1007
-    protected function _insert_update_cpt_item($post_id, $post)
1008
-    {
1009
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1010
-            // get out we're not processing an event save.
1011
-            return;
1012
-        }
1013
-        $event_values = array(
1014
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
1015
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
1016
-            'EVT_additional_limit'            => min(
1017
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1018
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
1019
-            ),
1020
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
1021
-                ? $this->_req_data['EVT_default_registration_status']
1022
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
1023
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
1024
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1025
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1026
-                ? $this->_req_data['timezone_string'] : null,
1027
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1028
-                ? $this->_req_data['externalURL'] : null,
1029
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1030
-                ? $this->_req_data['event_phone'] : null,
1031
-        );
1032
-        // update event
1033
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1034
-        // get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1035
-        $get_one_where = array(
1036
-            $this->_event_model()->primary_key_name() => $post_id,
1037
-            'OR'                                      => array(
1038
-                'status'   => $post->post_status,
1039
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1040
-                // but the returned object here has a status of "publish", so use the original post status as well
1041
-                'status*1' => $this->_req_data['original_post_status'],
1042
-            ),
1043
-        );
1044
-        $event = $this->_event_model()->get_one(array($get_one_where));
1045
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1046
-        $event_update_callbacks = apply_filters(
1047
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1048
-            array(
1049
-                array($this, '_default_venue_update'),
1050
-                array($this, '_default_tickets_update'),
1051
-            )
1052
-        );
1053
-        $att_success = true;
1054
-        foreach ($event_update_callbacks as $e_callback) {
1055
-            $_success = is_callable($e_callback)
1056
-                ? call_user_func($e_callback, $event, $this->_req_data)
1057
-                : false;
1058
-            // if ANY of these updates fail then we want the appropriate global error message
1059
-            $att_success = ! $att_success ? $att_success : $_success;
1060
-        }
1061
-        // any errors?
1062
-        if ($success && false === $att_success) {
1063
-            EE_Error::add_error(
1064
-                esc_html__(
1065
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1066
-                    'event_espresso'
1067
-                ),
1068
-                __FILE__,
1069
-                __FUNCTION__,
1070
-                __LINE__
1071
-            );
1072
-        } elseif ($success === false) {
1073
-            EE_Error::add_error(
1074
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1075
-                __FILE__,
1076
-                __FUNCTION__,
1077
-                __LINE__
1078
-            );
1079
-        }
1080
-    }
1081
-
1082
-
1083
-    /**
1084
-     * @see parent::restore_item()
1085
-     * @param int $post_id
1086
-     * @param int $revision_id
1087
-     */
1088
-    protected function _restore_cpt_item($post_id, $revision_id)
1089
-    {
1090
-        // copy existing event meta to new post
1091
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1092
-        if ($post_evt instanceof EE_Event) {
1093
-            // meta revision restore
1094
-            $post_evt->restore_revision($revision_id);
1095
-            // related objs restore
1096
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1097
-        }
1098
-    }
1099
-
1100
-
1101
-    /**
1102
-     * Attach the venue to the Event
1103
-     *
1104
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1105
-     * @param  array     $data   The request data from the form
1106
-     * @return bool           Success or fail.
1107
-     */
1108
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1109
-    {
1110
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1111
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1112
-        $rows_affected = null;
1113
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1114
-        // very important.  If we don't have a venue name...
1115
-        // then we'll get out because not necessary to create empty venue
1116
-        if (empty($data['venue_title'])) {
1117
-            return false;
1118
-        }
1119
-        $venue_array = array(
1120
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1121
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1122
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1123
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1124
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1125
-                : null,
1126
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1127
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1128
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1129
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1130
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1131
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1132
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1133
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1134
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1135
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1136
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1137
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1138
-            'status'              => 'publish',
1139
-        );
1140
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1141
-        if (! empty($venue_id)) {
1142
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1143
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1144
-            // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1145
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1146
-            return $rows_affected > 0 ? true : false;
1147
-        } else {
1148
-            // we insert the venue
1149
-            $venue_id = $venue_model->insert($venue_array);
1150
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1151
-            return ! empty($venue_id) ? true : false;
1152
-        }
1153
-        // when we have the ancestor come in it's already been handled by the revision save.
1154
-    }
1155
-
1156
-
1157
-    /**
1158
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1159
-     *
1160
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1161
-     * @param  array    $data   The request data from the form
1162
-     * @return array
1163
-     */
1164
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1165
-    {
1166
-        $success = true;
1167
-        $saved_dtt = null;
1168
-        $saved_tickets = array();
1169
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1170
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1171
-            // trim all values to ensure any excess whitespace is removed.
1172
-            $dtt = array_map('trim', $dtt);
1173
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1174
-                : $dtt['DTT_EVT_start'];
1175
-            $datetime_values = array(
1176
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1177
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1178
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1179
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1180
-                'DTT_order'     => $row,
1181
-            );
1182
-            // if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1183
-            if (! empty($dtt['DTT_ID'])) {
1184
-                $DTM = EE_Registry::instance()
1185
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1186
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1187
-                $DTM->set_date_format($incoming_date_formats[0]);
1188
-                $DTM->set_time_format($incoming_date_formats[1]);
1189
-                foreach ($datetime_values as $field => $value) {
1190
-                    $DTM->set($field, $value);
1191
-                }
1192
-                // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1193
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1194
-            } else {
1195
-                $DTM = EE_Registry::instance()->load_class(
1196
-                    'Datetime',
1197
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1198
-                    false,
1199
-                    false
1200
-                );
1201
-                foreach ($datetime_values as $field => $value) {
1202
-                    $DTM->set($field, $value);
1203
-                }
1204
-            }
1205
-            $DTM->save();
1206
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1207
-            // load DTT helper
1208
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1209
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1210
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1211
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1212
-                $DTT->save();
1213
-            }
1214
-            // now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1215
-            $saved_dtt = $DTT;
1216
-            $success = ! $success ? $success : $DTT;
1217
-            // if ANY of these updates fail then we want the appropriate global error message.
1218
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1219
-        }
1220
-        // no dtts get deleted so we don't do any of that logic here.
1221
-        // update tickets next
1222
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1223
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1224
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1225
-            $update_prices = false;
1226
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1227
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1228
-            // trim inputs to ensure any excess whitespace is removed.
1229
-            $tkt = array_map('trim', $tkt);
1230
-            if (empty($tkt['TKT_start_date'])) {
1231
-                // let's use now in the set timezone.
1232
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1233
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1234
-            }
1235
-            if (empty($tkt['TKT_end_date'])) {
1236
-                // use the start date of the first datetime
1237
-                $dtt = $evtobj->first_datetime();
1238
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1239
-                    $incoming_date_formats[0],
1240
-                    $incoming_date_formats[1]
1241
-                );
1242
-            }
1243
-            $TKT_values = array(
1244
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1245
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1246
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1247
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1248
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1249
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1250
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1251
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1252
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1253
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1254
-                'TKT_row'         => $row,
1255
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1256
-                'TKT_price'       => $ticket_price,
1257
-            );
1258
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1259
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1260
-                $TKT_values['TKT_ID'] = 0;
1261
-                $TKT_values['TKT_is_default'] = 0;
1262
-                $TKT_values['TKT_price'] = $ticket_price;
1263
-                $update_prices = true;
1264
-            }
1265
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1266
-            // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1267
-            // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1268
-            if (! empty($tkt['TKT_ID'])) {
1269
-                $TKT = EE_Registry::instance()
1270
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1271
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1272
-                if ($TKT instanceof EE_Ticket) {
1273
-                    $ticket_sold = $TKT->count_related(
1274
-                        'Registration',
1275
-                        array(
1276
-                            array(
1277
-                                'STS_ID' => array(
1278
-                                    'NOT IN',
1279
-                                    array(EEM_Registration::status_id_incomplete),
1280
-                                ),
1281
-                            ),
1282
-                        )
1283
-                    ) > 0 ? true : false;
1284
-                    // let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1285
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1286
-                                      && ! $TKT->get('TKT_deleted');
1287
-                    $TKT->set_date_format($incoming_date_formats[0]);
1288
-                    $TKT->set_time_format($incoming_date_formats[1]);
1289
-                    // set new values
1290
-                    foreach ($TKT_values as $field => $value) {
1291
-                        if ($field == 'TKT_qty') {
1292
-                            $TKT->set_qty($value);
1293
-                        } else {
1294
-                            $TKT->set($field, $value);
1295
-                        }
1296
-                    }
1297
-                    // if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1298
-                    if ($create_new_TKT) {
1299
-                        // archive the old ticket first
1300
-                        $TKT->set('TKT_deleted', 1);
1301
-                        $TKT->save();
1302
-                        // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1303
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1304
-                        // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1305
-                        $TKT = clone $TKT;
1306
-                        $TKT->set('TKT_ID', 0);
1307
-                        $TKT->set('TKT_deleted', 0);
1308
-                        $TKT->set('TKT_price', $ticket_price);
1309
-                        $TKT->set('TKT_sold', 0);
1310
-                        // now we need to make sure that $new prices are created as well and attached to new ticket.
1311
-                        $update_prices = true;
1312
-                    }
1313
-                    // make sure price is set if it hasn't been already
1314
-                    $TKT->set('TKT_price', $ticket_price);
1315
-                }
1316
-            } else {
1317
-                // no TKT_id so a new TKT
1318
-                $TKT_values['TKT_price'] = $ticket_price;
1319
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1320
-                if ($TKT instanceof EE_Ticket) {
1321
-                    // need to reset values to properly account for the date formats
1322
-                    $TKT->set_date_format($incoming_date_formats[0]);
1323
-                    $TKT->set_time_format($incoming_date_formats[1]);
1324
-                    $TKT->set_timezone($evtobj->get_timezone());
1325
-                    // set new values
1326
-                    foreach ($TKT_values as $field => $value) {
1327
-                        if ($field == 'TKT_qty') {
1328
-                            $TKT->set_qty($value);
1329
-                        } else {
1330
-                            $TKT->set($field, $value);
1331
-                        }
1332
-                    }
1333
-                    $update_prices = true;
1334
-                }
1335
-            }
1336
-            // cap ticket qty by datetime reg limits
1337
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1338
-            // update ticket.
1339
-            $TKT->save();
1340
-            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1341
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1342
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1343
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1344
-                $TKT->save();
1345
-            }
1346
-            // initially let's add the ticket to the dtt
1347
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1348
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1349
-            // add prices to ticket
1350
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1351
-        }
1352
-        // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1353
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1354
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1355
-        foreach ($tickets_removed as $id) {
1356
-            $id = absint($id);
1357
-            // get the ticket for this id
1358
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1359
-            if (! $tkt_to_remove instanceof EE_Ticket) {
1360
-                continue;
1361
-            }
1362
-
1363
-            // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1364
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1365
-            foreach ($dtts as $dtt) {
1366
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1367
-            }
1368
-            // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1369
-            $tkt_to_remove->delete_related_permanently('Price');
1370
-            // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1371
-            $tkt_to_remove->delete_permanently();
1372
-        }
1373
-        return array($saved_dtt, $saved_tickets);
1374
-    }
1375
-
1376
-
1377
-    /**
1378
-     * This attaches a list of given prices to a ticket.
1379
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1380
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1381
-     * price info and prices are automatically "archived" via the ticket.
1382
-     *
1383
-     * @access  private
1384
-     * @param array     $prices     Array of prices from the form.
1385
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1386
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1387
-     * @return  void
1388
-     */
1389
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1390
-    {
1391
-        foreach ($prices as $row => $prc) {
1392
-            $PRC_values = array(
1393
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1394
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1395
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1396
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1397
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1398
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1399
-                'PRC_order'      => $row,
1400
-            );
1401
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1402
-                $PRC_values['PRC_ID'] = 0;
1403
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1404
-            } else {
1405
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1406
-                // update this price with new values
1407
-                foreach ($PRC_values as $field => $newprc) {
1408
-                    $PRC->set($field, $newprc);
1409
-                }
1410
-                $PRC->save();
1411
-            }
1412
-            $ticket->_add_relation_to($PRC, 'Price');
1413
-        }
1414
-    }
1415
-
1416
-
1417
-    /**
1418
-     * Add in our autosave ajax handlers
1419
-     *
1420
-     */
1421
-    protected function _ee_autosave_create_new()
1422
-    {
1423
-    }
1424
-
1425
-
1426
-    /**
1427
-     * More autosave handlers.
1428
-     */
1429
-    protected function _ee_autosave_edit()
1430
-    {
1431
-        return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1432
-    }
1433
-
1434
-
1435
-    /**
1436
-     *    _generate_publish_box_extra_content
1437
-     */
1438
-    private function _generate_publish_box_extra_content()
1439
-    {
1440
-        // load formatter helper
1441
-        // args for getting related registrations
1442
-        $approved_query_args = array(
1443
-            array(
1444
-                'REG_deleted' => 0,
1445
-                'STS_ID'      => EEM_Registration::status_id_approved,
1446
-            ),
1447
-        );
1448
-        $not_approved_query_args = array(
1449
-            array(
1450
-                'REG_deleted' => 0,
1451
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1452
-            ),
1453
-        );
1454
-        $pending_payment_query_args = array(
1455
-            array(
1456
-                'REG_deleted' => 0,
1457
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1458
-            ),
1459
-        );
1460
-        // publish box
1461
-        $publish_box_extra_args = array(
1462
-            'view_approved_reg_url'        => add_query_arg(
1463
-                array(
1464
-                    'action'      => 'default',
1465
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1466
-                    '_reg_status' => EEM_Registration::status_id_approved,
1467
-                ),
1468
-                REG_ADMIN_URL
1469
-            ),
1470
-            'view_not_approved_reg_url'    => add_query_arg(
1471
-                array(
1472
-                    'action'      => 'default',
1473
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1474
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1475
-                ),
1476
-                REG_ADMIN_URL
1477
-            ),
1478
-            'view_pending_payment_reg_url' => add_query_arg(
1479
-                array(
1480
-                    'action'      => 'default',
1481
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1482
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1483
-                ),
1484
-                REG_ADMIN_URL
1485
-            ),
1486
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1487
-                'Registration',
1488
-                $approved_query_args
1489
-            ),
1490
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1491
-                'Registration',
1492
-                $not_approved_query_args
1493
-            ),
1494
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1495
-                'Registration',
1496
-                $pending_payment_query_args
1497
-            ),
1498
-            'misc_pub_section_class'       => apply_filters(
1499
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1500
-                'misc-pub-section'
1501
-            ),
1502
-        );
1503
-        ob_start();
1504
-        do_action(
1505
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1506
-            $this->_cpt_model_obj
1507
-        );
1508
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1509
-        // load template
1510
-        EEH_Template::display_template(
1511
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1512
-            $publish_box_extra_args
1513
-        );
1514
-    }
1515
-
1516
-
1517
-    /**
1518
-     * @return EE_Event
1519
-     */
1520
-    public function get_event_object()
1521
-    {
1522
-        return $this->_cpt_model_obj;
1523
-    }
1524
-
1525
-
1526
-
1527
-
1528
-    /** METABOXES * */
1529
-    /**
1530
-     * _register_event_editor_meta_boxes
1531
-     * add all metaboxes related to the event_editor
1532
-     *
1533
-     * @return void
1534
-     */
1535
-    protected function _register_event_editor_meta_boxes()
1536
-    {
1537
-        $this->verify_cpt_object();
1538
-        add_meta_box(
1539
-            'espresso_event_editor_tickets',
1540
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1541
-            array($this, 'ticket_metabox'),
1542
-            $this->page_slug,
1543
-            'normal',
1544
-            'high'
1545
-        );
1546
-        add_meta_box(
1547
-            'espresso_event_editor_event_options',
1548
-            esc_html__('Event Registration Options', 'event_espresso'),
1549
-            array($this, 'registration_options_meta_box'),
1550
-            $this->page_slug,
1551
-            'side',
1552
-            'default'
1553
-        );
1554
-        // NOTE: if you're looking for other metaboxes in here,
1555
-        // where a metabox has a related management page in the admin
1556
-        // you will find it setup in the related management page's "_Hooks" file.
1557
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1558
-    }
1559
-
1560
-
1561
-    /**
1562
-     * @throws DomainException
1563
-     * @throws EE_Error
1564
-     */
1565
-    public function ticket_metabox()
1566
-    {
1567
-        $existing_datetime_ids = $existing_ticket_ids = array();
1568
-        // defaults for template args
1569
-        $template_args = array(
1570
-            'existing_datetime_ids'    => '',
1571
-            'event_datetime_help_link' => '',
1572
-            'ticket_options_help_link' => '',
1573
-            'time'                     => null,
1574
-            'ticket_rows'              => '',
1575
-            'existing_ticket_ids'      => '',
1576
-            'total_ticket_rows'        => 1,
1577
-            'ticket_js_structure'      => '',
1578
-            'trash_icon'               => 'ee-lock-icon',
1579
-            'disabled'                 => '',
1580
-        );
1581
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1582
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1583
-        /**
1584
-         * 1. Start with retrieving Datetimes
1585
-         * 2. Fore each datetime get related tickets
1586
-         * 3. For each ticket get related prices
1587
-         */
1588
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1589
-        /** @type EE_Datetime $first_datetime */
1590
-        $first_datetime = reset($times);
1591
-        // do we get related tickets?
1592
-        if (
1593
-            $first_datetime instanceof EE_Datetime
1594
-            && $first_datetime->ID() !== 0
1595
-        ) {
1596
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1597
-            $template_args['time'] = $first_datetime;
1598
-            $related_tickets = $first_datetime->tickets(
1599
-                array(
1600
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1601
-                    'default_where_conditions' => 'none',
1602
-                )
1603
-            );
1604
-            if (! empty($related_tickets)) {
1605
-                $template_args['total_ticket_rows'] = count($related_tickets);
1606
-                $row = 0;
1607
-                foreach ($related_tickets as $ticket) {
1608
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1609
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1610
-                    $row++;
1611
-                }
1612
-            } else {
1613
-                $template_args['total_ticket_rows'] = 1;
1614
-                /** @type EE_Ticket $ticket */
1615
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1616
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1617
-            }
1618
-        } else {
1619
-            $template_args['time'] = $times[0];
1620
-            /** @type EE_Ticket $ticket */
1621
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1622
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1623
-            // NOTE: we're just sending the first default row
1624
-            // (decaf can't manage default tickets so this should be sufficient);
1625
-        }
1626
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1627
-            'event_editor_event_datetimes_help_tab'
1628
-        );
1629
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1630
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1631
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1632
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1633
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1634
-            true
1635
-        );
1636
-        $template = apply_filters(
1637
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1638
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1639
-        );
1640
-        EEH_Template::display_template($template, $template_args);
1641
-    }
1642
-
1643
-
1644
-    /**
1645
-     * Setup an individual ticket form for the decaf event editor page
1646
-     *
1647
-     * @access private
1648
-     * @param  EE_Ticket $ticket   the ticket object
1649
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1650
-     * @param int        $row
1651
-     * @return string generated html for the ticket row.
1652
-     */
1653
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1654
-    {
1655
-        $template_args = array(
1656
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1657
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1658
-                : '',
1659
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1660
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1661
-            'TKT_name'            => $ticket->get('TKT_name'),
1662
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1663
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1664
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1665
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1666
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1667
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1668
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1669
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1670
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1671
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1672
-                : ' disabled=disabled',
1673
-        );
1674
-        $price = $ticket->ID() !== 0
1675
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1676
-            : null;
1677
-        $price = $price instanceof EE_Price
1678
-            ? $price
1679
-            : EEM_Price::instance()->create_default_object();
1680
-        $price_args = array(
1681
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1682
-            'PRC_amount'            => $price->get('PRC_amount'),
1683
-            'PRT_ID'                => $price->get('PRT_ID'),
1684
-            'PRC_ID'                => $price->get('PRC_ID'),
1685
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1686
-        );
1687
-        // make sure we have default start and end dates if skeleton
1688
-        // handle rows that should NOT be empty
1689
-        if (empty($template_args['TKT_start_date'])) {
1690
-            // if empty then the start date will be now.
1691
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1692
-        }
1693
-        if (empty($template_args['TKT_end_date'])) {
1694
-            // get the earliest datetime (if present);
1695
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1696
-                ? $this->_cpt_model_obj->get_first_related(
1697
-                    'Datetime',
1698
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1699
-                )
1700
-                : null;
1701
-            if (! empty($earliest_dtt)) {
1702
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1703
-            } else {
1704
-                $template_args['TKT_end_date'] = date(
1705
-                    'Y-m-d h:i a',
1706
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1707
-                );
1708
-            }
1709
-        }
1710
-        $template_args = array_merge($template_args, $price_args);
1711
-        $template = apply_filters(
1712
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1713
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1714
-            $ticket
1715
-        );
1716
-        return EEH_Template::display_template($template, $template_args, true);
1717
-    }
1718
-
1719
-
1720
-    /**
1721
-     * @throws DomainException
1722
-     */
1723
-    public function registration_options_meta_box()
1724
-    {
1725
-        $yes_no_values = array(
1726
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1727
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1728
-        );
1729
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1730
-            array(
1731
-                EEM_Registration::status_id_cancelled,
1732
-                EEM_Registration::status_id_declined,
1733
-                EEM_Registration::status_id_incomplete,
1734
-            ),
1735
-            true
1736
-        );
1737
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1738
-        $template_args['_event'] = $this->_cpt_model_obj;
1739
-        $template_args['event'] = $this->_cpt_model_obj;
1740
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1741
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1742
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1743
-            'default_reg_status',
1744
-            $default_reg_status_values,
1745
-            $this->_cpt_model_obj->default_registration_status()
1746
-        );
1747
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1748
-            'display_desc',
1749
-            $yes_no_values,
1750
-            $this->_cpt_model_obj->display_description()
1751
-        );
1752
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1753
-            'display_ticket_selector',
1754
-            $yes_no_values,
1755
-            $this->_cpt_model_obj->display_ticket_selector(),
1756
-            '',
1757
-            '',
1758
-            false
1759
-        );
1760
-        $template_args['additional_registration_options'] = apply_filters(
1761
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1762
-            '',
1763
-            $template_args,
1764
-            $yes_no_values,
1765
-            $default_reg_status_values
1766
-        );
1767
-        EEH_Template::display_template(
1768
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1769
-            $template_args
1770
-        );
1771
-    }
1772
-
1773
-
1774
-    /**
1775
-     * _get_events()
1776
-     * This method simply returns all the events (for the given _view and paging)
1777
-     *
1778
-     * @access public
1779
-     * @param int  $per_page     count of items per page (20 default);
1780
-     * @param int  $current_page what is the current page being viewed.
1781
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1782
-     *                           If FALSE then we return an array of event objects
1783
-     *                           that match the given _view and paging parameters.
1784
-     * @return array an array of event objects.
1785
-     */
1786
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1787
-    {
1788
-        $EEME = $this->_event_model();
1789
-        $offset = ($current_page - 1) * $per_page;
1790
-        $limit = $count ? null : $offset . ',' . $per_page;
1791
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1792
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1793
-        if (isset($this->_req_data['month_range'])) {
1794
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1795
-            // simulate the FIRST day of the month, that fixes issues for months like February
1796
-            // where PHP doesn't know what to assume for date.
1797
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1798
-            $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1799
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1800
-        }
1801
-        $where = array();
1802
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1803
-        // determine what post_status our condition will have for the query.
1804
-        switch ($status) {
1805
-            case 'month':
1806
-            case 'today':
1807
-            case null:
1808
-            case 'all':
1809
-                break;
1810
-            case 'draft':
1811
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1812
-                break;
1813
-            default:
1814
-                $where['status'] = $status;
1815
-        }
1816
-        // categories?
1817
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1818
-            ? $this->_req_data['EVT_CAT'] : null;
1819
-        if (! empty($category)) {
1820
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1821
-            $where['Term_Taxonomy.term_id'] = $category;
1822
-        }
1823
-        // date where conditions
1824
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1825
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1826
-            $DateTime = new DateTime(
1827
-                $year_r . '-' . $month_r . '-01 00:00:00',
1828
-                new DateTimeZone('UTC')
1829
-            );
1830
-            $start = $DateTime->getTimestamp();
1831
-            // set the datetime to be the end of the month
1832
-            $DateTime->setDate(
1833
-                $year_r,
1834
-                $month_r,
1835
-                $DateTime->format('t')
1836
-            )->setTime(23, 59, 59);
1837
-            $end = $DateTime->getTimestamp();
1838
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1839
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1840
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1841
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1842
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1843
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1844
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1845
-            $now = date('Y-m-01');
1846
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1847
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1848
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1849
-                            ->setTime(23, 59, 59)
1850
-                            ->format(implode(' ', $start_formats));
1851
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1852
-        }
1853
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1854
-            $where['EVT_wp_user'] = get_current_user_id();
1855
-        } else {
1856
-            if (! isset($where['status'])) {
1857
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1858
-                    $where['OR'] = array(
1859
-                        'status*restrict_private' => array('!=', 'private'),
1860
-                        'AND'                     => array(
1861
-                            'status*inclusive' => array('=', 'private'),
1862
-                            'EVT_wp_user'      => get_current_user_id(),
1863
-                        ),
1864
-                    );
1865
-                }
1866
-            }
1867
-        }
1868
-        if (isset($this->_req_data['EVT_wp_user'])) {
1869
-            if (
1870
-                $this->_req_data['EVT_wp_user'] != get_current_user_id()
1871
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1872
-            ) {
1873
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1874
-            }
1875
-        }
1876
-        // search query handling
1877
-        if (isset($this->_req_data['s'])) {
1878
-            $search_string = '%' . $this->_req_data['s'] . '%';
1879
-            $where['OR'] = array(
1880
-                'EVT_name'       => array('LIKE', $search_string),
1881
-                'EVT_desc'       => array('LIKE', $search_string),
1882
-                'EVT_short_desc' => array('LIKE', $search_string),
1883
-            );
1884
-        }
1885
-        // filter events by venue.
1886
-        if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
1887
-            $where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
1888
-        }
1889
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1890
-        $query_params = apply_filters(
1891
-            'FHEE__Events_Admin_Page__get_events__query_params',
1892
-            array(
1893
-                $where,
1894
-                'limit'    => $limit,
1895
-                'order_by' => $orderby,
1896
-                'order'    => $order,
1897
-                'group_by' => 'EVT_ID',
1898
-            ),
1899
-            $this->_req_data
1900
-        );
1901
-
1902
-        // let's first check if we have special requests coming in.
1903
-        if (isset($this->_req_data['active_status'])) {
1904
-            switch ($this->_req_data['active_status']) {
1905
-                case 'upcoming':
1906
-                    return $EEME->get_upcoming_events($query_params, $count);
1907
-                    break;
1908
-                case 'expired':
1909
-                    return $EEME->get_expired_events($query_params, $count);
1910
-                    break;
1911
-                case 'active':
1912
-                    return $EEME->get_active_events($query_params, $count);
1913
-                    break;
1914
-                case 'inactive':
1915
-                    return $EEME->get_inactive_events($query_params, $count);
1916
-                    break;
1917
-            }
1918
-        }
1919
-
1920
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1921
-        return $events;
1922
-    }
1923
-
1924
-
1925
-    /**
1926
-     * handling for WordPress CPT actions (trash, restore, delete)
1927
-     *
1928
-     * @param string $post_id
1929
-     */
1930
-    public function trash_cpt_item($post_id)
1931
-    {
1932
-        $this->_req_data['EVT_ID'] = $post_id;
1933
-        $this->_trash_or_restore_event('trash', false);
1934
-    }
1935
-
1936
-
1937
-    /**
1938
-     * @param string $post_id
1939
-     */
1940
-    public function restore_cpt_item($post_id)
1941
-    {
1942
-        $this->_req_data['EVT_ID'] = $post_id;
1943
-        $this->_trash_or_restore_event('draft', false);
1944
-    }
1945
-
1946
-
1947
-    /**
1948
-     * @param string $post_id
1949
-     */
1950
-    public function delete_cpt_item($post_id)
1951
-    {
1952
-        throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso'));
1953
-        $this->_req_data['EVT_ID'] = $post_id;
1954
-        $this->_delete_event();
1955
-    }
1956
-
1957
-
1958
-    /**
1959
-     * _trash_or_restore_event
1960
-     *
1961
-     * @access protected
1962
-     * @param  string $event_status
1963
-     * @param bool    $redirect_after
1964
-     */
1965
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1966
-    {
1967
-        // determine the event id and set to array.
1968
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1969
-        // loop thru events
1970
-        if ($EVT_ID) {
1971
-            // clean status
1972
-            $event_status = sanitize_key($event_status);
1973
-            // grab status
1974
-            if (! empty($event_status)) {
1975
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1976
-            } else {
1977
-                $success = false;
1978
-                $msg = esc_html__(
1979
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1980
-                    'event_espresso'
1981
-                );
1982
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1983
-            }
1984
-        } else {
1985
-            $success = false;
1986
-            $msg = esc_html__(
1987
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1988
-                'event_espresso'
1989
-            );
1990
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1991
-        }
1992
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1993
-        if ($redirect_after) {
1994
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1995
-        }
1996
-    }
1997
-
1998
-
1999
-    /**
2000
-     * _trash_or_restore_events
2001
-     *
2002
-     * @access protected
2003
-     * @param  string $event_status
2004
-     * @return void
2005
-     */
2006
-    protected function _trash_or_restore_events($event_status = 'trash')
2007
-    {
2008
-        // clean status
2009
-        $event_status = sanitize_key($event_status);
2010
-        // grab status
2011
-        if (! empty($event_status)) {
2012
-            $success = true;
2013
-            // determine the event id and set to array.
2014
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2015
-            // loop thru events
2016
-            foreach ($EVT_IDs as $EVT_ID) {
2017
-                if ($EVT_ID = absint($EVT_ID)) {
2018
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2019
-                    $success = $results !== false ? $success : false;
2020
-                } else {
2021
-                    $msg = sprintf(
2022
-                        esc_html__(
2023
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2024
-                            'event_espresso'
2025
-                        ),
2026
-                        $EVT_ID
2027
-                    );
2028
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2029
-                    $success = false;
2030
-                }
2031
-            }
2032
-        } else {
2033
-            $success = false;
2034
-            $msg = esc_html__(
2035
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2036
-                'event_espresso'
2037
-            );
2038
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2039
-        }
2040
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2041
-        $success = $success ? 2 : false;
2042
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2043
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2044
-    }
2045
-
2046
-
2047
-    /**
2048
-     * @param  int    $EVT_ID
2049
-     * @param  string $event_status
2050
-     * @return bool
2051
-     */
2052
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2053
-    {
2054
-        // grab event id
2055
-        if (! $EVT_ID) {
2056
-            $msg = esc_html__(
2057
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2058
-                'event_espresso'
2059
-            );
2060
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2061
-            return false;
2062
-        }
2063
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2064
-        // clean status
2065
-        $event_status = sanitize_key($event_status);
2066
-        // grab status
2067
-        if (empty($event_status)) {
2068
-            $msg = esc_html__(
2069
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2070
-                'event_espresso'
2071
-            );
2072
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2073
-            return false;
2074
-        }
2075
-        // was event trashed or restored ?
2076
-        switch ($event_status) {
2077
-            case 'draft':
2078
-                $action = 'restored from the trash';
2079
-                $hook = 'AHEE_event_restored_from_trash';
2080
-                break;
2081
-            case 'trash':
2082
-                $action = 'moved to the trash';
2083
-                $hook = 'AHEE_event_moved_to_trash';
2084
-                break;
2085
-            default:
2086
-                $action = 'updated';
2087
-                $hook = false;
2088
-        }
2089
-        // use class to change status
2090
-        $this->_cpt_model_obj->set_status($event_status);
2091
-        $success = $this->_cpt_model_obj->save();
2092
-        if (! $success) {
2093
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2094
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2095
-            return false;
2096
-        }
2097
-        if ($hook) {
2098
-            do_action($hook);
2099
-        }
2100
-        return true;
2101
-    }
2102
-
2103
-
2104
-    /**
2105
-     * @param array $event_ids
2106
-     * @return array
2107
-     * @since   $VID:$
2108
-     */
2109
-    private function cleanEventIds(array $event_ids)
2110
-    {
2111
-        return array_map('absint', $event_ids);
2112
-    }
2113
-
2114
-
2115
-    /**
2116
-     * @return array
2117
-     * @since   $VID:$
2118
-     */
2119
-    private function getEventIdsFromRequest()
2120
-    {
2121
-        $event_ids = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : [];
2122
-        $event_ids = is_string($event_ids) ? explode(',', $event_ids) : (array) $event_ids;
2123
-        return $this->cleanEventIds($event_ids);
2124
-    }
2125
-
2126
-
2127
-    /**
2128
-     * @param bool $preview_delete
2129
-     * @throws EE_Error
2130
-     */
2131
-    protected function _delete_event($preview_delete = true)
2132
-    {
2133
-        $this->_delete_events($preview_delete);
2134
-    }
2135
-
2136
-
2137
-    /**
2138
-     * Gets the tree traversal batch persister.
2139
-     * @since 4.10.12.p
2140
-     * @return NodeGroupDao
2141
-     * @throws InvalidArgumentException
2142
-     * @throws InvalidDataTypeException
2143
-     * @throws InvalidInterfaceException
2144
-     */
2145
-    protected function getModelObjNodeGroupPersister()
2146
-    {
2147
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2148
-            $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2149
-        }
2150
-        return $this->model_obj_node_group_persister;
2151
-    }
2152
-
2153
-
2154
-    /**
2155
-     * @param bool $preview_delete
2156
-     * @return void
2157
-     * @throws EE_Error
2158
-     */
2159
-    protected function _delete_events($preview_delete = true)
2160
-    {
2161
-        $event_ids = $this->getEventIdsFromRequest();
2162
-        if ($preview_delete) {
2163
-            $this->generateDeletionPreview($event_ids);
2164
-        } else {
2165
-            EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2166
-        }
2167
-    }
2168
-
2169
-
2170
-    /**
2171
-     * @param array $event_ids
2172
-     */
2173
-    protected function generateDeletionPreview(array $event_ids)
2174
-    {
2175
-        $event_ids = $this->cleanEventIds($event_ids);
2176
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2177
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2178
-        $return_url = EE_Admin_Page::add_query_args_and_nonce(
2179
-            [
2180
-                'action' => 'preview_deletion',
2181
-                'deletion_job_code' => $deletion_job_code,
2182
-            ],
2183
-            $this->_admin_base_url
2184
-        );
2185
-        EEH_URL::safeRedirectAndExit(
2186
-            EE_Admin_Page::add_query_args_and_nonce(
2187
-                [
2188
-                    'page'              => 'espresso_batch',
2189
-                    'batch'             => EED_Batch::batch_job,
2190
-                    'EVT_IDs'           => $event_ids,
2191
-                    'deletion_job_code' => $deletion_job_code,
2192
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2193
-                    'return_url'        => urlencode($return_url),
2194
-                ],
2195
-                admin_url()
2196
-            )
2197
-        );
2198
-    }
2199
-
2200
-    /**
2201
-     * Checks for a POST submission
2202
-     * @since 4.10.12.p
2203
-     */
2204
-    protected function confirmDeletion()
2205
-    {
2206
-        $deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2207
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2208
-    }
2209
-
2210
-    /**
2211
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2212
-     * @since 4.10.12.p
2213
-     * @throws EE_Error
2214
-     */
2215
-    protected function previewDeletion()
2216
-    {
2217
-        $preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2218
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2219
-        $this->display_admin_page_with_no_sidebar();
2220
-    }
2221
-
2222
-    /**
2223
-     * get total number of events
2224
-     *
2225
-     * @access public
2226
-     * @return int
2227
-     */
2228
-    public function total_events()
2229
-    {
2230
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2231
-        return $count;
2232
-    }
2233
-
2234
-
2235
-    /**
2236
-     * get total number of draft events
2237
-     *
2238
-     * @access public
2239
-     * @return int
2240
-     */
2241
-    public function total_events_draft()
2242
-    {
2243
-        $where = array(
2244
-            'status' => array('IN', array('draft', 'auto-draft')),
2245
-        );
2246
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2247
-        return $count;
2248
-    }
2249
-
2250
-
2251
-    /**
2252
-     * get total number of trashed events
2253
-     *
2254
-     * @access public
2255
-     * @return int
2256
-     */
2257
-    public function total_trashed_events()
2258
-    {
2259
-        $where = array(
2260
-            'status' => 'trash',
2261
-        );
2262
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2263
-        return $count;
2264
-    }
2265
-
2266
-
2267
-    /**
2268
-     *    _default_event_settings
2269
-     *    This generates the Default Settings Tab
2270
-     *
2271
-     * @return void
2272
-     * @throws EE_Error
2273
-     */
2274
-    protected function _default_event_settings()
2275
-    {
2276
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2277
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2278
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2279
-        $this->display_admin_page_with_sidebar();
2280
-    }
2281
-
2282
-
2283
-    /**
2284
-     * Return the form for event settings.
2285
-     *
2286
-     * @return EE_Form_Section_Proper
2287
-     * @throws EE_Error
2288
-     */
2289
-    protected function _default_event_settings_form()
2290
-    {
2291
-        $registration_config = EE_Registry::instance()->CFG->registration;
2292
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2293
-            // exclude
2294
-            array(
2295
-                EEM_Registration::status_id_cancelled,
2296
-                EEM_Registration::status_id_declined,
2297
-                EEM_Registration::status_id_incomplete,
2298
-                EEM_Registration::status_id_wait_list,
2299
-            ),
2300
-            true
2301
-        );
2302
-        return new EE_Form_Section_Proper(
2303
-            array(
2304
-                'name'            => 'update_default_event_settings',
2305
-                'html_id'         => 'update_default_event_settings',
2306
-                'html_class'      => 'form-table',
2307
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2308
-                'subsections'     => apply_filters(
2309
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2310
-                    array(
2311
-                        'default_reg_status'  => new EE_Select_Input(
2312
-                            $registration_stati_for_selection,
2313
-                            array(
2314
-                                'default'         => isset($registration_config->default_STS_ID)
2315
-                                                     && array_key_exists(
2316
-                                                         $registration_config->default_STS_ID,
2317
-                                                         $registration_stati_for_selection
2318
-                                                     )
2319
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2320
-                                    : EEM_Registration::status_id_pending_payment,
2321
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2322
-                                                     . EEH_Template::get_help_tab_link(
2323
-                                                         'default_settings_status_help_tab'
2324
-                                                     ),
2325
-                                'html_help_text'  => esc_html__(
2326
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2327
-                                    'event_espresso'
2328
-                                ),
2329
-                            )
2330
-                        ),
2331
-                        'default_max_tickets' => new EE_Integer_Input(
2332
-                            array(
2333
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2334
-                                    ? $registration_config->default_maximum_number_of_tickets
2335
-                                    : EEM_Event::get_default_additional_limit(),
2336
-                                'html_label_text' => esc_html__(
2337
-                                    'Default Maximum Tickets Allowed Per Order:',
2338
-                                    'event_espresso'
2339
-                                )
2340
-                                                     . EEH_Template::get_help_tab_link(
2341
-                                                         'default_maximum_tickets_help_tab"'
2342
-                                                     ),
2343
-                                'html_help_text'  => esc_html__(
2344
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2345
-                                    'event_espresso'
2346
-                                ),
2347
-                            )
2348
-                        ),
2349
-                    )
2350
-                ),
2351
-            )
2352
-        );
2353
-    }
2354
-
2355
-
2356
-    /**
2357
-     * _update_default_event_settings
2358
-     *
2359
-     * @access protected
2360
-     * @return void
2361
-     * @throws EE_Error
2362
-     */
2363
-    protected function _update_default_event_settings()
2364
-    {
2365
-        $registration_config = EE_Registry::instance()->CFG->registration;
2366
-        $form = $this->_default_event_settings_form();
2367
-        if ($form->was_submitted()) {
2368
-            $form->receive_form_submission();
2369
-            if ($form->is_valid()) {
2370
-                $valid_data = $form->valid_data();
2371
-                if (isset($valid_data['default_reg_status'])) {
2372
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2373
-                }
2374
-                if (isset($valid_data['default_max_tickets'])) {
2375
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2376
-                }
2377
-                // update because data was valid!
2378
-                EE_Registry::instance()->CFG->update_espresso_config();
2379
-                EE_Error::overwrite_success();
2380
-                EE_Error::add_success(
2381
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2382
-                );
2383
-            }
2384
-        }
2385
-        $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2386
-    }
2387
-
2388
-
2389
-    /*************        Templates        *************/
2390
-    protected function _template_settings()
2391
-    {
2392
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2393
-        $this->_template_args['preview_img'] = '<img src="'
2394
-                                               . EVENTS_ASSETS_URL
2395
-                                               . '/images/'
2396
-                                               . 'caffeinated_template_features.jpg" alt="'
2397
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2398
-                                               . '" />';
2399
-        $this->_template_args['preview_text'] = '<strong>'
2400
-                                                . esc_html__(
2401
-                                                    'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2402
-                                                    'event_espresso'
2403
-                                                ) . '</strong>';
2404
-        $this->display_admin_caf_preview_page('template_settings_tab');
2405
-    }
2406
-
2407
-
2408
-    /** Event Category Stuff **/
2409
-    /**
2410
-     * set the _category property with the category object for the loaded page.
2411
-     *
2412
-     * @access private
2413
-     * @return void
2414
-     */
2415
-    private function _set_category_object()
2416
-    {
2417
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2418
-            return;
2419
-        } //already have the category object so get out.
2420
-        // set default category object
2421
-        $this->_set_empty_category_object();
2422
-        // only set if we've got an id
2423
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2424
-            return;
2425
-        }
2426
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2427
-        $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2428
-        if (! empty($term)) {
2429
-            $this->_category->category_name = $term->name;
2430
-            $this->_category->category_identifier = $term->slug;
2431
-            $this->_category->category_desc = $term->description;
2432
-            $this->_category->id = $term->term_id;
2433
-            $this->_category->parent = $term->parent;
2434
-        }
2435
-    }
2436
-
2437
-
2438
-    /**
2439
-     * Clears out category properties.
2440
-     */
2441
-    private function _set_empty_category_object()
2442
-    {
2443
-        $this->_category = new stdClass();
2444
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2445
-        $this->_category->id = $this->_category->parent = 0;
2446
-    }
2447
-
2448
-
2449
-    /**
2450
-     * @throws EE_Error
2451
-     */
2452
-    protected function _category_list_table()
2453
-    {
2454
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2455
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2456
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2457
-            'add_category',
2458
-            'add_category',
2459
-            array(),
2460
-            'add-new-h2'
2461
-        );
2462
-        $this->display_admin_list_table_page_with_sidebar();
2463
-    }
2464
-
2465
-
2466
-    /**
2467
-     * Output category details view.
2468
-     */
2469
-    protected function _category_details($view)
2470
-    {
2471
-        // load formatter helper
2472
-        // load field generator helper
2473
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2474
-        $this->_set_add_edit_form_tags($route);
2475
-        $this->_set_category_object();
2476
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2477
-        $delete_action = 'delete_category';
2478
-        // custom redirect
2479
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2480
-            array('action' => 'category_list'),
2481
-            $this->_admin_base_url
2482
-        );
2483
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2484
-        // take care of contents
2485
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2486
-        $this->display_admin_page_with_sidebar();
2487
-    }
2488
-
2489
-
2490
-    /**
2491
-     * Output category details content.
2492
-     */
2493
-    protected function _category_details_content()
2494
-    {
2495
-        $editor_args['category_desc'] = array(
2496
-            'type'          => 'wp_editor',
2497
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2498
-            'class'         => 'my_editor_custom',
2499
-            'wpeditor_args' => array('media_buttons' => false),
2500
-        );
2501
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2502
-        $all_terms = get_terms(
2503
-            array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),
2504
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2505
-        );
2506
-        // setup category select for term parents.
2507
-        $category_select_values[] = array(
2508
-            'text' => esc_html__('No Parent', 'event_espresso'),
2509
-            'id'   => 0,
2510
-        );
2511
-        foreach ($all_terms as $term) {
2512
-            $category_select_values[] = array(
2513
-                'text' => $term->name,
2514
-                'id'   => $term->term_id,
2515
-            );
2516
-        }
2517
-        $category_select = EEH_Form_Fields::select_input(
2518
-            'category_parent',
2519
-            $category_select_values,
2520
-            $this->_category->parent
2521
-        );
2522
-        $template_args = array(
2523
-            'category'                 => $this->_category,
2524
-            'category_select'          => $category_select,
2525
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2526
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2527
-            'disable'                  => '',
2528
-            'disabled_message'         => false,
2529
-        );
2530
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2531
-        return EEH_Template::display_template($template, $template_args, true);
2532
-    }
2533
-
2534
-
2535
-    /**
2536
-     * Handles deleting categories.
2537
-     */
2538
-    protected function _delete_categories()
2539
-    {
2540
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2541
-            : (array) $this->_req_data['category_id'];
2542
-        foreach ($cat_ids as $cat_id) {
2543
-            $this->_delete_category($cat_id);
2544
-        }
2545
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2546
-        $query_args = array(
2547
-            'action' => 'category_list',
2548
-        );
2549
-        $this->_redirect_after_action(0, '', '', $query_args);
2550
-    }
2551
-
2552
-
2553
-    /**
2554
-     * Handles deleting specific category.
2555
-     *
2556
-     * @param int $cat_id
2557
-     */
2558
-    protected function _delete_category($cat_id)
2559
-    {
2560
-        $cat_id = absint($cat_id);
2561
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2562
-    }
2563
-
2564
-
2565
-    /**
2566
-     * Handles triggering the update or insertion of a new category.
2567
-     *
2568
-     * @param bool $new_category true means we're triggering the insert of a new category.
2569
-     */
2570
-    protected function _insert_or_update_category($new_category)
2571
-    {
2572
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2573
-        $success = 0; // we already have a success message so lets not send another.
2574
-        if ($cat_id) {
2575
-            $query_args = array(
2576
-                'action'     => 'edit_category',
2577
-                'EVT_CAT_ID' => $cat_id,
2578
-            );
2579
-        } else {
2580
-            $query_args = array('action' => 'add_category');
2581
-        }
2582
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2583
-    }
2584
-
2585
-
2586
-    /**
2587
-     * Inserts or updates category
2588
-     *
2589
-     * @param bool $update (true indicates we're updating a category).
2590
-     * @return bool|mixed|string
2591
-     */
2592
-    private function _insert_category($update = false)
2593
-    {
2594
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2595
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2596
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2597
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2598
-        if (empty($category_name)) {
2599
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2600
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2601
-            return false;
2602
-        }
2603
-        $term_args = array(
2604
-            'name'        => $category_name,
2605
-            'description' => $category_desc,
2606
-            'parent'      => $category_parent,
2607
-        );
2608
-        // was the category_identifier input disabled?
2609
-        if (isset($this->_req_data['category_identifier'])) {
2610
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2611
-        }
2612
-        $insert_ids = $update
2613
-            ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2614
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2615
-        if (! is_array($insert_ids)) {
2616
-            $msg = esc_html__(
2617
-                'An error occurred and the category has not been saved to the database.',
2618
-                'event_espresso'
2619
-            );
2620
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2621
-        } else {
2622
-            $cat_id = $insert_ids['term_id'];
2623
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2624
-            EE_Error::add_success($msg);
2625
-        }
2626
-        return $cat_id;
2627
-    }
2628
-
2629
-
2630
-    /**
2631
-     * Gets categories or count of categories matching the arguments in the request.
2632
-     *
2633
-     * @param int  $per_page
2634
-     * @param int  $current_page
2635
-     * @param bool $count
2636
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2637
-     */
2638
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2639
-    {
2640
-        // testing term stuff
2641
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2642
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2643
-        $limit = ($current_page - 1) * $per_page;
2644
-        $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2645
-        if (isset($this->_req_data['s'])) {
2646
-            $sstr = '%' . $this->_req_data['s'] . '%';
2647
-            $where['OR'] = array(
2648
-                'Term.name'   => array('LIKE', $sstr),
2649
-                'description' => array('LIKE', $sstr),
2650
-            );
2651
-        }
2652
-        $query_params = array(
2653
-            $where,
2654
-            'order_by'   => array($orderby => $order),
2655
-            'limit'      => $limit . ',' . $per_page,
2656
-            'force_join' => array('Term'),
2657
-        );
2658
-        $categories = $count
2659
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2660
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2661
-        return $categories;
2662
-    }
2663
-
2664
-    /* end category stuff */
2665
-    /**************/
2666
-
2667
-
2668
-    /**
2669
-     * Callback for the `ee_save_timezone_setting` ajax action.
2670
-     *
2671
-     * @throws EE_Error
2672
-     */
2673
-    public function save_timezonestring_setting()
2674
-    {
2675
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2676
-            ? $this->_req_data['timezone_selected']
2677
-            : '';
2678
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2679
-            EE_Error::add_error(
2680
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2681
-                __FILE__,
2682
-                __FUNCTION__,
2683
-                __LINE__
2684
-            );
2685
-            $this->_template_args['error'] = true;
2686
-            $this->_return_json();
2687
-        }
2688
-
2689
-        update_option('timezone_string', $timezone_string);
2690
-        EE_Error::add_success(
2691
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2692
-        );
2693
-        $this->_template_args['success'] = true;
2694
-        $this->_return_json(true, array('action' => 'create_new'));
2695
-    }
22
+	/**
23
+	 * This will hold the event object for event_details screen.
24
+	 *
25
+	 * @var EE_Event $_event
26
+	 */
27
+	protected $_event;
28
+
29
+
30
+	/**
31
+	 * This will hold the category object for category_details screen.
32
+	 *
33
+	 * @var stdClass $_category
34
+	 */
35
+	protected $_category;
36
+
37
+
38
+	/**
39
+	 * This will hold the event model instance
40
+	 *
41
+	 * @var EEM_Event $_event_model
42
+	 */
43
+	protected $_event_model;
44
+
45
+
46
+	/**
47
+	 * @var EE_Event
48
+	 */
49
+	protected $_cpt_model_obj = false;
50
+
51
+
52
+	/**
53
+	 * @var NodeGroupDao
54
+	 */
55
+	protected $model_obj_node_group_persister;
56
+
57
+	/**
58
+	 * Initialize page props for this admin page group.
59
+	 */
60
+	protected function _init_page_props()
61
+	{
62
+		$this->page_slug = EVENTS_PG_SLUG;
63
+		$this->page_label = EVENTS_LABEL;
64
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
65
+		$this->_admin_base_path = EVENTS_ADMIN;
66
+		$this->_cpt_model_names = array(
67
+			'create_new' => 'EEM_Event',
68
+			'edit'       => 'EEM_Event',
69
+		);
70
+		$this->_cpt_edit_routes = array(
71
+			'espresso_events' => 'edit',
72
+		);
73
+		add_action(
74
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
75
+			array($this, 'verify_event_edit'),
76
+			10,
77
+			2
78
+		);
79
+	}
80
+
81
+
82
+	/**
83
+	 * Sets the ajax hooks used for this admin page group.
84
+	 */
85
+	protected function _ajax_hooks()
86
+	{
87
+		add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
88
+	}
89
+
90
+
91
+	/**
92
+	 * Sets the page properties for this admin page group.
93
+	 */
94
+	protected function _define_page_props()
95
+	{
96
+		$this->_admin_page_title = EVENTS_LABEL;
97
+		$this->_labels = array(
98
+			'buttons'      => array(
99
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
100
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
101
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
102
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
103
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
104
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
105
+			),
106
+			'editor_title' => array(
107
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
108
+			),
109
+			'publishbox'   => array(
110
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
111
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
112
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
113
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
114
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
115
+			),
116
+		);
117
+	}
118
+
119
+
120
+	/**
121
+	 * Sets the page routes property for this admin page group.
122
+	 */
123
+	protected function _set_page_routes()
124
+	{
125
+		// load formatter helper
126
+		// load field generator helper
127
+		// is there a evt_id in the request?
128
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
129
+			? $this->_req_data['EVT_ID']
130
+			: 0;
131
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
132
+		$this->_page_routes = array(
133
+			'default'                       => array(
134
+				'func'       => '_events_overview_list_table',
135
+				'capability' => 'ee_read_events',
136
+			),
137
+			'create_new'                    => array(
138
+				'func'       => '_create_new_cpt_item',
139
+				'capability' => 'ee_edit_events',
140
+			),
141
+			'edit'                          => array(
142
+				'func'       => '_edit_cpt_item',
143
+				'capability' => 'ee_edit_event',
144
+				'obj_id'     => $evt_id,
145
+			),
146
+			'copy_event'                    => array(
147
+				'func'       => '_copy_events',
148
+				'capability' => 'ee_edit_event',
149
+				'obj_id'     => $evt_id,
150
+				'noheader'   => true,
151
+			),
152
+			'trash_event'                   => array(
153
+				'func'       => '_trash_or_restore_event',
154
+				'args'       => array('event_status' => 'trash'),
155
+				'capability' => 'ee_delete_event',
156
+				'obj_id'     => $evt_id,
157
+				'noheader'   => true,
158
+			),
159
+			'trash_events'                  => array(
160
+				'func'       => '_trash_or_restore_events',
161
+				'args'       => array('event_status' => 'trash'),
162
+				'capability' => 'ee_delete_events',
163
+				'noheader'   => true,
164
+			),
165
+			'restore_event'                 => array(
166
+				'func'       => '_trash_or_restore_event',
167
+				'args'       => array('event_status' => 'draft'),
168
+				'capability' => 'ee_delete_event',
169
+				'obj_id'     => $evt_id,
170
+				'noheader'   => true,
171
+			),
172
+			'restore_events'                => array(
173
+				'func'       => '_trash_or_restore_events',
174
+				'args'       => array('event_status' => 'draft'),
175
+				'capability' => 'ee_delete_events',
176
+				'noheader'   => true,
177
+			),
178
+			'delete_event'                  => array(
179
+				'func'       => '_delete_event',
180
+				'capability' => 'ee_delete_event',
181
+				'obj_id'     => $evt_id,
182
+				'noheader'   => true,
183
+			),
184
+			'delete_events'                 => array(
185
+				'func'       => '_delete_events',
186
+				'capability' => 'ee_delete_events',
187
+				'noheader'   => true,
188
+			),
189
+			'view_report'                   => array(
190
+				'func'      => '_view_report',
191
+				'capablity' => 'ee_edit_events',
192
+			),
193
+			'default_event_settings'        => array(
194
+				'func'       => '_default_event_settings',
195
+				'capability' => 'manage_options',
196
+			),
197
+			'update_default_event_settings' => array(
198
+				'func'       => '_update_default_event_settings',
199
+				'capability' => 'manage_options',
200
+				'noheader'   => true,
201
+			),
202
+			'template_settings'             => array(
203
+				'func'       => '_template_settings',
204
+				'capability' => 'manage_options',
205
+			),
206
+			// event category tab related
207
+			'add_category'                  => array(
208
+				'func'       => '_category_details',
209
+				'capability' => 'ee_edit_event_category',
210
+				'args'       => array('add'),
211
+			),
212
+			'edit_category'                 => array(
213
+				'func'       => '_category_details',
214
+				'capability' => 'ee_edit_event_category',
215
+				'args'       => array('edit'),
216
+			),
217
+			'delete_categories'             => array(
218
+				'func'       => '_delete_categories',
219
+				'capability' => 'ee_delete_event_category',
220
+				'noheader'   => true,
221
+			),
222
+			'delete_category'               => array(
223
+				'func'       => '_delete_categories',
224
+				'capability' => 'ee_delete_event_category',
225
+				'noheader'   => true,
226
+			),
227
+			'insert_category'               => array(
228
+				'func'       => '_insert_or_update_category',
229
+				'args'       => array('new_category' => true),
230
+				'capability' => 'ee_edit_event_category',
231
+				'noheader'   => true,
232
+			),
233
+			'update_category'               => array(
234
+				'func'       => '_insert_or_update_category',
235
+				'args'       => array('new_category' => false),
236
+				'capability' => 'ee_edit_event_category',
237
+				'noheader'   => true,
238
+			),
239
+			'category_list'                 => array(
240
+				'func'       => '_category_list_table',
241
+				'capability' => 'ee_manage_event_categories',
242
+			),
243
+			'preview_deletion' => [
244
+				'func' => 'previewDeletion',
245
+				'capability' => 'ee_delete_events',
246
+			],
247
+			'confirm_deletion' => [
248
+				'func' => 'confirmDeletion',
249
+				'capability' => 'ee_delete_events',
250
+				'noheader' => true,
251
+			]
252
+		);
253
+	}
254
+
255
+
256
+	/**
257
+	 * Set the _page_config property for this admin page group.
258
+	 */
259
+	protected function _set_page_config()
260
+	{
261
+		$this->_page_config = array(
262
+			'default'                => array(
263
+				'nav'           => array(
264
+					'label' => esc_html__('Overview', 'event_espresso'),
265
+					'order' => 10,
266
+				),
267
+				'list_table'    => 'Events_Admin_List_Table',
268
+				'help_tabs'     => array(
269
+					'events_overview_help_tab'                       => array(
270
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
271
+						'filename' => 'events_overview',
272
+					),
273
+					'events_overview_table_column_headings_help_tab' => array(
274
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
275
+						'filename' => 'events_overview_table_column_headings',
276
+					),
277
+					'events_overview_filters_help_tab'               => array(
278
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
279
+						'filename' => 'events_overview_filters',
280
+					),
281
+					'events_overview_view_help_tab'                  => array(
282
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
283
+						'filename' => 'events_overview_views',
284
+					),
285
+					'events_overview_other_help_tab'                 => array(
286
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
287
+						'filename' => 'events_overview_other',
288
+					),
289
+				),
290
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
291
+				// 'help_tour'     => array(
292
+				//     'Event_Overview_Help_Tour',
293
+				//     // 'New_Features_Test_Help_Tour' for testing multiple help tour
294
+				// ),
295
+				'qtips'         => array(
296
+					'EE_Event_List_Table_Tips',
297
+				),
298
+				'require_nonce' => false,
299
+			),
300
+			'create_new'             => array(
301
+				'nav'           => array(
302
+					'label'      => esc_html__('Add Event', 'event_espresso'),
303
+					'order'      => 5,
304
+					'persistent' => false,
305
+				),
306
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
307
+				'help_tabs'     => array(
308
+					'event_editor_help_tab'                            => array(
309
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
310
+						'filename' => 'event_editor',
311
+					),
312
+					'event_editor_title_richtexteditor_help_tab'       => array(
313
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
314
+						'filename' => 'event_editor_title_richtexteditor',
315
+					),
316
+					'event_editor_venue_details_help_tab'              => array(
317
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
318
+						'filename' => 'event_editor_venue_details',
319
+					),
320
+					'event_editor_event_datetimes_help_tab'            => array(
321
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
322
+						'filename' => 'event_editor_event_datetimes',
323
+					),
324
+					'event_editor_event_tickets_help_tab'              => array(
325
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
326
+						'filename' => 'event_editor_event_tickets',
327
+					),
328
+					'event_editor_event_registration_options_help_tab' => array(
329
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
330
+						'filename' => 'event_editor_event_registration_options',
331
+					),
332
+					'event_editor_tags_categories_help_tab'            => array(
333
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
334
+						'filename' => 'event_editor_tags_categories',
335
+					),
336
+					'event_editor_questions_registrants_help_tab'      => array(
337
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
338
+						'filename' => 'event_editor_questions_registrants',
339
+					),
340
+					'event_editor_save_new_event_help_tab'             => array(
341
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
342
+						'filename' => 'event_editor_save_new_event',
343
+					),
344
+					'event_editor_other_help_tab'                      => array(
345
+						'title'    => esc_html__('Event Other', 'event_espresso'),
346
+						'filename' => 'event_editor_other',
347
+					),
348
+				),
349
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
350
+				// 'help_tour'     => array(
351
+				//     'Event_Editor_Help_Tour',
352
+				// ),
353
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
354
+				'require_nonce' => false,
355
+			),
356
+			'edit'                   => array(
357
+				'nav'           => array(
358
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
359
+					'order'      => 5,
360
+					'persistent' => false,
361
+					'url'        => isset($this->_req_data['post'])
362
+						? EE_Admin_Page::add_query_args_and_nonce(
363
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
364
+							$this->_current_page_view_url
365
+						)
366
+						: $this->_admin_base_url,
367
+				),
368
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
369
+				'help_tabs'     => array(
370
+					'event_editor_help_tab'                            => array(
371
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
372
+						'filename' => 'event_editor',
373
+					),
374
+					'event_editor_title_richtexteditor_help_tab'       => array(
375
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
376
+						'filename' => 'event_editor_title_richtexteditor',
377
+					),
378
+					'event_editor_venue_details_help_tab'              => array(
379
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
380
+						'filename' => 'event_editor_venue_details',
381
+					),
382
+					'event_editor_event_datetimes_help_tab'            => array(
383
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
384
+						'filename' => 'event_editor_event_datetimes',
385
+					),
386
+					'event_editor_event_tickets_help_tab'              => array(
387
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
388
+						'filename' => 'event_editor_event_tickets',
389
+					),
390
+					'event_editor_event_registration_options_help_tab' => array(
391
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
392
+						'filename' => 'event_editor_event_registration_options',
393
+					),
394
+					'event_editor_tags_categories_help_tab'            => array(
395
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
396
+						'filename' => 'event_editor_tags_categories',
397
+					),
398
+					'event_editor_questions_registrants_help_tab'      => array(
399
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
400
+						'filename' => 'event_editor_questions_registrants',
401
+					),
402
+					'event_editor_save_new_event_help_tab'             => array(
403
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
404
+						'filename' => 'event_editor_save_new_event',
405
+					),
406
+					'event_editor_other_help_tab'                      => array(
407
+						'title'    => esc_html__('Event Other', 'event_espresso'),
408
+						'filename' => 'event_editor_other',
409
+					),
410
+				),
411
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
412
+				'require_nonce' => false,
413
+			),
414
+			'default_event_settings' => array(
415
+				'nav'           => array(
416
+					'label' => esc_html__('Default Settings', 'event_espresso'),
417
+					'order' => 40,
418
+				),
419
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
420
+				'labels'        => array(
421
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
422
+				),
423
+				'help_tabs'     => array(
424
+					'default_settings_help_tab'        => array(
425
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
426
+						'filename' => 'events_default_settings',
427
+					),
428
+					'default_settings_status_help_tab' => array(
429
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
430
+						'filename' => 'events_default_settings_status',
431
+					),
432
+					'default_maximum_tickets_help_tab' => array(
433
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
434
+						'filename' => 'events_default_settings_max_tickets',
435
+					),
436
+				),
437
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
438
+				// 'help_tour'     => array('Event_Default_Settings_Help_Tour'),
439
+				'require_nonce' => false,
440
+			),
441
+			// template settings
442
+			'template_settings'      => array(
443
+				'nav'           => array(
444
+					'label' => esc_html__('Templates', 'event_espresso'),
445
+					'order' => 30,
446
+				),
447
+				'metaboxes'     => $this->_default_espresso_metaboxes,
448
+				'help_tabs'     => array(
449
+					'general_settings_templates_help_tab' => array(
450
+						'title'    => esc_html__('Templates', 'event_espresso'),
451
+						'filename' => 'general_settings_templates',
452
+					),
453
+				),
454
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
455
+				// 'help_tour'     => array('Templates_Help_Tour'),
456
+				'require_nonce' => false,
457
+			),
458
+			// event category stuff
459
+			'add_category'           => array(
460
+				'nav'           => array(
461
+					'label'      => esc_html__('Add Category', 'event_espresso'),
462
+					'order'      => 15,
463
+					'persistent' => false,
464
+				),
465
+				'help_tabs'     => array(
466
+					'add_category_help_tab' => array(
467
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
468
+						'filename' => 'events_add_category',
469
+					),
470
+				),
471
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
472
+				// 'help_tour'     => array('Event_Add_Category_Help_Tour'),
473
+				'metaboxes'     => array('_publish_post_box'),
474
+				'require_nonce' => false,
475
+			),
476
+			'edit_category'          => array(
477
+				'nav'           => array(
478
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
479
+					'order'      => 15,
480
+					'persistent' => false,
481
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
482
+						? add_query_arg(
483
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
484
+							$this->_current_page_view_url
485
+						)
486
+						: $this->_admin_base_url,
487
+				),
488
+				'help_tabs'     => array(
489
+					'edit_category_help_tab' => array(
490
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
491
+						'filename' => 'events_edit_category',
492
+					),
493
+				),
494
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
495
+				'metaboxes'     => array('_publish_post_box'),
496
+				'require_nonce' => false,
497
+			),
498
+			'category_list'          => array(
499
+				'nav'           => array(
500
+					'label' => esc_html__('Categories', 'event_espresso'),
501
+					'order' => 20,
502
+				),
503
+				'list_table'    => 'Event_Categories_Admin_List_Table',
504
+				'help_tabs'     => array(
505
+					'events_categories_help_tab'                       => array(
506
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
507
+						'filename' => 'events_categories',
508
+					),
509
+					'events_categories_table_column_headings_help_tab' => array(
510
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
511
+						'filename' => 'events_categories_table_column_headings',
512
+					),
513
+					'events_categories_view_help_tab'                  => array(
514
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
515
+						'filename' => 'events_categories_views',
516
+					),
517
+					'events_categories_other_help_tab'                 => array(
518
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
519
+						'filename' => 'events_categories_other',
520
+					),
521
+				),
522
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
523
+				// 'help_tour'     => array(
524
+				//     'Event_Categories_Help_Tour',
525
+				// ),
526
+				'metaboxes'     => $this->_default_espresso_metaboxes,
527
+				'require_nonce' => false,
528
+			),
529
+			'preview_deletion'           => array(
530
+				'nav'           => array(
531
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
532
+					'order'      => 15,
533
+					'persistent' => false,
534
+					'url'        => '',
535
+				),
536
+				'require_nonce' => false
537
+			)
538
+		);
539
+	}
540
+
541
+
542
+	/**
543
+	 * Used to register any global screen options if necessary for every route in this admin page group.
544
+	 */
545
+	protected function _add_screen_options()
546
+	{
547
+	}
548
+
549
+
550
+	/**
551
+	 * Implementing the screen options for the 'default' route.
552
+	 */
553
+	protected function _add_screen_options_default()
554
+	{
555
+		$this->_per_page_screen_option();
556
+	}
557
+
558
+
559
+	/**
560
+	 * Implementing screen options for the category list route.
561
+	 */
562
+	protected function _add_screen_options_category_list()
563
+	{
564
+		$page_title = $this->_admin_page_title;
565
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
566
+		$this->_per_page_screen_option();
567
+		$this->_admin_page_title = $page_title;
568
+	}
569
+
570
+
571
+	/**
572
+	 * Used to register any global feature pointers for the admin page group.
573
+	 */
574
+	protected function _add_feature_pointers()
575
+	{
576
+	}
577
+
578
+
579
+	/**
580
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
581
+	 */
582
+	public function load_scripts_styles()
583
+	{
584
+		wp_register_style(
585
+			'events-admin-css',
586
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
587
+			array(),
588
+			EVENT_ESPRESSO_VERSION
589
+		);
590
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
591
+		wp_enqueue_style('events-admin-css');
592
+		wp_enqueue_style('ee-cat-admin');
593
+		// todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
594
+		// registers for all views
595
+		// scripts
596
+		wp_register_script(
597
+			'event_editor_js',
598
+			EVENTS_ASSETS_URL . 'event_editor.js',
599
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
600
+			EVENT_ESPRESSO_VERSION,
601
+			true
602
+		);
603
+	}
604
+
605
+
606
+	/**
607
+	 * Enqueuing scripts and styles specific to this view
608
+	 */
609
+	public function load_scripts_styles_create_new()
610
+	{
611
+		$this->load_scripts_styles_edit();
612
+	}
613
+
614
+
615
+	/**
616
+	 * Enqueuing scripts and styles specific to this view
617
+	 */
618
+	public function load_scripts_styles_edit()
619
+	{
620
+		// styles
621
+		wp_enqueue_style('espresso-ui-theme');
622
+		wp_register_style(
623
+			'event-editor-css',
624
+			EVENTS_ASSETS_URL . 'event-editor.css',
625
+			array('ee-admin-css'),
626
+			EVENT_ESPRESSO_VERSION
627
+		);
628
+		wp_enqueue_style('event-editor-css');
629
+		// scripts
630
+		wp_register_script(
631
+			'event-datetime-metabox',
632
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
633
+			array('event_editor_js', 'ee-datepicker'),
634
+			EVENT_ESPRESSO_VERSION
635
+		);
636
+		wp_enqueue_script('event-datetime-metabox');
637
+	}
638
+
639
+
640
+	/**
641
+	 * Populating the _views property for the category list table view.
642
+	 */
643
+	protected function _set_list_table_views_category_list()
644
+	{
645
+		$this->_views = array(
646
+			'all' => array(
647
+				'slug'        => 'all',
648
+				'label'       => esc_html__('All', 'event_espresso'),
649
+				'count'       => 0,
650
+				'bulk_action' => array(
651
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
652
+				),
653
+			),
654
+		);
655
+	}
656
+
657
+
658
+	/**
659
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
660
+	 */
661
+	public function admin_init()
662
+	{
663
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
664
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
665
+			'event_espresso'
666
+		);
667
+	}
668
+
669
+
670
+	/**
671
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
672
+	 * group.
673
+	 */
674
+	public function admin_notices()
675
+	{
676
+	}
677
+
678
+
679
+	/**
680
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
681
+	 * this admin page group.
682
+	 */
683
+	public function admin_footer_scripts()
684
+	{
685
+	}
686
+
687
+
688
+	/**
689
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
690
+	 * warning (via EE_Error::add_error());
691
+	 *
692
+	 * @param  EE_Event $event Event object
693
+	 * @param string    $req_type
694
+	 * @return void
695
+	 * @throws EE_Error
696
+	 * @access public
697
+	 */
698
+	public function verify_event_edit($event = null, $req_type = '')
699
+	{
700
+		// don't need to do this when processing
701
+		if (! empty($req_type)) {
702
+			return;
703
+		}
704
+		// no event?
705
+		if (empty($event)) {
706
+			// set event
707
+			$event = $this->_cpt_model_obj;
708
+		}
709
+		// STILL no event?
710
+		if (! $event instanceof EE_Event) {
711
+			return;
712
+		}
713
+		$orig_status = $event->status();
714
+		// first check if event is active.
715
+		if (
716
+			$orig_status === EEM_Event::cancelled
717
+			|| $orig_status === EEM_Event::postponed
718
+			|| $event->is_expired()
719
+			|| $event->is_inactive()
720
+		) {
721
+			return;
722
+		}
723
+		// made it here so it IS active... next check that any of the tickets are sold.
724
+		if ($event->is_sold_out(true)) {
725
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
726
+				EE_Error::add_attention(
727
+					sprintf(
728
+						esc_html__(
729
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
730
+							'event_espresso'
731
+						),
732
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
733
+					)
734
+				);
735
+			}
736
+			return;
737
+		} elseif ($orig_status === EEM_Event::sold_out) {
738
+			EE_Error::add_attention(
739
+				sprintf(
740
+					esc_html__(
741
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
742
+						'event_espresso'
743
+					),
744
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
745
+				)
746
+			);
747
+		}
748
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
749
+		if (! $event->tickets_on_sale()) {
750
+			return;
751
+		}
752
+		// made it here so show warning
753
+		$this->_edit_event_warning();
754
+	}
755
+
756
+
757
+	/**
758
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
759
+	 * When needed, hook this into a EE_Error::add_error() notice.
760
+	 *
761
+	 * @access protected
762
+	 * @return void
763
+	 */
764
+	protected function _edit_event_warning()
765
+	{
766
+		// we don't want to add warnings during these requests
767
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
768
+			return;
769
+		}
770
+		EE_Error::add_attention(
771
+			sprintf(
772
+				esc_html__(
773
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
774
+					'event_espresso'
775
+				),
776
+				'<a class="espresso-help-tab-lnk">',
777
+				'</a>'
778
+			)
779
+		);
780
+	}
781
+
782
+
783
+	/**
784
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
785
+	 * Otherwise, do the normal logic
786
+	 *
787
+	 * @return string
788
+	 * @throws \EE_Error
789
+	 */
790
+	protected function _create_new_cpt_item()
791
+	{
792
+		$has_timezone_string = get_option('timezone_string');
793
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
794
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
795
+			EE_Error::add_attention(
796
+				sprintf(
797
+					esc_html__(
798
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
799
+						'event_espresso'
800
+					),
801
+					'<br>',
802
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
803
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
804
+					. '</select>',
805
+					'<button class="button button-secondary timezone-submit">',
806
+					'</button><span class="spinner"></span>'
807
+				),
808
+				__FILE__,
809
+				__FUNCTION__,
810
+				__LINE__
811
+			);
812
+		}
813
+		return parent::_create_new_cpt_item();
814
+	}
815
+
816
+
817
+	/**
818
+	 * Sets the _views property for the default route in this admin page group.
819
+	 */
820
+	protected function _set_list_table_views_default()
821
+	{
822
+		$this->_views = array(
823
+			'all'   => array(
824
+				'slug'        => 'all',
825
+				'label'       => esc_html__('View All Events', 'event_espresso'),
826
+				'count'       => 0,
827
+				'bulk_action' => array(
828
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
829
+				),
830
+			),
831
+			'draft' => array(
832
+				'slug'        => 'draft',
833
+				'label'       => esc_html__('Draft', 'event_espresso'),
834
+				'count'       => 0,
835
+				'bulk_action' => array(
836
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
837
+				),
838
+			),
839
+		);
840
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
841
+			$this->_views['trash'] = array(
842
+				'slug'        => 'trash',
843
+				'label'       => esc_html__('Trash', 'event_espresso'),
844
+				'count'       => 0,
845
+				'bulk_action' => array(
846
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
847
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
848
+				),
849
+			);
850
+		}
851
+	}
852
+
853
+
854
+	/**
855
+	 * Provides the legend item array for the default list table view.
856
+	 *
857
+	 * @return array
858
+	 */
859
+	protected function _event_legend_items()
860
+	{
861
+		$items = array(
862
+			'view_details'   => array(
863
+				'class' => 'dashicons dashicons-search',
864
+				'desc'  => esc_html__('View Event', 'event_espresso'),
865
+			),
866
+			'edit_event'     => array(
867
+				'class' => 'ee-icon ee-icon-calendar-edit',
868
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
869
+			),
870
+			'view_attendees' => array(
871
+				'class' => 'dashicons dashicons-groups',
872
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
873
+			),
874
+		);
875
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
876
+		$statuses = array(
877
+			'sold_out_status'  => array(
878
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
879
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
880
+			),
881
+			'active_status'    => array(
882
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
883
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
884
+			),
885
+			'upcoming_status'  => array(
886
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
887
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
888
+			),
889
+			'postponed_status' => array(
890
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
891
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
892
+			),
893
+			'cancelled_status' => array(
894
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
895
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
896
+			),
897
+			'expired_status'   => array(
898
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
899
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
900
+			),
901
+			'inactive_status'  => array(
902
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
903
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
904
+			),
905
+		);
906
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
907
+		return array_merge($items, $statuses);
908
+	}
909
+
910
+
911
+	/**
912
+	 * @return EEM_Event
913
+	 */
914
+	private function _event_model()
915
+	{
916
+		if (! $this->_event_model instanceof EEM_Event) {
917
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
918
+		}
919
+		return $this->_event_model;
920
+	}
921
+
922
+
923
+	/**
924
+	 * Adds extra buttons to the WP CPT permalink field row.
925
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
926
+	 *
927
+	 * @param  string $return    the current html
928
+	 * @param  int    $id        the post id for the page
929
+	 * @param  string $new_title What the title is
930
+	 * @param  string $new_slug  what the slug is
931
+	 * @return string            The new html string for the permalink area
932
+	 */
933
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
934
+	{
935
+		// make sure this is only when editing
936
+		if (! empty($id)) {
937
+			$post = get_post($id);
938
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
939
+					   . esc_html__('Shortcode', 'event_espresso')
940
+					   . '</a> ';
941
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
942
+					   . $post->ID
943
+					   . ']">';
944
+		}
945
+		return $return;
946
+	}
947
+
948
+
949
+	/**
950
+	 * _events_overview_list_table
951
+	 * This contains the logic for showing the events_overview list
952
+	 *
953
+	 * @access protected
954
+	 * @return void
955
+	 * @throws \EE_Error
956
+	 */
957
+	protected function _events_overview_list_table()
958
+	{
959
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
960
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
961
+			? (array) $this->_template_args['after_list_table']
962
+			: array();
963
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
964
+				. EEH_Template::get_button_or_link(
965
+					get_post_type_archive_link('espresso_events'),
966
+					esc_html__("View Event Archive Page", "event_espresso"),
967
+					'button'
968
+				);
969
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
970
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
971
+			'create_new',
972
+			'add',
973
+			array(),
974
+			'add-new-h2'
975
+		);
976
+		$this->display_admin_list_table_page_with_no_sidebar();
977
+	}
978
+
979
+
980
+	/**
981
+	 * this allows for extra misc actions in the default WP publish box
982
+	 *
983
+	 * @return void
984
+	 */
985
+	public function extra_misc_actions_publish_box()
986
+	{
987
+		$this->_generate_publish_box_extra_content();
988
+	}
989
+
990
+
991
+	/**
992
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
993
+	 * saved.
994
+	 * Typically you would use this to save any additional data.
995
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
996
+	 * ALSO very important.  When a post transitions from scheduled to published,
997
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
998
+	 * other meta saves. So MAKE sure that you handle this accordingly.
999
+	 *
1000
+	 * @access protected
1001
+	 * @abstract
1002
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
1003
+	 * @param  object $post    The post object of the cpt that was saved.
1004
+	 * @return void
1005
+	 * @throws \EE_Error
1006
+	 */
1007
+	protected function _insert_update_cpt_item($post_id, $post)
1008
+	{
1009
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1010
+			// get out we're not processing an event save.
1011
+			return;
1012
+		}
1013
+		$event_values = array(
1014
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
1015
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
1016
+			'EVT_additional_limit'            => min(
1017
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1018
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
1019
+			),
1020
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
1021
+				? $this->_req_data['EVT_default_registration_status']
1022
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
1023
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
1024
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1025
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1026
+				? $this->_req_data['timezone_string'] : null,
1027
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1028
+				? $this->_req_data['externalURL'] : null,
1029
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1030
+				? $this->_req_data['event_phone'] : null,
1031
+		);
1032
+		// update event
1033
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1034
+		// get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1035
+		$get_one_where = array(
1036
+			$this->_event_model()->primary_key_name() => $post_id,
1037
+			'OR'                                      => array(
1038
+				'status'   => $post->post_status,
1039
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1040
+				// but the returned object here has a status of "publish", so use the original post status as well
1041
+				'status*1' => $this->_req_data['original_post_status'],
1042
+			),
1043
+		);
1044
+		$event = $this->_event_model()->get_one(array($get_one_where));
1045
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1046
+		$event_update_callbacks = apply_filters(
1047
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1048
+			array(
1049
+				array($this, '_default_venue_update'),
1050
+				array($this, '_default_tickets_update'),
1051
+			)
1052
+		);
1053
+		$att_success = true;
1054
+		foreach ($event_update_callbacks as $e_callback) {
1055
+			$_success = is_callable($e_callback)
1056
+				? call_user_func($e_callback, $event, $this->_req_data)
1057
+				: false;
1058
+			// if ANY of these updates fail then we want the appropriate global error message
1059
+			$att_success = ! $att_success ? $att_success : $_success;
1060
+		}
1061
+		// any errors?
1062
+		if ($success && false === $att_success) {
1063
+			EE_Error::add_error(
1064
+				esc_html__(
1065
+					'Event Details saved successfully but something went wrong with saving attachments.',
1066
+					'event_espresso'
1067
+				),
1068
+				__FILE__,
1069
+				__FUNCTION__,
1070
+				__LINE__
1071
+			);
1072
+		} elseif ($success === false) {
1073
+			EE_Error::add_error(
1074
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1075
+				__FILE__,
1076
+				__FUNCTION__,
1077
+				__LINE__
1078
+			);
1079
+		}
1080
+	}
1081
+
1082
+
1083
+	/**
1084
+	 * @see parent::restore_item()
1085
+	 * @param int $post_id
1086
+	 * @param int $revision_id
1087
+	 */
1088
+	protected function _restore_cpt_item($post_id, $revision_id)
1089
+	{
1090
+		// copy existing event meta to new post
1091
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1092
+		if ($post_evt instanceof EE_Event) {
1093
+			// meta revision restore
1094
+			$post_evt->restore_revision($revision_id);
1095
+			// related objs restore
1096
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1097
+		}
1098
+	}
1099
+
1100
+
1101
+	/**
1102
+	 * Attach the venue to the Event
1103
+	 *
1104
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1105
+	 * @param  array     $data   The request data from the form
1106
+	 * @return bool           Success or fail.
1107
+	 */
1108
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1109
+	{
1110
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1111
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1112
+		$rows_affected = null;
1113
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1114
+		// very important.  If we don't have a venue name...
1115
+		// then we'll get out because not necessary to create empty venue
1116
+		if (empty($data['venue_title'])) {
1117
+			return false;
1118
+		}
1119
+		$venue_array = array(
1120
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1121
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1122
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1123
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1124
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1125
+				: null,
1126
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1127
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1128
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1129
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1130
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1131
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1132
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1133
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1134
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1135
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1136
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1137
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1138
+			'status'              => 'publish',
1139
+		);
1140
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1141
+		if (! empty($venue_id)) {
1142
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1143
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1144
+			// we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1145
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1146
+			return $rows_affected > 0 ? true : false;
1147
+		} else {
1148
+			// we insert the venue
1149
+			$venue_id = $venue_model->insert($venue_array);
1150
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1151
+			return ! empty($venue_id) ? true : false;
1152
+		}
1153
+		// when we have the ancestor come in it's already been handled by the revision save.
1154
+	}
1155
+
1156
+
1157
+	/**
1158
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1159
+	 *
1160
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1161
+	 * @param  array    $data   The request data from the form
1162
+	 * @return array
1163
+	 */
1164
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1165
+	{
1166
+		$success = true;
1167
+		$saved_dtt = null;
1168
+		$saved_tickets = array();
1169
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1170
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1171
+			// trim all values to ensure any excess whitespace is removed.
1172
+			$dtt = array_map('trim', $dtt);
1173
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1174
+				: $dtt['DTT_EVT_start'];
1175
+			$datetime_values = array(
1176
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1177
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1178
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1179
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1180
+				'DTT_order'     => $row,
1181
+			);
1182
+			// if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1183
+			if (! empty($dtt['DTT_ID'])) {
1184
+				$DTM = EE_Registry::instance()
1185
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1186
+								  ->get_one_by_ID($dtt['DTT_ID']);
1187
+				$DTM->set_date_format($incoming_date_formats[0]);
1188
+				$DTM->set_time_format($incoming_date_formats[1]);
1189
+				foreach ($datetime_values as $field => $value) {
1190
+					$DTM->set($field, $value);
1191
+				}
1192
+				// make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1193
+				$saved_dtts[ $DTM->ID() ] = $DTM;
1194
+			} else {
1195
+				$DTM = EE_Registry::instance()->load_class(
1196
+					'Datetime',
1197
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1198
+					false,
1199
+					false
1200
+				);
1201
+				foreach ($datetime_values as $field => $value) {
1202
+					$DTM->set($field, $value);
1203
+				}
1204
+			}
1205
+			$DTM->save();
1206
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1207
+			// load DTT helper
1208
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1209
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1210
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1211
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1212
+				$DTT->save();
1213
+			}
1214
+			// now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1215
+			$saved_dtt = $DTT;
1216
+			$success = ! $success ? $success : $DTT;
1217
+			// if ANY of these updates fail then we want the appropriate global error message.
1218
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1219
+		}
1220
+		// no dtts get deleted so we don't do any of that logic here.
1221
+		// update tickets next
1222
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1223
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1224
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1225
+			$update_prices = false;
1226
+			$ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1227
+				? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1228
+			// trim inputs to ensure any excess whitespace is removed.
1229
+			$tkt = array_map('trim', $tkt);
1230
+			if (empty($tkt['TKT_start_date'])) {
1231
+				// let's use now in the set timezone.
1232
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1233
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1234
+			}
1235
+			if (empty($tkt['TKT_end_date'])) {
1236
+				// use the start date of the first datetime
1237
+				$dtt = $evtobj->first_datetime();
1238
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1239
+					$incoming_date_formats[0],
1240
+					$incoming_date_formats[1]
1241
+				);
1242
+			}
1243
+			$TKT_values = array(
1244
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1245
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1246
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1247
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1248
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1249
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1250
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1251
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1252
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1253
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1254
+				'TKT_row'         => $row,
1255
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1256
+				'TKT_price'       => $ticket_price,
1257
+			);
1258
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1259
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1260
+				$TKT_values['TKT_ID'] = 0;
1261
+				$TKT_values['TKT_is_default'] = 0;
1262
+				$TKT_values['TKT_price'] = $ticket_price;
1263
+				$update_prices = true;
1264
+			}
1265
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1266
+			// we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1267
+			// keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1268
+			if (! empty($tkt['TKT_ID'])) {
1269
+				$TKT = EE_Registry::instance()
1270
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1271
+								  ->get_one_by_ID($tkt['TKT_ID']);
1272
+				if ($TKT instanceof EE_Ticket) {
1273
+					$ticket_sold = $TKT->count_related(
1274
+						'Registration',
1275
+						array(
1276
+							array(
1277
+								'STS_ID' => array(
1278
+									'NOT IN',
1279
+									array(EEM_Registration::status_id_incomplete),
1280
+								),
1281
+							),
1282
+						)
1283
+					) > 0 ? true : false;
1284
+					// let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1285
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1286
+									  && ! $TKT->get('TKT_deleted');
1287
+					$TKT->set_date_format($incoming_date_formats[0]);
1288
+					$TKT->set_time_format($incoming_date_formats[1]);
1289
+					// set new values
1290
+					foreach ($TKT_values as $field => $value) {
1291
+						if ($field == 'TKT_qty') {
1292
+							$TKT->set_qty($value);
1293
+						} else {
1294
+							$TKT->set($field, $value);
1295
+						}
1296
+					}
1297
+					// if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1298
+					if ($create_new_TKT) {
1299
+						// archive the old ticket first
1300
+						$TKT->set('TKT_deleted', 1);
1301
+						$TKT->save();
1302
+						// make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1303
+						$saved_tickets[ $TKT->ID() ] = $TKT;
1304
+						// create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1305
+						$TKT = clone $TKT;
1306
+						$TKT->set('TKT_ID', 0);
1307
+						$TKT->set('TKT_deleted', 0);
1308
+						$TKT->set('TKT_price', $ticket_price);
1309
+						$TKT->set('TKT_sold', 0);
1310
+						// now we need to make sure that $new prices are created as well and attached to new ticket.
1311
+						$update_prices = true;
1312
+					}
1313
+					// make sure price is set if it hasn't been already
1314
+					$TKT->set('TKT_price', $ticket_price);
1315
+				}
1316
+			} else {
1317
+				// no TKT_id so a new TKT
1318
+				$TKT_values['TKT_price'] = $ticket_price;
1319
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1320
+				if ($TKT instanceof EE_Ticket) {
1321
+					// need to reset values to properly account for the date formats
1322
+					$TKT->set_date_format($incoming_date_formats[0]);
1323
+					$TKT->set_time_format($incoming_date_formats[1]);
1324
+					$TKT->set_timezone($evtobj->get_timezone());
1325
+					// set new values
1326
+					foreach ($TKT_values as $field => $value) {
1327
+						if ($field == 'TKT_qty') {
1328
+							$TKT->set_qty($value);
1329
+						} else {
1330
+							$TKT->set($field, $value);
1331
+						}
1332
+					}
1333
+					$update_prices = true;
1334
+				}
1335
+			}
1336
+			// cap ticket qty by datetime reg limits
1337
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1338
+			// update ticket.
1339
+			$TKT->save();
1340
+			// before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1341
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1342
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1343
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1344
+				$TKT->save();
1345
+			}
1346
+			// initially let's add the ticket to the dtt
1347
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1348
+			$saved_tickets[ $TKT->ID() ] = $TKT;
1349
+			// add prices to ticket
1350
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1351
+		}
1352
+		// however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1353
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1354
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1355
+		foreach ($tickets_removed as $id) {
1356
+			$id = absint($id);
1357
+			// get the ticket for this id
1358
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1359
+			if (! $tkt_to_remove instanceof EE_Ticket) {
1360
+				continue;
1361
+			}
1362
+
1363
+			// need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1364
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1365
+			foreach ($dtts as $dtt) {
1366
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1367
+			}
1368
+			// need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1369
+			$tkt_to_remove->delete_related_permanently('Price');
1370
+			// finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1371
+			$tkt_to_remove->delete_permanently();
1372
+		}
1373
+		return array($saved_dtt, $saved_tickets);
1374
+	}
1375
+
1376
+
1377
+	/**
1378
+	 * This attaches a list of given prices to a ticket.
1379
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1380
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1381
+	 * price info and prices are automatically "archived" via the ticket.
1382
+	 *
1383
+	 * @access  private
1384
+	 * @param array     $prices     Array of prices from the form.
1385
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1386
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1387
+	 * @return  void
1388
+	 */
1389
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1390
+	{
1391
+		foreach ($prices as $row => $prc) {
1392
+			$PRC_values = array(
1393
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1394
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1395
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1396
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1397
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1398
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1399
+				'PRC_order'      => $row,
1400
+			);
1401
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1402
+				$PRC_values['PRC_ID'] = 0;
1403
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1404
+			} else {
1405
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1406
+				// update this price with new values
1407
+				foreach ($PRC_values as $field => $newprc) {
1408
+					$PRC->set($field, $newprc);
1409
+				}
1410
+				$PRC->save();
1411
+			}
1412
+			$ticket->_add_relation_to($PRC, 'Price');
1413
+		}
1414
+	}
1415
+
1416
+
1417
+	/**
1418
+	 * Add in our autosave ajax handlers
1419
+	 *
1420
+	 */
1421
+	protected function _ee_autosave_create_new()
1422
+	{
1423
+	}
1424
+
1425
+
1426
+	/**
1427
+	 * More autosave handlers.
1428
+	 */
1429
+	protected function _ee_autosave_edit()
1430
+	{
1431
+		return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1432
+	}
1433
+
1434
+
1435
+	/**
1436
+	 *    _generate_publish_box_extra_content
1437
+	 */
1438
+	private function _generate_publish_box_extra_content()
1439
+	{
1440
+		// load formatter helper
1441
+		// args for getting related registrations
1442
+		$approved_query_args = array(
1443
+			array(
1444
+				'REG_deleted' => 0,
1445
+				'STS_ID'      => EEM_Registration::status_id_approved,
1446
+			),
1447
+		);
1448
+		$not_approved_query_args = array(
1449
+			array(
1450
+				'REG_deleted' => 0,
1451
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1452
+			),
1453
+		);
1454
+		$pending_payment_query_args = array(
1455
+			array(
1456
+				'REG_deleted' => 0,
1457
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1458
+			),
1459
+		);
1460
+		// publish box
1461
+		$publish_box_extra_args = array(
1462
+			'view_approved_reg_url'        => add_query_arg(
1463
+				array(
1464
+					'action'      => 'default',
1465
+					'event_id'    => $this->_cpt_model_obj->ID(),
1466
+					'_reg_status' => EEM_Registration::status_id_approved,
1467
+				),
1468
+				REG_ADMIN_URL
1469
+			),
1470
+			'view_not_approved_reg_url'    => add_query_arg(
1471
+				array(
1472
+					'action'      => 'default',
1473
+					'event_id'    => $this->_cpt_model_obj->ID(),
1474
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1475
+				),
1476
+				REG_ADMIN_URL
1477
+			),
1478
+			'view_pending_payment_reg_url' => add_query_arg(
1479
+				array(
1480
+					'action'      => 'default',
1481
+					'event_id'    => $this->_cpt_model_obj->ID(),
1482
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1483
+				),
1484
+				REG_ADMIN_URL
1485
+			),
1486
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1487
+				'Registration',
1488
+				$approved_query_args
1489
+			),
1490
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1491
+				'Registration',
1492
+				$not_approved_query_args
1493
+			),
1494
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1495
+				'Registration',
1496
+				$pending_payment_query_args
1497
+			),
1498
+			'misc_pub_section_class'       => apply_filters(
1499
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1500
+				'misc-pub-section'
1501
+			),
1502
+		);
1503
+		ob_start();
1504
+		do_action(
1505
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1506
+			$this->_cpt_model_obj
1507
+		);
1508
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1509
+		// load template
1510
+		EEH_Template::display_template(
1511
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1512
+			$publish_box_extra_args
1513
+		);
1514
+	}
1515
+
1516
+
1517
+	/**
1518
+	 * @return EE_Event
1519
+	 */
1520
+	public function get_event_object()
1521
+	{
1522
+		return $this->_cpt_model_obj;
1523
+	}
1524
+
1525
+
1526
+
1527
+
1528
+	/** METABOXES * */
1529
+	/**
1530
+	 * _register_event_editor_meta_boxes
1531
+	 * add all metaboxes related to the event_editor
1532
+	 *
1533
+	 * @return void
1534
+	 */
1535
+	protected function _register_event_editor_meta_boxes()
1536
+	{
1537
+		$this->verify_cpt_object();
1538
+		add_meta_box(
1539
+			'espresso_event_editor_tickets',
1540
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1541
+			array($this, 'ticket_metabox'),
1542
+			$this->page_slug,
1543
+			'normal',
1544
+			'high'
1545
+		);
1546
+		add_meta_box(
1547
+			'espresso_event_editor_event_options',
1548
+			esc_html__('Event Registration Options', 'event_espresso'),
1549
+			array($this, 'registration_options_meta_box'),
1550
+			$this->page_slug,
1551
+			'side',
1552
+			'default'
1553
+		);
1554
+		// NOTE: if you're looking for other metaboxes in here,
1555
+		// where a metabox has a related management page in the admin
1556
+		// you will find it setup in the related management page's "_Hooks" file.
1557
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1558
+	}
1559
+
1560
+
1561
+	/**
1562
+	 * @throws DomainException
1563
+	 * @throws EE_Error
1564
+	 */
1565
+	public function ticket_metabox()
1566
+	{
1567
+		$existing_datetime_ids = $existing_ticket_ids = array();
1568
+		// defaults for template args
1569
+		$template_args = array(
1570
+			'existing_datetime_ids'    => '',
1571
+			'event_datetime_help_link' => '',
1572
+			'ticket_options_help_link' => '',
1573
+			'time'                     => null,
1574
+			'ticket_rows'              => '',
1575
+			'existing_ticket_ids'      => '',
1576
+			'total_ticket_rows'        => 1,
1577
+			'ticket_js_structure'      => '',
1578
+			'trash_icon'               => 'ee-lock-icon',
1579
+			'disabled'                 => '',
1580
+		);
1581
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1582
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1583
+		/**
1584
+		 * 1. Start with retrieving Datetimes
1585
+		 * 2. Fore each datetime get related tickets
1586
+		 * 3. For each ticket get related prices
1587
+		 */
1588
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1589
+		/** @type EE_Datetime $first_datetime */
1590
+		$first_datetime = reset($times);
1591
+		// do we get related tickets?
1592
+		if (
1593
+			$first_datetime instanceof EE_Datetime
1594
+			&& $first_datetime->ID() !== 0
1595
+		) {
1596
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1597
+			$template_args['time'] = $first_datetime;
1598
+			$related_tickets = $first_datetime->tickets(
1599
+				array(
1600
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1601
+					'default_where_conditions' => 'none',
1602
+				)
1603
+			);
1604
+			if (! empty($related_tickets)) {
1605
+				$template_args['total_ticket_rows'] = count($related_tickets);
1606
+				$row = 0;
1607
+				foreach ($related_tickets as $ticket) {
1608
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1609
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1610
+					$row++;
1611
+				}
1612
+			} else {
1613
+				$template_args['total_ticket_rows'] = 1;
1614
+				/** @type EE_Ticket $ticket */
1615
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1616
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1617
+			}
1618
+		} else {
1619
+			$template_args['time'] = $times[0];
1620
+			/** @type EE_Ticket $ticket */
1621
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1622
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1623
+			// NOTE: we're just sending the first default row
1624
+			// (decaf can't manage default tickets so this should be sufficient);
1625
+		}
1626
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1627
+			'event_editor_event_datetimes_help_tab'
1628
+		);
1629
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1630
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1631
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1632
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1633
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1634
+			true
1635
+		);
1636
+		$template = apply_filters(
1637
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1638
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1639
+		);
1640
+		EEH_Template::display_template($template, $template_args);
1641
+	}
1642
+
1643
+
1644
+	/**
1645
+	 * Setup an individual ticket form for the decaf event editor page
1646
+	 *
1647
+	 * @access private
1648
+	 * @param  EE_Ticket $ticket   the ticket object
1649
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1650
+	 * @param int        $row
1651
+	 * @return string generated html for the ticket row.
1652
+	 */
1653
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1654
+	{
1655
+		$template_args = array(
1656
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1657
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1658
+				: '',
1659
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1660
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1661
+			'TKT_name'            => $ticket->get('TKT_name'),
1662
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1663
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1664
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1665
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1666
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1667
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1668
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1669
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1670
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1671
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1672
+				: ' disabled=disabled',
1673
+		);
1674
+		$price = $ticket->ID() !== 0
1675
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1676
+			: null;
1677
+		$price = $price instanceof EE_Price
1678
+			? $price
1679
+			: EEM_Price::instance()->create_default_object();
1680
+		$price_args = array(
1681
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1682
+			'PRC_amount'            => $price->get('PRC_amount'),
1683
+			'PRT_ID'                => $price->get('PRT_ID'),
1684
+			'PRC_ID'                => $price->get('PRC_ID'),
1685
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1686
+		);
1687
+		// make sure we have default start and end dates if skeleton
1688
+		// handle rows that should NOT be empty
1689
+		if (empty($template_args['TKT_start_date'])) {
1690
+			// if empty then the start date will be now.
1691
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1692
+		}
1693
+		if (empty($template_args['TKT_end_date'])) {
1694
+			// get the earliest datetime (if present);
1695
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1696
+				? $this->_cpt_model_obj->get_first_related(
1697
+					'Datetime',
1698
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1699
+				)
1700
+				: null;
1701
+			if (! empty($earliest_dtt)) {
1702
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1703
+			} else {
1704
+				$template_args['TKT_end_date'] = date(
1705
+					'Y-m-d h:i a',
1706
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1707
+				);
1708
+			}
1709
+		}
1710
+		$template_args = array_merge($template_args, $price_args);
1711
+		$template = apply_filters(
1712
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1713
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1714
+			$ticket
1715
+		);
1716
+		return EEH_Template::display_template($template, $template_args, true);
1717
+	}
1718
+
1719
+
1720
+	/**
1721
+	 * @throws DomainException
1722
+	 */
1723
+	public function registration_options_meta_box()
1724
+	{
1725
+		$yes_no_values = array(
1726
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1727
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1728
+		);
1729
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1730
+			array(
1731
+				EEM_Registration::status_id_cancelled,
1732
+				EEM_Registration::status_id_declined,
1733
+				EEM_Registration::status_id_incomplete,
1734
+			),
1735
+			true
1736
+		);
1737
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1738
+		$template_args['_event'] = $this->_cpt_model_obj;
1739
+		$template_args['event'] = $this->_cpt_model_obj;
1740
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1741
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1742
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1743
+			'default_reg_status',
1744
+			$default_reg_status_values,
1745
+			$this->_cpt_model_obj->default_registration_status()
1746
+		);
1747
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1748
+			'display_desc',
1749
+			$yes_no_values,
1750
+			$this->_cpt_model_obj->display_description()
1751
+		);
1752
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1753
+			'display_ticket_selector',
1754
+			$yes_no_values,
1755
+			$this->_cpt_model_obj->display_ticket_selector(),
1756
+			'',
1757
+			'',
1758
+			false
1759
+		);
1760
+		$template_args['additional_registration_options'] = apply_filters(
1761
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1762
+			'',
1763
+			$template_args,
1764
+			$yes_no_values,
1765
+			$default_reg_status_values
1766
+		);
1767
+		EEH_Template::display_template(
1768
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1769
+			$template_args
1770
+		);
1771
+	}
1772
+
1773
+
1774
+	/**
1775
+	 * _get_events()
1776
+	 * This method simply returns all the events (for the given _view and paging)
1777
+	 *
1778
+	 * @access public
1779
+	 * @param int  $per_page     count of items per page (20 default);
1780
+	 * @param int  $current_page what is the current page being viewed.
1781
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1782
+	 *                           If FALSE then we return an array of event objects
1783
+	 *                           that match the given _view and paging parameters.
1784
+	 * @return array an array of event objects.
1785
+	 */
1786
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1787
+	{
1788
+		$EEME = $this->_event_model();
1789
+		$offset = ($current_page - 1) * $per_page;
1790
+		$limit = $count ? null : $offset . ',' . $per_page;
1791
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1792
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1793
+		if (isset($this->_req_data['month_range'])) {
1794
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1795
+			// simulate the FIRST day of the month, that fixes issues for months like February
1796
+			// where PHP doesn't know what to assume for date.
1797
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1798
+			$month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1799
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1800
+		}
1801
+		$where = array();
1802
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1803
+		// determine what post_status our condition will have for the query.
1804
+		switch ($status) {
1805
+			case 'month':
1806
+			case 'today':
1807
+			case null:
1808
+			case 'all':
1809
+				break;
1810
+			case 'draft':
1811
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1812
+				break;
1813
+			default:
1814
+				$where['status'] = $status;
1815
+		}
1816
+		// categories?
1817
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1818
+			? $this->_req_data['EVT_CAT'] : null;
1819
+		if (! empty($category)) {
1820
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1821
+			$where['Term_Taxonomy.term_id'] = $category;
1822
+		}
1823
+		// date where conditions
1824
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1825
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1826
+			$DateTime = new DateTime(
1827
+				$year_r . '-' . $month_r . '-01 00:00:00',
1828
+				new DateTimeZone('UTC')
1829
+			);
1830
+			$start = $DateTime->getTimestamp();
1831
+			// set the datetime to be the end of the month
1832
+			$DateTime->setDate(
1833
+				$year_r,
1834
+				$month_r,
1835
+				$DateTime->format('t')
1836
+			)->setTime(23, 59, 59);
1837
+			$end = $DateTime->getTimestamp();
1838
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1839
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1840
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1841
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1842
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1843
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1844
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1845
+			$now = date('Y-m-01');
1846
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1847
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1848
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1849
+							->setTime(23, 59, 59)
1850
+							->format(implode(' ', $start_formats));
1851
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1852
+		}
1853
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1854
+			$where['EVT_wp_user'] = get_current_user_id();
1855
+		} else {
1856
+			if (! isset($where['status'])) {
1857
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1858
+					$where['OR'] = array(
1859
+						'status*restrict_private' => array('!=', 'private'),
1860
+						'AND'                     => array(
1861
+							'status*inclusive' => array('=', 'private'),
1862
+							'EVT_wp_user'      => get_current_user_id(),
1863
+						),
1864
+					);
1865
+				}
1866
+			}
1867
+		}
1868
+		if (isset($this->_req_data['EVT_wp_user'])) {
1869
+			if (
1870
+				$this->_req_data['EVT_wp_user'] != get_current_user_id()
1871
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1872
+			) {
1873
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1874
+			}
1875
+		}
1876
+		// search query handling
1877
+		if (isset($this->_req_data['s'])) {
1878
+			$search_string = '%' . $this->_req_data['s'] . '%';
1879
+			$where['OR'] = array(
1880
+				'EVT_name'       => array('LIKE', $search_string),
1881
+				'EVT_desc'       => array('LIKE', $search_string),
1882
+				'EVT_short_desc' => array('LIKE', $search_string),
1883
+			);
1884
+		}
1885
+		// filter events by venue.
1886
+		if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
1887
+			$where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
1888
+		}
1889
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1890
+		$query_params = apply_filters(
1891
+			'FHEE__Events_Admin_Page__get_events__query_params',
1892
+			array(
1893
+				$where,
1894
+				'limit'    => $limit,
1895
+				'order_by' => $orderby,
1896
+				'order'    => $order,
1897
+				'group_by' => 'EVT_ID',
1898
+			),
1899
+			$this->_req_data
1900
+		);
1901
+
1902
+		// let's first check if we have special requests coming in.
1903
+		if (isset($this->_req_data['active_status'])) {
1904
+			switch ($this->_req_data['active_status']) {
1905
+				case 'upcoming':
1906
+					return $EEME->get_upcoming_events($query_params, $count);
1907
+					break;
1908
+				case 'expired':
1909
+					return $EEME->get_expired_events($query_params, $count);
1910
+					break;
1911
+				case 'active':
1912
+					return $EEME->get_active_events($query_params, $count);
1913
+					break;
1914
+				case 'inactive':
1915
+					return $EEME->get_inactive_events($query_params, $count);
1916
+					break;
1917
+			}
1918
+		}
1919
+
1920
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1921
+		return $events;
1922
+	}
1923
+
1924
+
1925
+	/**
1926
+	 * handling for WordPress CPT actions (trash, restore, delete)
1927
+	 *
1928
+	 * @param string $post_id
1929
+	 */
1930
+	public function trash_cpt_item($post_id)
1931
+	{
1932
+		$this->_req_data['EVT_ID'] = $post_id;
1933
+		$this->_trash_or_restore_event('trash', false);
1934
+	}
1935
+
1936
+
1937
+	/**
1938
+	 * @param string $post_id
1939
+	 */
1940
+	public function restore_cpt_item($post_id)
1941
+	{
1942
+		$this->_req_data['EVT_ID'] = $post_id;
1943
+		$this->_trash_or_restore_event('draft', false);
1944
+	}
1945
+
1946
+
1947
+	/**
1948
+	 * @param string $post_id
1949
+	 */
1950
+	public function delete_cpt_item($post_id)
1951
+	{
1952
+		throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso'));
1953
+		$this->_req_data['EVT_ID'] = $post_id;
1954
+		$this->_delete_event();
1955
+	}
1956
+
1957
+
1958
+	/**
1959
+	 * _trash_or_restore_event
1960
+	 *
1961
+	 * @access protected
1962
+	 * @param  string $event_status
1963
+	 * @param bool    $redirect_after
1964
+	 */
1965
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1966
+	{
1967
+		// determine the event id and set to array.
1968
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1969
+		// loop thru events
1970
+		if ($EVT_ID) {
1971
+			// clean status
1972
+			$event_status = sanitize_key($event_status);
1973
+			// grab status
1974
+			if (! empty($event_status)) {
1975
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1976
+			} else {
1977
+				$success = false;
1978
+				$msg = esc_html__(
1979
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1980
+					'event_espresso'
1981
+				);
1982
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1983
+			}
1984
+		} else {
1985
+			$success = false;
1986
+			$msg = esc_html__(
1987
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1988
+				'event_espresso'
1989
+			);
1990
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1991
+		}
1992
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1993
+		if ($redirect_after) {
1994
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1995
+		}
1996
+	}
1997
+
1998
+
1999
+	/**
2000
+	 * _trash_or_restore_events
2001
+	 *
2002
+	 * @access protected
2003
+	 * @param  string $event_status
2004
+	 * @return void
2005
+	 */
2006
+	protected function _trash_or_restore_events($event_status = 'trash')
2007
+	{
2008
+		// clean status
2009
+		$event_status = sanitize_key($event_status);
2010
+		// grab status
2011
+		if (! empty($event_status)) {
2012
+			$success = true;
2013
+			// determine the event id and set to array.
2014
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2015
+			// loop thru events
2016
+			foreach ($EVT_IDs as $EVT_ID) {
2017
+				if ($EVT_ID = absint($EVT_ID)) {
2018
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2019
+					$success = $results !== false ? $success : false;
2020
+				} else {
2021
+					$msg = sprintf(
2022
+						esc_html__(
2023
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2024
+							'event_espresso'
2025
+						),
2026
+						$EVT_ID
2027
+					);
2028
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2029
+					$success = false;
2030
+				}
2031
+			}
2032
+		} else {
2033
+			$success = false;
2034
+			$msg = esc_html__(
2035
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2036
+				'event_espresso'
2037
+			);
2038
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2039
+		}
2040
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2041
+		$success = $success ? 2 : false;
2042
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2043
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2044
+	}
2045
+
2046
+
2047
+	/**
2048
+	 * @param  int    $EVT_ID
2049
+	 * @param  string $event_status
2050
+	 * @return bool
2051
+	 */
2052
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2053
+	{
2054
+		// grab event id
2055
+		if (! $EVT_ID) {
2056
+			$msg = esc_html__(
2057
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2058
+				'event_espresso'
2059
+			);
2060
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2061
+			return false;
2062
+		}
2063
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2064
+		// clean status
2065
+		$event_status = sanitize_key($event_status);
2066
+		// grab status
2067
+		if (empty($event_status)) {
2068
+			$msg = esc_html__(
2069
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2070
+				'event_espresso'
2071
+			);
2072
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2073
+			return false;
2074
+		}
2075
+		// was event trashed or restored ?
2076
+		switch ($event_status) {
2077
+			case 'draft':
2078
+				$action = 'restored from the trash';
2079
+				$hook = 'AHEE_event_restored_from_trash';
2080
+				break;
2081
+			case 'trash':
2082
+				$action = 'moved to the trash';
2083
+				$hook = 'AHEE_event_moved_to_trash';
2084
+				break;
2085
+			default:
2086
+				$action = 'updated';
2087
+				$hook = false;
2088
+		}
2089
+		// use class to change status
2090
+		$this->_cpt_model_obj->set_status($event_status);
2091
+		$success = $this->_cpt_model_obj->save();
2092
+		if (! $success) {
2093
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2094
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2095
+			return false;
2096
+		}
2097
+		if ($hook) {
2098
+			do_action($hook);
2099
+		}
2100
+		return true;
2101
+	}
2102
+
2103
+
2104
+	/**
2105
+	 * @param array $event_ids
2106
+	 * @return array
2107
+	 * @since   $VID:$
2108
+	 */
2109
+	private function cleanEventIds(array $event_ids)
2110
+	{
2111
+		return array_map('absint', $event_ids);
2112
+	}
2113
+
2114
+
2115
+	/**
2116
+	 * @return array
2117
+	 * @since   $VID:$
2118
+	 */
2119
+	private function getEventIdsFromRequest()
2120
+	{
2121
+		$event_ids = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : [];
2122
+		$event_ids = is_string($event_ids) ? explode(',', $event_ids) : (array) $event_ids;
2123
+		return $this->cleanEventIds($event_ids);
2124
+	}
2125
+
2126
+
2127
+	/**
2128
+	 * @param bool $preview_delete
2129
+	 * @throws EE_Error
2130
+	 */
2131
+	protected function _delete_event($preview_delete = true)
2132
+	{
2133
+		$this->_delete_events($preview_delete);
2134
+	}
2135
+
2136
+
2137
+	/**
2138
+	 * Gets the tree traversal batch persister.
2139
+	 * @since 4.10.12.p
2140
+	 * @return NodeGroupDao
2141
+	 * @throws InvalidArgumentException
2142
+	 * @throws InvalidDataTypeException
2143
+	 * @throws InvalidInterfaceException
2144
+	 */
2145
+	protected function getModelObjNodeGroupPersister()
2146
+	{
2147
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2148
+			$this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2149
+		}
2150
+		return $this->model_obj_node_group_persister;
2151
+	}
2152
+
2153
+
2154
+	/**
2155
+	 * @param bool $preview_delete
2156
+	 * @return void
2157
+	 * @throws EE_Error
2158
+	 */
2159
+	protected function _delete_events($preview_delete = true)
2160
+	{
2161
+		$event_ids = $this->getEventIdsFromRequest();
2162
+		if ($preview_delete) {
2163
+			$this->generateDeletionPreview($event_ids);
2164
+		} else {
2165
+			EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2166
+		}
2167
+	}
2168
+
2169
+
2170
+	/**
2171
+	 * @param array $event_ids
2172
+	 */
2173
+	protected function generateDeletionPreview(array $event_ids)
2174
+	{
2175
+		$event_ids = $this->cleanEventIds($event_ids);
2176
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2177
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2178
+		$return_url = EE_Admin_Page::add_query_args_and_nonce(
2179
+			[
2180
+				'action' => 'preview_deletion',
2181
+				'deletion_job_code' => $deletion_job_code,
2182
+			],
2183
+			$this->_admin_base_url
2184
+		);
2185
+		EEH_URL::safeRedirectAndExit(
2186
+			EE_Admin_Page::add_query_args_and_nonce(
2187
+				[
2188
+					'page'              => 'espresso_batch',
2189
+					'batch'             => EED_Batch::batch_job,
2190
+					'EVT_IDs'           => $event_ids,
2191
+					'deletion_job_code' => $deletion_job_code,
2192
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2193
+					'return_url'        => urlencode($return_url),
2194
+				],
2195
+				admin_url()
2196
+			)
2197
+		);
2198
+	}
2199
+
2200
+	/**
2201
+	 * Checks for a POST submission
2202
+	 * @since 4.10.12.p
2203
+	 */
2204
+	protected function confirmDeletion()
2205
+	{
2206
+		$deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2207
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2208
+	}
2209
+
2210
+	/**
2211
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2212
+	 * @since 4.10.12.p
2213
+	 * @throws EE_Error
2214
+	 */
2215
+	protected function previewDeletion()
2216
+	{
2217
+		$preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2218
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2219
+		$this->display_admin_page_with_no_sidebar();
2220
+	}
2221
+
2222
+	/**
2223
+	 * get total number of events
2224
+	 *
2225
+	 * @access public
2226
+	 * @return int
2227
+	 */
2228
+	public function total_events()
2229
+	{
2230
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2231
+		return $count;
2232
+	}
2233
+
2234
+
2235
+	/**
2236
+	 * get total number of draft events
2237
+	 *
2238
+	 * @access public
2239
+	 * @return int
2240
+	 */
2241
+	public function total_events_draft()
2242
+	{
2243
+		$where = array(
2244
+			'status' => array('IN', array('draft', 'auto-draft')),
2245
+		);
2246
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2247
+		return $count;
2248
+	}
2249
+
2250
+
2251
+	/**
2252
+	 * get total number of trashed events
2253
+	 *
2254
+	 * @access public
2255
+	 * @return int
2256
+	 */
2257
+	public function total_trashed_events()
2258
+	{
2259
+		$where = array(
2260
+			'status' => 'trash',
2261
+		);
2262
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2263
+		return $count;
2264
+	}
2265
+
2266
+
2267
+	/**
2268
+	 *    _default_event_settings
2269
+	 *    This generates the Default Settings Tab
2270
+	 *
2271
+	 * @return void
2272
+	 * @throws EE_Error
2273
+	 */
2274
+	protected function _default_event_settings()
2275
+	{
2276
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2277
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2278
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2279
+		$this->display_admin_page_with_sidebar();
2280
+	}
2281
+
2282
+
2283
+	/**
2284
+	 * Return the form for event settings.
2285
+	 *
2286
+	 * @return EE_Form_Section_Proper
2287
+	 * @throws EE_Error
2288
+	 */
2289
+	protected function _default_event_settings_form()
2290
+	{
2291
+		$registration_config = EE_Registry::instance()->CFG->registration;
2292
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2293
+			// exclude
2294
+			array(
2295
+				EEM_Registration::status_id_cancelled,
2296
+				EEM_Registration::status_id_declined,
2297
+				EEM_Registration::status_id_incomplete,
2298
+				EEM_Registration::status_id_wait_list,
2299
+			),
2300
+			true
2301
+		);
2302
+		return new EE_Form_Section_Proper(
2303
+			array(
2304
+				'name'            => 'update_default_event_settings',
2305
+				'html_id'         => 'update_default_event_settings',
2306
+				'html_class'      => 'form-table',
2307
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2308
+				'subsections'     => apply_filters(
2309
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2310
+					array(
2311
+						'default_reg_status'  => new EE_Select_Input(
2312
+							$registration_stati_for_selection,
2313
+							array(
2314
+								'default'         => isset($registration_config->default_STS_ID)
2315
+													 && array_key_exists(
2316
+														 $registration_config->default_STS_ID,
2317
+														 $registration_stati_for_selection
2318
+													 )
2319
+									? sanitize_text_field($registration_config->default_STS_ID)
2320
+									: EEM_Registration::status_id_pending_payment,
2321
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2322
+													 . EEH_Template::get_help_tab_link(
2323
+														 'default_settings_status_help_tab'
2324
+													 ),
2325
+								'html_help_text'  => esc_html__(
2326
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2327
+									'event_espresso'
2328
+								),
2329
+							)
2330
+						),
2331
+						'default_max_tickets' => new EE_Integer_Input(
2332
+							array(
2333
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2334
+									? $registration_config->default_maximum_number_of_tickets
2335
+									: EEM_Event::get_default_additional_limit(),
2336
+								'html_label_text' => esc_html__(
2337
+									'Default Maximum Tickets Allowed Per Order:',
2338
+									'event_espresso'
2339
+								)
2340
+													 . EEH_Template::get_help_tab_link(
2341
+														 'default_maximum_tickets_help_tab"'
2342
+													 ),
2343
+								'html_help_text'  => esc_html__(
2344
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2345
+									'event_espresso'
2346
+								),
2347
+							)
2348
+						),
2349
+					)
2350
+				),
2351
+			)
2352
+		);
2353
+	}
2354
+
2355
+
2356
+	/**
2357
+	 * _update_default_event_settings
2358
+	 *
2359
+	 * @access protected
2360
+	 * @return void
2361
+	 * @throws EE_Error
2362
+	 */
2363
+	protected function _update_default_event_settings()
2364
+	{
2365
+		$registration_config = EE_Registry::instance()->CFG->registration;
2366
+		$form = $this->_default_event_settings_form();
2367
+		if ($form->was_submitted()) {
2368
+			$form->receive_form_submission();
2369
+			if ($form->is_valid()) {
2370
+				$valid_data = $form->valid_data();
2371
+				if (isset($valid_data['default_reg_status'])) {
2372
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2373
+				}
2374
+				if (isset($valid_data['default_max_tickets'])) {
2375
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2376
+				}
2377
+				// update because data was valid!
2378
+				EE_Registry::instance()->CFG->update_espresso_config();
2379
+				EE_Error::overwrite_success();
2380
+				EE_Error::add_success(
2381
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2382
+				);
2383
+			}
2384
+		}
2385
+		$this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2386
+	}
2387
+
2388
+
2389
+	/*************        Templates        *************/
2390
+	protected function _template_settings()
2391
+	{
2392
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2393
+		$this->_template_args['preview_img'] = '<img src="'
2394
+											   . EVENTS_ASSETS_URL
2395
+											   . '/images/'
2396
+											   . 'caffeinated_template_features.jpg" alt="'
2397
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2398
+											   . '" />';
2399
+		$this->_template_args['preview_text'] = '<strong>'
2400
+												. esc_html__(
2401
+													'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2402
+													'event_espresso'
2403
+												) . '</strong>';
2404
+		$this->display_admin_caf_preview_page('template_settings_tab');
2405
+	}
2406
+
2407
+
2408
+	/** Event Category Stuff **/
2409
+	/**
2410
+	 * set the _category property with the category object for the loaded page.
2411
+	 *
2412
+	 * @access private
2413
+	 * @return void
2414
+	 */
2415
+	private function _set_category_object()
2416
+	{
2417
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2418
+			return;
2419
+		} //already have the category object so get out.
2420
+		// set default category object
2421
+		$this->_set_empty_category_object();
2422
+		// only set if we've got an id
2423
+		if (! isset($this->_req_data['EVT_CAT_ID'])) {
2424
+			return;
2425
+		}
2426
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2427
+		$term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2428
+		if (! empty($term)) {
2429
+			$this->_category->category_name = $term->name;
2430
+			$this->_category->category_identifier = $term->slug;
2431
+			$this->_category->category_desc = $term->description;
2432
+			$this->_category->id = $term->term_id;
2433
+			$this->_category->parent = $term->parent;
2434
+		}
2435
+	}
2436
+
2437
+
2438
+	/**
2439
+	 * Clears out category properties.
2440
+	 */
2441
+	private function _set_empty_category_object()
2442
+	{
2443
+		$this->_category = new stdClass();
2444
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2445
+		$this->_category->id = $this->_category->parent = 0;
2446
+	}
2447
+
2448
+
2449
+	/**
2450
+	 * @throws EE_Error
2451
+	 */
2452
+	protected function _category_list_table()
2453
+	{
2454
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2455
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2456
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2457
+			'add_category',
2458
+			'add_category',
2459
+			array(),
2460
+			'add-new-h2'
2461
+		);
2462
+		$this->display_admin_list_table_page_with_sidebar();
2463
+	}
2464
+
2465
+
2466
+	/**
2467
+	 * Output category details view.
2468
+	 */
2469
+	protected function _category_details($view)
2470
+	{
2471
+		// load formatter helper
2472
+		// load field generator helper
2473
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2474
+		$this->_set_add_edit_form_tags($route);
2475
+		$this->_set_category_object();
2476
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2477
+		$delete_action = 'delete_category';
2478
+		// custom redirect
2479
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2480
+			array('action' => 'category_list'),
2481
+			$this->_admin_base_url
2482
+		);
2483
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2484
+		// take care of contents
2485
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2486
+		$this->display_admin_page_with_sidebar();
2487
+	}
2488
+
2489
+
2490
+	/**
2491
+	 * Output category details content.
2492
+	 */
2493
+	protected function _category_details_content()
2494
+	{
2495
+		$editor_args['category_desc'] = array(
2496
+			'type'          => 'wp_editor',
2497
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2498
+			'class'         => 'my_editor_custom',
2499
+			'wpeditor_args' => array('media_buttons' => false),
2500
+		);
2501
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2502
+		$all_terms = get_terms(
2503
+			array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),
2504
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2505
+		);
2506
+		// setup category select for term parents.
2507
+		$category_select_values[] = array(
2508
+			'text' => esc_html__('No Parent', 'event_espresso'),
2509
+			'id'   => 0,
2510
+		);
2511
+		foreach ($all_terms as $term) {
2512
+			$category_select_values[] = array(
2513
+				'text' => $term->name,
2514
+				'id'   => $term->term_id,
2515
+			);
2516
+		}
2517
+		$category_select = EEH_Form_Fields::select_input(
2518
+			'category_parent',
2519
+			$category_select_values,
2520
+			$this->_category->parent
2521
+		);
2522
+		$template_args = array(
2523
+			'category'                 => $this->_category,
2524
+			'category_select'          => $category_select,
2525
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2526
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2527
+			'disable'                  => '',
2528
+			'disabled_message'         => false,
2529
+		);
2530
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2531
+		return EEH_Template::display_template($template, $template_args, true);
2532
+	}
2533
+
2534
+
2535
+	/**
2536
+	 * Handles deleting categories.
2537
+	 */
2538
+	protected function _delete_categories()
2539
+	{
2540
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2541
+			: (array) $this->_req_data['category_id'];
2542
+		foreach ($cat_ids as $cat_id) {
2543
+			$this->_delete_category($cat_id);
2544
+		}
2545
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2546
+		$query_args = array(
2547
+			'action' => 'category_list',
2548
+		);
2549
+		$this->_redirect_after_action(0, '', '', $query_args);
2550
+	}
2551
+
2552
+
2553
+	/**
2554
+	 * Handles deleting specific category.
2555
+	 *
2556
+	 * @param int $cat_id
2557
+	 */
2558
+	protected function _delete_category($cat_id)
2559
+	{
2560
+		$cat_id = absint($cat_id);
2561
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2562
+	}
2563
+
2564
+
2565
+	/**
2566
+	 * Handles triggering the update or insertion of a new category.
2567
+	 *
2568
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2569
+	 */
2570
+	protected function _insert_or_update_category($new_category)
2571
+	{
2572
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2573
+		$success = 0; // we already have a success message so lets not send another.
2574
+		if ($cat_id) {
2575
+			$query_args = array(
2576
+				'action'     => 'edit_category',
2577
+				'EVT_CAT_ID' => $cat_id,
2578
+			);
2579
+		} else {
2580
+			$query_args = array('action' => 'add_category');
2581
+		}
2582
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2583
+	}
2584
+
2585
+
2586
+	/**
2587
+	 * Inserts or updates category
2588
+	 *
2589
+	 * @param bool $update (true indicates we're updating a category).
2590
+	 * @return bool|mixed|string
2591
+	 */
2592
+	private function _insert_category($update = false)
2593
+	{
2594
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2595
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2596
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2597
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2598
+		if (empty($category_name)) {
2599
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2600
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2601
+			return false;
2602
+		}
2603
+		$term_args = array(
2604
+			'name'        => $category_name,
2605
+			'description' => $category_desc,
2606
+			'parent'      => $category_parent,
2607
+		);
2608
+		// was the category_identifier input disabled?
2609
+		if (isset($this->_req_data['category_identifier'])) {
2610
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2611
+		}
2612
+		$insert_ids = $update
2613
+			? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2614
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2615
+		if (! is_array($insert_ids)) {
2616
+			$msg = esc_html__(
2617
+				'An error occurred and the category has not been saved to the database.',
2618
+				'event_espresso'
2619
+			);
2620
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2621
+		} else {
2622
+			$cat_id = $insert_ids['term_id'];
2623
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2624
+			EE_Error::add_success($msg);
2625
+		}
2626
+		return $cat_id;
2627
+	}
2628
+
2629
+
2630
+	/**
2631
+	 * Gets categories or count of categories matching the arguments in the request.
2632
+	 *
2633
+	 * @param int  $per_page
2634
+	 * @param int  $current_page
2635
+	 * @param bool $count
2636
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2637
+	 */
2638
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2639
+	{
2640
+		// testing term stuff
2641
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2642
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2643
+		$limit = ($current_page - 1) * $per_page;
2644
+		$where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2645
+		if (isset($this->_req_data['s'])) {
2646
+			$sstr = '%' . $this->_req_data['s'] . '%';
2647
+			$where['OR'] = array(
2648
+				'Term.name'   => array('LIKE', $sstr),
2649
+				'description' => array('LIKE', $sstr),
2650
+			);
2651
+		}
2652
+		$query_params = array(
2653
+			$where,
2654
+			'order_by'   => array($orderby => $order),
2655
+			'limit'      => $limit . ',' . $per_page,
2656
+			'force_join' => array('Term'),
2657
+		);
2658
+		$categories = $count
2659
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2660
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2661
+		return $categories;
2662
+	}
2663
+
2664
+	/* end category stuff */
2665
+	/**************/
2666
+
2667
+
2668
+	/**
2669
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2670
+	 *
2671
+	 * @throws EE_Error
2672
+	 */
2673
+	public function save_timezonestring_setting()
2674
+	{
2675
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2676
+			? $this->_req_data['timezone_selected']
2677
+			: '';
2678
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2679
+			EE_Error::add_error(
2680
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2681
+				__FILE__,
2682
+				__FUNCTION__,
2683
+				__LINE__
2684
+			);
2685
+			$this->_template_args['error'] = true;
2686
+			$this->_return_json();
2687
+		}
2688
+
2689
+		update_option('timezone_string', $timezone_string);
2690
+		EE_Error::add_success(
2691
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2692
+		);
2693
+		$this->_template_args['success'] = true;
2694
+		$this->_return_json(true, array('action' => 'create_new'));
2695
+	}
2696 2696
 }
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -583,11 +583,11 @@  discard block
 block discarded – undo
583 583
     {
584 584
         wp_register_style(
585 585
             'events-admin-css',
586
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
586
+            EVENTS_ASSETS_URL.'events-admin-page.css',
587 587
             array(),
588 588
             EVENT_ESPRESSO_VERSION
589 589
         );
590
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
590
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
591 591
         wp_enqueue_style('events-admin-css');
592 592
         wp_enqueue_style('ee-cat-admin');
593 593
         // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
         // scripts
596 596
         wp_register_script(
597 597
             'event_editor_js',
598
-            EVENTS_ASSETS_URL . 'event_editor.js',
598
+            EVENTS_ASSETS_URL.'event_editor.js',
599 599
             array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
600 600
             EVENT_ESPRESSO_VERSION,
601 601
             true
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
         wp_enqueue_style('espresso-ui-theme');
622 622
         wp_register_style(
623 623
             'event-editor-css',
624
-            EVENTS_ASSETS_URL . 'event-editor.css',
624
+            EVENTS_ASSETS_URL.'event-editor.css',
625 625
             array('ee-admin-css'),
626 626
             EVENT_ESPRESSO_VERSION
627 627
         );
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
         // scripts
630 630
         wp_register_script(
631 631
             'event-datetime-metabox',
632
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
632
+            EVENTS_ASSETS_URL.'event-datetime-metabox.js',
633 633
             array('event_editor_js', 'ee-datepicker'),
634 634
             EVENT_ESPRESSO_VERSION
635 635
         );
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
     public function verify_event_edit($event = null, $req_type = '')
699 699
     {
700 700
         // don't need to do this when processing
701
-        if (! empty($req_type)) {
701
+        if ( ! empty($req_type)) {
702 702
             return;
703 703
         }
704 704
         // no event?
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
             $event = $this->_cpt_model_obj;
708 708
         }
709 709
         // STILL no event?
710
-        if (! $event instanceof EE_Event) {
710
+        if ( ! $event instanceof EE_Event) {
711 711
             return;
712 712
         }
713 713
         $orig_status = $event->status();
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
             );
747 747
         }
748 748
         // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
749
-        if (! $event->tickets_on_sale()) {
749
+        if ( ! $event->tickets_on_sale()) {
750 750
             return;
751 751
         }
752 752
         // made it here so show warning
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
     {
792 792
         $has_timezone_string = get_option('timezone_string');
793 793
         // only nag them about setting their timezone if it's their first event, and they haven't already done it
794
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
794
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
795 795
             EE_Error::add_attention(
796 796
                 sprintf(
797 797
                     esc_html__(
@@ -875,31 +875,31 @@  discard block
 block discarded – undo
875 875
         $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
876 876
         $statuses = array(
877 877
             'sold_out_status'  => array(
878
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
878
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
879 879
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
880 880
             ),
881 881
             'active_status'    => array(
882
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
882
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
883 883
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
884 884
             ),
885 885
             'upcoming_status'  => array(
886
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
886
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
887 887
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
888 888
             ),
889 889
             'postponed_status' => array(
890
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
890
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
891 891
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
892 892
             ),
893 893
             'cancelled_status' => array(
894
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
894
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
895 895
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
896 896
             ),
897 897
             'expired_status'   => array(
898
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
898
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
899 899
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
900 900
             ),
901 901
             'inactive_status'  => array(
902
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
902
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
903 903
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
904 904
             ),
905 905
         );
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
      */
914 914
     private function _event_model()
915 915
     {
916
-        if (! $this->_event_model instanceof EEM_Event) {
916
+        if ( ! $this->_event_model instanceof EEM_Event) {
917 917
             $this->_event_model = EE_Registry::instance()->load_model('Event');
918 918
         }
919 919
         return $this->_event_model;
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
     public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
934 934
     {
935 935
         // make sure this is only when editing
936
-        if (! empty($id)) {
936
+        if ( ! empty($id)) {
937 937
             $post = get_post($id);
938 938
             $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
939 939
                        . esc_html__('Shortcode', 'event_espresso')
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
                     'button'
968 968
                 );
969 969
         $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
970
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
970
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
971 971
             'create_new',
972 972
             'add',
973 973
             array(),
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
      */
1108 1108
     protected function _default_venue_update(\EE_Event $evtobj, $data)
1109 1109
     {
1110
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1110
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1111 1111
         $venue_model = EE_Registry::instance()->load_model('Venue');
1112 1112
         $rows_affected = null;
1113 1113
         $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
             'status'              => 'publish',
1139 1139
         );
1140 1140
         // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1141
-        if (! empty($venue_id)) {
1141
+        if ( ! empty($venue_id)) {
1142 1142
             $update_where = array($venue_model->primary_key_name() => $venue_id);
1143 1143
             $rows_affected = $venue_model->update($venue_array, array($update_where));
1144 1144
             // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
@@ -1180,7 +1180,7 @@  discard block
 block discarded – undo
1180 1180
                 'DTT_order'     => $row,
1181 1181
             );
1182 1182
             // if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1183
-            if (! empty($dtt['DTT_ID'])) {
1183
+            if ( ! empty($dtt['DTT_ID'])) {
1184 1184
                 $DTM = EE_Registry::instance()
1185 1185
                                   ->load_model('Datetime', array($evtobj->get_timezone()))
1186 1186
                                   ->get_one_by_ID($dtt['DTT_ID']);
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
                     $DTM->set($field, $value);
1191 1191
                 }
1192 1192
                 // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1193
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1193
+                $saved_dtts[$DTM->ID()] = $DTM;
1194 1194
             } else {
1195 1195
                 $DTM = EE_Registry::instance()->load_class(
1196 1196
                     'Datetime',
@@ -1223,14 +1223,14 @@  discard block
 block discarded – undo
1223 1223
         foreach ($data['edit_tickets'] as $row => $tkt) {
1224 1224
             $incoming_date_formats = array('Y-m-d', 'h:i a');
1225 1225
             $update_prices = false;
1226
-            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1227
-                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1226
+            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1227
+                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1228 1228
             // trim inputs to ensure any excess whitespace is removed.
1229 1229
             $tkt = array_map('trim', $tkt);
1230 1230
             if (empty($tkt['TKT_start_date'])) {
1231 1231
                 // let's use now in the set timezone.
1232 1232
                 $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1233
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1233
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1234 1234
             }
1235 1235
             if (empty($tkt['TKT_end_date'])) {
1236 1236
                 // use the start date of the first datetime
@@ -1265,7 +1265,7 @@  discard block
 block discarded – undo
1265 1265
             // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1266 1266
             // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1267 1267
             // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1268
-            if (! empty($tkt['TKT_ID'])) {
1268
+            if ( ! empty($tkt['TKT_ID'])) {
1269 1269
                 $TKT = EE_Registry::instance()
1270 1270
                                   ->load_model('Ticket', array($evtobj->get_timezone()))
1271 1271
                                   ->get_one_by_ID($tkt['TKT_ID']);
@@ -1300,7 +1300,7 @@  discard block
 block discarded – undo
1300 1300
                         $TKT->set('TKT_deleted', 1);
1301 1301
                         $TKT->save();
1302 1302
                         // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1303
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1303
+                        $saved_tickets[$TKT->ID()] = $TKT;
1304 1304
                         // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1305 1305
                         $TKT = clone $TKT;
1306 1306
                         $TKT->set('TKT_ID', 0);
@@ -1345,9 +1345,9 @@  discard block
 block discarded – undo
1345 1345
             }
1346 1346
             // initially let's add the ticket to the dtt
1347 1347
             $saved_dtt->_add_relation_to($TKT, 'Ticket');
1348
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1348
+            $saved_tickets[$TKT->ID()] = $TKT;
1349 1349
             // add prices to ticket
1350
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1350
+            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1351 1351
         }
1352 1352
         // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1353 1353
         $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
@@ -1356,7 +1356,7 @@  discard block
 block discarded – undo
1356 1356
             $id = absint($id);
1357 1357
             // get the ticket for this id
1358 1358
             $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1359
-            if (! $tkt_to_remove instanceof EE_Ticket) {
1359
+            if ( ! $tkt_to_remove instanceof EE_Ticket) {
1360 1360
                 continue;
1361 1361
             }
1362 1362
 
@@ -1508,7 +1508,7 @@  discard block
 block discarded – undo
1508 1508
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1509 1509
         // load template
1510 1510
         EEH_Template::display_template(
1511
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1511
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1512 1512
             $publish_box_extra_args
1513 1513
         );
1514 1514
     }
@@ -1601,7 +1601,7 @@  discard block
 block discarded – undo
1601 1601
                     'default_where_conditions' => 'none',
1602 1602
                 )
1603 1603
             );
1604
-            if (! empty($related_tickets)) {
1604
+            if ( ! empty($related_tickets)) {
1605 1605
                 $template_args['total_ticket_rows'] = count($related_tickets);
1606 1606
                 $row = 0;
1607 1607
                 foreach ($related_tickets as $ticket) {
@@ -1635,7 +1635,7 @@  discard block
 block discarded – undo
1635 1635
         );
1636 1636
         $template = apply_filters(
1637 1637
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1638
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1638
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1639 1639
         );
1640 1640
         EEH_Template::display_template($template, $template_args);
1641 1641
     }
@@ -1653,7 +1653,7 @@  discard block
 block discarded – undo
1653 1653
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1654 1654
     {
1655 1655
         $template_args = array(
1656
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1656
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1657 1657
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1658 1658
                 : '',
1659 1659
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1665,10 +1665,10 @@  discard block
 block discarded – undo
1665 1665
             'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1666 1666
             'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1667 1667
             'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1668
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1669
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1668
+            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1669
+                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1670 1670
                 ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1671
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1671
+            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1672 1672
                 : ' disabled=disabled',
1673 1673
         );
1674 1674
         $price = $ticket->ID() !== 0
@@ -1698,7 +1698,7 @@  discard block
 block discarded – undo
1698 1698
                     array('order_by' => array('DTT_EVT_start' => 'ASC'))
1699 1699
                 )
1700 1700
                 : null;
1701
-            if (! empty($earliest_dtt)) {
1701
+            if ( ! empty($earliest_dtt)) {
1702 1702
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1703 1703
             } else {
1704 1704
                 $template_args['TKT_end_date'] = date(
@@ -1710,7 +1710,7 @@  discard block
 block discarded – undo
1710 1710
         $template_args = array_merge($template_args, $price_args);
1711 1711
         $template = apply_filters(
1712 1712
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1713
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1713
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1714 1714
             $ticket
1715 1715
         );
1716 1716
         return EEH_Template::display_template($template, $template_args, true);
@@ -1765,7 +1765,7 @@  discard block
 block discarded – undo
1765 1765
             $default_reg_status_values
1766 1766
         );
1767 1767
         EEH_Template::display_template(
1768
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1768
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1769 1769
             $template_args
1770 1770
         );
1771 1771
     }
@@ -1787,7 +1787,7 @@  discard block
 block discarded – undo
1787 1787
     {
1788 1788
         $EEME = $this->_event_model();
1789 1789
         $offset = ($current_page - 1) * $per_page;
1790
-        $limit = $count ? null : $offset . ',' . $per_page;
1790
+        $limit = $count ? null : $offset.','.$per_page;
1791 1791
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1792 1792
         $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1793 1793
         if (isset($this->_req_data['month_range'])) {
@@ -1816,7 +1816,7 @@  discard block
 block discarded – undo
1816 1816
         // categories?
1817 1817
         $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1818 1818
             ? $this->_req_data['EVT_CAT'] : null;
1819
-        if (! empty($category)) {
1819
+        if ( ! empty($category)) {
1820 1820
             $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1821 1821
             $where['Term_Taxonomy.term_id'] = $category;
1822 1822
         }
@@ -1824,7 +1824,7 @@  discard block
 block discarded – undo
1824 1824
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1825 1825
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1826 1826
             $DateTime = new DateTime(
1827
-                $year_r . '-' . $month_r . '-01 00:00:00',
1827
+                $year_r.'-'.$month_r.'-01 00:00:00',
1828 1828
                 new DateTimeZone('UTC')
1829 1829
             );
1830 1830
             $start = $DateTime->getTimestamp();
@@ -1850,11 +1850,11 @@  discard block
 block discarded – undo
1850 1850
                             ->format(implode(' ', $start_formats));
1851 1851
             $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1852 1852
         }
1853
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1853
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1854 1854
             $where['EVT_wp_user'] = get_current_user_id();
1855 1855
         } else {
1856
-            if (! isset($where['status'])) {
1857
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1856
+            if ( ! isset($where['status'])) {
1857
+                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1858 1858
                     $where['OR'] = array(
1859 1859
                         'status*restrict_private' => array('!=', 'private'),
1860 1860
                         'AND'                     => array(
@@ -1875,7 +1875,7 @@  discard block
 block discarded – undo
1875 1875
         }
1876 1876
         // search query handling
1877 1877
         if (isset($this->_req_data['s'])) {
1878
-            $search_string = '%' . $this->_req_data['s'] . '%';
1878
+            $search_string = '%'.$this->_req_data['s'].'%';
1879 1879
             $where['OR'] = array(
1880 1880
                 'EVT_name'       => array('LIKE', $search_string),
1881 1881
                 'EVT_desc'       => array('LIKE', $search_string),
@@ -1971,7 +1971,7 @@  discard block
 block discarded – undo
1971 1971
             // clean status
1972 1972
             $event_status = sanitize_key($event_status);
1973 1973
             // grab status
1974
-            if (! empty($event_status)) {
1974
+            if ( ! empty($event_status)) {
1975 1975
                 $success = $this->_change_event_status($EVT_ID, $event_status);
1976 1976
             } else {
1977 1977
                 $success = false;
@@ -2008,7 +2008,7 @@  discard block
 block discarded – undo
2008 2008
         // clean status
2009 2009
         $event_status = sanitize_key($event_status);
2010 2010
         // grab status
2011
-        if (! empty($event_status)) {
2011
+        if ( ! empty($event_status)) {
2012 2012
             $success = true;
2013 2013
             // determine the event id and set to array.
2014 2014
             $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
@@ -2052,7 +2052,7 @@  discard block
 block discarded – undo
2052 2052
     private function _change_event_status($EVT_ID = 0, $event_status = '')
2053 2053
     {
2054 2054
         // grab event id
2055
-        if (! $EVT_ID) {
2055
+        if ( ! $EVT_ID) {
2056 2056
             $msg = esc_html__(
2057 2057
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2058 2058
                 'event_espresso'
@@ -2089,7 +2089,7 @@  discard block
 block discarded – undo
2089 2089
         // use class to change status
2090 2090
         $this->_cpt_model_obj->set_status($event_status);
2091 2091
         $success = $this->_cpt_model_obj->save();
2092
-        if (! $success) {
2092
+        if ( ! $success) {
2093 2093
             $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2094 2094
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2095 2095
             return false;
@@ -2144,7 +2144,7 @@  discard block
 block discarded – undo
2144 2144
      */
2145 2145
     protected function getModelObjNodeGroupPersister()
2146 2146
     {
2147
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2147
+        if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2148 2148
             $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2149 2149
         }
2150 2150
         return $this->model_obj_node_group_persister;
@@ -2400,7 +2400,7 @@  discard block
 block discarded – undo
2400 2400
                                                 . esc_html__(
2401 2401
                                                     'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2402 2402
                                                     'event_espresso'
2403
-                                                ) . '</strong>';
2403
+                                                ).'</strong>';
2404 2404
         $this->display_admin_caf_preview_page('template_settings_tab');
2405 2405
     }
2406 2406
 
@@ -2420,12 +2420,12 @@  discard block
 block discarded – undo
2420 2420
         // set default category object
2421 2421
         $this->_set_empty_category_object();
2422 2422
         // only set if we've got an id
2423
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2423
+        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2424 2424
             return;
2425 2425
         }
2426 2426
         $category_id = absint($this->_req_data['EVT_CAT_ID']);
2427 2427
         $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2428
-        if (! empty($term)) {
2428
+        if ( ! empty($term)) {
2429 2429
             $this->_category->category_name = $term->name;
2430 2430
             $this->_category->category_identifier = $term->slug;
2431 2431
             $this->_category->category_desc = $term->description;
@@ -2453,7 +2453,7 @@  discard block
 block discarded – undo
2453 2453
     {
2454 2454
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2455 2455
         $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2456
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2456
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
2457 2457
             'add_category',
2458 2458
             'add_category',
2459 2459
             array(),
@@ -2527,7 +2527,7 @@  discard block
 block discarded – undo
2527 2527
             'disable'                  => '',
2528 2528
             'disabled_message'         => false,
2529 2529
         );
2530
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2530
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2531 2531
         return EEH_Template::display_template($template, $template_args, true);
2532 2532
     }
2533 2533
 
@@ -2612,7 +2612,7 @@  discard block
 block discarded – undo
2612 2612
         $insert_ids = $update
2613 2613
             ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2614 2614
             : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2615
-        if (! is_array($insert_ids)) {
2615
+        if ( ! is_array($insert_ids)) {
2616 2616
             $msg = esc_html__(
2617 2617
                 'An error occurred and the category has not been saved to the database.',
2618 2618
                 'event_espresso'
@@ -2643,7 +2643,7 @@  discard block
 block discarded – undo
2643 2643
         $limit = ($current_page - 1) * $per_page;
2644 2644
         $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2645 2645
         if (isset($this->_req_data['s'])) {
2646
-            $sstr = '%' . $this->_req_data['s'] . '%';
2646
+            $sstr = '%'.$this->_req_data['s'].'%';
2647 2647
             $where['OR'] = array(
2648 2648
                 'Term.name'   => array('LIKE', $sstr),
2649 2649
                 'description' => array('LIKE', $sstr),
@@ -2652,7 +2652,7 @@  discard block
 block discarded – undo
2652 2652
         $query_params = array(
2653 2653
             $where,
2654 2654
             'order_by'   => array($orderby => $order),
2655
-            'limit'      => $limit . ',' . $per_page,
2655
+            'limit'      => $limit.','.$per_page,
2656 2656
             'force_join' => array('Term'),
2657 2657
         );
2658 2658
         $categories = $count
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.23.rc.001');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.23.rc.001');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +4111 added lines, -4111 removed lines patch added patch discarded remove patch
@@ -18,4187 +18,4187 @@
 block discarded – undo
18 18
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @var LoaderInterface
23
-     */
24
-    protected $loader;
21
+	/**
22
+	 * @var LoaderInterface
23
+	 */
24
+	protected $loader;
25 25
 
26
-    /**
27
-     * @var RequestInterface
28
-     */
29
-    protected $request;
26
+	/**
27
+	 * @var RequestInterface
28
+	 */
29
+	protected $request;
30 30
 
31
-    // set in _init_page_props()
32
-    public $page_slug;
31
+	// set in _init_page_props()
32
+	public $page_slug;
33 33
 
34
-    public $page_label;
34
+	public $page_label;
35 35
 
36
-    public $page_folder;
36
+	public $page_folder;
37 37
 
38
-    // set in define_page_props()
39
-    protected $_admin_base_url;
38
+	// set in define_page_props()
39
+	protected $_admin_base_url;
40 40
 
41
-    protected $_admin_base_path;
41
+	protected $_admin_base_path;
42 42
 
43
-    protected $_admin_page_title;
43
+	protected $_admin_page_title;
44 44
 
45
-    protected $_labels;
45
+	protected $_labels;
46 46
 
47 47
 
48
-    // set early within EE_Admin_Init
49
-    protected $_wp_page_slug;
48
+	// set early within EE_Admin_Init
49
+	protected $_wp_page_slug;
50 50
 
51
-    // navtabs
52
-    protected $_nav_tabs;
51
+	// navtabs
52
+	protected $_nav_tabs;
53 53
 
54
-    protected $_default_nav_tab_name;
54
+	protected $_default_nav_tab_name;
55 55
 
56
-    /**
57
-     * @var array $_help_tour
58
-     */
59
-    protected $_help_tour = [];
56
+	/**
57
+	 * @var array $_help_tour
58
+	 */
59
+	protected $_help_tour = [];
60 60
 
61 61
 
62
-    // template variables (used by templates)
63
-    protected $_template_path;
62
+	// template variables (used by templates)
63
+	protected $_template_path;
64 64
 
65
-    protected $_column_template_path;
65
+	protected $_column_template_path;
66 66
 
67
-    /**
68
-     * @var array $_template_args
69
-     */
70
-    protected $_template_args = [];
67
+	/**
68
+	 * @var array $_template_args
69
+	 */
70
+	protected $_template_args = [];
71 71
 
72
-    /**
73
-     * this will hold the list table object for a given view.
74
-     *
75
-     * @var EE_Admin_List_Table $_list_table_object
76
-     */
77
-    protected $_list_table_object;
72
+	/**
73
+	 * this will hold the list table object for a given view.
74
+	 *
75
+	 * @var EE_Admin_List_Table $_list_table_object
76
+	 */
77
+	protected $_list_table_object;
78 78
 
79
-    // bools
80
-    protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
79
+	// bools
80
+	protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states.
81 81
 
82
-    protected $_routing;
82
+	protected $_routing;
83 83
 
84
-    // list table args
85
-    protected $_view;
84
+	// list table args
85
+	protected $_view;
86 86
 
87
-    protected $_views;
87
+	protected $_views;
88 88
 
89 89
 
90
-    // action => method pairs used for routing incoming requests
91
-    protected $_page_routes;
90
+	// action => method pairs used for routing incoming requests
91
+	protected $_page_routes;
92 92
 
93
-    /**
94
-     * @var array $_page_config
95
-     */
96
-    protected $_page_config;
93
+	/**
94
+	 * @var array $_page_config
95
+	 */
96
+	protected $_page_config;
97 97
 
98
-    /**
99
-     * the current page route and route config
100
-     *
101
-     * @var string $_route
102
-     */
103
-    protected $_route;
98
+	/**
99
+	 * the current page route and route config
100
+	 *
101
+	 * @var string $_route
102
+	 */
103
+	protected $_route;
104 104
 
105
-    /**
106
-     * @var string $_cpt_route
107
-     */
108
-    protected $_cpt_route;
105
+	/**
106
+	 * @var string $_cpt_route
107
+	 */
108
+	protected $_cpt_route;
109 109
 
110
-    /**
111
-     * @var array $_route_config
112
-     */
113
-    protected $_route_config;
110
+	/**
111
+	 * @var array $_route_config
112
+	 */
113
+	protected $_route_config;
114 114
 
115
-    /**
116
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
117
-     * actions.
118
-     *
119
-     * @since 4.6.x
120
-     * @var array.
121
-     */
122
-    protected $_default_route_query_args;
123
-
124
-    // set via request page and action args.
125
-    protected $_current_page;
126
-
127
-    protected $_current_view;
128
-
129
-    protected $_current_page_view_url;
130
-
131
-    /**
132
-     * unprocessed value for the 'action' request param (default '')
133
-     *
134
-     * @var string
135
-     */
136
-    protected $raw_req_action = '';
137
-
138
-    /**
139
-     * unprocessed value for the 'page' request param (default '')
140
-     *
141
-     * @var string
142
-     */
143
-    protected $raw_req_page = '';
144
-
145
-    /**
146
-     * sanitized request action (and nonce)
147
-     *
148
-     * @var string
149
-     */
150
-    protected $_req_action = '';
151
-
152
-    /**
153
-     * sanitized request action nonce
154
-     *
155
-     * @var string
156
-     */
157
-    protected $_req_nonce = '';
158
-
159
-    /**
160
-     * @var string
161
-     */
162
-    protected $_search_btn_label = '';
163
-
164
-    /**
165
-     * @var string
166
-     */
167
-    protected $_search_box_callback = '';
168
-
169
-    /**
170
-     * @var WP_Screen
171
-     */
172
-    protected $_current_screen;
173
-
174
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
175
-    protected $_hook_obj;
176
-
177
-    // for holding incoming request data
178
-    protected $_req_data = [];
179
-
180
-    // yes / no array for admin form fields
181
-    protected $_yes_no_values = [];
182
-
183
-    // some default things shared by all child classes
184
-    protected $_default_espresso_metaboxes;
185
-
186
-    /**
187
-     * @var EE_Registry
188
-     */
189
-    protected $EE = null;
190
-
191
-
192
-    /**
193
-     * This is just a property that flags whether the given route is a caffeinated route or not.
194
-     *
195
-     * @var boolean
196
-     */
197
-    protected $_is_caf = false;
198
-
199
-
200
-    /**
201
-     * @Constructor
202
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
203
-     * @throws EE_Error
204
-     * @throws InvalidArgumentException
205
-     * @throws ReflectionException
206
-     * @throws InvalidDataTypeException
207
-     * @throws InvalidInterfaceException
208
-     */
209
-    public function __construct($routing = true)
210
-    {
211
-        $this->loader  = LoaderFactory::getLoader();
212
-        $this->request = $this->loader->getShared(RequestInterface::class);
213
-        $this->_routing = $routing;
214
-
215
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
216
-            $this->_is_caf = true;
217
-        }
218
-        $this->_yes_no_values = [
219
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
220
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
221
-        ];
222
-        // set the _req_data property.
223
-        $this->_req_data = $this->request->requestParams();
224
-        // set initial page props (child method)
225
-        $this->_init_page_props();
226
-        // set global defaults
227
-        $this->_set_defaults();
228
-        // set early because incoming requests could be ajax related and we need to register those hooks.
229
-        $this->_global_ajax_hooks();
230
-        $this->_ajax_hooks();
231
-        // other_page_hooks have to be early too.
232
-        $this->_do_other_page_hooks();
233
-        // set up page dependencies
234
-        $this->_before_page_setup();
235
-        $this->_page_setup();
236
-        // die();
237
-    }
238
-
239
-
240
-    /**
241
-     * _init_page_props
242
-     * Child classes use to set at least the following properties:
243
-     * $page_slug.
244
-     * $page_label.
245
-     *
246
-     * @abstract
247
-     * @return void
248
-     */
249
-    abstract protected function _init_page_props();
250
-
251
-
252
-    /**
253
-     * _ajax_hooks
254
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
255
-     * Note: within the ajax callback methods.
256
-     *
257
-     * @abstract
258
-     * @return void
259
-     */
260
-    abstract protected function _ajax_hooks();
261
-
262
-
263
-    /**
264
-     * _define_page_props
265
-     * child classes define page properties in here.  Must include at least:
266
-     * $_admin_base_url = base_url for all admin pages
267
-     * $_admin_page_title = default admin_page_title for admin pages
268
-     * $_labels = array of default labels for various automatically generated elements:
269
-     *    array(
270
-     *        'buttons' => array(
271
-     *            'add' => esc_html__('label for add new button'),
272
-     *            'edit' => esc_html__('label for edit button'),
273
-     *            'delete' => esc_html__('label for delete button')
274
-     *            )
275
-     *        )
276
-     *
277
-     * @abstract
278
-     * @return void
279
-     */
280
-    abstract protected function _define_page_props();
281
-
282
-
283
-    /**
284
-     * _set_page_routes
285
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
286
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
287
-     * have a 'default' route. Here's the format
288
-     * $this->_page_routes = array(
289
-     *        'default' => array(
290
-     *            'func' => '_default_method_handling_route',
291
-     *            'args' => array('array','of','args'),
292
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
293
-     *            ajax request, backend processing)
294
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
295
-     *            headers route after.  The string you enter here should match the defined route reference for a
296
-     *            headers sent route.
297
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
298
-     *            this route.
299
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
300
-     *            checks).
301
-     *        ),
302
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
303
-     *        handling method.
304
-     *        )
305
-     * )
306
-     *
307
-     * @abstract
308
-     * @return void
309
-     */
310
-    abstract protected function _set_page_routes();
311
-
312
-
313
-    /**
314
-     * _set_page_config
315
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
316
-     * array corresponds to the page_route for the loaded page. Format:
317
-     * $this->_page_config = array(
318
-     *        'default' => array(
319
-     *            'labels' => array(
320
-     *                'buttons' => array(
321
-     *                    'add' => esc_html__('label for adding item'),
322
-     *                    'edit' => esc_html__('label for editing item'),
323
-     *                    'delete' => esc_html__('label for deleting item')
324
-     *                ),
325
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
326
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
327
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
328
-     *            _define_page_props() method
329
-     *            'nav' => array(
330
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
331
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
332
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
333
-     *                'order' => 10, //required to indicate tab position.
334
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
335
-     *                displayed then add this parameter.
336
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
337
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
338
-     *            metaboxes set for eventespresso admin pages.
339
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
340
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
341
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
342
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
343
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
344
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
345
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
346
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
347
-     *            want to display.
348
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
349
-     *                'tab_id' => array(
350
-     *                    'title' => 'tab_title',
351
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
352
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
353
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
354
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
355
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
356
-     *                    attempt to use the callback which should match the name of a method in the class
357
-     *                    ),
358
-     *                'tab2_id' => array(
359
-     *                    'title' => 'tab2 title',
360
-     *                    'filename' => 'file_name_2'
361
-     *                    'callback' => 'callback_method_for_content',
362
-     *                 ),
363
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
364
-     *            help tab area on an admin page. @return void
365
-     *
366
-     * @link
367
-     *                http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
368
-     *                'help_tour' => array(
369
-     *                'name_of_help_tour_class', //all help tours should be a child class of EE_Help_Tour and located
370
-     *                in a folder for this admin page named "help_tours", a file name matching the key given here
371
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
372
-     *                ),
373
-     *                'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default
374
-     *                is true if it isn't present).  To remove the requirement for a nonce check when this route is
375
-     *                visited just set
376
-     *                'require_nonce' to FALSE
377
-     *                )
378
-     *                )
379
-     *
380
-     * @abstract
381
-     */
382
-    abstract protected function _set_page_config();
383
-
384
-
385
-
386
-
387
-
388
-    /** end sample help_tour methods **/
389
-    /**
390
-     * _add_screen_options
391
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
392
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
393
-     * to a particular view.
394
-     *
395
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
396
-     *         see also WP_Screen object documents...
397
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
398
-     * @abstract
399
-     * @return void
400
-     */
401
-    abstract protected function _add_screen_options();
402
-
403
-
404
-    /**
405
-     * _add_feature_pointers
406
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
407
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
408
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
409
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
410
-     * extended) also see:
411
-     *
412
-     * @link   http://eamann.com/tech/wordpress-portland/
413
-     * @abstract
414
-     * @return void
415
-     */
416
-    abstract protected function _add_feature_pointers();
417
-
418
-
419
-    /**
420
-     * load_scripts_styles
421
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
422
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
423
-     * scripts/styles per view by putting them in a dynamic function in this format
424
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
425
-     *
426
-     * @abstract
427
-     * @return void
428
-     */
429
-    abstract public function load_scripts_styles();
430
-
431
-
432
-    /**
433
-     * admin_init
434
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
435
-     * all pages/views loaded by child class.
436
-     *
437
-     * @abstract
438
-     * @return void
439
-     */
440
-    abstract public function admin_init();
441
-
442
-
443
-    /**
444
-     * admin_notices
445
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
446
-     * all pages/views loaded by child class.
447
-     *
448
-     * @abstract
449
-     * @return void
450
-     */
451
-    abstract public function admin_notices();
452
-
453
-
454
-    /**
455
-     * admin_footer_scripts
456
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
457
-     * will apply to all pages/views loaded by child class.
458
-     *
459
-     * @return void
460
-     */
461
-    abstract public function admin_footer_scripts();
462
-
463
-
464
-    /**
465
-     * admin_footer
466
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
467
-     * apply to all pages/views loaded by child class.
468
-     *
469
-     * @return void
470
-     */
471
-    public function admin_footer()
472
-    {
473
-    }
474
-
475
-
476
-    /**
477
-     * _global_ajax_hooks
478
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
479
-     * Note: within the ajax callback methods.
480
-     *
481
-     * @abstract
482
-     * @return void
483
-     */
484
-    protected function _global_ajax_hooks()
485
-    {
486
-        // for lazy loading of metabox content
487
-        add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
488
-    }
489
-
490
-
491
-    public function ajax_metabox_content()
492
-    {
493
-        $content_id  = $this->request->getRequestParam('contentid', '');
494
-        $content_url = $this->request->getRequestParam('contenturl', '', 'url');
495
-        self::cached_rss_display($content_id, $content_url);
496
-        wp_die();
497
-    }
498
-
499
-
500
-    /**
501
-     * allows extending classes do something specific before the parent constructor runs _page_setup().
502
-     *
503
-     * @return void
504
-     */
505
-    protected function _before_page_setup()
506
-    {
507
-        // default is to do nothing
508
-    }
509
-
510
-
511
-    /**
512
-     * Makes sure any things that need to be loaded early get handled.
513
-     * We also escape early here if the page requested doesn't match the object.
514
-     *
515
-     * @final
516
-     * @return void
517
-     * @throws EE_Error
518
-     * @throws InvalidArgumentException
519
-     * @throws ReflectionException
520
-     * @throws InvalidDataTypeException
521
-     * @throws InvalidInterfaceException
522
-     */
523
-    final protected function _page_setup()
524
-    {
525
-        // requires?
526
-        // admin_init stuff - global - we're setting this REALLY early
527
-        // so if EE_Admin pages have to hook into other WP pages they can.
528
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
529
-        add_action('admin_init', [$this, 'admin_init_global'], 5);
530
-        // next verify if we need to load anything...
531
-        $this->_current_page = $this->request->getRequestParam('page', '', 'key');
532
-        $this->page_folder   = strtolower(
533
-            str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
534
-        );
535
-        global $ee_menu_slugs;
536
-        $ee_menu_slugs = (array) $ee_menu_slugs;
537
-        if (
538
-            ! $this->request->isAjax()
539
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
540
-        ) {
541
-            return;
542
-        }
543
-        // because WP List tables have two duplicate select inputs for choosing bulk actions,
544
-        // we need to copy the action from the second to the first
545
-        $action     = $this->request->getRequestParam('action', '-1', 'key');
546
-        $action2    = $this->request->getRequestParam('action2', '-1', 'key');
547
-        $action     = $action !== '-1' ? $action : $action2;
548
-        $req_action = $action !== '-1' ? $action : 'default';
549
-
550
-        // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
551
-        // then let's use the route as the action.
552
-        // This covers cases where we're coming in from a list table that isn't on the default route.
553
-        $route = $this->request->getRequestParam('route');
554
-        $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
555
-            ? $route
556
-            : $req_action;
557
-
558
-        $this->_current_view = $this->_req_action;
559
-        $this->_req_nonce    = $this->_req_action . '_nonce';
560
-        $this->_define_page_props();
561
-        $this->_current_page_view_url = add_query_arg(
562
-            ['page' => $this->_current_page, 'action' => $this->_current_view],
563
-            $this->_admin_base_url
564
-        );
565
-        // default things
566
-        $this->_default_espresso_metaboxes = [
567
-            '_espresso_news_post_box',
568
-            '_espresso_links_post_box',
569
-            '_espresso_ratings_request',
570
-            '_espresso_sponsors_post_box',
571
-        ];
572
-        // set page configs
573
-        $this->_set_page_routes();
574
-        $this->_set_page_config();
575
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
576
-        if ($this->request->requestParamIsSet('wp_referer')) {
577
-            $wp_referer = $this->request->getRequestParam('wp_referer');
578
-            if ($wp_referer) {
579
-                $this->_default_route_query_args['wp_referer'] = $wp_referer;
580
-            }
581
-        }
582
-        // for caffeinated and other extended functionality.
583
-        //  If there is a _extend_page_config method
584
-        // then let's run that to modify the all the various page configuration arrays
585
-        if (method_exists($this, '_extend_page_config')) {
586
-            $this->_extend_page_config();
587
-        }
588
-        // for CPT and other extended functionality.
589
-        // If there is an _extend_page_config_for_cpt
590
-        // then let's run that to modify all the various page configuration arrays.
591
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
592
-            $this->_extend_page_config_for_cpt();
593
-        }
594
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
595
-        $this->_page_routes = apply_filters(
596
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
597
-            $this->_page_routes,
598
-            $this
599
-        );
600
-        $this->_page_config = apply_filters(
601
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
602
-            $this->_page_config,
603
-            $this
604
-        );
605
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
606
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
607
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
608
-            add_action(
609
-                'AHEE__EE_Admin_Page__route_admin_request',
610
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
611
-                10,
612
-                2
613
-            );
614
-        }
615
-        // next route only if routing enabled
616
-        if ($this->_routing && ! $this->request->isAjax()) {
617
-            $this->_verify_routes();
618
-            // next let's just check user_access and kill if no access
619
-            $this->check_user_access();
620
-            if ($this->_is_UI_request) {
621
-                // admin_init stuff - global, all views for this page class, specific view
622
-                add_action('admin_init', [$this, 'admin_init'], 10);
623
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
624
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
625
-                }
626
-            } else {
627
-                // hijack regular WP loading and route admin request immediately
628
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
629
-                $this->route_admin_request();
630
-            }
631
-        }
632
-    }
633
-
634
-
635
-    /**
636
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
637
-     *
638
-     * @return void
639
-     * @throws EE_Error
640
-     */
641
-    private function _do_other_page_hooks()
642
-    {
643
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
644
-        foreach ($registered_pages as $page) {
645
-            // now let's setup the file name and class that should be present
646
-            $classname = str_replace('.class.php', '', $page);
647
-            // autoloaders should take care of loading file
648
-            if (! class_exists($classname)) {
649
-                $error_msg[] = sprintf(
650
-                    esc_html__(
651
-                        'Something went wrong with loading the %s admin hooks page.',
652
-                        'event_espresso'
653
-                    ),
654
-                    $page
655
-                );
656
-                $error_msg[] = $error_msg[0]
657
-                               . "\r\n"
658
-                               . sprintf(
659
-                                   esc_html__(
660
-                                       'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
661
-                                       'event_espresso'
662
-                                   ),
663
-                                   $page,
664
-                                   '<br />',
665
-                                   '<strong>' . $classname . '</strong>'
666
-                               );
667
-                throw new EE_Error(implode('||', $error_msg));
668
-            }
669
-            // notice we are passing the instance of this class to the hook object.
670
-            $this->loader->getShared($classname, [$this]);
671
-        }
672
-    }
673
-
674
-
675
-    /**
676
-     * @throws ReflectionException
677
-     * @throws EE_Error
678
-     */
679
-    public function load_page_dependencies()
680
-    {
681
-        try {
682
-            $this->_load_page_dependencies();
683
-        } catch (EE_Error $e) {
684
-            $e->get_error();
685
-        }
686
-    }
687
-
688
-
689
-    /**
690
-     * load_page_dependencies
691
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
692
-     *
693
-     * @return void
694
-     * @throws DomainException
695
-     * @throws EE_Error
696
-     * @throws InvalidArgumentException
697
-     * @throws InvalidDataTypeException
698
-     * @throws InvalidInterfaceException
699
-     */
700
-    protected function _load_page_dependencies()
701
-    {
702
-        // let's set the current_screen and screen options to override what WP set
703
-        $this->_current_screen = get_current_screen();
704
-        // load admin_notices - global, page class, and view specific
705
-        add_action('admin_notices', [$this, 'admin_notices_global'], 5);
706
-        add_action('admin_notices', [$this, 'admin_notices'], 10);
707
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
708
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
709
-        }
710
-        // load network admin_notices - global, page class, and view specific
711
-        add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
712
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
713
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
714
-        }
715
-        // this will save any per_page screen options if they are present
716
-        $this->_set_per_page_screen_options();
717
-        // setup list table properties
718
-        $this->_set_list_table();
719
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
720
-        // However in some cases the metaboxes will need to be added within a route handling callback.
721
-        $this->_add_registered_meta_boxes();
722
-        $this->_add_screen_columns();
723
-        // add screen options - global, page child class, and view specific
724
-        $this->_add_global_screen_options();
725
-        $this->_add_screen_options();
726
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
727
-        if (method_exists($this, $add_screen_options)) {
728
-            $this->{$add_screen_options}();
729
-        }
730
-        // add help tab(s) and tours- set via page_config and qtips.
731
-        // $this->_add_help_tour();
732
-        $this->_add_help_tabs();
733
-        $this->_add_qtips();
734
-        // add feature_pointers - global, page child class, and view specific
735
-        $this->_add_feature_pointers();
736
-        $this->_add_global_feature_pointers();
737
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
738
-        if (method_exists($this, $add_feature_pointer)) {
739
-            $this->{$add_feature_pointer}();
740
-        }
741
-        // enqueue scripts/styles - global, page class, and view specific
742
-        add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
743
-        add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
744
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
745
-            add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
746
-        }
747
-        add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
748
-        // admin_print_footer_scripts - global, page child class, and view specific.
749
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
750
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
751
-        // is a good use case. Notice the late priority we're giving these
752
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
753
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
754
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
755
-            add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
756
-        }
757
-        // admin footer scripts
758
-        add_action('admin_footer', [$this, 'admin_footer_global'], 99);
759
-        add_action('admin_footer', [$this, 'admin_footer'], 100);
760
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
761
-            add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
762
-        }
763
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
764
-        // targeted hook
765
-        do_action(
766
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
767
-        );
768
-    }
769
-
770
-
771
-    /**
772
-     * _set_defaults
773
-     * This sets some global defaults for class properties.
774
-     */
775
-    private function _set_defaults()
776
-    {
777
-        $this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
778
-        $this->_event                = $this->_template_path = $this->_column_template_path = null;
779
-        $this->_nav_tabs             = $this->_views = $this->_page_routes = [];
780
-        $this->_page_config          = $this->_default_route_query_args = [];
781
-        $this->_default_nav_tab_name = 'overview';
782
-        // init template args
783
-        $this->_template_args = [
784
-            'admin_page_header'  => '',
785
-            'admin_page_content' => '',
786
-            'post_body_content'  => '',
787
-            'before_list_table'  => '',
788
-            'after_list_table'   => '',
789
-        ];
790
-    }
791
-
792
-
793
-    /**
794
-     * route_admin_request
795
-     *
796
-     * @return void
797
-     * @throws InvalidArgumentException
798
-     * @throws InvalidInterfaceException
799
-     * @throws InvalidDataTypeException
800
-     * @throws EE_Error
801
-     * @throws ReflectionException
802
-     * @see    _route_admin_request()
803
-     */
804
-    public function route_admin_request()
805
-    {
806
-        try {
807
-            $this->_route_admin_request();
808
-        } catch (EE_Error $e) {
809
-            $e->get_error();
810
-        }
811
-    }
812
-
813
-
814
-    public function set_wp_page_slug($wp_page_slug)
815
-    {
816
-        $this->_wp_page_slug = $wp_page_slug;
817
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
818
-        if (is_network_admin()) {
819
-            $this->_wp_page_slug .= '-network';
820
-        }
821
-    }
822
-
823
-
824
-    /**
825
-     * _verify_routes
826
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
827
-     * we know if we need to drop out.
828
-     *
829
-     * @return bool
830
-     * @throws EE_Error
831
-     */
832
-    protected function _verify_routes()
833
-    {
834
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
835
-        if (! $this->_current_page && ! $this->request->isAjax()) {
836
-            return false;
837
-        }
838
-        $this->_route = false;
839
-        // check that the page_routes array is not empty
840
-        if (empty($this->_page_routes)) {
841
-            // user error msg
842
-            $error_msg = sprintf(
843
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
844
-                $this->_admin_page_title
845
-            );
846
-            // developer error msg
847
-            $error_msg .= '||' . $error_msg
848
-                          . esc_html__(
849
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
850
-                              'event_espresso'
851
-                          );
852
-            throw new EE_Error($error_msg);
853
-        }
854
-        // and that the requested page route exists
855
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
856
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
857
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
858
-                ? $this->_page_config[ $this->_req_action ]
859
-                : [];
860
-        } else {
861
-            // user error msg
862
-            $error_msg = sprintf(
863
-                esc_html__(
864
-                    'The requested page route does not exist for the %s admin page.',
865
-                    'event_espresso'
866
-                ),
867
-                $this->_admin_page_title
868
-            );
869
-            // developer error msg
870
-            $error_msg .= '||' . $error_msg
871
-                          . sprintf(
872
-                              esc_html__(
873
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
874
-                                  'event_espresso'
875
-                              ),
876
-                              $this->_req_action
877
-                          );
878
-            throw new EE_Error($error_msg);
879
-        }
880
-        // and that a default route exists
881
-        if (! array_key_exists('default', $this->_page_routes)) {
882
-            // user error msg
883
-            $error_msg = sprintf(
884
-                esc_html__(
885
-                    'A default page route has not been set for the % admin page.',
886
-                    'event_espresso'
887
-                ),
888
-                $this->_admin_page_title
889
-            );
890
-            // developer error msg
891
-            $error_msg .= '||' . $error_msg
892
-                          . esc_html__(
893
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
894
-                              'event_espresso'
895
-                          );
896
-            throw new EE_Error($error_msg);
897
-        }
898
-        // first lets' catch if the UI request has EVER been set.
899
-        if ($this->_is_UI_request === null) {
900
-            // lets set if this is a UI request or not.
901
-            $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
902
-            // wait a minute... we might have a noheader in the route array
903
-            $this->_is_UI_request = ! (
904
-                is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
905
-            )
906
-                ? $this->_is_UI_request
907
-                : false;
908
-        }
909
-        $this->_set_current_labels();
910
-        return true;
911
-    }
912
-
913
-
914
-    /**
915
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
916
-     *
917
-     * @param string $route the route name we're verifying
918
-     * @return bool we'll throw an exception if this isn't a valid route.
919
-     * @throws EE_Error
920
-     */
921
-    protected function _verify_route($route)
922
-    {
923
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
924
-            return true;
925
-        }
926
-        // user error msg
927
-        $error_msg = sprintf(
928
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
929
-            $this->_admin_page_title
930
-        );
931
-        // developer error msg
932
-        $error_msg .= '||' . $error_msg
933
-                      . sprintf(
934
-                          esc_html__(
935
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
936
-                              'event_espresso'
937
-                          ),
938
-                          $route
939
-                      );
940
-        throw new EE_Error($error_msg);
941
-    }
942
-
943
-
944
-    /**
945
-     * perform nonce verification
946
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
947
-     * using this method (and save retyping!)
948
-     *
949
-     * @param string $nonce     The nonce sent
950
-     * @param string $nonce_ref The nonce reference string (name0)
951
-     * @return void
952
-     * @throws EE_Error
953
-     */
954
-    protected function _verify_nonce($nonce, $nonce_ref)
955
-    {
956
-        // verify nonce against expected value
957
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
958
-            // these are not the droids you are looking for !!!
959
-            $msg = sprintf(
960
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
961
-                '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
962
-                '</a>'
963
-            );
964
-            if (WP_DEBUG) {
965
-                $msg .= "\n  ";
966
-                $msg .= sprintf(
967
-                    esc_html__(
968
-                        'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
969
-                        'event_espresso'
970
-                    ),
971
-                    __CLASS__
972
-                );
973
-            }
974
-            if (! $this->request->isAjax()) {
975
-                wp_die($msg);
976
-            }
977
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
978
-            $this->_return_json();
979
-        }
980
-    }
981
-
982
-
983
-    /**
984
-     * _route_admin_request()
985
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
986
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
987
-     * in the page routes and then will try to load the corresponding method.
988
-     *
989
-     * @return void
990
-     * @throws EE_Error
991
-     * @throws InvalidArgumentException
992
-     * @throws InvalidDataTypeException
993
-     * @throws InvalidInterfaceException
994
-     * @throws ReflectionException
995
-     */
996
-    protected function _route_admin_request()
997
-    {
998
-        if (! $this->_is_UI_request) {
999
-            $this->_verify_routes();
1000
-        }
1001
-        $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1002
-        if ($this->_req_action !== 'default' && $nonce_check) {
1003
-            // set nonce from post data
1004
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
1005
-            $this->_verify_nonce($nonce, $this->_req_nonce);
1006
-        }
1007
-        // set the nav_tabs array but ONLY if this is  UI_request
1008
-        if ($this->_is_UI_request) {
1009
-            $this->_set_nav_tabs();
1010
-        }
1011
-        // grab callback function
1012
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
1013
-        // check if callback has args
1014
-        $args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1015
-        $error_msg = '';
1016
-        // action right before calling route
1017
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1018
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1019
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1020
-        }
1021
-        // right before calling the route, let's clean the _wp_http_referer
1022
-        $this->request->setServerParam(
1023
-            'REQUEST_URI',
1024
-            remove_query_arg(
1025
-                '_wp_http_referer',
1026
-                wp_unslash($this->request->getServerParam('REQUEST_URI'))
1027
-            )
1028
-        );
1029
-        if (! empty($func)) {
1030
-            if (is_array($func)) {
1031
-                list($class, $method) = $func;
1032
-            } elseif (strpos($func, '::') !== false) {
1033
-                list($class, $method) = explode('::', $func);
1034
-            } else {
1035
-                $class  = $this;
1036
-                $method = $func;
1037
-            }
1038
-            if (! (is_object($class) && $class === $this)) {
1039
-                // send along this admin page object for access by addons.
1040
-                $args['admin_page_object'] = $this;
1041
-            }
1042
-            if (
115
+	/**
116
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
117
+	 * actions.
118
+	 *
119
+	 * @since 4.6.x
120
+	 * @var array.
121
+	 */
122
+	protected $_default_route_query_args;
123
+
124
+	// set via request page and action args.
125
+	protected $_current_page;
126
+
127
+	protected $_current_view;
128
+
129
+	protected $_current_page_view_url;
130
+
131
+	/**
132
+	 * unprocessed value for the 'action' request param (default '')
133
+	 *
134
+	 * @var string
135
+	 */
136
+	protected $raw_req_action = '';
137
+
138
+	/**
139
+	 * unprocessed value for the 'page' request param (default '')
140
+	 *
141
+	 * @var string
142
+	 */
143
+	protected $raw_req_page = '';
144
+
145
+	/**
146
+	 * sanitized request action (and nonce)
147
+	 *
148
+	 * @var string
149
+	 */
150
+	protected $_req_action = '';
151
+
152
+	/**
153
+	 * sanitized request action nonce
154
+	 *
155
+	 * @var string
156
+	 */
157
+	protected $_req_nonce = '';
158
+
159
+	/**
160
+	 * @var string
161
+	 */
162
+	protected $_search_btn_label = '';
163
+
164
+	/**
165
+	 * @var string
166
+	 */
167
+	protected $_search_box_callback = '';
168
+
169
+	/**
170
+	 * @var WP_Screen
171
+	 */
172
+	protected $_current_screen;
173
+
174
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
175
+	protected $_hook_obj;
176
+
177
+	// for holding incoming request data
178
+	protected $_req_data = [];
179
+
180
+	// yes / no array for admin form fields
181
+	protected $_yes_no_values = [];
182
+
183
+	// some default things shared by all child classes
184
+	protected $_default_espresso_metaboxes;
185
+
186
+	/**
187
+	 * @var EE_Registry
188
+	 */
189
+	protected $EE = null;
190
+
191
+
192
+	/**
193
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
194
+	 *
195
+	 * @var boolean
196
+	 */
197
+	protected $_is_caf = false;
198
+
199
+
200
+	/**
201
+	 * @Constructor
202
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
203
+	 * @throws EE_Error
204
+	 * @throws InvalidArgumentException
205
+	 * @throws ReflectionException
206
+	 * @throws InvalidDataTypeException
207
+	 * @throws InvalidInterfaceException
208
+	 */
209
+	public function __construct($routing = true)
210
+	{
211
+		$this->loader  = LoaderFactory::getLoader();
212
+		$this->request = $this->loader->getShared(RequestInterface::class);
213
+		$this->_routing = $routing;
214
+
215
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
216
+			$this->_is_caf = true;
217
+		}
218
+		$this->_yes_no_values = [
219
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
220
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
221
+		];
222
+		// set the _req_data property.
223
+		$this->_req_data = $this->request->requestParams();
224
+		// set initial page props (child method)
225
+		$this->_init_page_props();
226
+		// set global defaults
227
+		$this->_set_defaults();
228
+		// set early because incoming requests could be ajax related and we need to register those hooks.
229
+		$this->_global_ajax_hooks();
230
+		$this->_ajax_hooks();
231
+		// other_page_hooks have to be early too.
232
+		$this->_do_other_page_hooks();
233
+		// set up page dependencies
234
+		$this->_before_page_setup();
235
+		$this->_page_setup();
236
+		// die();
237
+	}
238
+
239
+
240
+	/**
241
+	 * _init_page_props
242
+	 * Child classes use to set at least the following properties:
243
+	 * $page_slug.
244
+	 * $page_label.
245
+	 *
246
+	 * @abstract
247
+	 * @return void
248
+	 */
249
+	abstract protected function _init_page_props();
250
+
251
+
252
+	/**
253
+	 * _ajax_hooks
254
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
255
+	 * Note: within the ajax callback methods.
256
+	 *
257
+	 * @abstract
258
+	 * @return void
259
+	 */
260
+	abstract protected function _ajax_hooks();
261
+
262
+
263
+	/**
264
+	 * _define_page_props
265
+	 * child classes define page properties in here.  Must include at least:
266
+	 * $_admin_base_url = base_url for all admin pages
267
+	 * $_admin_page_title = default admin_page_title for admin pages
268
+	 * $_labels = array of default labels for various automatically generated elements:
269
+	 *    array(
270
+	 *        'buttons' => array(
271
+	 *            'add' => esc_html__('label for add new button'),
272
+	 *            'edit' => esc_html__('label for edit button'),
273
+	 *            'delete' => esc_html__('label for delete button')
274
+	 *            )
275
+	 *        )
276
+	 *
277
+	 * @abstract
278
+	 * @return void
279
+	 */
280
+	abstract protected function _define_page_props();
281
+
282
+
283
+	/**
284
+	 * _set_page_routes
285
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
286
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
287
+	 * have a 'default' route. Here's the format
288
+	 * $this->_page_routes = array(
289
+	 *        'default' => array(
290
+	 *            'func' => '_default_method_handling_route',
291
+	 *            'args' => array('array','of','args'),
292
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
293
+	 *            ajax request, backend processing)
294
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
295
+	 *            headers route after.  The string you enter here should match the defined route reference for a
296
+	 *            headers sent route.
297
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
298
+	 *            this route.
299
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
300
+	 *            checks).
301
+	 *        ),
302
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
303
+	 *        handling method.
304
+	 *        )
305
+	 * )
306
+	 *
307
+	 * @abstract
308
+	 * @return void
309
+	 */
310
+	abstract protected function _set_page_routes();
311
+
312
+
313
+	/**
314
+	 * _set_page_config
315
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
316
+	 * array corresponds to the page_route for the loaded page. Format:
317
+	 * $this->_page_config = array(
318
+	 *        'default' => array(
319
+	 *            'labels' => array(
320
+	 *                'buttons' => array(
321
+	 *                    'add' => esc_html__('label for adding item'),
322
+	 *                    'edit' => esc_html__('label for editing item'),
323
+	 *                    'delete' => esc_html__('label for deleting item')
324
+	 *                ),
325
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
326
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
327
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
328
+	 *            _define_page_props() method
329
+	 *            'nav' => array(
330
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
331
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
332
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
333
+	 *                'order' => 10, //required to indicate tab position.
334
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
335
+	 *                displayed then add this parameter.
336
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
337
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
338
+	 *            metaboxes set for eventespresso admin pages.
339
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
340
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
341
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
342
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
343
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
344
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
345
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
346
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
347
+	 *            want to display.
348
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
349
+	 *                'tab_id' => array(
350
+	 *                    'title' => 'tab_title',
351
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
352
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
353
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
354
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
355
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
356
+	 *                    attempt to use the callback which should match the name of a method in the class
357
+	 *                    ),
358
+	 *                'tab2_id' => array(
359
+	 *                    'title' => 'tab2 title',
360
+	 *                    'filename' => 'file_name_2'
361
+	 *                    'callback' => 'callback_method_for_content',
362
+	 *                 ),
363
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
364
+	 *            help tab area on an admin page. @return void
365
+	 *
366
+	 * @link
367
+	 *                http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
368
+	 *                'help_tour' => array(
369
+	 *                'name_of_help_tour_class', //all help tours should be a child class of EE_Help_Tour and located
370
+	 *                in a folder for this admin page named "help_tours", a file name matching the key given here
371
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
372
+	 *                ),
373
+	 *                'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default
374
+	 *                is true if it isn't present).  To remove the requirement for a nonce check when this route is
375
+	 *                visited just set
376
+	 *                'require_nonce' to FALSE
377
+	 *                )
378
+	 *                )
379
+	 *
380
+	 * @abstract
381
+	 */
382
+	abstract protected function _set_page_config();
383
+
384
+
385
+
386
+
387
+
388
+	/** end sample help_tour methods **/
389
+	/**
390
+	 * _add_screen_options
391
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
392
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
393
+	 * to a particular view.
394
+	 *
395
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
396
+	 *         see also WP_Screen object documents...
397
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
398
+	 * @abstract
399
+	 * @return void
400
+	 */
401
+	abstract protected function _add_screen_options();
402
+
403
+
404
+	/**
405
+	 * _add_feature_pointers
406
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
407
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
408
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
409
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
410
+	 * extended) also see:
411
+	 *
412
+	 * @link   http://eamann.com/tech/wordpress-portland/
413
+	 * @abstract
414
+	 * @return void
415
+	 */
416
+	abstract protected function _add_feature_pointers();
417
+
418
+
419
+	/**
420
+	 * load_scripts_styles
421
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
422
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
423
+	 * scripts/styles per view by putting them in a dynamic function in this format
424
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
425
+	 *
426
+	 * @abstract
427
+	 * @return void
428
+	 */
429
+	abstract public function load_scripts_styles();
430
+
431
+
432
+	/**
433
+	 * admin_init
434
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
435
+	 * all pages/views loaded by child class.
436
+	 *
437
+	 * @abstract
438
+	 * @return void
439
+	 */
440
+	abstract public function admin_init();
441
+
442
+
443
+	/**
444
+	 * admin_notices
445
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
446
+	 * all pages/views loaded by child class.
447
+	 *
448
+	 * @abstract
449
+	 * @return void
450
+	 */
451
+	abstract public function admin_notices();
452
+
453
+
454
+	/**
455
+	 * admin_footer_scripts
456
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
457
+	 * will apply to all pages/views loaded by child class.
458
+	 *
459
+	 * @return void
460
+	 */
461
+	abstract public function admin_footer_scripts();
462
+
463
+
464
+	/**
465
+	 * admin_footer
466
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
467
+	 * apply to all pages/views loaded by child class.
468
+	 *
469
+	 * @return void
470
+	 */
471
+	public function admin_footer()
472
+	{
473
+	}
474
+
475
+
476
+	/**
477
+	 * _global_ajax_hooks
478
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
479
+	 * Note: within the ajax callback methods.
480
+	 *
481
+	 * @abstract
482
+	 * @return void
483
+	 */
484
+	protected function _global_ajax_hooks()
485
+	{
486
+		// for lazy loading of metabox content
487
+		add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
488
+	}
489
+
490
+
491
+	public function ajax_metabox_content()
492
+	{
493
+		$content_id  = $this->request->getRequestParam('contentid', '');
494
+		$content_url = $this->request->getRequestParam('contenturl', '', 'url');
495
+		self::cached_rss_display($content_id, $content_url);
496
+		wp_die();
497
+	}
498
+
499
+
500
+	/**
501
+	 * allows extending classes do something specific before the parent constructor runs _page_setup().
502
+	 *
503
+	 * @return void
504
+	 */
505
+	protected function _before_page_setup()
506
+	{
507
+		// default is to do nothing
508
+	}
509
+
510
+
511
+	/**
512
+	 * Makes sure any things that need to be loaded early get handled.
513
+	 * We also escape early here if the page requested doesn't match the object.
514
+	 *
515
+	 * @final
516
+	 * @return void
517
+	 * @throws EE_Error
518
+	 * @throws InvalidArgumentException
519
+	 * @throws ReflectionException
520
+	 * @throws InvalidDataTypeException
521
+	 * @throws InvalidInterfaceException
522
+	 */
523
+	final protected function _page_setup()
524
+	{
525
+		// requires?
526
+		// admin_init stuff - global - we're setting this REALLY early
527
+		// so if EE_Admin pages have to hook into other WP pages they can.
528
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
529
+		add_action('admin_init', [$this, 'admin_init_global'], 5);
530
+		// next verify if we need to load anything...
531
+		$this->_current_page = $this->request->getRequestParam('page', '', 'key');
532
+		$this->page_folder   = strtolower(
533
+			str_replace(['_Admin_Page', 'Extend_'], '', get_class($this))
534
+		);
535
+		global $ee_menu_slugs;
536
+		$ee_menu_slugs = (array) $ee_menu_slugs;
537
+		if (
538
+			! $this->request->isAjax()
539
+			&& (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
540
+		) {
541
+			return;
542
+		}
543
+		// because WP List tables have two duplicate select inputs for choosing bulk actions,
544
+		// we need to copy the action from the second to the first
545
+		$action     = $this->request->getRequestParam('action', '-1', 'key');
546
+		$action2    = $this->request->getRequestParam('action2', '-1', 'key');
547
+		$action     = $action !== '-1' ? $action : $action2;
548
+		$req_action = $action !== '-1' ? $action : 'default';
549
+
550
+		// if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
551
+		// then let's use the route as the action.
552
+		// This covers cases where we're coming in from a list table that isn't on the default route.
553
+		$route = $this->request->getRequestParam('route');
554
+		$this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
555
+			? $route
556
+			: $req_action;
557
+
558
+		$this->_current_view = $this->_req_action;
559
+		$this->_req_nonce    = $this->_req_action . '_nonce';
560
+		$this->_define_page_props();
561
+		$this->_current_page_view_url = add_query_arg(
562
+			['page' => $this->_current_page, 'action' => $this->_current_view],
563
+			$this->_admin_base_url
564
+		);
565
+		// default things
566
+		$this->_default_espresso_metaboxes = [
567
+			'_espresso_news_post_box',
568
+			'_espresso_links_post_box',
569
+			'_espresso_ratings_request',
570
+			'_espresso_sponsors_post_box',
571
+		];
572
+		// set page configs
573
+		$this->_set_page_routes();
574
+		$this->_set_page_config();
575
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
576
+		if ($this->request->requestParamIsSet('wp_referer')) {
577
+			$wp_referer = $this->request->getRequestParam('wp_referer');
578
+			if ($wp_referer) {
579
+				$this->_default_route_query_args['wp_referer'] = $wp_referer;
580
+			}
581
+		}
582
+		// for caffeinated and other extended functionality.
583
+		//  If there is a _extend_page_config method
584
+		// then let's run that to modify the all the various page configuration arrays
585
+		if (method_exists($this, '_extend_page_config')) {
586
+			$this->_extend_page_config();
587
+		}
588
+		// for CPT and other extended functionality.
589
+		// If there is an _extend_page_config_for_cpt
590
+		// then let's run that to modify all the various page configuration arrays.
591
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
592
+			$this->_extend_page_config_for_cpt();
593
+		}
594
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
595
+		$this->_page_routes = apply_filters(
596
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
597
+			$this->_page_routes,
598
+			$this
599
+		);
600
+		$this->_page_config = apply_filters(
601
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
602
+			$this->_page_config,
603
+			$this
604
+		);
605
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
606
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
607
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
608
+			add_action(
609
+				'AHEE__EE_Admin_Page__route_admin_request',
610
+				[$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
611
+				10,
612
+				2
613
+			);
614
+		}
615
+		// next route only if routing enabled
616
+		if ($this->_routing && ! $this->request->isAjax()) {
617
+			$this->_verify_routes();
618
+			// next let's just check user_access and kill if no access
619
+			$this->check_user_access();
620
+			if ($this->_is_UI_request) {
621
+				// admin_init stuff - global, all views for this page class, specific view
622
+				add_action('admin_init', [$this, 'admin_init'], 10);
623
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
624
+					add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
625
+				}
626
+			} else {
627
+				// hijack regular WP loading and route admin request immediately
628
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
629
+				$this->route_admin_request();
630
+			}
631
+		}
632
+	}
633
+
634
+
635
+	/**
636
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
637
+	 *
638
+	 * @return void
639
+	 * @throws EE_Error
640
+	 */
641
+	private function _do_other_page_hooks()
642
+	{
643
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
644
+		foreach ($registered_pages as $page) {
645
+			// now let's setup the file name and class that should be present
646
+			$classname = str_replace('.class.php', '', $page);
647
+			// autoloaders should take care of loading file
648
+			if (! class_exists($classname)) {
649
+				$error_msg[] = sprintf(
650
+					esc_html__(
651
+						'Something went wrong with loading the %s admin hooks page.',
652
+						'event_espresso'
653
+					),
654
+					$page
655
+				);
656
+				$error_msg[] = $error_msg[0]
657
+							   . "\r\n"
658
+							   . sprintf(
659
+								   esc_html__(
660
+									   'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
661
+									   'event_espresso'
662
+								   ),
663
+								   $page,
664
+								   '<br />',
665
+								   '<strong>' . $classname . '</strong>'
666
+							   );
667
+				throw new EE_Error(implode('||', $error_msg));
668
+			}
669
+			// notice we are passing the instance of this class to the hook object.
670
+			$this->loader->getShared($classname, [$this]);
671
+		}
672
+	}
673
+
674
+
675
+	/**
676
+	 * @throws ReflectionException
677
+	 * @throws EE_Error
678
+	 */
679
+	public function load_page_dependencies()
680
+	{
681
+		try {
682
+			$this->_load_page_dependencies();
683
+		} catch (EE_Error $e) {
684
+			$e->get_error();
685
+		}
686
+	}
687
+
688
+
689
+	/**
690
+	 * load_page_dependencies
691
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
692
+	 *
693
+	 * @return void
694
+	 * @throws DomainException
695
+	 * @throws EE_Error
696
+	 * @throws InvalidArgumentException
697
+	 * @throws InvalidDataTypeException
698
+	 * @throws InvalidInterfaceException
699
+	 */
700
+	protected function _load_page_dependencies()
701
+	{
702
+		// let's set the current_screen and screen options to override what WP set
703
+		$this->_current_screen = get_current_screen();
704
+		// load admin_notices - global, page class, and view specific
705
+		add_action('admin_notices', [$this, 'admin_notices_global'], 5);
706
+		add_action('admin_notices', [$this, 'admin_notices'], 10);
707
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
708
+			add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
709
+		}
710
+		// load network admin_notices - global, page class, and view specific
711
+		add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
712
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
713
+			add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
714
+		}
715
+		// this will save any per_page screen options if they are present
716
+		$this->_set_per_page_screen_options();
717
+		// setup list table properties
718
+		$this->_set_list_table();
719
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
720
+		// However in some cases the metaboxes will need to be added within a route handling callback.
721
+		$this->_add_registered_meta_boxes();
722
+		$this->_add_screen_columns();
723
+		// add screen options - global, page child class, and view specific
724
+		$this->_add_global_screen_options();
725
+		$this->_add_screen_options();
726
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
727
+		if (method_exists($this, $add_screen_options)) {
728
+			$this->{$add_screen_options}();
729
+		}
730
+		// add help tab(s) and tours- set via page_config and qtips.
731
+		// $this->_add_help_tour();
732
+		$this->_add_help_tabs();
733
+		$this->_add_qtips();
734
+		// add feature_pointers - global, page child class, and view specific
735
+		$this->_add_feature_pointers();
736
+		$this->_add_global_feature_pointers();
737
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
738
+		if (method_exists($this, $add_feature_pointer)) {
739
+			$this->{$add_feature_pointer}();
740
+		}
741
+		// enqueue scripts/styles - global, page class, and view specific
742
+		add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
743
+		add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
744
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
745
+			add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
746
+		}
747
+		add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
748
+		// admin_print_footer_scripts - global, page child class, and view specific.
749
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
750
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
751
+		// is a good use case. Notice the late priority we're giving these
752
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
753
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
754
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
755
+			add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
756
+		}
757
+		// admin footer scripts
758
+		add_action('admin_footer', [$this, 'admin_footer_global'], 99);
759
+		add_action('admin_footer', [$this, 'admin_footer'], 100);
760
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
761
+			add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
762
+		}
763
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
764
+		// targeted hook
765
+		do_action(
766
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
767
+		);
768
+	}
769
+
770
+
771
+	/**
772
+	 * _set_defaults
773
+	 * This sets some global defaults for class properties.
774
+	 */
775
+	private function _set_defaults()
776
+	{
777
+		$this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
778
+		$this->_event                = $this->_template_path = $this->_column_template_path = null;
779
+		$this->_nav_tabs             = $this->_views = $this->_page_routes = [];
780
+		$this->_page_config          = $this->_default_route_query_args = [];
781
+		$this->_default_nav_tab_name = 'overview';
782
+		// init template args
783
+		$this->_template_args = [
784
+			'admin_page_header'  => '',
785
+			'admin_page_content' => '',
786
+			'post_body_content'  => '',
787
+			'before_list_table'  => '',
788
+			'after_list_table'   => '',
789
+		];
790
+	}
791
+
792
+
793
+	/**
794
+	 * route_admin_request
795
+	 *
796
+	 * @return void
797
+	 * @throws InvalidArgumentException
798
+	 * @throws InvalidInterfaceException
799
+	 * @throws InvalidDataTypeException
800
+	 * @throws EE_Error
801
+	 * @throws ReflectionException
802
+	 * @see    _route_admin_request()
803
+	 */
804
+	public function route_admin_request()
805
+	{
806
+		try {
807
+			$this->_route_admin_request();
808
+		} catch (EE_Error $e) {
809
+			$e->get_error();
810
+		}
811
+	}
812
+
813
+
814
+	public function set_wp_page_slug($wp_page_slug)
815
+	{
816
+		$this->_wp_page_slug = $wp_page_slug;
817
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
818
+		if (is_network_admin()) {
819
+			$this->_wp_page_slug .= '-network';
820
+		}
821
+	}
822
+
823
+
824
+	/**
825
+	 * _verify_routes
826
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
827
+	 * we know if we need to drop out.
828
+	 *
829
+	 * @return bool
830
+	 * @throws EE_Error
831
+	 */
832
+	protected function _verify_routes()
833
+	{
834
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
835
+		if (! $this->_current_page && ! $this->request->isAjax()) {
836
+			return false;
837
+		}
838
+		$this->_route = false;
839
+		// check that the page_routes array is not empty
840
+		if (empty($this->_page_routes)) {
841
+			// user error msg
842
+			$error_msg = sprintf(
843
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
844
+				$this->_admin_page_title
845
+			);
846
+			// developer error msg
847
+			$error_msg .= '||' . $error_msg
848
+						  . esc_html__(
849
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
850
+							  'event_espresso'
851
+						  );
852
+			throw new EE_Error($error_msg);
853
+		}
854
+		// and that the requested page route exists
855
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
856
+			$this->_route        = $this->_page_routes[ $this->_req_action ];
857
+			$this->_route_config = isset($this->_page_config[ $this->_req_action ])
858
+				? $this->_page_config[ $this->_req_action ]
859
+				: [];
860
+		} else {
861
+			// user error msg
862
+			$error_msg = sprintf(
863
+				esc_html__(
864
+					'The requested page route does not exist for the %s admin page.',
865
+					'event_espresso'
866
+				),
867
+				$this->_admin_page_title
868
+			);
869
+			// developer error msg
870
+			$error_msg .= '||' . $error_msg
871
+						  . sprintf(
872
+							  esc_html__(
873
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
874
+								  'event_espresso'
875
+							  ),
876
+							  $this->_req_action
877
+						  );
878
+			throw new EE_Error($error_msg);
879
+		}
880
+		// and that a default route exists
881
+		if (! array_key_exists('default', $this->_page_routes)) {
882
+			// user error msg
883
+			$error_msg = sprintf(
884
+				esc_html__(
885
+					'A default page route has not been set for the % admin page.',
886
+					'event_espresso'
887
+				),
888
+				$this->_admin_page_title
889
+			);
890
+			// developer error msg
891
+			$error_msg .= '||' . $error_msg
892
+						  . esc_html__(
893
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
894
+							  'event_espresso'
895
+						  );
896
+			throw new EE_Error($error_msg);
897
+		}
898
+		// first lets' catch if the UI request has EVER been set.
899
+		if ($this->_is_UI_request === null) {
900
+			// lets set if this is a UI request or not.
901
+			$this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
902
+			// wait a minute... we might have a noheader in the route array
903
+			$this->_is_UI_request = ! (
904
+				is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
905
+			)
906
+				? $this->_is_UI_request
907
+				: false;
908
+		}
909
+		$this->_set_current_labels();
910
+		return true;
911
+	}
912
+
913
+
914
+	/**
915
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
916
+	 *
917
+	 * @param string $route the route name we're verifying
918
+	 * @return bool we'll throw an exception if this isn't a valid route.
919
+	 * @throws EE_Error
920
+	 */
921
+	protected function _verify_route($route)
922
+	{
923
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
924
+			return true;
925
+		}
926
+		// user error msg
927
+		$error_msg = sprintf(
928
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
929
+			$this->_admin_page_title
930
+		);
931
+		// developer error msg
932
+		$error_msg .= '||' . $error_msg
933
+					  . sprintf(
934
+						  esc_html__(
935
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
936
+							  'event_espresso'
937
+						  ),
938
+						  $route
939
+					  );
940
+		throw new EE_Error($error_msg);
941
+	}
942
+
943
+
944
+	/**
945
+	 * perform nonce verification
946
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
947
+	 * using this method (and save retyping!)
948
+	 *
949
+	 * @param string $nonce     The nonce sent
950
+	 * @param string $nonce_ref The nonce reference string (name0)
951
+	 * @return void
952
+	 * @throws EE_Error
953
+	 */
954
+	protected function _verify_nonce($nonce, $nonce_ref)
955
+	{
956
+		// verify nonce against expected value
957
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
958
+			// these are not the droids you are looking for !!!
959
+			$msg = sprintf(
960
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
961
+				'<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
962
+				'</a>'
963
+			);
964
+			if (WP_DEBUG) {
965
+				$msg .= "\n  ";
966
+				$msg .= sprintf(
967
+					esc_html__(
968
+						'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
969
+						'event_espresso'
970
+					),
971
+					__CLASS__
972
+				);
973
+			}
974
+			if (! $this->request->isAjax()) {
975
+				wp_die($msg);
976
+			}
977
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
978
+			$this->_return_json();
979
+		}
980
+	}
981
+
982
+
983
+	/**
984
+	 * _route_admin_request()
985
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
986
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
987
+	 * in the page routes and then will try to load the corresponding method.
988
+	 *
989
+	 * @return void
990
+	 * @throws EE_Error
991
+	 * @throws InvalidArgumentException
992
+	 * @throws InvalidDataTypeException
993
+	 * @throws InvalidInterfaceException
994
+	 * @throws ReflectionException
995
+	 */
996
+	protected function _route_admin_request()
997
+	{
998
+		if (! $this->_is_UI_request) {
999
+			$this->_verify_routes();
1000
+		}
1001
+		$nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1002
+		if ($this->_req_action !== 'default' && $nonce_check) {
1003
+			// set nonce from post data
1004
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
1005
+			$this->_verify_nonce($nonce, $this->_req_nonce);
1006
+		}
1007
+		// set the nav_tabs array but ONLY if this is  UI_request
1008
+		if ($this->_is_UI_request) {
1009
+			$this->_set_nav_tabs();
1010
+		}
1011
+		// grab callback function
1012
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
1013
+		// check if callback has args
1014
+		$args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1015
+		$error_msg = '';
1016
+		// action right before calling route
1017
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1018
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1019
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1020
+		}
1021
+		// right before calling the route, let's clean the _wp_http_referer
1022
+		$this->request->setServerParam(
1023
+			'REQUEST_URI',
1024
+			remove_query_arg(
1025
+				'_wp_http_referer',
1026
+				wp_unslash($this->request->getServerParam('REQUEST_URI'))
1027
+			)
1028
+		);
1029
+		if (! empty($func)) {
1030
+			if (is_array($func)) {
1031
+				list($class, $method) = $func;
1032
+			} elseif (strpos($func, '::') !== false) {
1033
+				list($class, $method) = explode('::', $func);
1034
+			} else {
1035
+				$class  = $this;
1036
+				$method = $func;
1037
+			}
1038
+			if (! (is_object($class) && $class === $this)) {
1039
+				// send along this admin page object for access by addons.
1040
+				$args['admin_page_object'] = $this;
1041
+			}
1042
+			if (
1043 1043
 // is it a method on a class that doesn't work?
1044
-                (
1045
-                    (
1046
-                        method_exists($class, $method)
1047
-                        && call_user_func_array([$class, $method], $args) === false
1048
-                    )
1049
-                    && (
1050
-                        // is it a standalone function that doesn't work?
1051
-                        function_exists($method)
1052
-                        && call_user_func_array(
1053
-                            $func,
1054
-                            array_merge(['admin_page_object' => $this], $args)
1055
-                        ) === false
1056
-                    )
1057
-                )
1058
-                || (
1059
-                    // is it neither a class method NOR a standalone function?
1060
-                    ! method_exists($class, $method)
1061
-                    && ! function_exists($method)
1062
-                )
1063
-            ) {
1064
-                // user error msg
1065
-                $error_msg = esc_html__(
1066
-                    'An error occurred. The  requested page route could not be found.',
1067
-                    'event_espresso'
1068
-                );
1069
-                // developer error msg
1070
-                $error_msg .= '||';
1071
-                $error_msg .= sprintf(
1072
-                    esc_html__(
1073
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1074
-                        'event_espresso'
1075
-                    ),
1076
-                    $method
1077
-                );
1078
-            }
1079
-            if (! empty($error_msg)) {
1080
-                throw new EE_Error($error_msg);
1081
-            }
1082
-        }
1083
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1084
-        // then we need to reset the routing properties to the new route.
1085
-        // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1086
-        if (
1087
-            $this->_is_UI_request === false
1088
-            && is_array($this->_route)
1089
-            && ! empty($this->_route['headers_sent_route'])
1090
-        ) {
1091
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1092
-        }
1093
-    }
1094
-
1095
-
1096
-    /**
1097
-     * This method just allows the resetting of page properties in the case where a no headers
1098
-     * route redirects to a headers route in its route config.
1099
-     *
1100
-     * @param string $new_route New (non header) route to redirect to.
1101
-     * @return   void
1102
-     * @throws ReflectionException
1103
-     * @throws InvalidArgumentException
1104
-     * @throws InvalidInterfaceException
1105
-     * @throws InvalidDataTypeException
1106
-     * @throws EE_Error
1107
-     * @since   4.3.0
1108
-     */
1109
-    protected function _reset_routing_properties($new_route)
1110
-    {
1111
-        $this->_is_UI_request = true;
1112
-        // now we set the current route to whatever the headers_sent_route is set at
1113
-        $this->request->setRequestParam('action', $new_route);
1114
-        // rerun page setup
1115
-        $this->_page_setup();
1116
-    }
1117
-
1118
-
1119
-    /**
1120
-     * _add_query_arg
1121
-     * adds nonce to array of arguments then calls WP add_query_arg function
1122
-     *(internally just uses EEH_URL's function with the same name)
1123
-     *
1124
-     * @param array  $args
1125
-     * @param string $url
1126
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1127
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1128
-     *                                        Example usage: If the current page is:
1129
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1130
-     *                                        &action=default&event_id=20&month_range=March%202015
1131
-     *                                        &_wpnonce=5467821
1132
-     *                                        and you call:
1133
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1134
-     *                                        array(
1135
-     *                                        'action' => 'resend_something',
1136
-     *                                        'page=>espresso_registrations'
1137
-     *                                        ),
1138
-     *                                        $some_url,
1139
-     *                                        true
1140
-     *                                        );
1141
-     *                                        It will produce a url in this structure:
1142
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1143
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1144
-     *                                        month_range]=March%202015
1145
-     * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1146
-     * @return string
1147
-     */
1148
-    public static function add_query_args_and_nonce(
1149
-        $args = [],
1150
-        $url = false,
1151
-        $sticky = false,
1152
-        $exclude_nonce = false
1153
-    ) {
1154
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1155
-        if ($sticky) {
1156
-            /** @var RequestInterface $request */
1157
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1158
-            $request->unSetRequestParams(['_wp_http_referer', 'wp_referer']);
1159
-            foreach ($request->requestParams() as $key => $value) {
1160
-                // do not add nonces
1161
-                if (strpos($key, 'nonce') !== false) {
1162
-                    continue;
1163
-                }
1164
-                $args[ 'wp_referer[' . $key . ']' ] = $value;
1165
-            }
1166
-        }
1167
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1168
-    }
1169
-
1170
-
1171
-    /**
1172
-     * This returns a generated link that will load the related help tab.
1173
-     *
1174
-     * @param string $help_tab_id the id for the connected help tab
1175
-     * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1176
-     * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1177
-     * @return string              generated link
1178
-     * @uses EEH_Template::get_help_tab_link()
1179
-     */
1180
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1181
-    {
1182
-        return EEH_Template::get_help_tab_link(
1183
-            $help_tab_id,
1184
-            $this->page_slug,
1185
-            $this->_req_action,
1186
-            $icon_style,
1187
-            $help_text
1188
-        );
1189
-    }
1190
-
1191
-
1192
-    /**
1193
-     * _add_help_tabs
1194
-     * Note child classes define their help tabs within the page_config array.
1195
-     *
1196
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1197
-     * @return void
1198
-     * @throws DomainException
1199
-     * @throws EE_Error
1200
-     */
1201
-    protected function _add_help_tabs()
1202
-    {
1203
-        $tour_buttons = '';
1204
-        if (isset($this->_page_config[ $this->_req_action ])) {
1205
-            $config = $this->_page_config[ $this->_req_action ];
1206
-            // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1207
-            // is there a help tour for the current route?  if there is let's setup the tour buttons
1208
-            // if (isset($this->_help_tour[ $this->_req_action ])) {
1209
-            //     $tb = array();
1210
-            //     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1211
-            //     foreach ($this->_help_tour['tours'] as $tour) {
1212
-            //         // if this is the end tour then we don't need to setup a button
1213
-            //         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1214
-            //             continue;
1215
-            //         }
1216
-            //         $tb[] = '<button id="trigger-tour-'
1217
-            //                 . $tour->get_slug()
1218
-            //                 . '" class="button-primary trigger-ee-help-tour">'
1219
-            //                 . $tour->get_label()
1220
-            //                 . '</button>';
1221
-            //     }
1222
-            //     $tour_buttons .= implode('<br />', $tb);
1223
-            //     $tour_buttons .= '</div></div>';
1224
-            // }
1225
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1226
-            if (is_array($config) && isset($config['help_sidebar'])) {
1227
-                // check that the callback given is valid
1228
-                if (! method_exists($this, $config['help_sidebar'])) {
1229
-                    throw new EE_Error(
1230
-                        sprintf(
1231
-                            esc_html__(
1232
-                                'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1233
-                                'event_espresso'
1234
-                            ),
1235
-                            $config['help_sidebar'],
1236
-                            get_class($this)
1237
-                        )
1238
-                    );
1239
-                }
1240
-                $content = apply_filters(
1241
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1242
-                    $this->{$config['help_sidebar']}()
1243
-                );
1244
-                $content .= $tour_buttons; // add help tour buttons.
1245
-                // do we have any help tours setup?  Cause if we do we want to add the buttons
1246
-                $this->_current_screen->set_help_sidebar($content);
1247
-            }
1248
-            // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar.
1249
-            if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1250
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1251
-            }
1252
-            // handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1253
-            if (! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1254
-                $_ht['id']      = $this->page_slug;
1255
-                $_ht['title']   = esc_html__('Help Tours', 'event_espresso');
1256
-                $_ht['content'] = '<p>'
1257
-                                  . esc_html__(
1258
-                                      'The buttons to the right allow you to start/restart any help tours available for this page',
1259
-                                      'event_espresso'
1260
-                                  ) . '</p>';
1261
-                $this->_current_screen->add_help_tab($_ht);
1262
-            }
1263
-            if (! isset($config['help_tabs'])) {
1264
-                return;
1265
-            } //no help tabs for this route
1266
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1267
-                // we're here so there ARE help tabs!
1268
-                // make sure we've got what we need
1269
-                if (! isset($cfg['title'])) {
1270
-                    throw new EE_Error(
1271
-                        esc_html__(
1272
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1273
-                            'event_espresso'
1274
-                        )
1275
-                    );
1276
-                }
1277
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1278
-                    throw new EE_Error(
1279
-                        esc_html__(
1280
-                            'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1281
-                            'event_espresso'
1282
-                        )
1283
-                    );
1284
-                }
1285
-                // first priority goes to content.
1286
-                if (! empty($cfg['content'])) {
1287
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1288
-                    // second priority goes to filename
1289
-                } elseif (! empty($cfg['filename'])) {
1290
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1291
-                    // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1292
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1293
-                                                             . basename($this->_get_dir())
1294
-                                                             . '/help_tabs/'
1295
-                                                             . $cfg['filename']
1296
-                                                             . '.help_tab.php' : $file_path;
1297
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1298
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1299
-                        EE_Error::add_error(
1300
-                            sprintf(
1301
-                                esc_html__(
1302
-                                    'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1303
-                                    'event_espresso'
1304
-                                ),
1305
-                                $tab_id,
1306
-                                key($config),
1307
-                                $file_path
1308
-                            ),
1309
-                            __FILE__,
1310
-                            __FUNCTION__,
1311
-                            __LINE__
1312
-                        );
1313
-                        return;
1314
-                    }
1315
-                    $template_args['admin_page_obj'] = $this;
1316
-                    $content                         = EEH_Template::display_template(
1317
-                        $file_path,
1318
-                        $template_args,
1319
-                        true
1320
-                    );
1321
-                } else {
1322
-                    $content = '';
1323
-                }
1324
-                // check if callback is valid
1325
-                if (
1326
-                    empty($content)
1327
-                    && (
1328
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1329
-                    )
1330
-                ) {
1331
-                    EE_Error::add_error(
1332
-                        sprintf(
1333
-                            esc_html__(
1334
-                                'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1335
-                                'event_espresso'
1336
-                            ),
1337
-                            $cfg['title']
1338
-                        ),
1339
-                        __FILE__,
1340
-                        __FUNCTION__,
1341
-                        __LINE__
1342
-                    );
1343
-                    return;
1344
-                }
1345
-                // setup config array for help tab method
1346
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1347
-                $_ht = [
1348
-                    'id'       => $id,
1349
-                    'title'    => $cfg['title'],
1350
-                    'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1351
-                    'content'  => $content,
1352
-                ];
1353
-                $this->_current_screen->add_help_tab($_ht);
1354
-            }
1355
-        }
1356
-    }
1357
-
1358
-
1359
-    /**
1360
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1361
-     * an array with properties for setting up usage of the joyride plugin
1362
-     *
1363
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1364
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1365
-     *         _set_page_config() comments
1366
-     * @return void
1367
-     * @throws InvalidArgumentException
1368
-     * @throws InvalidDataTypeException
1369
-     * @throws InvalidInterfaceException
1370
-     */
1371
-    protected function _add_help_tour()
1372
-    {
1373
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1374
-        // $tours = array();
1375
-        // $this->_help_tour = array();
1376
-        // // exit early if help tours are turned off globally
1377
-        // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1378
-        //     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1379
-        // ) {
1380
-        //     return;
1381
-        // }
1382
-        // // loop through _page_config to find any help_tour defined
1383
-        // foreach ($this->_page_config as $route => $config) {
1384
-        //     // we're only going to set things up for this route
1385
-        //     if ($route !== $this->_req_action) {
1386
-        //         continue;
1387
-        //     }
1388
-        //     if (isset($config['help_tour'])) {
1389
-        //         foreach ($config['help_tour'] as $tour) {
1390
-        //             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1391
-        //             // let's see if we can get that file...
1392
-        //             // if not its possible this is a decaf route not set in caffeinated
1393
-        //             // so lets try and get the caffeinated equivalent
1394
-        //             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1395
-        //                                                      . basename($this->_get_dir())
1396
-        //                                                      . '/help_tours/'
1397
-        //                                                      . $tour
1398
-        //                                                      . '.class.php' : $file_path;
1399
-        //             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1400
-        //             if (! is_readable($file_path)) {
1401
-        //                 EE_Error::add_error(
1402
-        //                     sprintf(
1403
-        //                         esc_html__(
1404
-        //                             'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1405
-        //                             'event_espresso'
1406
-        //                         ),
1407
-        //                         $file_path,
1408
-        //                         $tour
1409
-        //                     ),
1410
-        //                     __FILE__,
1411
-        //                     __FUNCTION__,
1412
-        //                     __LINE__
1413
-        //                 );
1414
-        //                 return;
1415
-        //             }
1416
-        //             require_once $file_path;
1417
-        //             if (! class_exists($tour)) {
1418
-        //                 $error_msg[] = sprintf(
1419
-        //                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1420
-        //                     $tour
1421
-        //                 );
1422
-        //                 $error_msg[] = $error_msg[0] . "\r\n"
1423
-        //                                . sprintf(
1424
-        //                                    esc_html__(
1425
-        //                                        'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1426
-        //                                        'event_espresso'
1427
-        //                                    ),
1428
-        //                                    $tour,
1429
-        //                                    '<br />',
1430
-        //                                    $tour,
1431
-        //                                    $this->_req_action,
1432
-        //                                    get_class($this)
1433
-        //                                );
1434
-        //                 throw new EE_Error(implode('||', $error_msg));
1435
-        //             }
1436
-        //             $tour_obj = new $tour($this->_is_caf);
1437
-        //             $tours[] = $tour_obj;
1438
-        //             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1439
-        //         }
1440
-        //         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1441
-        //         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1442
-        //         $tours[] = $end_stop_tour;
1443
-        //         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1444
-        //     }
1445
-        // }
1446
-        //
1447
-        // if (! empty($tours)) {
1448
-        //     $this->_help_tour['tours'] = $tours;
1449
-        // }
1450
-        // // that's it!  Now that the $_help_tours property is set (or not)
1451
-        // // the scripts and html should be taken care of automatically.
1452
-        //
1453
-        // /**
1454
-        //  * Allow extending the help tours variable.
1455
-        //  *
1456
-        //  * @param Array $_help_tour The array containing all help tour information to be displayed.
1457
-        //  */
1458
-        // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1459
-    }
1460
-
1461
-
1462
-    /**
1463
-     * This simply sets up any qtips that have been defined in the page config
1464
-     *
1465
-     * @return void
1466
-     */
1467
-    protected function _add_qtips()
1468
-    {
1469
-        if (isset($this->_route_config['qtips'])) {
1470
-            $qtips = (array) $this->_route_config['qtips'];
1471
-            // load qtip loader
1472
-            $path = [
1473
-                $this->_get_dir() . '/qtips/',
1474
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1475
-            ];
1476
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1477
-        }
1478
-    }
1479
-
1480
-
1481
-    /**
1482
-     * _set_nav_tabs
1483
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1484
-     * wish to add additional tabs or modify accordingly.
1485
-     *
1486
-     * @return void
1487
-     * @throws InvalidArgumentException
1488
-     * @throws InvalidInterfaceException
1489
-     * @throws InvalidDataTypeException
1490
-     */
1491
-    protected function _set_nav_tabs()
1492
-    {
1493
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1494
-        $i = 0;
1495
-        foreach ($this->_page_config as $slug => $config) {
1496
-            if (! is_array($config) || empty($config['nav'])) {
1497
-                continue;
1498
-            }
1499
-            // no nav tab for this config
1500
-            // check for persistent flag
1501
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1502
-                // nav tab is only to appear when route requested.
1503
-                continue;
1504
-            }
1505
-            if (! $this->check_user_access($slug, true)) {
1506
-                // no nav tab because current user does not have access.
1507
-                continue;
1508
-            }
1509
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1510
-            $this->_nav_tabs[ $slug ] = [
1511
-                'url'       => isset($config['nav']['url'])
1512
-                    ? $config['nav']['url']
1513
-                    : self::add_query_args_and_nonce(
1514
-                        ['action' => $slug],
1515
-                        $this->_admin_base_url
1516
-                    ),
1517
-                'link_text' => isset($config['nav']['label'])
1518
-                    ? $config['nav']['label']
1519
-                    : ucwords(
1520
-                        str_replace('_', ' ', $slug)
1521
-                    ),
1522
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1523
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1524
-            ];
1525
-            $i++;
1526
-        }
1527
-        // if $this->_nav_tabs is empty then lets set the default
1528
-        if (empty($this->_nav_tabs)) {
1529
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1530
-                'url'       => $this->_admin_base_url,
1531
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1532
-                'css_class' => 'nav-tab-active',
1533
-                'order'     => 10,
1534
-            ];
1535
-        }
1536
-        // now let's sort the tabs according to order
1537
-        usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1538
-    }
1539
-
1540
-
1541
-    /**
1542
-     * _set_current_labels
1543
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1544
-     * property array
1545
-     *
1546
-     * @return void
1547
-     */
1548
-    private function _set_current_labels()
1549
-    {
1550
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1551
-            foreach ($this->_route_config['labels'] as $label => $text) {
1552
-                if (is_array($text)) {
1553
-                    foreach ($text as $sublabel => $subtext) {
1554
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1555
-                    }
1556
-                } else {
1557
-                    $this->_labels[ $label ] = $text;
1558
-                }
1559
-            }
1560
-        }
1561
-    }
1562
-
1563
-
1564
-    /**
1565
-     *        verifies user access for this admin page
1566
-     *
1567
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1568
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1569
-     *                               return false if verify fail.
1570
-     * @return bool
1571
-     * @throws InvalidArgumentException
1572
-     * @throws InvalidDataTypeException
1573
-     * @throws InvalidInterfaceException
1574
-     */
1575
-    public function check_user_access($route_to_check = '', $verify_only = false)
1576
-    {
1577
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1578
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1579
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1580
-                          && is_array(
1581
-                              $this->_page_routes[ $route_to_check ]
1582
-                          )
1583
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1584
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1585
-        if (empty($capability) && empty($route_to_check)) {
1586
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1587
-                : $this->_route['capability'];
1588
-        } else {
1589
-            $capability = empty($capability) ? 'manage_options' : $capability;
1590
-        }
1591
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1592
-        if (
1593
-            ! $this->request->isAjax()
1594
-            && (
1595
-                ! function_exists('is_admin')
1596
-                || ! EE_Registry::instance()->CAP->current_user_can(
1597
-                    $capability,
1598
-                    $this->page_slug
1599
-                    . '_'
1600
-                    . $route_to_check,
1601
-                    $id
1602
-                )
1603
-            )
1604
-        ) {
1605
-            if ($verify_only) {
1606
-                return false;
1607
-            }
1608
-            if (is_user_logged_in()) {
1609
-                wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1610
-            } else {
1611
-                return false;
1612
-            }
1613
-        }
1614
-        return true;
1615
-    }
1616
-
1617
-
1618
-    /**
1619
-     * admin_init_global
1620
-     * This runs all the code that we want executed within the WP admin_init hook.
1621
-     * This method executes for ALL EE Admin pages.
1622
-     *
1623
-     * @return void
1624
-     */
1625
-    public function admin_init_global()
1626
-    {
1627
-    }
1628
-
1629
-
1630
-    /**
1631
-     * wp_loaded_global
1632
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1633
-     * EE_Admin page and will execute on every EE Admin Page load
1634
-     *
1635
-     * @return void
1636
-     */
1637
-    public function wp_loaded()
1638
-    {
1639
-    }
1640
-
1641
-
1642
-    /**
1643
-     * admin_notices
1644
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1645
-     * ALL EE_Admin pages.
1646
-     *
1647
-     * @return void
1648
-     */
1649
-    public function admin_notices_global()
1650
-    {
1651
-        $this->_display_no_javascript_warning();
1652
-        $this->_display_espresso_notices();
1653
-    }
1654
-
1655
-
1656
-    public function network_admin_notices_global()
1657
-    {
1658
-        $this->_display_no_javascript_warning();
1659
-        $this->_display_espresso_notices();
1660
-    }
1661
-
1662
-
1663
-    /**
1664
-     * admin_footer_scripts_global
1665
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1666
-     * will apply on ALL EE_Admin pages.
1667
-     *
1668
-     * @return void
1669
-     */
1670
-    public function admin_footer_scripts_global()
1671
-    {
1672
-        $this->_add_admin_page_ajax_loading_img();
1673
-        $this->_add_admin_page_overlay();
1674
-        // if metaboxes are present we need to add the nonce field
1675
-        if (
1676
-            isset($this->_route_config['metaboxes'])
1677
-            || isset($this->_route_config['list_table'])
1678
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1679
-        ) {
1680
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1681
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1682
-        }
1683
-    }
1684
-
1685
-
1686
-    /**
1687
-     * admin_footer_global
1688
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1689
-     * ALL EE_Admin Pages.
1690
-     *
1691
-     * @return void
1692
-     */
1693
-    public function admin_footer_global()
1694
-    {
1695
-        // dialog container for dialog helper
1696
-        echo '
1044
+				(
1045
+					(
1046
+						method_exists($class, $method)
1047
+						&& call_user_func_array([$class, $method], $args) === false
1048
+					)
1049
+					&& (
1050
+						// is it a standalone function that doesn't work?
1051
+						function_exists($method)
1052
+						&& call_user_func_array(
1053
+							$func,
1054
+							array_merge(['admin_page_object' => $this], $args)
1055
+						) === false
1056
+					)
1057
+				)
1058
+				|| (
1059
+					// is it neither a class method NOR a standalone function?
1060
+					! method_exists($class, $method)
1061
+					&& ! function_exists($method)
1062
+				)
1063
+			) {
1064
+				// user error msg
1065
+				$error_msg = esc_html__(
1066
+					'An error occurred. The  requested page route could not be found.',
1067
+					'event_espresso'
1068
+				);
1069
+				// developer error msg
1070
+				$error_msg .= '||';
1071
+				$error_msg .= sprintf(
1072
+					esc_html__(
1073
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1074
+						'event_espresso'
1075
+					),
1076
+					$method
1077
+				);
1078
+			}
1079
+			if (! empty($error_msg)) {
1080
+				throw new EE_Error($error_msg);
1081
+			}
1082
+		}
1083
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1084
+		// then we need to reset the routing properties to the new route.
1085
+		// now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1086
+		if (
1087
+			$this->_is_UI_request === false
1088
+			&& is_array($this->_route)
1089
+			&& ! empty($this->_route['headers_sent_route'])
1090
+		) {
1091
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1092
+		}
1093
+	}
1094
+
1095
+
1096
+	/**
1097
+	 * This method just allows the resetting of page properties in the case where a no headers
1098
+	 * route redirects to a headers route in its route config.
1099
+	 *
1100
+	 * @param string $new_route New (non header) route to redirect to.
1101
+	 * @return   void
1102
+	 * @throws ReflectionException
1103
+	 * @throws InvalidArgumentException
1104
+	 * @throws InvalidInterfaceException
1105
+	 * @throws InvalidDataTypeException
1106
+	 * @throws EE_Error
1107
+	 * @since   4.3.0
1108
+	 */
1109
+	protected function _reset_routing_properties($new_route)
1110
+	{
1111
+		$this->_is_UI_request = true;
1112
+		// now we set the current route to whatever the headers_sent_route is set at
1113
+		$this->request->setRequestParam('action', $new_route);
1114
+		// rerun page setup
1115
+		$this->_page_setup();
1116
+	}
1117
+
1118
+
1119
+	/**
1120
+	 * _add_query_arg
1121
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1122
+	 *(internally just uses EEH_URL's function with the same name)
1123
+	 *
1124
+	 * @param array  $args
1125
+	 * @param string $url
1126
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1127
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1128
+	 *                                        Example usage: If the current page is:
1129
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1130
+	 *                                        &action=default&event_id=20&month_range=March%202015
1131
+	 *                                        &_wpnonce=5467821
1132
+	 *                                        and you call:
1133
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1134
+	 *                                        array(
1135
+	 *                                        'action' => 'resend_something',
1136
+	 *                                        'page=>espresso_registrations'
1137
+	 *                                        ),
1138
+	 *                                        $some_url,
1139
+	 *                                        true
1140
+	 *                                        );
1141
+	 *                                        It will produce a url in this structure:
1142
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1143
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1144
+	 *                                        month_range]=March%202015
1145
+	 * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1146
+	 * @return string
1147
+	 */
1148
+	public static function add_query_args_and_nonce(
1149
+		$args = [],
1150
+		$url = false,
1151
+		$sticky = false,
1152
+		$exclude_nonce = false
1153
+	) {
1154
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1155
+		if ($sticky) {
1156
+			/** @var RequestInterface $request */
1157
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1158
+			$request->unSetRequestParams(['_wp_http_referer', 'wp_referer']);
1159
+			foreach ($request->requestParams() as $key => $value) {
1160
+				// do not add nonces
1161
+				if (strpos($key, 'nonce') !== false) {
1162
+					continue;
1163
+				}
1164
+				$args[ 'wp_referer[' . $key . ']' ] = $value;
1165
+			}
1166
+		}
1167
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1168
+	}
1169
+
1170
+
1171
+	/**
1172
+	 * This returns a generated link that will load the related help tab.
1173
+	 *
1174
+	 * @param string $help_tab_id the id for the connected help tab
1175
+	 * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1176
+	 * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1177
+	 * @return string              generated link
1178
+	 * @uses EEH_Template::get_help_tab_link()
1179
+	 */
1180
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1181
+	{
1182
+		return EEH_Template::get_help_tab_link(
1183
+			$help_tab_id,
1184
+			$this->page_slug,
1185
+			$this->_req_action,
1186
+			$icon_style,
1187
+			$help_text
1188
+		);
1189
+	}
1190
+
1191
+
1192
+	/**
1193
+	 * _add_help_tabs
1194
+	 * Note child classes define their help tabs within the page_config array.
1195
+	 *
1196
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1197
+	 * @return void
1198
+	 * @throws DomainException
1199
+	 * @throws EE_Error
1200
+	 */
1201
+	protected function _add_help_tabs()
1202
+	{
1203
+		$tour_buttons = '';
1204
+		if (isset($this->_page_config[ $this->_req_action ])) {
1205
+			$config = $this->_page_config[ $this->_req_action ];
1206
+			// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1207
+			// is there a help tour for the current route?  if there is let's setup the tour buttons
1208
+			// if (isset($this->_help_tour[ $this->_req_action ])) {
1209
+			//     $tb = array();
1210
+			//     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1211
+			//     foreach ($this->_help_tour['tours'] as $tour) {
1212
+			//         // if this is the end tour then we don't need to setup a button
1213
+			//         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1214
+			//             continue;
1215
+			//         }
1216
+			//         $tb[] = '<button id="trigger-tour-'
1217
+			//                 . $tour->get_slug()
1218
+			//                 . '" class="button-primary trigger-ee-help-tour">'
1219
+			//                 . $tour->get_label()
1220
+			//                 . '</button>';
1221
+			//     }
1222
+			//     $tour_buttons .= implode('<br />', $tb);
1223
+			//     $tour_buttons .= '</div></div>';
1224
+			// }
1225
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1226
+			if (is_array($config) && isset($config['help_sidebar'])) {
1227
+				// check that the callback given is valid
1228
+				if (! method_exists($this, $config['help_sidebar'])) {
1229
+					throw new EE_Error(
1230
+						sprintf(
1231
+							esc_html__(
1232
+								'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1233
+								'event_espresso'
1234
+							),
1235
+							$config['help_sidebar'],
1236
+							get_class($this)
1237
+						)
1238
+					);
1239
+				}
1240
+				$content = apply_filters(
1241
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1242
+					$this->{$config['help_sidebar']}()
1243
+				);
1244
+				$content .= $tour_buttons; // add help tour buttons.
1245
+				// do we have any help tours setup?  Cause if we do we want to add the buttons
1246
+				$this->_current_screen->set_help_sidebar($content);
1247
+			}
1248
+			// if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar.
1249
+			if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1250
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1251
+			}
1252
+			// handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1253
+			if (! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1254
+				$_ht['id']      = $this->page_slug;
1255
+				$_ht['title']   = esc_html__('Help Tours', 'event_espresso');
1256
+				$_ht['content'] = '<p>'
1257
+								  . esc_html__(
1258
+									  'The buttons to the right allow you to start/restart any help tours available for this page',
1259
+									  'event_espresso'
1260
+								  ) . '</p>';
1261
+				$this->_current_screen->add_help_tab($_ht);
1262
+			}
1263
+			if (! isset($config['help_tabs'])) {
1264
+				return;
1265
+			} //no help tabs for this route
1266
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1267
+				// we're here so there ARE help tabs!
1268
+				// make sure we've got what we need
1269
+				if (! isset($cfg['title'])) {
1270
+					throw new EE_Error(
1271
+						esc_html__(
1272
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1273
+							'event_espresso'
1274
+						)
1275
+					);
1276
+				}
1277
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1278
+					throw new EE_Error(
1279
+						esc_html__(
1280
+							'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1281
+							'event_espresso'
1282
+						)
1283
+					);
1284
+				}
1285
+				// first priority goes to content.
1286
+				if (! empty($cfg['content'])) {
1287
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1288
+					// second priority goes to filename
1289
+				} elseif (! empty($cfg['filename'])) {
1290
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1291
+					// it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1292
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1293
+															 . basename($this->_get_dir())
1294
+															 . '/help_tabs/'
1295
+															 . $cfg['filename']
1296
+															 . '.help_tab.php' : $file_path;
1297
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1298
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1299
+						EE_Error::add_error(
1300
+							sprintf(
1301
+								esc_html__(
1302
+									'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1303
+									'event_espresso'
1304
+								),
1305
+								$tab_id,
1306
+								key($config),
1307
+								$file_path
1308
+							),
1309
+							__FILE__,
1310
+							__FUNCTION__,
1311
+							__LINE__
1312
+						);
1313
+						return;
1314
+					}
1315
+					$template_args['admin_page_obj'] = $this;
1316
+					$content                         = EEH_Template::display_template(
1317
+						$file_path,
1318
+						$template_args,
1319
+						true
1320
+					);
1321
+				} else {
1322
+					$content = '';
1323
+				}
1324
+				// check if callback is valid
1325
+				if (
1326
+					empty($content)
1327
+					&& (
1328
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1329
+					)
1330
+				) {
1331
+					EE_Error::add_error(
1332
+						sprintf(
1333
+							esc_html__(
1334
+								'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1335
+								'event_espresso'
1336
+							),
1337
+							$cfg['title']
1338
+						),
1339
+						__FILE__,
1340
+						__FUNCTION__,
1341
+						__LINE__
1342
+					);
1343
+					return;
1344
+				}
1345
+				// setup config array for help tab method
1346
+				$id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1347
+				$_ht = [
1348
+					'id'       => $id,
1349
+					'title'    => $cfg['title'],
1350
+					'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1351
+					'content'  => $content,
1352
+				];
1353
+				$this->_current_screen->add_help_tab($_ht);
1354
+			}
1355
+		}
1356
+	}
1357
+
1358
+
1359
+	/**
1360
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1361
+	 * an array with properties for setting up usage of the joyride plugin
1362
+	 *
1363
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1364
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1365
+	 *         _set_page_config() comments
1366
+	 * @return void
1367
+	 * @throws InvalidArgumentException
1368
+	 * @throws InvalidDataTypeException
1369
+	 * @throws InvalidInterfaceException
1370
+	 */
1371
+	protected function _add_help_tour()
1372
+	{
1373
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1374
+		// $tours = array();
1375
+		// $this->_help_tour = array();
1376
+		// // exit early if help tours are turned off globally
1377
+		// if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1378
+		//     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1379
+		// ) {
1380
+		//     return;
1381
+		// }
1382
+		// // loop through _page_config to find any help_tour defined
1383
+		// foreach ($this->_page_config as $route => $config) {
1384
+		//     // we're only going to set things up for this route
1385
+		//     if ($route !== $this->_req_action) {
1386
+		//         continue;
1387
+		//     }
1388
+		//     if (isset($config['help_tour'])) {
1389
+		//         foreach ($config['help_tour'] as $tour) {
1390
+		//             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1391
+		//             // let's see if we can get that file...
1392
+		//             // if not its possible this is a decaf route not set in caffeinated
1393
+		//             // so lets try and get the caffeinated equivalent
1394
+		//             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1395
+		//                                                      . basename($this->_get_dir())
1396
+		//                                                      . '/help_tours/'
1397
+		//                                                      . $tour
1398
+		//                                                      . '.class.php' : $file_path;
1399
+		//             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1400
+		//             if (! is_readable($file_path)) {
1401
+		//                 EE_Error::add_error(
1402
+		//                     sprintf(
1403
+		//                         esc_html__(
1404
+		//                             'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1405
+		//                             'event_espresso'
1406
+		//                         ),
1407
+		//                         $file_path,
1408
+		//                         $tour
1409
+		//                     ),
1410
+		//                     __FILE__,
1411
+		//                     __FUNCTION__,
1412
+		//                     __LINE__
1413
+		//                 );
1414
+		//                 return;
1415
+		//             }
1416
+		//             require_once $file_path;
1417
+		//             if (! class_exists($tour)) {
1418
+		//                 $error_msg[] = sprintf(
1419
+		//                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1420
+		//                     $tour
1421
+		//                 );
1422
+		//                 $error_msg[] = $error_msg[0] . "\r\n"
1423
+		//                                . sprintf(
1424
+		//                                    esc_html__(
1425
+		//                                        'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1426
+		//                                        'event_espresso'
1427
+		//                                    ),
1428
+		//                                    $tour,
1429
+		//                                    '<br />',
1430
+		//                                    $tour,
1431
+		//                                    $this->_req_action,
1432
+		//                                    get_class($this)
1433
+		//                                );
1434
+		//                 throw new EE_Error(implode('||', $error_msg));
1435
+		//             }
1436
+		//             $tour_obj = new $tour($this->_is_caf);
1437
+		//             $tours[] = $tour_obj;
1438
+		//             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1439
+		//         }
1440
+		//         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1441
+		//         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1442
+		//         $tours[] = $end_stop_tour;
1443
+		//         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1444
+		//     }
1445
+		// }
1446
+		//
1447
+		// if (! empty($tours)) {
1448
+		//     $this->_help_tour['tours'] = $tours;
1449
+		// }
1450
+		// // that's it!  Now that the $_help_tours property is set (or not)
1451
+		// // the scripts and html should be taken care of automatically.
1452
+		//
1453
+		// /**
1454
+		//  * Allow extending the help tours variable.
1455
+		//  *
1456
+		//  * @param Array $_help_tour The array containing all help tour information to be displayed.
1457
+		//  */
1458
+		// $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1459
+	}
1460
+
1461
+
1462
+	/**
1463
+	 * This simply sets up any qtips that have been defined in the page config
1464
+	 *
1465
+	 * @return void
1466
+	 */
1467
+	protected function _add_qtips()
1468
+	{
1469
+		if (isset($this->_route_config['qtips'])) {
1470
+			$qtips = (array) $this->_route_config['qtips'];
1471
+			// load qtip loader
1472
+			$path = [
1473
+				$this->_get_dir() . '/qtips/',
1474
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1475
+			];
1476
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1477
+		}
1478
+	}
1479
+
1480
+
1481
+	/**
1482
+	 * _set_nav_tabs
1483
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1484
+	 * wish to add additional tabs or modify accordingly.
1485
+	 *
1486
+	 * @return void
1487
+	 * @throws InvalidArgumentException
1488
+	 * @throws InvalidInterfaceException
1489
+	 * @throws InvalidDataTypeException
1490
+	 */
1491
+	protected function _set_nav_tabs()
1492
+	{
1493
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1494
+		$i = 0;
1495
+		foreach ($this->_page_config as $slug => $config) {
1496
+			if (! is_array($config) || empty($config['nav'])) {
1497
+				continue;
1498
+			}
1499
+			// no nav tab for this config
1500
+			// check for persistent flag
1501
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1502
+				// nav tab is only to appear when route requested.
1503
+				continue;
1504
+			}
1505
+			if (! $this->check_user_access($slug, true)) {
1506
+				// no nav tab because current user does not have access.
1507
+				continue;
1508
+			}
1509
+			$css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1510
+			$this->_nav_tabs[ $slug ] = [
1511
+				'url'       => isset($config['nav']['url'])
1512
+					? $config['nav']['url']
1513
+					: self::add_query_args_and_nonce(
1514
+						['action' => $slug],
1515
+						$this->_admin_base_url
1516
+					),
1517
+				'link_text' => isset($config['nav']['label'])
1518
+					? $config['nav']['label']
1519
+					: ucwords(
1520
+						str_replace('_', ' ', $slug)
1521
+					),
1522
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1523
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1524
+			];
1525
+			$i++;
1526
+		}
1527
+		// if $this->_nav_tabs is empty then lets set the default
1528
+		if (empty($this->_nav_tabs)) {
1529
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1530
+				'url'       => $this->_admin_base_url,
1531
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1532
+				'css_class' => 'nav-tab-active',
1533
+				'order'     => 10,
1534
+			];
1535
+		}
1536
+		// now let's sort the tabs according to order
1537
+		usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1538
+	}
1539
+
1540
+
1541
+	/**
1542
+	 * _set_current_labels
1543
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1544
+	 * property array
1545
+	 *
1546
+	 * @return void
1547
+	 */
1548
+	private function _set_current_labels()
1549
+	{
1550
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1551
+			foreach ($this->_route_config['labels'] as $label => $text) {
1552
+				if (is_array($text)) {
1553
+					foreach ($text as $sublabel => $subtext) {
1554
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1555
+					}
1556
+				} else {
1557
+					$this->_labels[ $label ] = $text;
1558
+				}
1559
+			}
1560
+		}
1561
+	}
1562
+
1563
+
1564
+	/**
1565
+	 *        verifies user access for this admin page
1566
+	 *
1567
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1568
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1569
+	 *                               return false if verify fail.
1570
+	 * @return bool
1571
+	 * @throws InvalidArgumentException
1572
+	 * @throws InvalidDataTypeException
1573
+	 * @throws InvalidInterfaceException
1574
+	 */
1575
+	public function check_user_access($route_to_check = '', $verify_only = false)
1576
+	{
1577
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1578
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1579
+		$capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1580
+						  && is_array(
1581
+							  $this->_page_routes[ $route_to_check ]
1582
+						  )
1583
+						  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1584
+			? $this->_page_routes[ $route_to_check ]['capability'] : null;
1585
+		if (empty($capability) && empty($route_to_check)) {
1586
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1587
+				: $this->_route['capability'];
1588
+		} else {
1589
+			$capability = empty($capability) ? 'manage_options' : $capability;
1590
+		}
1591
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1592
+		if (
1593
+			! $this->request->isAjax()
1594
+			&& (
1595
+				! function_exists('is_admin')
1596
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1597
+					$capability,
1598
+					$this->page_slug
1599
+					. '_'
1600
+					. $route_to_check,
1601
+					$id
1602
+				)
1603
+			)
1604
+		) {
1605
+			if ($verify_only) {
1606
+				return false;
1607
+			}
1608
+			if (is_user_logged_in()) {
1609
+				wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1610
+			} else {
1611
+				return false;
1612
+			}
1613
+		}
1614
+		return true;
1615
+	}
1616
+
1617
+
1618
+	/**
1619
+	 * admin_init_global
1620
+	 * This runs all the code that we want executed within the WP admin_init hook.
1621
+	 * This method executes for ALL EE Admin pages.
1622
+	 *
1623
+	 * @return void
1624
+	 */
1625
+	public function admin_init_global()
1626
+	{
1627
+	}
1628
+
1629
+
1630
+	/**
1631
+	 * wp_loaded_global
1632
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1633
+	 * EE_Admin page and will execute on every EE Admin Page load
1634
+	 *
1635
+	 * @return void
1636
+	 */
1637
+	public function wp_loaded()
1638
+	{
1639
+	}
1640
+
1641
+
1642
+	/**
1643
+	 * admin_notices
1644
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1645
+	 * ALL EE_Admin pages.
1646
+	 *
1647
+	 * @return void
1648
+	 */
1649
+	public function admin_notices_global()
1650
+	{
1651
+		$this->_display_no_javascript_warning();
1652
+		$this->_display_espresso_notices();
1653
+	}
1654
+
1655
+
1656
+	public function network_admin_notices_global()
1657
+	{
1658
+		$this->_display_no_javascript_warning();
1659
+		$this->_display_espresso_notices();
1660
+	}
1661
+
1662
+
1663
+	/**
1664
+	 * admin_footer_scripts_global
1665
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1666
+	 * will apply on ALL EE_Admin pages.
1667
+	 *
1668
+	 * @return void
1669
+	 */
1670
+	public function admin_footer_scripts_global()
1671
+	{
1672
+		$this->_add_admin_page_ajax_loading_img();
1673
+		$this->_add_admin_page_overlay();
1674
+		// if metaboxes are present we need to add the nonce field
1675
+		if (
1676
+			isset($this->_route_config['metaboxes'])
1677
+			|| isset($this->_route_config['list_table'])
1678
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1679
+		) {
1680
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1681
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1682
+		}
1683
+	}
1684
+
1685
+
1686
+	/**
1687
+	 * admin_footer_global
1688
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on
1689
+	 * ALL EE_Admin Pages.
1690
+	 *
1691
+	 * @return void
1692
+	 */
1693
+	public function admin_footer_global()
1694
+	{
1695
+		// dialog container for dialog helper
1696
+		echo '
1697 1697
         <div class="ee-admin-dialog-container auto-hide hidden">
1698 1698
             <div class="ee-notices"></div>
1699 1699
             <div class="ee-admin-dialog-container-inner-content"></div>
1700 1700
         </div>
1701 1701
         ';
1702 1702
 
1703
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1704
-        // help tour stuff?
1705
-        // if (isset($this->_help_tour[ $this->_req_action ])) {
1706
-        //     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1707
-        // }
1708
-        // current set timezone for timezone js
1709
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1710
-    }
1711
-
1712
-
1713
-    /**
1714
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1715
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1716
-     * help popups then in your templates or your content you set "triggers" for the content using the
1717
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1718
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1719
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1720
-     * for the
1721
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1722
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1723
-     *    'help_trigger_id' => array(
1724
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1725
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1726
-     *    )
1727
-     * );
1728
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1729
-     *
1730
-     * @param array $help_array
1731
-     * @param bool  $display
1732
-     * @return string content
1733
-     * @throws DomainException
1734
-     * @throws EE_Error
1735
-     */
1736
-    protected function _set_help_popup_content($help_array = [], $display = false)
1737
-    {
1738
-        $content    = '';
1739
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1740
-        // loop through the array and setup content
1741
-        foreach ($help_array as $trigger => $help) {
1742
-            // make sure the array is setup properly
1743
-            if (! isset($help['title']) || ! isset($help['content'])) {
1744
-                throw new EE_Error(
1745
-                    esc_html__(
1746
-                        'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1747
-                        'event_espresso'
1748
-                    )
1749
-                );
1750
-            }
1751
-            // we're good so let'd setup the template vars and then assign parsed template content to our content.
1752
-            $template_args = [
1753
-                'help_popup_id'      => $trigger,
1754
-                'help_popup_title'   => $help['title'],
1755
-                'help_popup_content' => $help['content'],
1756
-            ];
1757
-            $content       .= EEH_Template::display_template(
1758
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1759
-                $template_args,
1760
-                true
1761
-            );
1762
-        }
1763
-        if ($display) {
1764
-            echo $content; // already escaped
1765
-            return '';
1766
-        }
1767
-        return $content;
1768
-    }
1769
-
1770
-
1771
-    /**
1772
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1773
-     *
1774
-     * @return array properly formatted array for help popup content
1775
-     * @throws EE_Error
1776
-     */
1777
-    private function _get_help_content()
1778
-    {
1779
-        // what is the method we're looking for?
1780
-        $method_name = '_help_popup_content_' . $this->_req_action;
1781
-        // if method doesn't exist let's get out.
1782
-        if (! method_exists($this, $method_name)) {
1783
-            return [];
1784
-        }
1785
-        // k we're good to go let's retrieve the help array
1786
-        $help_array = call_user_func([$this, $method_name]);
1787
-        // make sure we've got an array!
1788
-        if (! is_array($help_array)) {
1789
-            throw new EE_Error(
1790
-                esc_html__(
1791
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1792
-                    'event_espresso'
1793
-                )
1794
-            );
1795
-        }
1796
-        return $help_array;
1797
-    }
1798
-
1799
-
1800
-    /**
1801
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1802
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1803
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1804
-     *
1805
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1806
-     * @param boolean $display    if false then we return the trigger string
1807
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1808
-     * @return string
1809
-     * @throws DomainException
1810
-     * @throws EE_Error
1811
-     */
1812
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1813
-    {
1814
-        if ($this->request->isAjax()) {
1815
-            return '';
1816
-        }
1817
-        // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1818
-        $help_array   = $this->_get_help_content();
1819
-        $help_content = '';
1820
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1821
-            $help_array[ $trigger_id ] = [
1822
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1823
-                'content' => esc_html__(
1824
-                    'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1825
-                    'event_espresso'
1826
-                ),
1827
-            ];
1828
-            $help_content              = $this->_set_help_popup_content($help_array, false);
1829
-        }
1830
-        // let's setup the trigger
1831
-        $content = '<a class="ee-dialog" href="?height='
1832
-                   . esc_attr($dimensions[0])
1833
-                   . '&width='
1834
-                   . esc_attr($dimensions[1])
1835
-                   . '&inlineId='
1836
-                   . esc_attr($trigger_id)
1837
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1838
-        $content .= $help_content;
1839
-        if ($display) {
1840
-            echo $content; // already escaped
1841
-            return '';
1842
-        }
1843
-        return $content;
1844
-    }
1845
-
1846
-
1847
-    /**
1848
-     * _add_global_screen_options
1849
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1850
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1851
-     *
1852
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1853
-     *         see also WP_Screen object documents...
1854
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1855
-     * @abstract
1856
-     * @return void
1857
-     */
1858
-    private function _add_global_screen_options()
1859
-    {
1860
-    }
1861
-
1862
-
1863
-    /**
1864
-     * _add_global_feature_pointers
1865
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1866
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1867
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1868
-     *
1869
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1870
-     *         extended) also see:
1871
-     * @link   http://eamann.com/tech/wordpress-portland/
1872
-     * @abstract
1873
-     * @return void
1874
-     */
1875
-    private function _add_global_feature_pointers()
1876
-    {
1877
-    }
1878
-
1879
-
1880
-    /**
1881
-     * load_global_scripts_styles
1882
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1883
-     *
1884
-     * @return void
1885
-     */
1886
-    public function load_global_scripts_styles()
1887
-    {
1888
-        /** STYLES **/
1889
-        // add debugging styles
1890
-        if (WP_DEBUG) {
1891
-            add_action('admin_head', [$this, 'add_xdebug_style']);
1892
-        }
1893
-        // register all styles
1894
-        wp_register_style(
1895
-            'espresso-ui-theme',
1896
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1897
-            [],
1898
-            EVENT_ESPRESSO_VERSION
1899
-        );
1900
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1901
-        // helpers styles
1902
-        wp_register_style(
1903
-            'ee-text-links',
1904
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1905
-            [],
1906
-            EVENT_ESPRESSO_VERSION
1907
-        );
1908
-        /** SCRIPTS **/
1909
-        // register all scripts
1910
-        wp_register_script(
1911
-            'ee-dialog',
1912
-            EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1913
-            ['jquery', 'jquery-ui-draggable'],
1914
-            EVENT_ESPRESSO_VERSION,
1915
-            true
1916
-        );
1917
-        wp_register_script(
1918
-            'ee_admin_js',
1919
-            EE_ADMIN_URL . 'assets/ee-admin-page.js',
1920
-            ['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1921
-            EVENT_ESPRESSO_VERSION,
1922
-            true
1923
-        );
1924
-        wp_register_script(
1925
-            'jquery-ui-timepicker-addon',
1926
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1927
-            ['jquery-ui-datepicker', 'jquery-ui-slider'],
1928
-            EVENT_ESPRESSO_VERSION,
1929
-            true
1930
-        );
1931
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1932
-        // if (EE_Registry::instance()->CFG->admin->help_tour_activation) {
1933
-        //     add_filter('FHEE_load_joyride', '__return_true');
1934
-        // }
1935
-        // script for sorting tables
1936
-        wp_register_script(
1937
-            'espresso_ajax_table_sorting',
1938
-            EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1939
-            ['ee_admin_js', 'jquery-ui-sortable'],
1940
-            EVENT_ESPRESSO_VERSION,
1941
-            true
1942
-        );
1943
-        // script for parsing uri's
1944
-        wp_register_script(
1945
-            'ee-parse-uri',
1946
-            EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1947
-            [],
1948
-            EVENT_ESPRESSO_VERSION,
1949
-            true
1950
-        );
1951
-        // and parsing associative serialized form elements
1952
-        wp_register_script(
1953
-            'ee-serialize-full-array',
1954
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1955
-            ['jquery'],
1956
-            EVENT_ESPRESSO_VERSION,
1957
-            true
1958
-        );
1959
-        // helpers scripts
1960
-        wp_register_script(
1961
-            'ee-text-links',
1962
-            EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1963
-            ['jquery'],
1964
-            EVENT_ESPRESSO_VERSION,
1965
-            true
1966
-        );
1967
-        wp_register_script(
1968
-            'ee-moment-core',
1969
-            EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1970
-            [],
1971
-            EVENT_ESPRESSO_VERSION,
1972
-            true
1973
-        );
1974
-        wp_register_script(
1975
-            'ee-moment',
1976
-            EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1977
-            ['ee-moment-core'],
1978
-            EVENT_ESPRESSO_VERSION,
1979
-            true
1980
-        );
1981
-        wp_register_script(
1982
-            'ee-datepicker',
1983
-            EE_ADMIN_URL . 'assets/ee-datepicker.js',
1984
-            ['jquery-ui-timepicker-addon', 'ee-moment'],
1985
-            EVENT_ESPRESSO_VERSION,
1986
-            true
1987
-        );
1988
-        // google charts
1989
-        wp_register_script(
1990
-            'google-charts',
1991
-            'https://www.gstatic.com/charts/loader.js',
1992
-            [],
1993
-            EVENT_ESPRESSO_VERSION,
1994
-            false
1995
-        );
1996
-        // ENQUEUE ALL BASICS BY DEFAULT
1997
-        wp_enqueue_style('ee-admin-css');
1998
-        wp_enqueue_script('ee_admin_js');
1999
-        wp_enqueue_script('ee-accounting');
2000
-        wp_enqueue_script('jquery-validate');
2001
-        // taking care of metaboxes
2002
-        if (
2003
-            empty($this->_cpt_route)
2004
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
2005
-        ) {
2006
-            wp_enqueue_script('dashboard');
2007
-        }
2008
-        // LOCALIZED DATA
2009
-        // localize script for ajax lazy loading
2010
-        $lazy_loader_container_ids = apply_filters(
2011
-            'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
2012
-            ['espresso_news_post_box_content']
2013
-        );
2014
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
2015
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
2016
-        // /**
2017
-        //  * help tour stuff
2018
-        //  */
2019
-        // if (! empty($this->_help_tour)) {
2020
-        //     // register the js for kicking things off
2021
-        //     wp_enqueue_script(
2022
-        //         'ee-help-tour',
2023
-        //         EE_ADMIN_URL . 'assets/ee-help-tour.js',
2024
-        //         array('jquery-joyride'),
2025
-        //         EVENT_ESPRESSO_VERSION,
2026
-        //         true
2027
-        //     );
2028
-        //     $tours = array();
2029
-        //     // setup tours for the js tour object
2030
-        //     foreach ($this->_help_tour['tours'] as $tour) {
2031
-        //         if ($tour instanceof EE_Help_Tour) {
2032
-        //             $tours[] = array(
2033
-        //                 'id'      => $tour->get_slug(),
2034
-        //                 'options' => $tour->get_options(),
2035
-        //             );
2036
-        //         }
2037
-        //     }
2038
-        //     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
2039
-        //     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
2040
-        // }
2041
-
2042
-        add_filter(
2043
-            'admin_body_class',
2044
-            function ($classes) {
2045
-                if (strpos($classes, 'espresso-admin') === false) {
2046
-                    $classes .= ' espresso-admin';
2047
-                }
2048
-                return $classes;
2049
-            }
2050
-        );
2051
-    }
2052
-
2053
-
2054
-    /**
2055
-     *        admin_footer_scripts_eei18n_js_strings
2056
-     *
2057
-     * @return        void
2058
-     */
2059
-    public function admin_footer_scripts_eei18n_js_strings()
2060
-    {
2061
-        EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
2062
-        EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
2063
-            __(
2064
-                'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
2065
-                'event_espresso'
2066
-            )
2067
-        );
2068
-        EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
2069
-        EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
2070
-        EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
2071
-        EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
2072
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
2073
-        EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
2074
-        EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
2075
-        EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
2076
-        EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
2077
-        EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
2078
-        EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
2079
-        EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
2080
-        EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
2081
-        EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
2082
-        EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
2083
-        EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
2084
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
2085
-        EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
2086
-        EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
2087
-        EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
2088
-        EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
2089
-        EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
2090
-        EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
2091
-        EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
2092
-        EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
2093
-        EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
2094
-        EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
2095
-        EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
2096
-        EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
2097
-        EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
2098
-        EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
2099
-        EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
2100
-        EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
2101
-        EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
2102
-        EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
2103
-        EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
2104
-        EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
2105
-        EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
2106
-    }
2107
-
2108
-
2109
-    /**
2110
-     *        load enhanced xdebug styles for ppl with failing eyesight
2111
-     *
2112
-     * @return        void
2113
-     */
2114
-    public function add_xdebug_style()
2115
-    {
2116
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2117
-    }
2118
-
2119
-
2120
-    /************************/
2121
-    /** LIST TABLE METHODS **/
2122
-    /************************/
2123
-    /**
2124
-     * this sets up the list table if the current view requires it.
2125
-     *
2126
-     * @return void
2127
-     * @throws EE_Error
2128
-     */
2129
-    protected function _set_list_table()
2130
-    {
2131
-        // first is this a list_table view?
2132
-        if (! isset($this->_route_config['list_table'])) {
2133
-            return;
2134
-        } //not a list_table view so get out.
2135
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2136
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2137
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2138
-            // user error msg
2139
-            $error_msg = esc_html__(
2140
-                'An error occurred. The requested list table views could not be found.',
2141
-                'event_espresso'
2142
-            );
2143
-            // developer error msg
2144
-            $error_msg .= '||'
2145
-                          . sprintf(
2146
-                              esc_html__(
2147
-                                  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2148
-                                  'event_espresso'
2149
-                              ),
2150
-                              $this->_req_action,
2151
-                              $list_table_view
2152
-                          );
2153
-            throw new EE_Error($error_msg);
2154
-        }
2155
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2156
-        $this->_views = apply_filters(
2157
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2158
-            $this->_views
2159
-        );
2160
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2161
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2162
-        $this->_set_list_table_view();
2163
-        $this->_set_list_table_object();
2164
-    }
2165
-
2166
-
2167
-    /**
2168
-     * set current view for List Table
2169
-     *
2170
-     * @return void
2171
-     */
2172
-    protected function _set_list_table_view()
2173
-    {
2174
-        $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2175
-        $status = $this->request->getRequestParam('status', null, 'key');
2176
-        $this->_view = $status && array_key_exists($status, $this->_views)
2177
-            ? $status
2178
-            : $this->_view;
2179
-    }
2180
-
2181
-
2182
-    /**
2183
-     * _set_list_table_object
2184
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2185
-     *
2186
-     * @throws InvalidInterfaceException
2187
-     * @throws InvalidArgumentException
2188
-     * @throws InvalidDataTypeException
2189
-     * @throws EE_Error
2190
-     * @throws InvalidInterfaceException
2191
-     */
2192
-    protected function _set_list_table_object()
2193
-    {
2194
-        if (isset($this->_route_config['list_table'])) {
2195
-            if (! class_exists($this->_route_config['list_table'])) {
2196
-                throw new EE_Error(
2197
-                    sprintf(
2198
-                        esc_html__(
2199
-                            'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2200
-                            'event_espresso'
2201
-                        ),
2202
-                        $this->_route_config['list_table'],
2203
-                        get_class($this)
2204
-                    )
2205
-                );
2206
-            }
2207
-            $this->_list_table_object = $this->loader->getShared(
2208
-                $this->_route_config['list_table'],
2209
-                [$this]
2210
-            );
2211
-        }
2212
-    }
2213
-
2214
-
2215
-    /**
2216
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2217
-     *
2218
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2219
-     *                                                    urls.  The array should be indexed by the view it is being
2220
-     *                                                    added to.
2221
-     * @return array
2222
-     */
2223
-    public function get_list_table_view_RLs($extra_query_args = [])
2224
-    {
2225
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2226
-        if (empty($this->_views)) {
2227
-            $this->_views = [];
2228
-        }
2229
-        // cycle thru views
2230
-        foreach ($this->_views as $key => $view) {
2231
-            $query_args = [];
2232
-            // check for current view
2233
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2234
-            $query_args['action']                        = $this->_req_action;
2235
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2236
-            $query_args['status']                        = $view['slug'];
2237
-            // merge any other arguments sent in.
2238
-            if (isset($extra_query_args[ $view['slug'] ])) {
2239
-                $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2240
-            }
2241
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2242
-        }
2243
-        return $this->_views;
2244
-    }
2245
-
2246
-
2247
-    /**
2248
-     * _entries_per_page_dropdown
2249
-     * generates a dropdown box for selecting the number of visible rows in an admin page list table
2250
-     *
2251
-     * @param int $max_entries total number of rows in the table
2252
-     * @return string
2253
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2254
-     *         WP does it.
2255
-     */
2256
-    protected function _entries_per_page_dropdown($max_entries = 0)
2257
-    {
2258
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2259
-        $values   = [10, 25, 50, 100];
2260
-        $per_page = $this->request->getRequestParam('per_page', 10, 'int');
2261
-        if ($max_entries) {
2262
-            $values[] = $max_entries;
2263
-            sort($values);
2264
-        }
2265
-        $entries_per_page_dropdown = '
1703
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1704
+		// help tour stuff?
1705
+		// if (isset($this->_help_tour[ $this->_req_action ])) {
1706
+		//     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1707
+		// }
1708
+		// current set timezone for timezone js
1709
+		echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1710
+	}
1711
+
1712
+
1713
+	/**
1714
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1715
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1716
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1717
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1718
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1719
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1720
+	 * for the
1721
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1722
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1723
+	 *    'help_trigger_id' => array(
1724
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1725
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1726
+	 *    )
1727
+	 * );
1728
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1729
+	 *
1730
+	 * @param array $help_array
1731
+	 * @param bool  $display
1732
+	 * @return string content
1733
+	 * @throws DomainException
1734
+	 * @throws EE_Error
1735
+	 */
1736
+	protected function _set_help_popup_content($help_array = [], $display = false)
1737
+	{
1738
+		$content    = '';
1739
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1740
+		// loop through the array and setup content
1741
+		foreach ($help_array as $trigger => $help) {
1742
+			// make sure the array is setup properly
1743
+			if (! isset($help['title']) || ! isset($help['content'])) {
1744
+				throw new EE_Error(
1745
+					esc_html__(
1746
+						'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1747
+						'event_espresso'
1748
+					)
1749
+				);
1750
+			}
1751
+			// we're good so let'd setup the template vars and then assign parsed template content to our content.
1752
+			$template_args = [
1753
+				'help_popup_id'      => $trigger,
1754
+				'help_popup_title'   => $help['title'],
1755
+				'help_popup_content' => $help['content'],
1756
+			];
1757
+			$content       .= EEH_Template::display_template(
1758
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1759
+				$template_args,
1760
+				true
1761
+			);
1762
+		}
1763
+		if ($display) {
1764
+			echo $content; // already escaped
1765
+			return '';
1766
+		}
1767
+		return $content;
1768
+	}
1769
+
1770
+
1771
+	/**
1772
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1773
+	 *
1774
+	 * @return array properly formatted array for help popup content
1775
+	 * @throws EE_Error
1776
+	 */
1777
+	private function _get_help_content()
1778
+	{
1779
+		// what is the method we're looking for?
1780
+		$method_name = '_help_popup_content_' . $this->_req_action;
1781
+		// if method doesn't exist let's get out.
1782
+		if (! method_exists($this, $method_name)) {
1783
+			return [];
1784
+		}
1785
+		// k we're good to go let's retrieve the help array
1786
+		$help_array = call_user_func([$this, $method_name]);
1787
+		// make sure we've got an array!
1788
+		if (! is_array($help_array)) {
1789
+			throw new EE_Error(
1790
+				esc_html__(
1791
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1792
+					'event_espresso'
1793
+				)
1794
+			);
1795
+		}
1796
+		return $help_array;
1797
+	}
1798
+
1799
+
1800
+	/**
1801
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1802
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1803
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1804
+	 *
1805
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1806
+	 * @param boolean $display    if false then we return the trigger string
1807
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1808
+	 * @return string
1809
+	 * @throws DomainException
1810
+	 * @throws EE_Error
1811
+	 */
1812
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1813
+	{
1814
+		if ($this->request->isAjax()) {
1815
+			return '';
1816
+		}
1817
+		// let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1818
+		$help_array   = $this->_get_help_content();
1819
+		$help_content = '';
1820
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1821
+			$help_array[ $trigger_id ] = [
1822
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1823
+				'content' => esc_html__(
1824
+					'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1825
+					'event_espresso'
1826
+				),
1827
+			];
1828
+			$help_content              = $this->_set_help_popup_content($help_array, false);
1829
+		}
1830
+		// let's setup the trigger
1831
+		$content = '<a class="ee-dialog" href="?height='
1832
+				   . esc_attr($dimensions[0])
1833
+				   . '&width='
1834
+				   . esc_attr($dimensions[1])
1835
+				   . '&inlineId='
1836
+				   . esc_attr($trigger_id)
1837
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1838
+		$content .= $help_content;
1839
+		if ($display) {
1840
+			echo $content; // already escaped
1841
+			return '';
1842
+		}
1843
+		return $content;
1844
+	}
1845
+
1846
+
1847
+	/**
1848
+	 * _add_global_screen_options
1849
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1850
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1851
+	 *
1852
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1853
+	 *         see also WP_Screen object documents...
1854
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1855
+	 * @abstract
1856
+	 * @return void
1857
+	 */
1858
+	private function _add_global_screen_options()
1859
+	{
1860
+	}
1861
+
1862
+
1863
+	/**
1864
+	 * _add_global_feature_pointers
1865
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1866
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1867
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1868
+	 *
1869
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1870
+	 *         extended) also see:
1871
+	 * @link   http://eamann.com/tech/wordpress-portland/
1872
+	 * @abstract
1873
+	 * @return void
1874
+	 */
1875
+	private function _add_global_feature_pointers()
1876
+	{
1877
+	}
1878
+
1879
+
1880
+	/**
1881
+	 * load_global_scripts_styles
1882
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1883
+	 *
1884
+	 * @return void
1885
+	 */
1886
+	public function load_global_scripts_styles()
1887
+	{
1888
+		/** STYLES **/
1889
+		// add debugging styles
1890
+		if (WP_DEBUG) {
1891
+			add_action('admin_head', [$this, 'add_xdebug_style']);
1892
+		}
1893
+		// register all styles
1894
+		wp_register_style(
1895
+			'espresso-ui-theme',
1896
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1897
+			[],
1898
+			EVENT_ESPRESSO_VERSION
1899
+		);
1900
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', [], EVENT_ESPRESSO_VERSION);
1901
+		// helpers styles
1902
+		wp_register_style(
1903
+			'ee-text-links',
1904
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css',
1905
+			[],
1906
+			EVENT_ESPRESSO_VERSION
1907
+		);
1908
+		/** SCRIPTS **/
1909
+		// register all scripts
1910
+		wp_register_script(
1911
+			'ee-dialog',
1912
+			EE_ADMIN_URL . 'assets/ee-dialog-helper.js',
1913
+			['jquery', 'jquery-ui-draggable'],
1914
+			EVENT_ESPRESSO_VERSION,
1915
+			true
1916
+		);
1917
+		wp_register_script(
1918
+			'ee_admin_js',
1919
+			EE_ADMIN_URL . 'assets/ee-admin-page.js',
1920
+			['espresso_core', 'ee-parse-uri', 'ee-dialog'],
1921
+			EVENT_ESPRESSO_VERSION,
1922
+			true
1923
+		);
1924
+		wp_register_script(
1925
+			'jquery-ui-timepicker-addon',
1926
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js',
1927
+			['jquery-ui-datepicker', 'jquery-ui-slider'],
1928
+			EVENT_ESPRESSO_VERSION,
1929
+			true
1930
+		);
1931
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1932
+		// if (EE_Registry::instance()->CFG->admin->help_tour_activation) {
1933
+		//     add_filter('FHEE_load_joyride', '__return_true');
1934
+		// }
1935
+		// script for sorting tables
1936
+		wp_register_script(
1937
+			'espresso_ajax_table_sorting',
1938
+			EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js',
1939
+			['ee_admin_js', 'jquery-ui-sortable'],
1940
+			EVENT_ESPRESSO_VERSION,
1941
+			true
1942
+		);
1943
+		// script for parsing uri's
1944
+		wp_register_script(
1945
+			'ee-parse-uri',
1946
+			EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js',
1947
+			[],
1948
+			EVENT_ESPRESSO_VERSION,
1949
+			true
1950
+		);
1951
+		// and parsing associative serialized form elements
1952
+		wp_register_script(
1953
+			'ee-serialize-full-array',
1954
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js',
1955
+			['jquery'],
1956
+			EVENT_ESPRESSO_VERSION,
1957
+			true
1958
+		);
1959
+		// helpers scripts
1960
+		wp_register_script(
1961
+			'ee-text-links',
1962
+			EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js',
1963
+			['jquery'],
1964
+			EVENT_ESPRESSO_VERSION,
1965
+			true
1966
+		);
1967
+		wp_register_script(
1968
+			'ee-moment-core',
1969
+			EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js',
1970
+			[],
1971
+			EVENT_ESPRESSO_VERSION,
1972
+			true
1973
+		);
1974
+		wp_register_script(
1975
+			'ee-moment',
1976
+			EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js',
1977
+			['ee-moment-core'],
1978
+			EVENT_ESPRESSO_VERSION,
1979
+			true
1980
+		);
1981
+		wp_register_script(
1982
+			'ee-datepicker',
1983
+			EE_ADMIN_URL . 'assets/ee-datepicker.js',
1984
+			['jquery-ui-timepicker-addon', 'ee-moment'],
1985
+			EVENT_ESPRESSO_VERSION,
1986
+			true
1987
+		);
1988
+		// google charts
1989
+		wp_register_script(
1990
+			'google-charts',
1991
+			'https://www.gstatic.com/charts/loader.js',
1992
+			[],
1993
+			EVENT_ESPRESSO_VERSION,
1994
+			false
1995
+		);
1996
+		// ENQUEUE ALL BASICS BY DEFAULT
1997
+		wp_enqueue_style('ee-admin-css');
1998
+		wp_enqueue_script('ee_admin_js');
1999
+		wp_enqueue_script('ee-accounting');
2000
+		wp_enqueue_script('jquery-validate');
2001
+		// taking care of metaboxes
2002
+		if (
2003
+			empty($this->_cpt_route)
2004
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
2005
+		) {
2006
+			wp_enqueue_script('dashboard');
2007
+		}
2008
+		// LOCALIZED DATA
2009
+		// localize script for ajax lazy loading
2010
+		$lazy_loader_container_ids = apply_filters(
2011
+			'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
2012
+			['espresso_news_post_box_content']
2013
+		);
2014
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
2015
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
2016
+		// /**
2017
+		//  * help tour stuff
2018
+		//  */
2019
+		// if (! empty($this->_help_tour)) {
2020
+		//     // register the js for kicking things off
2021
+		//     wp_enqueue_script(
2022
+		//         'ee-help-tour',
2023
+		//         EE_ADMIN_URL . 'assets/ee-help-tour.js',
2024
+		//         array('jquery-joyride'),
2025
+		//         EVENT_ESPRESSO_VERSION,
2026
+		//         true
2027
+		//     );
2028
+		//     $tours = array();
2029
+		//     // setup tours for the js tour object
2030
+		//     foreach ($this->_help_tour['tours'] as $tour) {
2031
+		//         if ($tour instanceof EE_Help_Tour) {
2032
+		//             $tours[] = array(
2033
+		//                 'id'      => $tour->get_slug(),
2034
+		//                 'options' => $tour->get_options(),
2035
+		//             );
2036
+		//         }
2037
+		//     }
2038
+		//     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
2039
+		//     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
2040
+		// }
2041
+
2042
+		add_filter(
2043
+			'admin_body_class',
2044
+			function ($classes) {
2045
+				if (strpos($classes, 'espresso-admin') === false) {
2046
+					$classes .= ' espresso-admin';
2047
+				}
2048
+				return $classes;
2049
+			}
2050
+		);
2051
+	}
2052
+
2053
+
2054
+	/**
2055
+	 *        admin_footer_scripts_eei18n_js_strings
2056
+	 *
2057
+	 * @return        void
2058
+	 */
2059
+	public function admin_footer_scripts_eei18n_js_strings()
2060
+	{
2061
+		EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
2062
+		EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
2063
+			__(
2064
+				'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
2065
+				'event_espresso'
2066
+			)
2067
+		);
2068
+		EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
2069
+		EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
2070
+		EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
2071
+		EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
2072
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
2073
+		EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
2074
+		EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
2075
+		EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
2076
+		EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
2077
+		EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
2078
+		EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
2079
+		EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
2080
+		EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
2081
+		EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
2082
+		EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
2083
+		EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
2084
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
2085
+		EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
2086
+		EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
2087
+		EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
2088
+		EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
2089
+		EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
2090
+		EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
2091
+		EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
2092
+		EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
2093
+		EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
2094
+		EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
2095
+		EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
2096
+		EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
2097
+		EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
2098
+		EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
2099
+		EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
2100
+		EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
2101
+		EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
2102
+		EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
2103
+		EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
2104
+		EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
2105
+		EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
2106
+	}
2107
+
2108
+
2109
+	/**
2110
+	 *        load enhanced xdebug styles for ppl with failing eyesight
2111
+	 *
2112
+	 * @return        void
2113
+	 */
2114
+	public function add_xdebug_style()
2115
+	{
2116
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2117
+	}
2118
+
2119
+
2120
+	/************************/
2121
+	/** LIST TABLE METHODS **/
2122
+	/************************/
2123
+	/**
2124
+	 * this sets up the list table if the current view requires it.
2125
+	 *
2126
+	 * @return void
2127
+	 * @throws EE_Error
2128
+	 */
2129
+	protected function _set_list_table()
2130
+	{
2131
+		// first is this a list_table view?
2132
+		if (! isset($this->_route_config['list_table'])) {
2133
+			return;
2134
+		} //not a list_table view so get out.
2135
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2136
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2137
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2138
+			// user error msg
2139
+			$error_msg = esc_html__(
2140
+				'An error occurred. The requested list table views could not be found.',
2141
+				'event_espresso'
2142
+			);
2143
+			// developer error msg
2144
+			$error_msg .= '||'
2145
+						  . sprintf(
2146
+							  esc_html__(
2147
+								  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2148
+								  'event_espresso'
2149
+							  ),
2150
+							  $this->_req_action,
2151
+							  $list_table_view
2152
+						  );
2153
+			throw new EE_Error($error_msg);
2154
+		}
2155
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2156
+		$this->_views = apply_filters(
2157
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2158
+			$this->_views
2159
+		);
2160
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2161
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2162
+		$this->_set_list_table_view();
2163
+		$this->_set_list_table_object();
2164
+	}
2165
+
2166
+
2167
+	/**
2168
+	 * set current view for List Table
2169
+	 *
2170
+	 * @return void
2171
+	 */
2172
+	protected function _set_list_table_view()
2173
+	{
2174
+		$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2175
+		$status = $this->request->getRequestParam('status', null, 'key');
2176
+		$this->_view = $status && array_key_exists($status, $this->_views)
2177
+			? $status
2178
+			: $this->_view;
2179
+	}
2180
+
2181
+
2182
+	/**
2183
+	 * _set_list_table_object
2184
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2185
+	 *
2186
+	 * @throws InvalidInterfaceException
2187
+	 * @throws InvalidArgumentException
2188
+	 * @throws InvalidDataTypeException
2189
+	 * @throws EE_Error
2190
+	 * @throws InvalidInterfaceException
2191
+	 */
2192
+	protected function _set_list_table_object()
2193
+	{
2194
+		if (isset($this->_route_config['list_table'])) {
2195
+			if (! class_exists($this->_route_config['list_table'])) {
2196
+				throw new EE_Error(
2197
+					sprintf(
2198
+						esc_html__(
2199
+							'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2200
+							'event_espresso'
2201
+						),
2202
+						$this->_route_config['list_table'],
2203
+						get_class($this)
2204
+					)
2205
+				);
2206
+			}
2207
+			$this->_list_table_object = $this->loader->getShared(
2208
+				$this->_route_config['list_table'],
2209
+				[$this]
2210
+			);
2211
+		}
2212
+	}
2213
+
2214
+
2215
+	/**
2216
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2217
+	 *
2218
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2219
+	 *                                                    urls.  The array should be indexed by the view it is being
2220
+	 *                                                    added to.
2221
+	 * @return array
2222
+	 */
2223
+	public function get_list_table_view_RLs($extra_query_args = [])
2224
+	{
2225
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2226
+		if (empty($this->_views)) {
2227
+			$this->_views = [];
2228
+		}
2229
+		// cycle thru views
2230
+		foreach ($this->_views as $key => $view) {
2231
+			$query_args = [];
2232
+			// check for current view
2233
+			$this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2234
+			$query_args['action']                        = $this->_req_action;
2235
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2236
+			$query_args['status']                        = $view['slug'];
2237
+			// merge any other arguments sent in.
2238
+			if (isset($extra_query_args[ $view['slug'] ])) {
2239
+				$query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]);
2240
+			}
2241
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2242
+		}
2243
+		return $this->_views;
2244
+	}
2245
+
2246
+
2247
+	/**
2248
+	 * _entries_per_page_dropdown
2249
+	 * generates a dropdown box for selecting the number of visible rows in an admin page list table
2250
+	 *
2251
+	 * @param int $max_entries total number of rows in the table
2252
+	 * @return string
2253
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2254
+	 *         WP does it.
2255
+	 */
2256
+	protected function _entries_per_page_dropdown($max_entries = 0)
2257
+	{
2258
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2259
+		$values   = [10, 25, 50, 100];
2260
+		$per_page = $this->request->getRequestParam('per_page', 10, 'int');
2261
+		if ($max_entries) {
2262
+			$values[] = $max_entries;
2263
+			sort($values);
2264
+		}
2265
+		$entries_per_page_dropdown = '
2266 2266
 			<div id="entries-per-page-dv" class="alignleft actions">
2267 2267
 				<label class="hide-if-no-js">
2268 2268
 					Show
2269 2269
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2270
-        foreach ($values as $value) {
2271
-            if ($value < $max_entries) {
2272
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2273
-                $entries_per_page_dropdown .= '
2270
+		foreach ($values as $value) {
2271
+			if ($value < $max_entries) {
2272
+				$selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2273
+				$entries_per_page_dropdown .= '
2274 2274
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2275
-            }
2276
-        }
2277
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2278
-        $entries_per_page_dropdown .= '
2275
+			}
2276
+		}
2277
+		$selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2278
+		$entries_per_page_dropdown .= '
2279 2279
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2280
-        $entries_per_page_dropdown .= '
2280
+		$entries_per_page_dropdown .= '
2281 2281
 					</select>
2282 2282
 					entries
2283 2283
 				</label>
2284 2284
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2285 2285
 			</div>
2286 2286
 		';
2287
-        return $entries_per_page_dropdown;
2288
-    }
2289
-
2290
-
2291
-    /**
2292
-     *        _set_search_attributes
2293
-     *
2294
-     * @return        void
2295
-     */
2296
-    public function _set_search_attributes()
2297
-    {
2298
-        $this->_template_args['search']['btn_label'] = sprintf(
2299
-            esc_html__('Search %s', 'event_espresso'),
2300
-            empty($this->_search_btn_label) ? $this->page_label
2301
-                : $this->_search_btn_label
2302
-        );
2303
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2304
-    }
2305
-
2306
-
2307
-
2308
-    /*** END LIST TABLE METHODS **/
2309
-
2310
-
2311
-    /**
2312
-     * _add_registered_metaboxes
2313
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2314
-     *
2315
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2316
-     * @return void
2317
-     * @throws EE_Error
2318
-     */
2319
-    private function _add_registered_meta_boxes()
2320
-    {
2321
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2322
-        // we only add meta boxes if the page_route calls for it
2323
-        if (
2324
-            is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2325
-            && is_array(
2326
-                $this->_route_config['metaboxes']
2327
-            )
2328
-        ) {
2329
-            // this simply loops through the callbacks provided
2330
-            // and checks if there is a corresponding callback registered by the child
2331
-            // if there is then we go ahead and process the metabox loader.
2332
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2333
-                // first check for Closures
2334
-                if ($metabox_callback instanceof Closure) {
2335
-                    $result = $metabox_callback();
2336
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2337
-                    $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2338
-                } else {
2339
-                    $result = call_user_func([$this, &$metabox_callback]);
2340
-                }
2341
-                if ($result === false) {
2342
-                    // user error msg
2343
-                    $error_msg = esc_html__(
2344
-                        'An error occurred. The  requested metabox could not be found.',
2345
-                        'event_espresso'
2346
-                    );
2347
-                    // developer error msg
2348
-                    $error_msg .= '||'
2349
-                                  . sprintf(
2350
-                                      esc_html__(
2351
-                                          'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2352
-                                          'event_espresso'
2353
-                                      ),
2354
-                                      $metabox_callback
2355
-                                  );
2356
-                    throw new EE_Error($error_msg);
2357
-                }
2358
-            }
2359
-        }
2360
-    }
2361
-
2362
-
2363
-    /**
2364
-     * _add_screen_columns
2365
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2366
-     * the dynamic column template and we'll setup the column options for the page.
2367
-     *
2368
-     * @return void
2369
-     */
2370
-    private function _add_screen_columns()
2371
-    {
2372
-        if (
2373
-            is_array($this->_route_config)
2374
-            && isset($this->_route_config['columns'])
2375
-            && is_array($this->_route_config['columns'])
2376
-            && count($this->_route_config['columns']) === 2
2377
-        ) {
2378
-            add_screen_option(
2379
-                'layout_columns',
2380
-                [
2381
-                    'max'     => (int) $this->_route_config['columns'][0],
2382
-                    'default' => (int) $this->_route_config['columns'][1],
2383
-                ]
2384
-            );
2385
-            $this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2386
-            $screen_id                                           = $this->_current_screen->id;
2387
-            $screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2388
-            $total_columns                                       = ! empty($screen_columns)
2389
-                ? $screen_columns
2390
-                : $this->_route_config['columns'][1];
2391
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2392
-            $this->_template_args['current_page']                = $this->_wp_page_slug;
2393
-            $this->_template_args['screen']                      = $this->_current_screen;
2394
-            $this->_column_template_path                         = EE_ADMIN_TEMPLATE
2395
-                                                                   . 'admin_details_metabox_column_wrapper.template.php';
2396
-            // finally if we don't have has_metaboxes set in the route config
2397
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2398
-            $this->_route_config['has_metaboxes'] = true;
2399
-        }
2400
-    }
2401
-
2402
-
2403
-
2404
-    /** GLOBALLY AVAILABLE METABOXES **/
2405
-
2406
-
2407
-    /**
2408
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2409
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2410
-     * these get loaded on.
2411
-     */
2412
-    private function _espresso_news_post_box()
2413
-    {
2414
-        $news_box_title = apply_filters(
2415
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2416
-            esc_html__('New @ Event Espresso', 'event_espresso')
2417
-        );
2418
-        add_meta_box(
2419
-            'espresso_news_post_box',
2420
-            $news_box_title,
2421
-            [
2422
-                $this,
2423
-                'espresso_news_post_box',
2424
-            ],
2425
-            $this->_wp_page_slug,
2426
-            'side'
2427
-        );
2428
-    }
2429
-
2430
-
2431
-    /**
2432
-     * Code for setting up espresso ratings request metabox.
2433
-     */
2434
-    protected function _espresso_ratings_request()
2435
-    {
2436
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2437
-            return;
2438
-        }
2439
-        $ratings_box_title = apply_filters(
2440
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2441
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2442
-        );
2443
-        add_meta_box(
2444
-            'espresso_ratings_request',
2445
-            $ratings_box_title,
2446
-            [
2447
-                $this,
2448
-                'espresso_ratings_request',
2449
-            ],
2450
-            $this->_wp_page_slug,
2451
-            'side'
2452
-        );
2453
-    }
2454
-
2455
-
2456
-    /**
2457
-     * Code for setting up espresso ratings request metabox content.
2458
-     *
2459
-     * @throws DomainException
2460
-     */
2461
-    public function espresso_ratings_request()
2462
-    {
2463
-        EEH_Template::display_template(
2464
-            EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2465
-            []
2466
-        );
2467
-    }
2468
-
2469
-
2470
-    public static function cached_rss_display($rss_id, $url)
2471
-    {
2472
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2473
-                     . esc_html__('Loading&#8230;', 'event_espresso')
2474
-                     . '</p><p class="hide-if-js">'
2475
-                     . esc_html__('This widget requires JavaScript.', 'event_espresso')
2476
-                     . '</p>';
2477
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2478
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2479
-        $post      = '</div>' . "\n";
2480
-        $cache_key = 'ee_rss_' . md5($rss_id);
2481
-        $output    = get_transient($cache_key);
2482
-        if ($output !== false) {
2483
-            echo $pre . $output . $post; // already escaped
2484
-            return true;
2485
-        }
2486
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2487
-            echo $pre . $loading . $post; // already escaped
2488
-            return false;
2489
-        }
2490
-        ob_start();
2491
-        wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2492
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2493
-        return true;
2494
-    }
2495
-
2496
-
2497
-    public function espresso_news_post_box()
2498
-    {
2499
-        ?>
2287
+		return $entries_per_page_dropdown;
2288
+	}
2289
+
2290
+
2291
+	/**
2292
+	 *        _set_search_attributes
2293
+	 *
2294
+	 * @return        void
2295
+	 */
2296
+	public function _set_search_attributes()
2297
+	{
2298
+		$this->_template_args['search']['btn_label'] = sprintf(
2299
+			esc_html__('Search %s', 'event_espresso'),
2300
+			empty($this->_search_btn_label) ? $this->page_label
2301
+				: $this->_search_btn_label
2302
+		);
2303
+		$this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2304
+	}
2305
+
2306
+
2307
+
2308
+	/*** END LIST TABLE METHODS **/
2309
+
2310
+
2311
+	/**
2312
+	 * _add_registered_metaboxes
2313
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2314
+	 *
2315
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2316
+	 * @return void
2317
+	 * @throws EE_Error
2318
+	 */
2319
+	private function _add_registered_meta_boxes()
2320
+	{
2321
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2322
+		// we only add meta boxes if the page_route calls for it
2323
+		if (
2324
+			is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2325
+			&& is_array(
2326
+				$this->_route_config['metaboxes']
2327
+			)
2328
+		) {
2329
+			// this simply loops through the callbacks provided
2330
+			// and checks if there is a corresponding callback registered by the child
2331
+			// if there is then we go ahead and process the metabox loader.
2332
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2333
+				// first check for Closures
2334
+				if ($metabox_callback instanceof Closure) {
2335
+					$result = $metabox_callback();
2336
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2337
+					$result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2338
+				} else {
2339
+					$result = call_user_func([$this, &$metabox_callback]);
2340
+				}
2341
+				if ($result === false) {
2342
+					// user error msg
2343
+					$error_msg = esc_html__(
2344
+						'An error occurred. The  requested metabox could not be found.',
2345
+						'event_espresso'
2346
+					);
2347
+					// developer error msg
2348
+					$error_msg .= '||'
2349
+								  . sprintf(
2350
+									  esc_html__(
2351
+										  'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2352
+										  'event_espresso'
2353
+									  ),
2354
+									  $metabox_callback
2355
+								  );
2356
+					throw new EE_Error($error_msg);
2357
+				}
2358
+			}
2359
+		}
2360
+	}
2361
+
2362
+
2363
+	/**
2364
+	 * _add_screen_columns
2365
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2366
+	 * the dynamic column template and we'll setup the column options for the page.
2367
+	 *
2368
+	 * @return void
2369
+	 */
2370
+	private function _add_screen_columns()
2371
+	{
2372
+		if (
2373
+			is_array($this->_route_config)
2374
+			&& isset($this->_route_config['columns'])
2375
+			&& is_array($this->_route_config['columns'])
2376
+			&& count($this->_route_config['columns']) === 2
2377
+		) {
2378
+			add_screen_option(
2379
+				'layout_columns',
2380
+				[
2381
+					'max'     => (int) $this->_route_config['columns'][0],
2382
+					'default' => (int) $this->_route_config['columns'][1],
2383
+				]
2384
+			);
2385
+			$this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2386
+			$screen_id                                           = $this->_current_screen->id;
2387
+			$screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2388
+			$total_columns                                       = ! empty($screen_columns)
2389
+				? $screen_columns
2390
+				: $this->_route_config['columns'][1];
2391
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2392
+			$this->_template_args['current_page']                = $this->_wp_page_slug;
2393
+			$this->_template_args['screen']                      = $this->_current_screen;
2394
+			$this->_column_template_path                         = EE_ADMIN_TEMPLATE
2395
+																   . 'admin_details_metabox_column_wrapper.template.php';
2396
+			// finally if we don't have has_metaboxes set in the route config
2397
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2398
+			$this->_route_config['has_metaboxes'] = true;
2399
+		}
2400
+	}
2401
+
2402
+
2403
+
2404
+	/** GLOBALLY AVAILABLE METABOXES **/
2405
+
2406
+
2407
+	/**
2408
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2409
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2410
+	 * these get loaded on.
2411
+	 */
2412
+	private function _espresso_news_post_box()
2413
+	{
2414
+		$news_box_title = apply_filters(
2415
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2416
+			esc_html__('New @ Event Espresso', 'event_espresso')
2417
+		);
2418
+		add_meta_box(
2419
+			'espresso_news_post_box',
2420
+			$news_box_title,
2421
+			[
2422
+				$this,
2423
+				'espresso_news_post_box',
2424
+			],
2425
+			$this->_wp_page_slug,
2426
+			'side'
2427
+		);
2428
+	}
2429
+
2430
+
2431
+	/**
2432
+	 * Code for setting up espresso ratings request metabox.
2433
+	 */
2434
+	protected function _espresso_ratings_request()
2435
+	{
2436
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2437
+			return;
2438
+		}
2439
+		$ratings_box_title = apply_filters(
2440
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2441
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2442
+		);
2443
+		add_meta_box(
2444
+			'espresso_ratings_request',
2445
+			$ratings_box_title,
2446
+			[
2447
+				$this,
2448
+				'espresso_ratings_request',
2449
+			],
2450
+			$this->_wp_page_slug,
2451
+			'side'
2452
+		);
2453
+	}
2454
+
2455
+
2456
+	/**
2457
+	 * Code for setting up espresso ratings request metabox content.
2458
+	 *
2459
+	 * @throws DomainException
2460
+	 */
2461
+	public function espresso_ratings_request()
2462
+	{
2463
+		EEH_Template::display_template(
2464
+			EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php',
2465
+			[]
2466
+		);
2467
+	}
2468
+
2469
+
2470
+	public static function cached_rss_display($rss_id, $url)
2471
+	{
2472
+		$loading   = '<p class="widget-loading hide-if-no-js">'
2473
+					 . esc_html__('Loading&#8230;', 'event_espresso')
2474
+					 . '</p><p class="hide-if-js">'
2475
+					 . esc_html__('This widget requires JavaScript.', 'event_espresso')
2476
+					 . '</p>';
2477
+		$pre       = '<div class="espresso-rss-display">' . "\n\t";
2478
+		$pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2479
+		$post      = '</div>' . "\n";
2480
+		$cache_key = 'ee_rss_' . md5($rss_id);
2481
+		$output    = get_transient($cache_key);
2482
+		if ($output !== false) {
2483
+			echo $pre . $output . $post; // already escaped
2484
+			return true;
2485
+		}
2486
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2487
+			echo $pre . $loading . $post; // already escaped
2488
+			return false;
2489
+		}
2490
+		ob_start();
2491
+		wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2492
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2493
+		return true;
2494
+	}
2495
+
2496
+
2497
+	public function espresso_news_post_box()
2498
+	{
2499
+		?>
2500 2500
         <div class="padding">
2501 2501
             <div id="espresso_news_post_box_content" class="infolinks">
2502 2502
                 <?php
2503
-                // Get RSS Feed(s)
2504
-                self::cached_rss_display(
2505
-                    'espresso_news_post_box_content',
2506
-                    urlencode(
2507
-                        apply_filters(
2508
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2509
-                            'https://eventespresso.com/feed/'
2510
-                        )
2511
-                    )
2512
-                );
2513
-                ?>
2503
+				// Get RSS Feed(s)
2504
+				self::cached_rss_display(
2505
+					'espresso_news_post_box_content',
2506
+					urlencode(
2507
+						apply_filters(
2508
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2509
+							'https://eventespresso.com/feed/'
2510
+						)
2511
+					)
2512
+				);
2513
+				?>
2514 2514
             </div>
2515 2515
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2516 2516
         </div>
2517 2517
         <?php
2518
-    }
2519
-
2520
-
2521
-    private function _espresso_links_post_box()
2522
-    {
2523
-        // Hiding until we actually have content to put in here...
2524
-        // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2525
-    }
2526
-
2527
-
2528
-    public function espresso_links_post_box()
2529
-    {
2530
-        // Hiding until we actually have content to put in here...
2531
-        // EEH_Template::display_template(
2532
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2533
-        // );
2534
-    }
2535
-
2536
-
2537
-    protected function _espresso_sponsors_post_box()
2538
-    {
2539
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2540
-            add_meta_box(
2541
-                'espresso_sponsors_post_box',
2542
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2543
-                [$this, 'espresso_sponsors_post_box'],
2544
-                $this->_wp_page_slug,
2545
-                'side'
2546
-            );
2547
-        }
2548
-    }
2549
-
2550
-
2551
-    public function espresso_sponsors_post_box()
2552
-    {
2553
-        EEH_Template::display_template(
2554
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2555
-        );
2556
-    }
2557
-
2558
-
2559
-    private function _publish_post_box()
2560
-    {
2561
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2562
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2563
-        // then we'll use that for the metabox label.
2564
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2565
-        if (! empty($this->_labels['publishbox'])) {
2566
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2567
-                : $this->_labels['publishbox'];
2568
-        } else {
2569
-            $box_label = esc_html__('Publish', 'event_espresso');
2570
-        }
2571
-        $box_label = apply_filters(
2572
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2573
-            $box_label,
2574
-            $this->_req_action,
2575
-            $this
2576
-        );
2577
-        add_meta_box(
2578
-            $meta_box_ref,
2579
-            $box_label,
2580
-            [$this, 'editor_overview'],
2581
-            $this->_current_screen->id,
2582
-            'side',
2583
-            'high'
2584
-        );
2585
-    }
2586
-
2587
-
2588
-    public function editor_overview()
2589
-    {
2590
-        // if we have extra content set let's add it in if not make sure its empty
2591
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2592
-            ? $this->_template_args['publish_box_extra_content']
2593
-            : '';
2594
-        echo EEH_Template::display_template(
2595
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2596
-            $this->_template_args,
2597
-            true
2598
-        );
2599
-    }
2600
-
2601
-
2602
-    /** end of globally available metaboxes section **/
2603
-
2604
-
2605
-    /**
2606
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2607
-     * protected method.
2608
-     *
2609
-     * @param string $name
2610
-     * @param int    $id
2611
-     * @param bool   $delete
2612
-     * @param string $save_close_redirect_URL
2613
-     * @param bool   $both_btns
2614
-     * @throws EE_Error
2615
-     * @throws InvalidArgumentException
2616
-     * @throws InvalidDataTypeException
2617
-     * @throws InvalidInterfaceException
2618
-     * @see   $this->_set_publish_post_box_vars for param details
2619
-     * @since 4.6.0
2620
-     */
2621
-    public function set_publish_post_box_vars(
2622
-        $name = '',
2623
-        $id = 0,
2624
-        $delete = false,
2625
-        $save_close_redirect_URL = '',
2626
-        $both_btns = true
2627
-    ) {
2628
-        $this->_set_publish_post_box_vars(
2629
-            $name,
2630
-            $id,
2631
-            $delete,
2632
-            $save_close_redirect_URL,
2633
-            $both_btns
2634
-        );
2635
-    }
2636
-
2637
-
2638
-    /**
2639
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2640
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2641
-     * save, and save and close buttons to work properly, then you will want to include a
2642
-     * values for the name and id arguments.
2643
-     *
2644
-     * @param string  $name                       key used for the action ID (i.e. event_id)
2645
-     * @param int     $id                         id attached to the item published
2646
-     * @param string  $delete                     page route callback for the delete action
2647
-     * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2648
-     * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2649
-     *                                            the Save button
2650
-     * @throws EE_Error
2651
-     * @throws InvalidArgumentException
2652
-     * @throws InvalidDataTypeException
2653
-     * @throws InvalidInterfaceException
2654
-     * @todo  Add in validation for name/id arguments.
2655
-     */
2656
-    protected function _set_publish_post_box_vars(
2657
-        $name = '',
2658
-        $id = 0,
2659
-        $delete = '',
2660
-        $save_close_redirect_URL = '',
2661
-        $both_btns = true
2662
-    ) {
2663
-        // if Save & Close, use a custom redirect URL or default to the main page?
2664
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2665
-            ? $save_close_redirect_URL
2666
-            : $this->_admin_base_url;
2667
-        // create the Save & Close and Save buttons
2668
-        $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2669
-        // if we have extra content set let's add it in if not make sure its empty
2670
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2671
-            ? $this->_template_args['publish_box_extra_content']
2672
-            : '';
2673
-        if ($delete && ! empty($id)) {
2674
-            // make sure we have a default if just true is sent.
2675
-            $delete           = ! empty($delete) ? $delete : 'delete';
2676
-            $delete_link_args = [$name => $id];
2677
-            $delete           = $this->get_action_link_or_button(
2678
-                $delete,
2679
-                $delete,
2680
-                $delete_link_args,
2681
-                'submitdelete deletion',
2682
-                '',
2683
-                false
2684
-            );
2685
-        }
2686
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2687
-        if (! empty($name) && ! empty($id)) {
2688
-            $hidden_field_arr[ $name ] = [
2689
-                'type'  => 'hidden',
2690
-                'value' => $id,
2691
-            ];
2692
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2693
-        } else {
2694
-            $hf = '';
2695
-        }
2696
-        // add hidden field
2697
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2698
-            ? $hf[ $name ]['field']
2699
-            : $hf;
2700
-    }
2701
-
2702
-
2703
-    /**
2704
-     * displays an error message to ppl who have javascript disabled
2705
-     *
2706
-     * @return void
2707
-     */
2708
-    private function _display_no_javascript_warning()
2709
-    {
2710
-        ?>
2518
+	}
2519
+
2520
+
2521
+	private function _espresso_links_post_box()
2522
+	{
2523
+		// Hiding until we actually have content to put in here...
2524
+		// add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2525
+	}
2526
+
2527
+
2528
+	public function espresso_links_post_box()
2529
+	{
2530
+		// Hiding until we actually have content to put in here...
2531
+		// EEH_Template::display_template(
2532
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2533
+		// );
2534
+	}
2535
+
2536
+
2537
+	protected function _espresso_sponsors_post_box()
2538
+	{
2539
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2540
+			add_meta_box(
2541
+				'espresso_sponsors_post_box',
2542
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2543
+				[$this, 'espresso_sponsors_post_box'],
2544
+				$this->_wp_page_slug,
2545
+				'side'
2546
+			);
2547
+		}
2548
+	}
2549
+
2550
+
2551
+	public function espresso_sponsors_post_box()
2552
+	{
2553
+		EEH_Template::display_template(
2554
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2555
+		);
2556
+	}
2557
+
2558
+
2559
+	private function _publish_post_box()
2560
+	{
2561
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2562
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2563
+		// then we'll use that for the metabox label.
2564
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2565
+		if (! empty($this->_labels['publishbox'])) {
2566
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2567
+				: $this->_labels['publishbox'];
2568
+		} else {
2569
+			$box_label = esc_html__('Publish', 'event_espresso');
2570
+		}
2571
+		$box_label = apply_filters(
2572
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2573
+			$box_label,
2574
+			$this->_req_action,
2575
+			$this
2576
+		);
2577
+		add_meta_box(
2578
+			$meta_box_ref,
2579
+			$box_label,
2580
+			[$this, 'editor_overview'],
2581
+			$this->_current_screen->id,
2582
+			'side',
2583
+			'high'
2584
+		);
2585
+	}
2586
+
2587
+
2588
+	public function editor_overview()
2589
+	{
2590
+		// if we have extra content set let's add it in if not make sure its empty
2591
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2592
+			? $this->_template_args['publish_box_extra_content']
2593
+			: '';
2594
+		echo EEH_Template::display_template(
2595
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2596
+			$this->_template_args,
2597
+			true
2598
+		);
2599
+	}
2600
+
2601
+
2602
+	/** end of globally available metaboxes section **/
2603
+
2604
+
2605
+	/**
2606
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2607
+	 * protected method.
2608
+	 *
2609
+	 * @param string $name
2610
+	 * @param int    $id
2611
+	 * @param bool   $delete
2612
+	 * @param string $save_close_redirect_URL
2613
+	 * @param bool   $both_btns
2614
+	 * @throws EE_Error
2615
+	 * @throws InvalidArgumentException
2616
+	 * @throws InvalidDataTypeException
2617
+	 * @throws InvalidInterfaceException
2618
+	 * @see   $this->_set_publish_post_box_vars for param details
2619
+	 * @since 4.6.0
2620
+	 */
2621
+	public function set_publish_post_box_vars(
2622
+		$name = '',
2623
+		$id = 0,
2624
+		$delete = false,
2625
+		$save_close_redirect_URL = '',
2626
+		$both_btns = true
2627
+	) {
2628
+		$this->_set_publish_post_box_vars(
2629
+			$name,
2630
+			$id,
2631
+			$delete,
2632
+			$save_close_redirect_URL,
2633
+			$both_btns
2634
+		);
2635
+	}
2636
+
2637
+
2638
+	/**
2639
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2640
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2641
+	 * save, and save and close buttons to work properly, then you will want to include a
2642
+	 * values for the name and id arguments.
2643
+	 *
2644
+	 * @param string  $name                       key used for the action ID (i.e. event_id)
2645
+	 * @param int     $id                         id attached to the item published
2646
+	 * @param string  $delete                     page route callback for the delete action
2647
+	 * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2648
+	 * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2649
+	 *                                            the Save button
2650
+	 * @throws EE_Error
2651
+	 * @throws InvalidArgumentException
2652
+	 * @throws InvalidDataTypeException
2653
+	 * @throws InvalidInterfaceException
2654
+	 * @todo  Add in validation for name/id arguments.
2655
+	 */
2656
+	protected function _set_publish_post_box_vars(
2657
+		$name = '',
2658
+		$id = 0,
2659
+		$delete = '',
2660
+		$save_close_redirect_URL = '',
2661
+		$both_btns = true
2662
+	) {
2663
+		// if Save & Close, use a custom redirect URL or default to the main page?
2664
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2665
+			? $save_close_redirect_URL
2666
+			: $this->_admin_base_url;
2667
+		// create the Save & Close and Save buttons
2668
+		$this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2669
+		// if we have extra content set let's add it in if not make sure its empty
2670
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2671
+			? $this->_template_args['publish_box_extra_content']
2672
+			: '';
2673
+		if ($delete && ! empty($id)) {
2674
+			// make sure we have a default if just true is sent.
2675
+			$delete           = ! empty($delete) ? $delete : 'delete';
2676
+			$delete_link_args = [$name => $id];
2677
+			$delete           = $this->get_action_link_or_button(
2678
+				$delete,
2679
+				$delete,
2680
+				$delete_link_args,
2681
+				'submitdelete deletion',
2682
+				'',
2683
+				false
2684
+			);
2685
+		}
2686
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2687
+		if (! empty($name) && ! empty($id)) {
2688
+			$hidden_field_arr[ $name ] = [
2689
+				'type'  => 'hidden',
2690
+				'value' => $id,
2691
+			];
2692
+			$hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2693
+		} else {
2694
+			$hf = '';
2695
+		}
2696
+		// add hidden field
2697
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2698
+			? $hf[ $name ]['field']
2699
+			: $hf;
2700
+	}
2701
+
2702
+
2703
+	/**
2704
+	 * displays an error message to ppl who have javascript disabled
2705
+	 *
2706
+	 * @return void
2707
+	 */
2708
+	private function _display_no_javascript_warning()
2709
+	{
2710
+		?>
2711 2711
         <noscript>
2712 2712
             <div id="no-js-message" class="error">
2713 2713
                 <p style="font-size:1.3em;">
2714 2714
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2715 2715
                     <?php esc_html_e(
2716
-                        'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2717
-                        'event_espresso'
2718
-                    ); ?>
2716
+						'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2717
+						'event_espresso'
2718
+					); ?>
2719 2719
                 </p>
2720 2720
             </div>
2721 2721
         </noscript>
2722 2722
         <?php
2723
-    }
2724
-
2725
-
2726
-    /**
2727
-     * displays espresso success and/or error notices
2728
-     *
2729
-     * @return void
2730
-     */
2731
-    private function _display_espresso_notices()
2732
-    {
2733
-        $notices = $this->_get_transient(true);
2734
-        echo stripslashes($notices);
2735
-    }
2736
-
2737
-
2738
-    /**
2739
-     * spinny things pacify the masses
2740
-     *
2741
-     * @return void
2742
-     */
2743
-    protected function _add_admin_page_ajax_loading_img()
2744
-    {
2745
-        ?>
2723
+	}
2724
+
2725
+
2726
+	/**
2727
+	 * displays espresso success and/or error notices
2728
+	 *
2729
+	 * @return void
2730
+	 */
2731
+	private function _display_espresso_notices()
2732
+	{
2733
+		$notices = $this->_get_transient(true);
2734
+		echo stripslashes($notices);
2735
+	}
2736
+
2737
+
2738
+	/**
2739
+	 * spinny things pacify the masses
2740
+	 *
2741
+	 * @return void
2742
+	 */
2743
+	protected function _add_admin_page_ajax_loading_img()
2744
+	{
2745
+		?>
2746 2746
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2747 2747
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2748
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2748
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2749 2749
         </div>
2750 2750
         <?php
2751
-    }
2751
+	}
2752 2752
 
2753 2753
 
2754
-    /**
2755
-     * add admin page overlay for modal boxes
2756
-     *
2757
-     * @return void
2758
-     */
2759
-    protected function _add_admin_page_overlay()
2760
-    {
2761
-        ?>
2754
+	/**
2755
+	 * add admin page overlay for modal boxes
2756
+	 *
2757
+	 * @return void
2758
+	 */
2759
+	protected function _add_admin_page_overlay()
2760
+	{
2761
+		?>
2762 2762
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2763 2763
         <?php
2764
-    }
2765
-
2766
-
2767
-    /**
2768
-     * facade for add_meta_box
2769
-     *
2770
-     * @param string  $action        where the metabox get's displayed
2771
-     * @param string  $title         Title of Metabox (output in metabox header)
2772
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2773
-     *                               instead of the one created in here.
2774
-     * @param array   $callback_args an array of args supplied for the metabox
2775
-     * @param string  $column        what metabox column
2776
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2777
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2778
-     *                               created but just set our own callback for wp's add_meta_box.
2779
-     * @throws DomainException
2780
-     */
2781
-    public function _add_admin_page_meta_box(
2782
-        $action,
2783
-        $title,
2784
-        $callback,
2785
-        $callback_args,
2786
-        $column = 'normal',
2787
-        $priority = 'high',
2788
-        $create_func = true
2789
-    ) {
2790
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2791
-        // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2792
-        if (empty($callback_args) && $create_func) {
2793
-            $callback_args = [
2794
-                'template_path' => $this->_template_path,
2795
-                'template_args' => $this->_template_args,
2796
-            ];
2797
-        }
2798
-        // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2799
-        $call_back_func = $create_func
2800
-            ? function ($post, $metabox) {
2801
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2802
-                echo EEH_Template::display_template(
2803
-                    $metabox['args']['template_path'],
2804
-                    $metabox['args']['template_args'],
2805
-                    true
2806
-                );
2807
-            }
2808
-            : $callback;
2809
-        add_meta_box(
2810
-            str_replace('_', '-', $action) . '-mbox',
2811
-            $title,
2812
-            $call_back_func,
2813
-            $this->_wp_page_slug,
2814
-            $column,
2815
-            $priority,
2816
-            $callback_args
2817
-        );
2818
-    }
2819
-
2820
-
2821
-    /**
2822
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2823
-     *
2824
-     * @throws DomainException
2825
-     * @throws EE_Error
2826
-     */
2827
-    public function display_admin_page_with_metabox_columns()
2828
-    {
2829
-        $this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2830
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2831
-            $this->_column_template_path,
2832
-            $this->_template_args,
2833
-            true
2834
-        );
2835
-        // the final wrapper
2836
-        $this->admin_page_wrapper();
2837
-    }
2838
-
2839
-
2840
-    /**
2841
-     * generates  HTML wrapper for an admin details page
2842
-     *
2843
-     * @return void
2844
-     * @throws EE_Error
2845
-     * @throws DomainException
2846
-     */
2847
-    public function display_admin_page_with_sidebar()
2848
-    {
2849
-        $this->_display_admin_page(true);
2850
-    }
2851
-
2852
-
2853
-    /**
2854
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2855
-     *
2856
-     * @return void
2857
-     * @throws EE_Error
2858
-     * @throws DomainException
2859
-     */
2860
-    public function display_admin_page_with_no_sidebar()
2861
-    {
2862
-        $this->_display_admin_page();
2863
-    }
2864
-
2865
-
2866
-    /**
2867
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2868
-     *
2869
-     * @return void
2870
-     * @throws EE_Error
2871
-     * @throws DomainException
2872
-     */
2873
-    public function display_about_admin_page()
2874
-    {
2875
-        $this->_display_admin_page(false, true);
2876
-    }
2877
-
2878
-
2879
-    /**
2880
-     * display_admin_page
2881
-     * contains the code for actually displaying an admin page
2882
-     *
2883
-     * @param boolean $sidebar true with sidebar, false without
2884
-     * @param boolean $about   use the about_admin_wrapper instead of the default.
2885
-     * @return void
2886
-     * @throws DomainException
2887
-     * @throws EE_Error
2888
-     */
2889
-    private function _display_admin_page($sidebar = false, $about = false)
2890
-    {
2891
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2892
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2893
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2894
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2895
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2896
-        $this->_template_args['current_page']              = $this->_wp_page_slug;
2897
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2898
-            ? 'poststuff'
2899
-            : 'espresso-default-admin';
2900
-        $template_path                                     = $sidebar
2901
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2902
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2903
-        if ($this->request->isAjax()) {
2904
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2905
-        }
2906
-        $template_path                                     = ! empty($this->_column_template_path)
2907
-            ? $this->_column_template_path : $template_path;
2908
-        $this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2909
-            ? $this->_template_args['admin_page_content']
2910
-            : '';
2911
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2912
-            ? $this->_template_args['before_admin_page_content']
2913
-            : '';
2914
-        $this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2915
-            ? $this->_template_args['after_admin_page_content']
2916
-            : '';
2917
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
2918
-            $template_path,
2919
-            $this->_template_args,
2920
-            true
2921
-        );
2922
-        // the final template wrapper
2923
-        $this->admin_page_wrapper($about);
2924
-    }
2925
-
2926
-
2927
-    /**
2928
-     * This is used to display caf preview pages.
2929
-     *
2930
-     * @param string $utm_campaign_source what is the key used for google analytics link
2931
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2932
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2933
-     * @return void
2934
-     * @throws DomainException
2935
-     * @throws EE_Error
2936
-     * @throws InvalidArgumentException
2937
-     * @throws InvalidDataTypeException
2938
-     * @throws InvalidInterfaceException
2939
-     * @since 4.3.2
2940
-     */
2941
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2942
-    {
2943
-        // let's generate a default preview action button if there isn't one already present.
2944
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2945
-            'Upgrade to Event Espresso 4 Right Now',
2946
-            'event_espresso'
2947
-        );
2948
-        $buy_now_url                                   = add_query_arg(
2949
-            [
2950
-                'ee_ver'       => 'ee4',
2951
-                'utm_source'   => 'ee4_plugin_admin',
2952
-                'utm_medium'   => 'link',
2953
-                'utm_campaign' => $utm_campaign_source,
2954
-                'utm_content'  => 'buy_now_button',
2955
-            ],
2956
-            'https://eventespresso.com/pricing/'
2957
-        );
2958
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2959
-            ? $this->get_action_link_or_button(
2960
-                '',
2961
-                'buy_now',
2962
-                [],
2963
-                'button-primary button-large',
2964
-                esc_url_raw($buy_now_url),
2965
-                true
2966
-            )
2967
-            : $this->_template_args['preview_action_button'];
2968
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2969
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2970
-            $this->_template_args,
2971
-            true
2972
-        );
2973
-        $this->_display_admin_page($display_sidebar);
2974
-    }
2975
-
2976
-
2977
-    /**
2978
-     * display_admin_list_table_page_with_sidebar
2979
-     * generates HTML wrapper for an admin_page with list_table
2980
-     *
2981
-     * @return void
2982
-     * @throws EE_Error
2983
-     * @throws DomainException
2984
-     */
2985
-    public function display_admin_list_table_page_with_sidebar()
2986
-    {
2987
-        $this->_display_admin_list_table_page(true);
2988
-    }
2989
-
2990
-
2991
-    /**
2992
-     * display_admin_list_table_page_with_no_sidebar
2993
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2994
-     *
2995
-     * @return void
2996
-     * @throws EE_Error
2997
-     * @throws DomainException
2998
-     */
2999
-    public function display_admin_list_table_page_with_no_sidebar()
3000
-    {
3001
-        $this->_display_admin_list_table_page();
3002
-    }
3003
-
3004
-
3005
-    /**
3006
-     * generates html wrapper for an admin_list_table page
3007
-     *
3008
-     * @param boolean $sidebar whether to display with sidebar or not.
3009
-     * @return void
3010
-     * @throws DomainException
3011
-     * @throws EE_Error
3012
-     */
3013
-    private function _display_admin_list_table_page($sidebar = false)
3014
-    {
3015
-        // setup search attributes
3016
-        $this->_set_search_attributes();
3017
-        $this->_template_args['current_page']     = $this->_wp_page_slug;
3018
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
3019
-        $this->_template_args['table_url']        = $this->request->isAjax()
3020
-            ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
3021
-            : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
3022
-        $this->_template_args['list_table']       = $this->_list_table_object;
3023
-        $this->_template_args['current_route']    = $this->_req_action;
3024
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
3025
-        $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
3026
-        if (! empty($ajax_sorting_callback)) {
3027
-            $sortable_list_table_form_fields = wp_nonce_field(
3028
-                $ajax_sorting_callback . '_nonce',
3029
-                $ajax_sorting_callback . '_nonce',
3030
-                false,
3031
-                false
3032
-            );
3033
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3034
-                                                . $this->page_slug
3035
-                                                . '" />';
3036
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3037
-                                                . $ajax_sorting_callback
3038
-                                                . '" />';
3039
-        } else {
3040
-            $sortable_list_table_form_fields = '';
3041
-        }
3042
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3043
-        $hidden_form_fields                                      =
3044
-            isset($this->_template_args['list_table_hidden_fields'])
3045
-                ? $this->_template_args['list_table_hidden_fields']
3046
-                : '';
3047
-        $nonce_ref                                               = $this->_req_action . '_nonce';
3048
-        $hidden_form_fields                                      .= '<input type="hidden" name="'
3049
-                                                                    . $nonce_ref
3050
-                                                                    . '" value="'
3051
-                                                                    . wp_create_nonce($nonce_ref)
3052
-                                                                    . '">';
3053
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
3054
-        // display message about search results?
3055
-        $search = $this->request->getRequestParam('s');
3056
-        $this->_template_args['before_list_table'] .= ! empty($search)
3057
-            ? '<p class="ee-search-results">' . sprintf(
3058
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3059
-                trim($search, '%')
3060
-            ) . '</p>'
3061
-            : '';
3062
-        // filter before_list_table template arg
3063
-        $this->_template_args['before_list_table'] = apply_filters(
3064
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3065
-            $this->_template_args['before_list_table'],
3066
-            $this->page_slug,
3067
-            $this->request->requestParams(),
3068
-            $this->_req_action
3069
-        );
3070
-        // convert to array and filter again
3071
-        // arrays are easier to inject new items in a specific location,
3072
-        // but would not be backwards compatible, so we have to add a new filter
3073
-        $this->_template_args['before_list_table'] = implode(
3074
-            " \n",
3075
-            (array) apply_filters(
3076
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3077
-                (array) $this->_template_args['before_list_table'],
3078
-                $this->page_slug,
3079
-                $this->request->requestParams(),
3080
-                $this->_req_action
3081
-            )
3082
-        );
3083
-        // filter after_list_table template arg
3084
-        $this->_template_args['after_list_table'] = apply_filters(
3085
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3086
-            $this->_template_args['after_list_table'],
3087
-            $this->page_slug,
3088
-            $this->request->requestParams(),
3089
-            $this->_req_action
3090
-        );
3091
-        // convert to array and filter again
3092
-        // arrays are easier to inject new items in a specific location,
3093
-        // but would not be backwards compatible, so we have to add a new filter
3094
-        $this->_template_args['after_list_table']   = implode(
3095
-            " \n",
3096
-            (array) apply_filters(
3097
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3098
-                (array) $this->_template_args['after_list_table'],
3099
-                $this->page_slug,
3100
-                $this->request->requestParams(),
3101
-                $this->_req_action
3102
-            )
3103
-        );
3104
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3105
-            $template_path,
3106
-            $this->_template_args,
3107
-            true
3108
-        );
3109
-        // the final template wrapper
3110
-        if ($sidebar) {
3111
-            $this->display_admin_page_with_sidebar();
3112
-        } else {
3113
-            $this->display_admin_page_with_no_sidebar();
3114
-        }
3115
-    }
3116
-
3117
-
3118
-    /**
3119
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3120
-     * html string for the legend.
3121
-     * $items are expected in an array in the following format:
3122
-     * $legend_items = array(
3123
-     *        'item_id' => array(
3124
-     *            'icon' => 'http://url_to_icon_being_described.png',
3125
-     *            'desc' => esc_html__('localized description of item');
3126
-     *        )
3127
-     * );
3128
-     *
3129
-     * @param array $items see above for format of array
3130
-     * @return string html string of legend
3131
-     * @throws DomainException
3132
-     */
3133
-    protected function _display_legend($items)
3134
-    {
3135
-        $this->_template_args['items'] = apply_filters(
3136
-            'FHEE__EE_Admin_Page___display_legend__items',
3137
-            (array) $items,
3138
-            $this
3139
-        );
3140
-        return EEH_Template::display_template(
3141
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3142
-            $this->_template_args,
3143
-            true
3144
-        );
3145
-    }
3146
-
3147
-
3148
-    /**
3149
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3150
-     * The returned json object is created from an array in the following format:
3151
-     * array(
3152
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3153
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3154
-     *  'notices' => '', // - contains any EE_Error formatted notices
3155
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3156
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3157
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3158
-     *  that might be included in here)
3159
-     * )
3160
-     * The json object is populated by whatever is set in the $_template_args property.
3161
-     *
3162
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3163
-     *                                 instead of displayed.
3164
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3165
-     * @return void
3166
-     * @throws EE_Error
3167
-     */
3168
-    protected function _return_json($sticky_notices = false, $notices_arguments = [])
3169
-    {
3170
-        // make sure any EE_Error notices have been handled.
3171
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3172
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3173
-        unset($this->_template_args['data']);
3174
-        $json = [
3175
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3176
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3177
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3178
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3179
-            'notices'   => EE_Error::get_notices(),
3180
-            'content'   => isset($this->_template_args['admin_page_content'])
3181
-                ? $this->_template_args['admin_page_content'] : '',
3182
-            'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3183
-            'isEEajax'  => true
3184
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3185
-        ];
3186
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3187
-        if (null === error_get_last() || ! headers_sent()) {
3188
-            header('Content-Type: application/json; charset=UTF-8');
3189
-        }
3190
-        echo wp_json_encode($json);
3191
-        exit();
3192
-    }
3193
-
3194
-
3195
-    /**
3196
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3197
-     *
3198
-     * @return void
3199
-     * @throws EE_Error
3200
-     */
3201
-    public function return_json()
3202
-    {
3203
-        if ($this->request->isAjax()) {
3204
-            $this->_return_json();
3205
-        } else {
3206
-            throw new EE_Error(
3207
-                sprintf(
3208
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3209
-                    __FUNCTION__
3210
-                )
3211
-            );
3212
-        }
3213
-    }
3214
-
3215
-
3216
-    /**
3217
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3218
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3219
-     *
3220
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3221
-     */
3222
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3223
-    {
3224
-        $this->_hook_obj = $hook_obj;
3225
-    }
3226
-
3227
-
3228
-    /**
3229
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3230
-     *
3231
-     * @param boolean $about whether to use the special about page wrapper or default.
3232
-     * @return void
3233
-     * @throws DomainException
3234
-     * @throws EE_Error
3235
-     */
3236
-    public function admin_page_wrapper($about = false)
3237
-    {
3238
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3239
-        $this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3240
-        $this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3241
-        $this->_template_args['admin_page_title']          = $this->_admin_page_title;
3242
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3243
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3244
-            isset($this->_template_args['before_admin_page_content'])
3245
-                ? $this->_template_args['before_admin_page_content']
3246
-                : ''
3247
-        );
3248
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3249
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3250
-            isset($this->_template_args['after_admin_page_content'])
3251
-                ? $this->_template_args['after_admin_page_content']
3252
-                : ''
3253
-        );
3254
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3255
-        // load settings page wrapper template
3256
-        $template_path = ! $this->request->isAjax()
3257
-            ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3258
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
3259
-        // about page?
3260
-        $template_path = $about
3261
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3262
-            : $template_path;
3263
-        if ($this->request->isAjax()) {
3264
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3265
-                $template_path,
3266
-                $this->_template_args,
3267
-                true
3268
-            );
3269
-            $this->_return_json();
3270
-        } else {
3271
-            EEH_Template::display_template($template_path, $this->_template_args);
3272
-        }
3273
-    }
3274
-
3275
-
3276
-    /**
3277
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3278
-     *
3279
-     * @return string html
3280
-     * @throws EE_Error
3281
-     */
3282
-    protected function _get_main_nav_tabs()
3283
-    {
3284
-        // let's generate the html using the EEH_Tabbed_Content helper.
3285
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3286
-        // (rather than setting in the page_routes array)
3287
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3288
-    }
3289
-
3290
-
3291
-    /**
3292
-     *        sort nav tabs
3293
-     *
3294
-     * @param $a
3295
-     * @param $b
3296
-     * @return int
3297
-     */
3298
-    private function _sort_nav_tabs($a, $b)
3299
-    {
3300
-        if ($a['order'] === $b['order']) {
3301
-            return 0;
3302
-        }
3303
-        return ($a['order'] < $b['order']) ? -1 : 1;
3304
-    }
3305
-
3306
-
3307
-    /**
3308
-     *    generates HTML for the forms used on admin pages
3309
-     *
3310
-     * @param array  $input_vars   - array of input field details
3311
-     * @param string $generator    (options are 'string' or 'array', basically use this to indicate which generator to
3312
-     *                             use)
3313
-     * @param bool   $id
3314
-     * @return string
3315
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3316
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3317
-     */
3318
-    protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3319
-    {
3320
-        return $generator === 'string'
3321
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3322
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3323
-    }
3324
-
3325
-
3326
-    /**
3327
-     * generates the "Save" and "Save & Close" buttons for edit forms
3328
-     *
3329
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3330
-     *                                   Close" button.
3331
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3332
-     *                                   'Save', [1] => 'save & close')
3333
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3334
-     *                                   via the "name" value in the button).  We can also use this to just dump
3335
-     *                                   default actions by submitting some other value.
3336
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3337
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3338
-     *                                   close (normal form handling).
3339
-     */
3340
-    protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3341
-    {
3342
-        // make sure $text and $actions are in an array
3343
-        $text          = (array) $text;
3344
-        $actions       = (array) $actions;
3345
-        $referrer_url  = empty($referrer)
3346
-            ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3347
-              . $this->request->getServerParam('REQUEST_URI')
3348
-              . '" />'
3349
-            : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3350
-              . $referrer
3351
-              . '" />';
3352
-        $button_text   = ! empty($text)
3353
-            ? $text
3354
-            : [
3355
-                esc_html__('Save', 'event_espresso'),
3356
-                esc_html__('Save and Close', 'event_espresso'),
3357
-            ];
3358
-        $default_names = ['save', 'save_and_close'];
3359
-        // add in a hidden index for the current page (so save and close redirects properly)
3360
-        $this->_template_args['save_buttons'] = $referrer_url;
3361
-        foreach ($button_text as $key => $button) {
3362
-            $ref                                  = $default_names[ $key ];
3363
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3364
-                                                     . $ref
3365
-                                                     . '" value="'
3366
-                                                     . $button
3367
-                                                     . '" name="'
3368
-                                                     . (! empty($actions) ? $actions[ $key ] : $ref)
3369
-                                                     . '" id="'
3370
-                                                     . $this->_current_view . '_' . $ref
3371
-                                                     . '" />';
3372
-            if (! $both) {
3373
-                break;
3374
-            }
3375
-        }
3376
-    }
3377
-
3378
-
3379
-    /**
3380
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3381
-     *
3382
-     * @param string $route
3383
-     * @param array  $additional_hidden_fields
3384
-     * @see   $this->_set_add_edit_form_tags() for details on params
3385
-     * @since 4.6.0
3386
-     */
3387
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3388
-    {
3389
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3390
-    }
3391
-
3392
-
3393
-    /**
3394
-     * set form open and close tags on add/edit pages.
3395
-     *
3396
-     * @param string $route                    the route you want the form to direct to
3397
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3398
-     * @return void
3399
-     */
3400
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3401
-    {
3402
-        if (empty($route)) {
3403
-            $user_msg = esc_html__(
3404
-                'An error occurred. No action was set for this page\'s form.',
3405
-                'event_espresso'
3406
-            );
3407
-            $dev_msg  = $user_msg . "\n"
3408
-                        . sprintf(
3409
-                            esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3410
-                            __FUNCTION__,
3411
-                            __CLASS__
3412
-                        );
3413
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3414
-        }
3415
-        // open form
3416
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3417
-                                                             . $this->_admin_base_url
3418
-                                                             . '" id="'
3419
-                                                             . $route
3420
-                                                             . '_event_form" >';
3421
-        // add nonce
3422
-        $nonce                                             =
3423
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3424
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3425
-        // add REQUIRED form action
3426
-        $hidden_fields = [
3427
-            'action' => ['type' => 'hidden', 'value' => $route],
3428
-        ];
3429
-        // merge arrays
3430
-        $hidden_fields = is_array($additional_hidden_fields)
3431
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3432
-            : $hidden_fields;
3433
-        // generate form fields
3434
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3435
-        // add fields to form
3436
-        foreach ((array) $form_fields as $field_name => $form_field) {
3437
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3438
-        }
3439
-        // close form
3440
-        $this->_template_args['after_admin_page_content'] = '</form>';
3441
-    }
3442
-
3443
-
3444
-    /**
3445
-     * Public Wrapper for _redirect_after_action() method since its
3446
-     * discovered it would be useful for external code to have access.
3447
-     *
3448
-     * @param bool   $success
3449
-     * @param string $what
3450
-     * @param string $action_desc
3451
-     * @param array  $query_args
3452
-     * @param bool   $override_overwrite
3453
-     * @throws EE_Error
3454
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3455
-     * @since 4.5.0
3456
-     */
3457
-    public function redirect_after_action(
3458
-        $success = false,
3459
-        $what = 'item',
3460
-        $action_desc = 'processed',
3461
-        $query_args = [],
3462
-        $override_overwrite = false
3463
-    ) {
3464
-        $this->_redirect_after_action(
3465
-            $success,
3466
-            $what,
3467
-            $action_desc,
3468
-            $query_args,
3469
-            $override_overwrite
3470
-        );
3471
-    }
3472
-
3473
-
3474
-    /**
3475
-     * Helper method for merging existing request data with the returned redirect url.
3476
-     *
3477
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3478
-     * filters are still applied.
3479
-     *
3480
-     * @param array $new_route_data
3481
-     * @return array
3482
-     */
3483
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3484
-    {
3485
-        foreach ($this->request->requestParams() as $ref => $value) {
3486
-            // unset nonces
3487
-            if (strpos($ref, 'nonce') !== false) {
3488
-                $this->request->unSetRequestParam($ref);
3489
-                continue;
3490
-            }
3491
-            // urlencode values.
3492
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3493
-            $this->request->setRequestParam($ref, $value);
3494
-        }
3495
-        return array_merge($this->request->requestParams(), $new_route_data);
3496
-    }
3497
-
3498
-
3499
-    /**
3500
-     *    _redirect_after_action
3501
-     *
3502
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3503
-     * @param string $what               - what the action was performed on
3504
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3505
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3506
-     *                                   action is completed
3507
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3508
-     *                                   override this so that they show.
3509
-     * @return void
3510
-     * @throws EE_Error
3511
-     */
3512
-    protected function _redirect_after_action(
3513
-        $success = 0,
3514
-        $what = 'item',
3515
-        $action_desc = 'processed',
3516
-        $query_args = [],
3517
-        $override_overwrite = false
3518
-    ) {
3519
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3520
-        // class name for actions/filters.
3521
-        $classname = get_class($this);
3522
-        // set redirect url.
3523
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3524
-        // otherwise we go with whatever is set as the _admin_base_url
3525
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3526
-        $notices      = EE_Error::get_notices(false);
3527
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3528
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3529
-            EE_Error::overwrite_success();
3530
-        }
3531
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3532
-            // how many records affected ? more than one record ? or just one ?
3533
-            if ($success > 1) {
3534
-                // set plural msg
3535
-                EE_Error::add_success(
3536
-                    sprintf(
3537
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3538
-                        $what,
3539
-                        $action_desc
3540
-                    ),
3541
-                    __FILE__,
3542
-                    __FUNCTION__,
3543
-                    __LINE__
3544
-                );
3545
-            } elseif ($success === 1) {
3546
-                // set singular msg
3547
-                EE_Error::add_success(
3548
-                    sprintf(
3549
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3550
-                        $what,
3551
-                        $action_desc
3552
-                    ),
3553
-                    __FILE__,
3554
-                    __FUNCTION__,
3555
-                    __LINE__
3556
-                );
3557
-            }
3558
-        }
3559
-        // check that $query_args isn't something crazy
3560
-        if (! is_array($query_args)) {
3561
-            $query_args = [];
3562
-        }
3563
-        /**
3564
-         * Allow injecting actions before the query_args are modified for possible different
3565
-         * redirections on save and close actions
3566
-         *
3567
-         * @param array $query_args       The original query_args array coming into the
3568
-         *                                method.
3569
-         * @since 4.2.0
3570
-         */
3571
-        do_action(
3572
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3573
-            $query_args
3574
-        );
3575
-        // calculate where we're going (if we have a "save and close" button pushed)
3576
-
3577
-        if (
3578
-            $this->request->requestParamIsSet('save_and_close')
3579
-            && $this->request->requestParamIsSet('save_and_close_referrer')
3580
-        ) {
3581
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3582
-            $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3583
-            // regenerate query args array from referrer URL
3584
-            parse_str($parsed_url['query'], $query_args);
3585
-            // correct page and action will be in the query args now
3586
-            $redirect_url = admin_url('admin.php');
3587
-        }
3588
-        // merge any default query_args set in _default_route_query_args property
3589
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3590
-            $args_to_merge = [];
3591
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3592
-                // is there a wp_referer array in our _default_route_query_args property?
3593
-                if ($query_param === 'wp_referer') {
3594
-                    $query_value = (array) $query_value;
3595
-                    foreach ($query_value as $reference => $value) {
3596
-                        if (strpos($reference, 'nonce') !== false) {
3597
-                            continue;
3598
-                        }
3599
-                        // finally we will override any arguments in the referer with
3600
-                        // what might be set on the _default_route_query_args array.
3601
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3602
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3603
-                        } else {
3604
-                            $args_to_merge[ $reference ] = urlencode($value);
3605
-                        }
3606
-                    }
3607
-                    continue;
3608
-                }
3609
-                $args_to_merge[ $query_param ] = $query_value;
3610
-            }
3611
-            // now let's merge these arguments but override with what was specifically sent in to the
3612
-            // redirect.
3613
-            $query_args = array_merge($args_to_merge, $query_args);
3614
-        }
3615
-        $this->_process_notices($query_args);
3616
-        // generate redirect url
3617
-        // if redirecting to anything other than the main page, add a nonce
3618
-        if (isset($query_args['action'])) {
3619
-            // manually generate wp_nonce and merge that with the query vars
3620
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3621
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3622
-        }
3623
-        // we're adding some hooks and filters in here for processing any things just before redirects
3624
-        // (example: an admin page has done an insert or update and we want to run something after that).
3625
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3626
-        $redirect_url = apply_filters(
3627
-            'FHEE_redirect_' . $classname . $this->_req_action,
3628
-            self::add_query_args_and_nonce($query_args, $redirect_url),
3629
-            $query_args
3630
-        );
3631
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3632
-        if ($this->request->isAjax()) {
3633
-            $default_data                    = [
3634
-                'close'        => true,
3635
-                'redirect_url' => $redirect_url,
3636
-                'where'        => 'main',
3637
-                'what'         => 'append',
3638
-            ];
3639
-            $this->_template_args['success'] = $success;
3640
-            $this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3641
-                $default_data,
3642
-                $this->_template_args['data']
3643
-            ) : $default_data;
3644
-            $this->_return_json();
3645
-        }
3646
-        wp_safe_redirect($redirect_url);
3647
-        exit();
3648
-    }
3649
-
3650
-
3651
-    /**
3652
-     * process any notices before redirecting (or returning ajax request)
3653
-     * This method sets the $this->_template_args['notices'] attribute;
3654
-     *
3655
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3656
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3657
-     *                                  page_routes haven't been defined yet.
3658
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3659
-     *                                  still save a transient for the notice.
3660
-     * @return void
3661
-     * @throws EE_Error
3662
-     */
3663
-    protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3664
-    {
3665
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3666
-        if ($this->request->isAjax()) {
3667
-            $notices = EE_Error::get_notices(false);
3668
-            if (empty($this->_template_args['success'])) {
3669
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3670
-            }
3671
-            if (empty($this->_template_args['errors'])) {
3672
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3673
-            }
3674
-            if (empty($this->_template_args['attention'])) {
3675
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3676
-            }
3677
-        }
3678
-        $this->_template_args['notices'] = EE_Error::get_notices();
3679
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3680
-        if (! $this->request->isAjax() || $sticky_notices) {
3681
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3682
-            $this->_add_transient(
3683
-                $route,
3684
-                $this->_template_args['notices'],
3685
-                true,
3686
-                $skip_route_verify
3687
-            );
3688
-        }
3689
-    }
3690
-
3691
-
3692
-    /**
3693
-     * get_action_link_or_button
3694
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3695
-     *
3696
-     * @param string $action        use this to indicate which action the url is generated with.
3697
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3698
-     *                              property.
3699
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3700
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3701
-     * @param string $base_url      If this is not provided
3702
-     *                              the _admin_base_url will be used as the default for the button base_url.
3703
-     *                              Otherwise this value will be used.
3704
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3705
-     * @return string
3706
-     * @throws InvalidArgumentException
3707
-     * @throws InvalidInterfaceException
3708
-     * @throws InvalidDataTypeException
3709
-     * @throws EE_Error
3710
-     */
3711
-    public function get_action_link_or_button(
3712
-        $action,
3713
-        $type = 'add',
3714
-        $extra_request = [],
3715
-        $class = 'button-primary',
3716
-        $base_url = '',
3717
-        $exclude_nonce = false
3718
-    ) {
3719
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3720
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3721
-            throw new EE_Error(
3722
-                sprintf(
3723
-                    esc_html__(
3724
-                        'There is no page route for given action for the button.  This action was given: %s',
3725
-                        'event_espresso'
3726
-                    ),
3727
-                    $action
3728
-                )
3729
-            );
3730
-        }
3731
-        if (! isset($this->_labels['buttons'][ $type ])) {
3732
-            throw new EE_Error(
3733
-                sprintf(
3734
-                    esc_html__(
3735
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3736
-                        'event_espresso'
3737
-                    ),
3738
-                    $type
3739
-                )
3740
-            );
3741
-        }
3742
-        // finally check user access for this button.
3743
-        $has_access = $this->check_user_access($action, true);
3744
-        if (! $has_access) {
3745
-            return '';
3746
-        }
3747
-        $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3748
-        $query_args = [
3749
-            'action' => $action,
3750
-        ];
3751
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3752
-        if (! empty($extra_request)) {
3753
-            $query_args = array_merge($extra_request, $query_args);
3754
-        }
3755
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3756
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3757
-    }
3758
-
3759
-
3760
-    /**
3761
-     * _per_page_screen_option
3762
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3763
-     *
3764
-     * @return void
3765
-     * @throws InvalidArgumentException
3766
-     * @throws InvalidInterfaceException
3767
-     * @throws InvalidDataTypeException
3768
-     */
3769
-    protected function _per_page_screen_option()
3770
-    {
3771
-        $option = 'per_page';
3772
-        $args   = [
3773
-            'label'   => apply_filters(
3774
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3775
-                $this->_admin_page_title,
3776
-                $this
3777
-            ),
3778
-            'default' => (int) apply_filters(
3779
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3780
-                20
3781
-            ),
3782
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3783
-        ];
3784
-        // ONLY add the screen option if the user has access to it.
3785
-        if ($this->check_user_access($this->_current_view, true)) {
3786
-            add_screen_option($option, $args);
3787
-        }
3788
-    }
3789
-
3790
-
3791
-    /**
3792
-     * set_per_page_screen_option
3793
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3794
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3795
-     * admin_menu.
3796
-     *
3797
-     * @return void
3798
-     */
3799
-    private function _set_per_page_screen_options()
3800
-    {
3801
-        if ($this->request->requestParamIsSet('wp_screen_options')) {
3802
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3803
-            if (! $user = wp_get_current_user()) {
3804
-                return;
3805
-            }
3806
-            $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3807
-            if (! $option) {
3808
-                return;
3809
-            }
3810
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3811
-            $map_option = $option;
3812
-            $option     = str_replace('-', '_', $option);
3813
-            switch ($map_option) {
3814
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3815
-                    $max_value = apply_filters(
3816
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3817
-                        999,
3818
-                        $this->_current_page,
3819
-                        $this->_current_view
3820
-                    );
3821
-                    if ($value < 1) {
3822
-                        return;
3823
-                    }
3824
-                    $value = min($value, $max_value);
3825
-                    break;
3826
-                default:
3827
-                    $value = apply_filters(
3828
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3829
-                        false,
3830
-                        $option,
3831
-                        $value
3832
-                    );
3833
-                    if (false === $value) {
3834
-                        return;
3835
-                    }
3836
-                    break;
3837
-            }
3838
-            update_user_meta($user->ID, $option, $value);
3839
-            wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3840
-            exit;
3841
-        }
3842
-    }
3843
-
3844
-
3845
-    /**
3846
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3847
-     *
3848
-     * @param array $data array that will be assigned to template args.
3849
-     */
3850
-    public function set_template_args($data)
3851
-    {
3852
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3853
-    }
3854
-
3855
-
3856
-    /**
3857
-     * This makes available the WP transient system for temporarily moving data between routes
3858
-     *
3859
-     * @param string $route             the route that should receive the transient
3860
-     * @param array  $data              the data that gets sent
3861
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3862
-     *                                  normal route transient.
3863
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3864
-     *                                  when we are adding a transient before page_routes have been defined.
3865
-     * @return void
3866
-     * @throws EE_Error
3867
-     */
3868
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3869
-    {
3870
-        $user_id = get_current_user_id();
3871
-        if (! $skip_route_verify) {
3872
-            $this->_verify_route($route);
3873
-        }
3874
-        // now let's set the string for what kind of transient we're setting
3875
-        $transient = $notices
3876
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3877
-            : 'rte_tx_' . $route . '_' . $user_id;
3878
-        $data      = $notices ? ['notices' => $data] : $data;
3879
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3880
-        $existing = is_multisite() && is_network_admin()
3881
-            ? get_site_transient($transient)
3882
-            : get_transient($transient);
3883
-        if ($existing) {
3884
-            $data = array_merge((array) $data, (array) $existing);
3885
-        }
3886
-        if (is_multisite() && is_network_admin()) {
3887
-            set_site_transient($transient, $data, 8);
3888
-        } else {
3889
-            set_transient($transient, $data, 8);
3890
-        }
3891
-    }
3892
-
3893
-
3894
-    /**
3895
-     * this retrieves the temporary transient that has been set for moving data between routes.
3896
-     *
3897
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3898
-     * @param string $route
3899
-     * @return mixed data
3900
-     */
3901
-    protected function _get_transient($notices = false, $route = '')
3902
-    {
3903
-        $user_id   = get_current_user_id();
3904
-        $route     = ! $route ? $this->_req_action : $route;
3905
-        $transient = $notices
3906
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3907
-            : 'rte_tx_' . $route . '_' . $user_id;
3908
-        $data      = is_multisite() && is_network_admin()
3909
-            ? get_site_transient($transient)
3910
-            : get_transient($transient);
3911
-        // delete transient after retrieval (just in case it hasn't expired);
3912
-        if (is_multisite() && is_network_admin()) {
3913
-            delete_site_transient($transient);
3914
-        } else {
3915
-            delete_transient($transient);
3916
-        }
3917
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3918
-    }
3919
-
3920
-
3921
-    /**
3922
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3923
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3924
-     * default route callback on the EE_Admin page you want it run.)
3925
-     *
3926
-     * @return void
3927
-     */
3928
-    protected function _transient_garbage_collection()
3929
-    {
3930
-        global $wpdb;
3931
-        // retrieve all existing transients
3932
-        $query =
3933
-            "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3934
-        if ($results = $wpdb->get_results($query)) {
3935
-            foreach ($results as $result) {
3936
-                $transient = str_replace('_transient_', '', $result->option_name);
3937
-                get_transient($transient);
3938
-                if (is_multisite() && is_network_admin()) {
3939
-                    get_site_transient($transient);
3940
-                }
3941
-            }
3942
-        }
3943
-    }
3944
-
3945
-
3946
-    /**
3947
-     * get_view
3948
-     *
3949
-     * @return string content of _view property
3950
-     */
3951
-    public function get_view()
3952
-    {
3953
-        return $this->_view;
3954
-    }
3955
-
3956
-
3957
-    /**
3958
-     * getter for the protected $_views property
3959
-     *
3960
-     * @return array
3961
-     */
3962
-    public function get_views()
3963
-    {
3964
-        return $this->_views;
3965
-    }
3966
-
3967
-
3968
-    /**
3969
-     * get_current_page
3970
-     *
3971
-     * @return string _current_page property value
3972
-     */
3973
-    public function get_current_page()
3974
-    {
3975
-        return $this->_current_page;
3976
-    }
3977
-
3978
-
3979
-    /**
3980
-     * get_current_view
3981
-     *
3982
-     * @return string _current_view property value
3983
-     */
3984
-    public function get_current_view()
3985
-    {
3986
-        return $this->_current_view;
3987
-    }
3988
-
3989
-
3990
-    /**
3991
-     * get_current_screen
3992
-     *
3993
-     * @return object The current WP_Screen object
3994
-     */
3995
-    public function get_current_screen()
3996
-    {
3997
-        return $this->_current_screen;
3998
-    }
3999
-
4000
-
4001
-    /**
4002
-     * get_current_page_view_url
4003
-     *
4004
-     * @return string This returns the url for the current_page_view.
4005
-     */
4006
-    public function get_current_page_view_url()
4007
-    {
4008
-        return $this->_current_page_view_url;
4009
-    }
4010
-
4011
-
4012
-    /**
4013
-     * just returns the Request
4014
-     *
4015
-     * @return RequestInterface
4016
-     */
4017
-    public function get_request()
4018
-    {
4019
-        return $this->request;
4020
-    }
4021
-
4022
-
4023
-    /**
4024
-     * just returns the _req_data property
4025
-     *
4026
-     * @return array
4027
-     */
4028
-    public function get_request_data()
4029
-    {
4030
-        return $this->request->requestParams();
4031
-    }
4032
-
4033
-
4034
-    /**
4035
-     * returns the _req_data protected property
4036
-     *
4037
-     * @return string
4038
-     */
4039
-    public function get_req_action()
4040
-    {
4041
-        return $this->_req_action;
4042
-    }
4043
-
4044
-
4045
-    /**
4046
-     * @return bool  value of $_is_caf property
4047
-     */
4048
-    public function is_caf()
4049
-    {
4050
-        return $this->_is_caf;
4051
-    }
4052
-
4053
-
4054
-    /**
4055
-     * @return mixed
4056
-     */
4057
-    public function default_espresso_metaboxes()
4058
-    {
4059
-        return $this->_default_espresso_metaboxes;
4060
-    }
4061
-
4062
-
4063
-    /**
4064
-     * @return mixed
4065
-     */
4066
-    public function admin_base_url()
4067
-    {
4068
-        return $this->_admin_base_url;
4069
-    }
4070
-
4071
-
4072
-    /**
4073
-     * @return mixed
4074
-     */
4075
-    public function wp_page_slug()
4076
-    {
4077
-        return $this->_wp_page_slug;
4078
-    }
4079
-
4080
-
4081
-    /**
4082
-     * updates  espresso configuration settings
4083
-     *
4084
-     * @param string                   $tab
4085
-     * @param EE_Config_Base|EE_Config $config
4086
-     * @param string                   $file file where error occurred
4087
-     * @param string                   $func function  where error occurred
4088
-     * @param string                   $line line no where error occurred
4089
-     * @return boolean
4090
-     */
4091
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4092
-    {
4093
-        // remove any options that are NOT going to be saved with the config settings.
4094
-        if (isset($config->core->ee_ueip_optin)) {
4095
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
4096
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4097
-            update_option('ee_ueip_has_notified', true);
4098
-        }
4099
-        // and save it (note we're also doing the network save here)
4100
-        $net_saved    = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4101
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
4102
-        if ($config_saved && $net_saved) {
4103
-            EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4104
-            return true;
4105
-        }
4106
-        EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4107
-        return false;
4108
-    }
4109
-
4110
-
4111
-    /**
4112
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4113
-     *
4114
-     * @return array
4115
-     */
4116
-    public function get_yes_no_values()
4117
-    {
4118
-        return $this->_yes_no_values;
4119
-    }
4120
-
4121
-
4122
-    protected function _get_dir()
4123
-    {
4124
-        $reflector = new ReflectionClass(get_class($this));
4125
-        return dirname($reflector->getFileName());
4126
-    }
4127
-
4128
-
4129
-    /**
4130
-     * A helper for getting a "next link".
4131
-     *
4132
-     * @param string $url   The url to link to
4133
-     * @param string $class The class to use.
4134
-     * @return string
4135
-     */
4136
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4137
-    {
4138
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4139
-    }
4140
-
4141
-
4142
-    /**
4143
-     * A helper for getting a "previous link".
4144
-     *
4145
-     * @param string $url   The url to link to
4146
-     * @param string $class The class to use.
4147
-     * @return string
4148
-     */
4149
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4150
-    {
4151
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4152
-    }
4153
-
4154
-
4155
-
4156
-
4157
-
4158
-
4159
-
4160
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4161
-
4162
-
4163
-    /**
4164
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4165
-     * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4166
-     * _req_data array.
4167
-     *
4168
-     * @return bool success/fail
4169
-     * @throws EE_Error
4170
-     * @throws InvalidArgumentException
4171
-     * @throws ReflectionException
4172
-     * @throws InvalidDataTypeException
4173
-     * @throws InvalidInterfaceException
4174
-     */
4175
-    protected function _process_resend_registration()
4176
-    {
4177
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4178
-        do_action(
4179
-            'AHEE__EE_Admin_Page___process_resend_registration',
4180
-            $this->_template_args['success'],
4181
-            $this->request->requestParams()
4182
-        );
4183
-        return $this->_template_args['success'];
4184
-    }
4185
-
4186
-
4187
-    /**
4188
-     * This automatically processes any payment message notifications when manual payment has been applied.
4189
-     *
4190
-     * @param EE_Payment $payment
4191
-     * @return bool success/fail
4192
-     */
4193
-    protected function _process_payment_notification(EE_Payment $payment)
4194
-    {
4195
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4196
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4197
-        $this->_template_args['success'] = apply_filters(
4198
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4199
-            false,
4200
-            $payment
4201
-        );
4202
-        return $this->_template_args['success'];
4203
-    }
2764
+	}
2765
+
2766
+
2767
+	/**
2768
+	 * facade for add_meta_box
2769
+	 *
2770
+	 * @param string  $action        where the metabox get's displayed
2771
+	 * @param string  $title         Title of Metabox (output in metabox header)
2772
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2773
+	 *                               instead of the one created in here.
2774
+	 * @param array   $callback_args an array of args supplied for the metabox
2775
+	 * @param string  $column        what metabox column
2776
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2777
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2778
+	 *                               created but just set our own callback for wp's add_meta_box.
2779
+	 * @throws DomainException
2780
+	 */
2781
+	public function _add_admin_page_meta_box(
2782
+		$action,
2783
+		$title,
2784
+		$callback,
2785
+		$callback_args,
2786
+		$column = 'normal',
2787
+		$priority = 'high',
2788
+		$create_func = true
2789
+	) {
2790
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2791
+		// if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2792
+		if (empty($callback_args) && $create_func) {
2793
+			$callback_args = [
2794
+				'template_path' => $this->_template_path,
2795
+				'template_args' => $this->_template_args,
2796
+			];
2797
+		}
2798
+		// if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2799
+		$call_back_func = $create_func
2800
+			? function ($post, $metabox) {
2801
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2802
+				echo EEH_Template::display_template(
2803
+					$metabox['args']['template_path'],
2804
+					$metabox['args']['template_args'],
2805
+					true
2806
+				);
2807
+			}
2808
+			: $callback;
2809
+		add_meta_box(
2810
+			str_replace('_', '-', $action) . '-mbox',
2811
+			$title,
2812
+			$call_back_func,
2813
+			$this->_wp_page_slug,
2814
+			$column,
2815
+			$priority,
2816
+			$callback_args
2817
+		);
2818
+	}
2819
+
2820
+
2821
+	/**
2822
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2823
+	 *
2824
+	 * @throws DomainException
2825
+	 * @throws EE_Error
2826
+	 */
2827
+	public function display_admin_page_with_metabox_columns()
2828
+	{
2829
+		$this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2830
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2831
+			$this->_column_template_path,
2832
+			$this->_template_args,
2833
+			true
2834
+		);
2835
+		// the final wrapper
2836
+		$this->admin_page_wrapper();
2837
+	}
2838
+
2839
+
2840
+	/**
2841
+	 * generates  HTML wrapper for an admin details page
2842
+	 *
2843
+	 * @return void
2844
+	 * @throws EE_Error
2845
+	 * @throws DomainException
2846
+	 */
2847
+	public function display_admin_page_with_sidebar()
2848
+	{
2849
+		$this->_display_admin_page(true);
2850
+	}
2851
+
2852
+
2853
+	/**
2854
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2855
+	 *
2856
+	 * @return void
2857
+	 * @throws EE_Error
2858
+	 * @throws DomainException
2859
+	 */
2860
+	public function display_admin_page_with_no_sidebar()
2861
+	{
2862
+		$this->_display_admin_page();
2863
+	}
2864
+
2865
+
2866
+	/**
2867
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2868
+	 *
2869
+	 * @return void
2870
+	 * @throws EE_Error
2871
+	 * @throws DomainException
2872
+	 */
2873
+	public function display_about_admin_page()
2874
+	{
2875
+		$this->_display_admin_page(false, true);
2876
+	}
2877
+
2878
+
2879
+	/**
2880
+	 * display_admin_page
2881
+	 * contains the code for actually displaying an admin page
2882
+	 *
2883
+	 * @param boolean $sidebar true with sidebar, false without
2884
+	 * @param boolean $about   use the about_admin_wrapper instead of the default.
2885
+	 * @return void
2886
+	 * @throws DomainException
2887
+	 * @throws EE_Error
2888
+	 */
2889
+	private function _display_admin_page($sidebar = false, $about = false)
2890
+	{
2891
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2892
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2893
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2894
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2895
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2896
+		$this->_template_args['current_page']              = $this->_wp_page_slug;
2897
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2898
+			? 'poststuff'
2899
+			: 'espresso-default-admin';
2900
+		$template_path                                     = $sidebar
2901
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2902
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2903
+		if ($this->request->isAjax()) {
2904
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2905
+		}
2906
+		$template_path                                     = ! empty($this->_column_template_path)
2907
+			? $this->_column_template_path : $template_path;
2908
+		$this->_template_args['post_body_content']         = isset($this->_template_args['admin_page_content'])
2909
+			? $this->_template_args['admin_page_content']
2910
+			: '';
2911
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2912
+			? $this->_template_args['before_admin_page_content']
2913
+			: '';
2914
+		$this->_template_args['after_admin_page_content']  = isset($this->_template_args['after_admin_page_content'])
2915
+			? $this->_template_args['after_admin_page_content']
2916
+			: '';
2917
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
2918
+			$template_path,
2919
+			$this->_template_args,
2920
+			true
2921
+		);
2922
+		// the final template wrapper
2923
+		$this->admin_page_wrapper($about);
2924
+	}
2925
+
2926
+
2927
+	/**
2928
+	 * This is used to display caf preview pages.
2929
+	 *
2930
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2931
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2932
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2933
+	 * @return void
2934
+	 * @throws DomainException
2935
+	 * @throws EE_Error
2936
+	 * @throws InvalidArgumentException
2937
+	 * @throws InvalidDataTypeException
2938
+	 * @throws InvalidInterfaceException
2939
+	 * @since 4.3.2
2940
+	 */
2941
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2942
+	{
2943
+		// let's generate a default preview action button if there isn't one already present.
2944
+		$this->_labels['buttons']['buy_now']           = esc_html__(
2945
+			'Upgrade to Event Espresso 4 Right Now',
2946
+			'event_espresso'
2947
+		);
2948
+		$buy_now_url                                   = add_query_arg(
2949
+			[
2950
+				'ee_ver'       => 'ee4',
2951
+				'utm_source'   => 'ee4_plugin_admin',
2952
+				'utm_medium'   => 'link',
2953
+				'utm_campaign' => $utm_campaign_source,
2954
+				'utm_content'  => 'buy_now_button',
2955
+			],
2956
+			'https://eventespresso.com/pricing/'
2957
+		);
2958
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2959
+			? $this->get_action_link_or_button(
2960
+				'',
2961
+				'buy_now',
2962
+				[],
2963
+				'button-primary button-large',
2964
+				esc_url_raw($buy_now_url),
2965
+				true
2966
+			)
2967
+			: $this->_template_args['preview_action_button'];
2968
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
2969
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2970
+			$this->_template_args,
2971
+			true
2972
+		);
2973
+		$this->_display_admin_page($display_sidebar);
2974
+	}
2975
+
2976
+
2977
+	/**
2978
+	 * display_admin_list_table_page_with_sidebar
2979
+	 * generates HTML wrapper for an admin_page with list_table
2980
+	 *
2981
+	 * @return void
2982
+	 * @throws EE_Error
2983
+	 * @throws DomainException
2984
+	 */
2985
+	public function display_admin_list_table_page_with_sidebar()
2986
+	{
2987
+		$this->_display_admin_list_table_page(true);
2988
+	}
2989
+
2990
+
2991
+	/**
2992
+	 * display_admin_list_table_page_with_no_sidebar
2993
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2994
+	 *
2995
+	 * @return void
2996
+	 * @throws EE_Error
2997
+	 * @throws DomainException
2998
+	 */
2999
+	public function display_admin_list_table_page_with_no_sidebar()
3000
+	{
3001
+		$this->_display_admin_list_table_page();
3002
+	}
3003
+
3004
+
3005
+	/**
3006
+	 * generates html wrapper for an admin_list_table page
3007
+	 *
3008
+	 * @param boolean $sidebar whether to display with sidebar or not.
3009
+	 * @return void
3010
+	 * @throws DomainException
3011
+	 * @throws EE_Error
3012
+	 */
3013
+	private function _display_admin_list_table_page($sidebar = false)
3014
+	{
3015
+		// setup search attributes
3016
+		$this->_set_search_attributes();
3017
+		$this->_template_args['current_page']     = $this->_wp_page_slug;
3018
+		$template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
3019
+		$this->_template_args['table_url']        = $this->request->isAjax()
3020
+			? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
3021
+			: add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
3022
+		$this->_template_args['list_table']       = $this->_list_table_object;
3023
+		$this->_template_args['current_route']    = $this->_req_action;
3024
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
3025
+		$ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
3026
+		if (! empty($ajax_sorting_callback)) {
3027
+			$sortable_list_table_form_fields = wp_nonce_field(
3028
+				$ajax_sorting_callback . '_nonce',
3029
+				$ajax_sorting_callback . '_nonce',
3030
+				false,
3031
+				false
3032
+			);
3033
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3034
+												. $this->page_slug
3035
+												. '" />';
3036
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3037
+												. $ajax_sorting_callback
3038
+												. '" />';
3039
+		} else {
3040
+			$sortable_list_table_form_fields = '';
3041
+		}
3042
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3043
+		$hidden_form_fields                                      =
3044
+			isset($this->_template_args['list_table_hidden_fields'])
3045
+				? $this->_template_args['list_table_hidden_fields']
3046
+				: '';
3047
+		$nonce_ref                                               = $this->_req_action . '_nonce';
3048
+		$hidden_form_fields                                      .= '<input type="hidden" name="'
3049
+																	. $nonce_ref
3050
+																	. '" value="'
3051
+																	. wp_create_nonce($nonce_ref)
3052
+																	. '">';
3053
+		$this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
3054
+		// display message about search results?
3055
+		$search = $this->request->getRequestParam('s');
3056
+		$this->_template_args['before_list_table'] .= ! empty($search)
3057
+			? '<p class="ee-search-results">' . sprintf(
3058
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3059
+				trim($search, '%')
3060
+			) . '</p>'
3061
+			: '';
3062
+		// filter before_list_table template arg
3063
+		$this->_template_args['before_list_table'] = apply_filters(
3064
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3065
+			$this->_template_args['before_list_table'],
3066
+			$this->page_slug,
3067
+			$this->request->requestParams(),
3068
+			$this->_req_action
3069
+		);
3070
+		// convert to array and filter again
3071
+		// arrays are easier to inject new items in a specific location,
3072
+		// but would not be backwards compatible, so we have to add a new filter
3073
+		$this->_template_args['before_list_table'] = implode(
3074
+			" \n",
3075
+			(array) apply_filters(
3076
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3077
+				(array) $this->_template_args['before_list_table'],
3078
+				$this->page_slug,
3079
+				$this->request->requestParams(),
3080
+				$this->_req_action
3081
+			)
3082
+		);
3083
+		// filter after_list_table template arg
3084
+		$this->_template_args['after_list_table'] = apply_filters(
3085
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3086
+			$this->_template_args['after_list_table'],
3087
+			$this->page_slug,
3088
+			$this->request->requestParams(),
3089
+			$this->_req_action
3090
+		);
3091
+		// convert to array and filter again
3092
+		// arrays are easier to inject new items in a specific location,
3093
+		// but would not be backwards compatible, so we have to add a new filter
3094
+		$this->_template_args['after_list_table']   = implode(
3095
+			" \n",
3096
+			(array) apply_filters(
3097
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3098
+				(array) $this->_template_args['after_list_table'],
3099
+				$this->page_slug,
3100
+				$this->request->requestParams(),
3101
+				$this->_req_action
3102
+			)
3103
+		);
3104
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3105
+			$template_path,
3106
+			$this->_template_args,
3107
+			true
3108
+		);
3109
+		// the final template wrapper
3110
+		if ($sidebar) {
3111
+			$this->display_admin_page_with_sidebar();
3112
+		} else {
3113
+			$this->display_admin_page_with_no_sidebar();
3114
+		}
3115
+	}
3116
+
3117
+
3118
+	/**
3119
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3120
+	 * html string for the legend.
3121
+	 * $items are expected in an array in the following format:
3122
+	 * $legend_items = array(
3123
+	 *        'item_id' => array(
3124
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3125
+	 *            'desc' => esc_html__('localized description of item');
3126
+	 *        )
3127
+	 * );
3128
+	 *
3129
+	 * @param array $items see above for format of array
3130
+	 * @return string html string of legend
3131
+	 * @throws DomainException
3132
+	 */
3133
+	protected function _display_legend($items)
3134
+	{
3135
+		$this->_template_args['items'] = apply_filters(
3136
+			'FHEE__EE_Admin_Page___display_legend__items',
3137
+			(array) $items,
3138
+			$this
3139
+		);
3140
+		return EEH_Template::display_template(
3141
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3142
+			$this->_template_args,
3143
+			true
3144
+		);
3145
+	}
3146
+
3147
+
3148
+	/**
3149
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3150
+	 * The returned json object is created from an array in the following format:
3151
+	 * array(
3152
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3153
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3154
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3155
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3156
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3157
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3158
+	 *  that might be included in here)
3159
+	 * )
3160
+	 * The json object is populated by whatever is set in the $_template_args property.
3161
+	 *
3162
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3163
+	 *                                 instead of displayed.
3164
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3165
+	 * @return void
3166
+	 * @throws EE_Error
3167
+	 */
3168
+	protected function _return_json($sticky_notices = false, $notices_arguments = [])
3169
+	{
3170
+		// make sure any EE_Error notices have been handled.
3171
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3172
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3173
+		unset($this->_template_args['data']);
3174
+		$json = [
3175
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3176
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3177
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3178
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3179
+			'notices'   => EE_Error::get_notices(),
3180
+			'content'   => isset($this->_template_args['admin_page_content'])
3181
+				? $this->_template_args['admin_page_content'] : '',
3182
+			'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3183
+			'isEEajax'  => true
3184
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3185
+		];
3186
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3187
+		if (null === error_get_last() || ! headers_sent()) {
3188
+			header('Content-Type: application/json; charset=UTF-8');
3189
+		}
3190
+		echo wp_json_encode($json);
3191
+		exit();
3192
+	}
3193
+
3194
+
3195
+	/**
3196
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3197
+	 *
3198
+	 * @return void
3199
+	 * @throws EE_Error
3200
+	 */
3201
+	public function return_json()
3202
+	{
3203
+		if ($this->request->isAjax()) {
3204
+			$this->_return_json();
3205
+		} else {
3206
+			throw new EE_Error(
3207
+				sprintf(
3208
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3209
+					__FUNCTION__
3210
+				)
3211
+			);
3212
+		}
3213
+	}
3214
+
3215
+
3216
+	/**
3217
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3218
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3219
+	 *
3220
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3221
+	 */
3222
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3223
+	{
3224
+		$this->_hook_obj = $hook_obj;
3225
+	}
3226
+
3227
+
3228
+	/**
3229
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3230
+	 *
3231
+	 * @param boolean $about whether to use the special about page wrapper or default.
3232
+	 * @return void
3233
+	 * @throws DomainException
3234
+	 * @throws EE_Error
3235
+	 */
3236
+	public function admin_page_wrapper($about = false)
3237
+	{
3238
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3239
+		$this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3240
+		$this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3241
+		$this->_template_args['admin_page_title']          = $this->_admin_page_title;
3242
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3243
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3244
+			isset($this->_template_args['before_admin_page_content'])
3245
+				? $this->_template_args['before_admin_page_content']
3246
+				: ''
3247
+		);
3248
+		$this->_template_args['after_admin_page_content']  = apply_filters(
3249
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3250
+			isset($this->_template_args['after_admin_page_content'])
3251
+				? $this->_template_args['after_admin_page_content']
3252
+				: ''
3253
+		);
3254
+		$this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3255
+		// load settings page wrapper template
3256
+		$template_path = ! $this->request->isAjax()
3257
+			? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3258
+			: EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
3259
+		// about page?
3260
+		$template_path = $about
3261
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3262
+			: $template_path;
3263
+		if ($this->request->isAjax()) {
3264
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3265
+				$template_path,
3266
+				$this->_template_args,
3267
+				true
3268
+			);
3269
+			$this->_return_json();
3270
+		} else {
3271
+			EEH_Template::display_template($template_path, $this->_template_args);
3272
+		}
3273
+	}
3274
+
3275
+
3276
+	/**
3277
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3278
+	 *
3279
+	 * @return string html
3280
+	 * @throws EE_Error
3281
+	 */
3282
+	protected function _get_main_nav_tabs()
3283
+	{
3284
+		// let's generate the html using the EEH_Tabbed_Content helper.
3285
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3286
+		// (rather than setting in the page_routes array)
3287
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3288
+	}
3289
+
3290
+
3291
+	/**
3292
+	 *        sort nav tabs
3293
+	 *
3294
+	 * @param $a
3295
+	 * @param $b
3296
+	 * @return int
3297
+	 */
3298
+	private function _sort_nav_tabs($a, $b)
3299
+	{
3300
+		if ($a['order'] === $b['order']) {
3301
+			return 0;
3302
+		}
3303
+		return ($a['order'] < $b['order']) ? -1 : 1;
3304
+	}
3305
+
3306
+
3307
+	/**
3308
+	 *    generates HTML for the forms used on admin pages
3309
+	 *
3310
+	 * @param array  $input_vars   - array of input field details
3311
+	 * @param string $generator    (options are 'string' or 'array', basically use this to indicate which generator to
3312
+	 *                             use)
3313
+	 * @param bool   $id
3314
+	 * @return string
3315
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3316
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3317
+	 */
3318
+	protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3319
+	{
3320
+		return $generator === 'string'
3321
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3322
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3323
+	}
3324
+
3325
+
3326
+	/**
3327
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3328
+	 *
3329
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3330
+	 *                                   Close" button.
3331
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3332
+	 *                                   'Save', [1] => 'save & close')
3333
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3334
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3335
+	 *                                   default actions by submitting some other value.
3336
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3337
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3338
+	 *                                   close (normal form handling).
3339
+	 */
3340
+	protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3341
+	{
3342
+		// make sure $text and $actions are in an array
3343
+		$text          = (array) $text;
3344
+		$actions       = (array) $actions;
3345
+		$referrer_url  = empty($referrer)
3346
+			? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3347
+			  . $this->request->getServerParam('REQUEST_URI')
3348
+			  . '" />'
3349
+			: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3350
+			  . $referrer
3351
+			  . '" />';
3352
+		$button_text   = ! empty($text)
3353
+			? $text
3354
+			: [
3355
+				esc_html__('Save', 'event_espresso'),
3356
+				esc_html__('Save and Close', 'event_espresso'),
3357
+			];
3358
+		$default_names = ['save', 'save_and_close'];
3359
+		// add in a hidden index for the current page (so save and close redirects properly)
3360
+		$this->_template_args['save_buttons'] = $referrer_url;
3361
+		foreach ($button_text as $key => $button) {
3362
+			$ref                                  = $default_names[ $key ];
3363
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3364
+													 . $ref
3365
+													 . '" value="'
3366
+													 . $button
3367
+													 . '" name="'
3368
+													 . (! empty($actions) ? $actions[ $key ] : $ref)
3369
+													 . '" id="'
3370
+													 . $this->_current_view . '_' . $ref
3371
+													 . '" />';
3372
+			if (! $both) {
3373
+				break;
3374
+			}
3375
+		}
3376
+	}
3377
+
3378
+
3379
+	/**
3380
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3381
+	 *
3382
+	 * @param string $route
3383
+	 * @param array  $additional_hidden_fields
3384
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3385
+	 * @since 4.6.0
3386
+	 */
3387
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3388
+	{
3389
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3390
+	}
3391
+
3392
+
3393
+	/**
3394
+	 * set form open and close tags on add/edit pages.
3395
+	 *
3396
+	 * @param string $route                    the route you want the form to direct to
3397
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3398
+	 * @return void
3399
+	 */
3400
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3401
+	{
3402
+		if (empty($route)) {
3403
+			$user_msg = esc_html__(
3404
+				'An error occurred. No action was set for this page\'s form.',
3405
+				'event_espresso'
3406
+			);
3407
+			$dev_msg  = $user_msg . "\n"
3408
+						. sprintf(
3409
+							esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3410
+							__FUNCTION__,
3411
+							__CLASS__
3412
+						);
3413
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3414
+		}
3415
+		// open form
3416
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3417
+															 . $this->_admin_base_url
3418
+															 . '" id="'
3419
+															 . $route
3420
+															 . '_event_form" >';
3421
+		// add nonce
3422
+		$nonce                                             =
3423
+			wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3424
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3425
+		// add REQUIRED form action
3426
+		$hidden_fields = [
3427
+			'action' => ['type' => 'hidden', 'value' => $route],
3428
+		];
3429
+		// merge arrays
3430
+		$hidden_fields = is_array($additional_hidden_fields)
3431
+			? array_merge($hidden_fields, $additional_hidden_fields)
3432
+			: $hidden_fields;
3433
+		// generate form fields
3434
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3435
+		// add fields to form
3436
+		foreach ((array) $form_fields as $field_name => $form_field) {
3437
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3438
+		}
3439
+		// close form
3440
+		$this->_template_args['after_admin_page_content'] = '</form>';
3441
+	}
3442
+
3443
+
3444
+	/**
3445
+	 * Public Wrapper for _redirect_after_action() method since its
3446
+	 * discovered it would be useful for external code to have access.
3447
+	 *
3448
+	 * @param bool   $success
3449
+	 * @param string $what
3450
+	 * @param string $action_desc
3451
+	 * @param array  $query_args
3452
+	 * @param bool   $override_overwrite
3453
+	 * @throws EE_Error
3454
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3455
+	 * @since 4.5.0
3456
+	 */
3457
+	public function redirect_after_action(
3458
+		$success = false,
3459
+		$what = 'item',
3460
+		$action_desc = 'processed',
3461
+		$query_args = [],
3462
+		$override_overwrite = false
3463
+	) {
3464
+		$this->_redirect_after_action(
3465
+			$success,
3466
+			$what,
3467
+			$action_desc,
3468
+			$query_args,
3469
+			$override_overwrite
3470
+		);
3471
+	}
3472
+
3473
+
3474
+	/**
3475
+	 * Helper method for merging existing request data with the returned redirect url.
3476
+	 *
3477
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3478
+	 * filters are still applied.
3479
+	 *
3480
+	 * @param array $new_route_data
3481
+	 * @return array
3482
+	 */
3483
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3484
+	{
3485
+		foreach ($this->request->requestParams() as $ref => $value) {
3486
+			// unset nonces
3487
+			if (strpos($ref, 'nonce') !== false) {
3488
+				$this->request->unSetRequestParam($ref);
3489
+				continue;
3490
+			}
3491
+			// urlencode values.
3492
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3493
+			$this->request->setRequestParam($ref, $value);
3494
+		}
3495
+		return array_merge($this->request->requestParams(), $new_route_data);
3496
+	}
3497
+
3498
+
3499
+	/**
3500
+	 *    _redirect_after_action
3501
+	 *
3502
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3503
+	 * @param string $what               - what the action was performed on
3504
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3505
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3506
+	 *                                   action is completed
3507
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3508
+	 *                                   override this so that they show.
3509
+	 * @return void
3510
+	 * @throws EE_Error
3511
+	 */
3512
+	protected function _redirect_after_action(
3513
+		$success = 0,
3514
+		$what = 'item',
3515
+		$action_desc = 'processed',
3516
+		$query_args = [],
3517
+		$override_overwrite = false
3518
+	) {
3519
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3520
+		// class name for actions/filters.
3521
+		$classname = get_class($this);
3522
+		// set redirect url.
3523
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3524
+		// otherwise we go with whatever is set as the _admin_base_url
3525
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3526
+		$notices      = EE_Error::get_notices(false);
3527
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3528
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3529
+			EE_Error::overwrite_success();
3530
+		}
3531
+		if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3532
+			// how many records affected ? more than one record ? or just one ?
3533
+			if ($success > 1) {
3534
+				// set plural msg
3535
+				EE_Error::add_success(
3536
+					sprintf(
3537
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3538
+						$what,
3539
+						$action_desc
3540
+					),
3541
+					__FILE__,
3542
+					__FUNCTION__,
3543
+					__LINE__
3544
+				);
3545
+			} elseif ($success === 1) {
3546
+				// set singular msg
3547
+				EE_Error::add_success(
3548
+					sprintf(
3549
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3550
+						$what,
3551
+						$action_desc
3552
+					),
3553
+					__FILE__,
3554
+					__FUNCTION__,
3555
+					__LINE__
3556
+				);
3557
+			}
3558
+		}
3559
+		// check that $query_args isn't something crazy
3560
+		if (! is_array($query_args)) {
3561
+			$query_args = [];
3562
+		}
3563
+		/**
3564
+		 * Allow injecting actions before the query_args are modified for possible different
3565
+		 * redirections on save and close actions
3566
+		 *
3567
+		 * @param array $query_args       The original query_args array coming into the
3568
+		 *                                method.
3569
+		 * @since 4.2.0
3570
+		 */
3571
+		do_action(
3572
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3573
+			$query_args
3574
+		);
3575
+		// calculate where we're going (if we have a "save and close" button pushed)
3576
+
3577
+		if (
3578
+			$this->request->requestParamIsSet('save_and_close')
3579
+			&& $this->request->requestParamIsSet('save_and_close_referrer')
3580
+		) {
3581
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3582
+			$parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3583
+			// regenerate query args array from referrer URL
3584
+			parse_str($parsed_url['query'], $query_args);
3585
+			// correct page and action will be in the query args now
3586
+			$redirect_url = admin_url('admin.php');
3587
+		}
3588
+		// merge any default query_args set in _default_route_query_args property
3589
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3590
+			$args_to_merge = [];
3591
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3592
+				// is there a wp_referer array in our _default_route_query_args property?
3593
+				if ($query_param === 'wp_referer') {
3594
+					$query_value = (array) $query_value;
3595
+					foreach ($query_value as $reference => $value) {
3596
+						if (strpos($reference, 'nonce') !== false) {
3597
+							continue;
3598
+						}
3599
+						// finally we will override any arguments in the referer with
3600
+						// what might be set on the _default_route_query_args array.
3601
+						if (isset($this->_default_route_query_args[ $reference ])) {
3602
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3603
+						} else {
3604
+							$args_to_merge[ $reference ] = urlencode($value);
3605
+						}
3606
+					}
3607
+					continue;
3608
+				}
3609
+				$args_to_merge[ $query_param ] = $query_value;
3610
+			}
3611
+			// now let's merge these arguments but override with what was specifically sent in to the
3612
+			// redirect.
3613
+			$query_args = array_merge($args_to_merge, $query_args);
3614
+		}
3615
+		$this->_process_notices($query_args);
3616
+		// generate redirect url
3617
+		// if redirecting to anything other than the main page, add a nonce
3618
+		if (isset($query_args['action'])) {
3619
+			// manually generate wp_nonce and merge that with the query vars
3620
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3621
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3622
+		}
3623
+		// we're adding some hooks and filters in here for processing any things just before redirects
3624
+		// (example: an admin page has done an insert or update and we want to run something after that).
3625
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3626
+		$redirect_url = apply_filters(
3627
+			'FHEE_redirect_' . $classname . $this->_req_action,
3628
+			self::add_query_args_and_nonce($query_args, $redirect_url),
3629
+			$query_args
3630
+		);
3631
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3632
+		if ($this->request->isAjax()) {
3633
+			$default_data                    = [
3634
+				'close'        => true,
3635
+				'redirect_url' => $redirect_url,
3636
+				'where'        => 'main',
3637
+				'what'         => 'append',
3638
+			];
3639
+			$this->_template_args['success'] = $success;
3640
+			$this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3641
+				$default_data,
3642
+				$this->_template_args['data']
3643
+			) : $default_data;
3644
+			$this->_return_json();
3645
+		}
3646
+		wp_safe_redirect($redirect_url);
3647
+		exit();
3648
+	}
3649
+
3650
+
3651
+	/**
3652
+	 * process any notices before redirecting (or returning ajax request)
3653
+	 * This method sets the $this->_template_args['notices'] attribute;
3654
+	 *
3655
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3656
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3657
+	 *                                  page_routes haven't been defined yet.
3658
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3659
+	 *                                  still save a transient for the notice.
3660
+	 * @return void
3661
+	 * @throws EE_Error
3662
+	 */
3663
+	protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3664
+	{
3665
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3666
+		if ($this->request->isAjax()) {
3667
+			$notices = EE_Error::get_notices(false);
3668
+			if (empty($this->_template_args['success'])) {
3669
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3670
+			}
3671
+			if (empty($this->_template_args['errors'])) {
3672
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3673
+			}
3674
+			if (empty($this->_template_args['attention'])) {
3675
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3676
+			}
3677
+		}
3678
+		$this->_template_args['notices'] = EE_Error::get_notices();
3679
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3680
+		if (! $this->request->isAjax() || $sticky_notices) {
3681
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3682
+			$this->_add_transient(
3683
+				$route,
3684
+				$this->_template_args['notices'],
3685
+				true,
3686
+				$skip_route_verify
3687
+			);
3688
+		}
3689
+	}
3690
+
3691
+
3692
+	/**
3693
+	 * get_action_link_or_button
3694
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3695
+	 *
3696
+	 * @param string $action        use this to indicate which action the url is generated with.
3697
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3698
+	 *                              property.
3699
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3700
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3701
+	 * @param string $base_url      If this is not provided
3702
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3703
+	 *                              Otherwise this value will be used.
3704
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3705
+	 * @return string
3706
+	 * @throws InvalidArgumentException
3707
+	 * @throws InvalidInterfaceException
3708
+	 * @throws InvalidDataTypeException
3709
+	 * @throws EE_Error
3710
+	 */
3711
+	public function get_action_link_or_button(
3712
+		$action,
3713
+		$type = 'add',
3714
+		$extra_request = [],
3715
+		$class = 'button-primary',
3716
+		$base_url = '',
3717
+		$exclude_nonce = false
3718
+	) {
3719
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3720
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3721
+			throw new EE_Error(
3722
+				sprintf(
3723
+					esc_html__(
3724
+						'There is no page route for given action for the button.  This action was given: %s',
3725
+						'event_espresso'
3726
+					),
3727
+					$action
3728
+				)
3729
+			);
3730
+		}
3731
+		if (! isset($this->_labels['buttons'][ $type ])) {
3732
+			throw new EE_Error(
3733
+				sprintf(
3734
+					esc_html__(
3735
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3736
+						'event_espresso'
3737
+					),
3738
+					$type
3739
+				)
3740
+			);
3741
+		}
3742
+		// finally check user access for this button.
3743
+		$has_access = $this->check_user_access($action, true);
3744
+		if (! $has_access) {
3745
+			return '';
3746
+		}
3747
+		$_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3748
+		$query_args = [
3749
+			'action' => $action,
3750
+		];
3751
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3752
+		if (! empty($extra_request)) {
3753
+			$query_args = array_merge($extra_request, $query_args);
3754
+		}
3755
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3756
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3757
+	}
3758
+
3759
+
3760
+	/**
3761
+	 * _per_page_screen_option
3762
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3763
+	 *
3764
+	 * @return void
3765
+	 * @throws InvalidArgumentException
3766
+	 * @throws InvalidInterfaceException
3767
+	 * @throws InvalidDataTypeException
3768
+	 */
3769
+	protected function _per_page_screen_option()
3770
+	{
3771
+		$option = 'per_page';
3772
+		$args   = [
3773
+			'label'   => apply_filters(
3774
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3775
+				$this->_admin_page_title,
3776
+				$this
3777
+			),
3778
+			'default' => (int) apply_filters(
3779
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3780
+				20
3781
+			),
3782
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3783
+		];
3784
+		// ONLY add the screen option if the user has access to it.
3785
+		if ($this->check_user_access($this->_current_view, true)) {
3786
+			add_screen_option($option, $args);
3787
+		}
3788
+	}
3789
+
3790
+
3791
+	/**
3792
+	 * set_per_page_screen_option
3793
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3794
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3795
+	 * admin_menu.
3796
+	 *
3797
+	 * @return void
3798
+	 */
3799
+	private function _set_per_page_screen_options()
3800
+	{
3801
+		if ($this->request->requestParamIsSet('wp_screen_options')) {
3802
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3803
+			if (! $user = wp_get_current_user()) {
3804
+				return;
3805
+			}
3806
+			$option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3807
+			if (! $option) {
3808
+				return;
3809
+			}
3810
+			$value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3811
+			$map_option = $option;
3812
+			$option     = str_replace('-', '_', $option);
3813
+			switch ($map_option) {
3814
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3815
+					$max_value = apply_filters(
3816
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3817
+						999,
3818
+						$this->_current_page,
3819
+						$this->_current_view
3820
+					);
3821
+					if ($value < 1) {
3822
+						return;
3823
+					}
3824
+					$value = min($value, $max_value);
3825
+					break;
3826
+				default:
3827
+					$value = apply_filters(
3828
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3829
+						false,
3830
+						$option,
3831
+						$value
3832
+					);
3833
+					if (false === $value) {
3834
+						return;
3835
+					}
3836
+					break;
3837
+			}
3838
+			update_user_meta($user->ID, $option, $value);
3839
+			wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3840
+			exit;
3841
+		}
3842
+	}
3843
+
3844
+
3845
+	/**
3846
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3847
+	 *
3848
+	 * @param array $data array that will be assigned to template args.
3849
+	 */
3850
+	public function set_template_args($data)
3851
+	{
3852
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3853
+	}
3854
+
3855
+
3856
+	/**
3857
+	 * This makes available the WP transient system for temporarily moving data between routes
3858
+	 *
3859
+	 * @param string $route             the route that should receive the transient
3860
+	 * @param array  $data              the data that gets sent
3861
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3862
+	 *                                  normal route transient.
3863
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3864
+	 *                                  when we are adding a transient before page_routes have been defined.
3865
+	 * @return void
3866
+	 * @throws EE_Error
3867
+	 */
3868
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3869
+	{
3870
+		$user_id = get_current_user_id();
3871
+		if (! $skip_route_verify) {
3872
+			$this->_verify_route($route);
3873
+		}
3874
+		// now let's set the string for what kind of transient we're setting
3875
+		$transient = $notices
3876
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3877
+			: 'rte_tx_' . $route . '_' . $user_id;
3878
+		$data      = $notices ? ['notices' => $data] : $data;
3879
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3880
+		$existing = is_multisite() && is_network_admin()
3881
+			? get_site_transient($transient)
3882
+			: get_transient($transient);
3883
+		if ($existing) {
3884
+			$data = array_merge((array) $data, (array) $existing);
3885
+		}
3886
+		if (is_multisite() && is_network_admin()) {
3887
+			set_site_transient($transient, $data, 8);
3888
+		} else {
3889
+			set_transient($transient, $data, 8);
3890
+		}
3891
+	}
3892
+
3893
+
3894
+	/**
3895
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3896
+	 *
3897
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3898
+	 * @param string $route
3899
+	 * @return mixed data
3900
+	 */
3901
+	protected function _get_transient($notices = false, $route = '')
3902
+	{
3903
+		$user_id   = get_current_user_id();
3904
+		$route     = ! $route ? $this->_req_action : $route;
3905
+		$transient = $notices
3906
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3907
+			: 'rte_tx_' . $route . '_' . $user_id;
3908
+		$data      = is_multisite() && is_network_admin()
3909
+			? get_site_transient($transient)
3910
+			: get_transient($transient);
3911
+		// delete transient after retrieval (just in case it hasn't expired);
3912
+		if (is_multisite() && is_network_admin()) {
3913
+			delete_site_transient($transient);
3914
+		} else {
3915
+			delete_transient($transient);
3916
+		}
3917
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3918
+	}
3919
+
3920
+
3921
+	/**
3922
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3923
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3924
+	 * default route callback on the EE_Admin page you want it run.)
3925
+	 *
3926
+	 * @return void
3927
+	 */
3928
+	protected function _transient_garbage_collection()
3929
+	{
3930
+		global $wpdb;
3931
+		// retrieve all existing transients
3932
+		$query =
3933
+			"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3934
+		if ($results = $wpdb->get_results($query)) {
3935
+			foreach ($results as $result) {
3936
+				$transient = str_replace('_transient_', '', $result->option_name);
3937
+				get_transient($transient);
3938
+				if (is_multisite() && is_network_admin()) {
3939
+					get_site_transient($transient);
3940
+				}
3941
+			}
3942
+		}
3943
+	}
3944
+
3945
+
3946
+	/**
3947
+	 * get_view
3948
+	 *
3949
+	 * @return string content of _view property
3950
+	 */
3951
+	public function get_view()
3952
+	{
3953
+		return $this->_view;
3954
+	}
3955
+
3956
+
3957
+	/**
3958
+	 * getter for the protected $_views property
3959
+	 *
3960
+	 * @return array
3961
+	 */
3962
+	public function get_views()
3963
+	{
3964
+		return $this->_views;
3965
+	}
3966
+
3967
+
3968
+	/**
3969
+	 * get_current_page
3970
+	 *
3971
+	 * @return string _current_page property value
3972
+	 */
3973
+	public function get_current_page()
3974
+	{
3975
+		return $this->_current_page;
3976
+	}
3977
+
3978
+
3979
+	/**
3980
+	 * get_current_view
3981
+	 *
3982
+	 * @return string _current_view property value
3983
+	 */
3984
+	public function get_current_view()
3985
+	{
3986
+		return $this->_current_view;
3987
+	}
3988
+
3989
+
3990
+	/**
3991
+	 * get_current_screen
3992
+	 *
3993
+	 * @return object The current WP_Screen object
3994
+	 */
3995
+	public function get_current_screen()
3996
+	{
3997
+		return $this->_current_screen;
3998
+	}
3999
+
4000
+
4001
+	/**
4002
+	 * get_current_page_view_url
4003
+	 *
4004
+	 * @return string This returns the url for the current_page_view.
4005
+	 */
4006
+	public function get_current_page_view_url()
4007
+	{
4008
+		return $this->_current_page_view_url;
4009
+	}
4010
+
4011
+
4012
+	/**
4013
+	 * just returns the Request
4014
+	 *
4015
+	 * @return RequestInterface
4016
+	 */
4017
+	public function get_request()
4018
+	{
4019
+		return $this->request;
4020
+	}
4021
+
4022
+
4023
+	/**
4024
+	 * just returns the _req_data property
4025
+	 *
4026
+	 * @return array
4027
+	 */
4028
+	public function get_request_data()
4029
+	{
4030
+		return $this->request->requestParams();
4031
+	}
4032
+
4033
+
4034
+	/**
4035
+	 * returns the _req_data protected property
4036
+	 *
4037
+	 * @return string
4038
+	 */
4039
+	public function get_req_action()
4040
+	{
4041
+		return $this->_req_action;
4042
+	}
4043
+
4044
+
4045
+	/**
4046
+	 * @return bool  value of $_is_caf property
4047
+	 */
4048
+	public function is_caf()
4049
+	{
4050
+		return $this->_is_caf;
4051
+	}
4052
+
4053
+
4054
+	/**
4055
+	 * @return mixed
4056
+	 */
4057
+	public function default_espresso_metaboxes()
4058
+	{
4059
+		return $this->_default_espresso_metaboxes;
4060
+	}
4061
+
4062
+
4063
+	/**
4064
+	 * @return mixed
4065
+	 */
4066
+	public function admin_base_url()
4067
+	{
4068
+		return $this->_admin_base_url;
4069
+	}
4070
+
4071
+
4072
+	/**
4073
+	 * @return mixed
4074
+	 */
4075
+	public function wp_page_slug()
4076
+	{
4077
+		return $this->_wp_page_slug;
4078
+	}
4079
+
4080
+
4081
+	/**
4082
+	 * updates  espresso configuration settings
4083
+	 *
4084
+	 * @param string                   $tab
4085
+	 * @param EE_Config_Base|EE_Config $config
4086
+	 * @param string                   $file file where error occurred
4087
+	 * @param string                   $func function  where error occurred
4088
+	 * @param string                   $line line no where error occurred
4089
+	 * @return boolean
4090
+	 */
4091
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4092
+	{
4093
+		// remove any options that are NOT going to be saved with the config settings.
4094
+		if (isset($config->core->ee_ueip_optin)) {
4095
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
4096
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4097
+			update_option('ee_ueip_has_notified', true);
4098
+		}
4099
+		// and save it (note we're also doing the network save here)
4100
+		$net_saved    = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4101
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
4102
+		if ($config_saved && $net_saved) {
4103
+			EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4104
+			return true;
4105
+		}
4106
+		EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4107
+		return false;
4108
+	}
4109
+
4110
+
4111
+	/**
4112
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4113
+	 *
4114
+	 * @return array
4115
+	 */
4116
+	public function get_yes_no_values()
4117
+	{
4118
+		return $this->_yes_no_values;
4119
+	}
4120
+
4121
+
4122
+	protected function _get_dir()
4123
+	{
4124
+		$reflector = new ReflectionClass(get_class($this));
4125
+		return dirname($reflector->getFileName());
4126
+	}
4127
+
4128
+
4129
+	/**
4130
+	 * A helper for getting a "next link".
4131
+	 *
4132
+	 * @param string $url   The url to link to
4133
+	 * @param string $class The class to use.
4134
+	 * @return string
4135
+	 */
4136
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4137
+	{
4138
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4139
+	}
4140
+
4141
+
4142
+	/**
4143
+	 * A helper for getting a "previous link".
4144
+	 *
4145
+	 * @param string $url   The url to link to
4146
+	 * @param string $class The class to use.
4147
+	 * @return string
4148
+	 */
4149
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4150
+	{
4151
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4152
+	}
4153
+
4154
+
4155
+
4156
+
4157
+
4158
+
4159
+
4160
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4161
+
4162
+
4163
+	/**
4164
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4165
+	 * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4166
+	 * _req_data array.
4167
+	 *
4168
+	 * @return bool success/fail
4169
+	 * @throws EE_Error
4170
+	 * @throws InvalidArgumentException
4171
+	 * @throws ReflectionException
4172
+	 * @throws InvalidDataTypeException
4173
+	 * @throws InvalidInterfaceException
4174
+	 */
4175
+	protected function _process_resend_registration()
4176
+	{
4177
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4178
+		do_action(
4179
+			'AHEE__EE_Admin_Page___process_resend_registration',
4180
+			$this->_template_args['success'],
4181
+			$this->request->requestParams()
4182
+		);
4183
+		return $this->_template_args['success'];
4184
+	}
4185
+
4186
+
4187
+	/**
4188
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4189
+	 *
4190
+	 * @param EE_Payment $payment
4191
+	 * @return bool success/fail
4192
+	 */
4193
+	protected function _process_payment_notification(EE_Payment $payment)
4194
+	{
4195
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4196
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4197
+		$this->_template_args['success'] = apply_filters(
4198
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4199
+			false,
4200
+			$payment
4201
+		);
4202
+		return $this->_template_args['success'];
4203
+	}
4204 4204
 }
Please login to merge, or discard this patch.
modules/messages/EED_Messages.module.php 2 patches
Indentation   +1331 added lines, -1331 removed lines patch added patch discarded remove patch
@@ -16,1344 +16,1344 @@
 block discarded – undo
16 16
 class EED_Messages extends EED_Module
17 17
 {
18 18
 
19
-    /**
20
-     * This holds the EE_messages controller
21
-     *
22
-     * @deprecated 4.9.0
23
-     * @var EE_messages $_EEMSG
24
-     */
25
-    protected static $_EEMSG;
26
-
27
-    /**
28
-     * @type EE_Message_Resource_Manager $_message_resource_manager
29
-     */
30
-    protected static $_message_resource_manager;
31
-
32
-    /**
33
-     * This holds the EE_Messages_Processor business class.
34
-     *
35
-     * @type EE_Messages_Processor
36
-     */
37
-    protected static $_MSG_PROCESSOR;
38
-
39
-    /**
40
-     * holds all the paths for various messages components.
41
-     * Utilized by autoloader registry
42
-     *
43
-     * @var array
44
-     */
45
-    protected static $_MSG_PATHS;
46
-
47
-
48
-    /**
49
-     * This will hold an array of messages template packs that are registered in the messages system.
50
-     * Format is:
51
-     * array(
52
-     *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
53
-     * )
54
-     *
55
-     * @var EE_Messages_Template_Pack[]
56
-     */
57
-    protected static $_TMP_PACKS = array();
58
-
59
-
60
-    /**
61
-     * @return EED_Messages|EED_Module
62
-     * @throws EE_Error
63
-     * @throws ReflectionException
64
-     */
65
-    public static function instance()
66
-    {
67
-        return parent::get_instance(__CLASS__);
68
-    }
69
-
70
-
71
-    /**
72
-     *  set_hooks - for hooking into EE Core, other modules, etc
73
-     *
74
-     * @since 4.5.0
75
-     * @return    void
76
-     */
77
-    public static function set_hooks()
78
-    {
79
-        // actions
80
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
81
-        add_action(
82
-            'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
83
-            array('EED_Messages', 'maybe_registration'),
84
-            10,
85
-            2
86
-        );
87
-        // filters
88
-        add_filter(
89
-            'FHEE__EE_Registration__receipt_url__receipt_url',
90
-            array('EED_Messages', 'registration_message_trigger_url'),
91
-            10,
92
-            4
93
-        );
94
-        add_filter(
95
-            'FHEE__EE_Registration__invoice_url__invoice_url',
96
-            array('EED_Messages', 'registration_message_trigger_url'),
97
-            10,
98
-            4
99
-        );
100
-        // register routes
101
-        self::_register_routes();
102
-    }
103
-
104
-    /**
105
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
-     *
107
-     * @access    public
108
-     * @return    void
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        // actions
113
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
114
-        add_action(
115
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
116
-            array('EED_Messages', 'payment_reminder'),
117
-            10
118
-        );
119
-        add_action(
120
-            'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
121
-            array('EED_Messages', 'maybe_registration'),
122
-            10,
123
-            3
124
-        );
125
-        add_action(
126
-            'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
127
-            array('EED_Messages', 'send_newsletter_message'),
128
-            10,
129
-            2
130
-        );
131
-        add_action(
132
-            'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
133
-            array('EED_Messages', 'cancelled_registration'),
134
-            10
135
-        );
136
-        add_action(
137
-            'AHEE__EE_Admin_Page___process_admin_payment_notification',
138
-            array('EED_Messages', 'process_admin_payment'),
139
-            10,
140
-            1
141
-        );
142
-        // filters
143
-        add_filter(
144
-            'FHEE__EE_Admin_Page___process_resend_registration__success',
145
-            array('EED_Messages', 'process_resend'),
146
-            10,
147
-            2
148
-        );
149
-        add_filter(
150
-            'FHEE__EE_Registration__receipt_url__receipt_url',
151
-            array('EED_Messages', 'registration_message_trigger_url'),
152
-            10,
153
-            4
154
-        );
155
-        add_filter(
156
-            'FHEE__EE_Registration__invoice_url__invoice_url',
157
-            array('EED_Messages', 'registration_message_trigger_url'),
158
-            10,
159
-            4
160
-        );
161
-    }
162
-
163
-
164
-    /**
165
-     * All the message triggers done by route go in here.
166
-     *
167
-     * @since 4.5.0
168
-     * @return void
169
-     */
170
-    protected static function _register_routes()
171
-    {
172
-        EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
173
-        EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
174
-        EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
175
-        EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
176
-        do_action('AHEE__EED_Messages___register_routes');
177
-    }
178
-
179
-
180
-    /**
181
-     * This is called when a browser display trigger is executed.
182
-     * The browser display trigger is typically used when a already generated message is displayed directly in the
183
-     * browser.
184
-     *
185
-     * @since 4.9.0
186
-     * @param WP $WP
187
-     * @throws EE_Error
188
-     * @throws InvalidArgumentException
189
-     * @throws ReflectionException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidInterfaceException
192
-     */
193
-    public function browser_trigger($WP)
194
-    {
195
-        // ensure controller is loaded
196
-        self::_load_controller();
197
-        $token = self::getRequest()->getRequestParam('token');
198
-        try {
199
-            $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
200
-            self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
201
-        } catch (EE_Error $e) {
202
-            $error_msg = esc_html__(
203
-                'Please note that a system message failed to send due to a technical issue.',
204
-                'event_espresso'
205
-            );
206
-            // add specific message for developers if WP_DEBUG in on
207
-            $error_msg .= '||' . $e->getMessage();
208
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209
-        }
210
-    }
211
-
212
-
213
-    /**
214
-     * This is called when a browser error trigger is executed.
215
-     * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
216
-     * message and display it.
217
-     *
218
-     * @since 4.9.0
219
-     * @param $WP
220
-     * @throws EE_Error
221
-     * @throws InvalidArgumentException
222
-     * @throws InvalidDataTypeException
223
-     * @throws InvalidInterfaceException
224
-     */
225
-    public function browser_error_trigger($WP)
226
-    {
227
-        $token = self::getRequest()->getRequestParam('token');
228
-        if ($token) {
229
-            $message = EEM_Message::instance()->get_one_by_token($token);
230
-            if ($message instanceof EE_Message) {
231
-                header('HTTP/1.1 200 OK');
232
-                $error_msg = nl2br($message->error_message());
233
-                ?>
19
+	/**
20
+	 * This holds the EE_messages controller
21
+	 *
22
+	 * @deprecated 4.9.0
23
+	 * @var EE_messages $_EEMSG
24
+	 */
25
+	protected static $_EEMSG;
26
+
27
+	/**
28
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
29
+	 */
30
+	protected static $_message_resource_manager;
31
+
32
+	/**
33
+	 * This holds the EE_Messages_Processor business class.
34
+	 *
35
+	 * @type EE_Messages_Processor
36
+	 */
37
+	protected static $_MSG_PROCESSOR;
38
+
39
+	/**
40
+	 * holds all the paths for various messages components.
41
+	 * Utilized by autoloader registry
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected static $_MSG_PATHS;
46
+
47
+
48
+	/**
49
+	 * This will hold an array of messages template packs that are registered in the messages system.
50
+	 * Format is:
51
+	 * array(
52
+	 *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
53
+	 * )
54
+	 *
55
+	 * @var EE_Messages_Template_Pack[]
56
+	 */
57
+	protected static $_TMP_PACKS = array();
58
+
59
+
60
+	/**
61
+	 * @return EED_Messages|EED_Module
62
+	 * @throws EE_Error
63
+	 * @throws ReflectionException
64
+	 */
65
+	public static function instance()
66
+	{
67
+		return parent::get_instance(__CLASS__);
68
+	}
69
+
70
+
71
+	/**
72
+	 *  set_hooks - for hooking into EE Core, other modules, etc
73
+	 *
74
+	 * @since 4.5.0
75
+	 * @return    void
76
+	 */
77
+	public static function set_hooks()
78
+	{
79
+		// actions
80
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
81
+		add_action(
82
+			'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
83
+			array('EED_Messages', 'maybe_registration'),
84
+			10,
85
+			2
86
+		);
87
+		// filters
88
+		add_filter(
89
+			'FHEE__EE_Registration__receipt_url__receipt_url',
90
+			array('EED_Messages', 'registration_message_trigger_url'),
91
+			10,
92
+			4
93
+		);
94
+		add_filter(
95
+			'FHEE__EE_Registration__invoice_url__invoice_url',
96
+			array('EED_Messages', 'registration_message_trigger_url'),
97
+			10,
98
+			4
99
+		);
100
+		// register routes
101
+		self::_register_routes();
102
+	}
103
+
104
+	/**
105
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
+	 *
107
+	 * @access    public
108
+	 * @return    void
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		// actions
113
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
114
+		add_action(
115
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
116
+			array('EED_Messages', 'payment_reminder'),
117
+			10
118
+		);
119
+		add_action(
120
+			'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
121
+			array('EED_Messages', 'maybe_registration'),
122
+			10,
123
+			3
124
+		);
125
+		add_action(
126
+			'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
127
+			array('EED_Messages', 'send_newsletter_message'),
128
+			10,
129
+			2
130
+		);
131
+		add_action(
132
+			'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
133
+			array('EED_Messages', 'cancelled_registration'),
134
+			10
135
+		);
136
+		add_action(
137
+			'AHEE__EE_Admin_Page___process_admin_payment_notification',
138
+			array('EED_Messages', 'process_admin_payment'),
139
+			10,
140
+			1
141
+		);
142
+		// filters
143
+		add_filter(
144
+			'FHEE__EE_Admin_Page___process_resend_registration__success',
145
+			array('EED_Messages', 'process_resend'),
146
+			10,
147
+			2
148
+		);
149
+		add_filter(
150
+			'FHEE__EE_Registration__receipt_url__receipt_url',
151
+			array('EED_Messages', 'registration_message_trigger_url'),
152
+			10,
153
+			4
154
+		);
155
+		add_filter(
156
+			'FHEE__EE_Registration__invoice_url__invoice_url',
157
+			array('EED_Messages', 'registration_message_trigger_url'),
158
+			10,
159
+			4
160
+		);
161
+	}
162
+
163
+
164
+	/**
165
+	 * All the message triggers done by route go in here.
166
+	 *
167
+	 * @since 4.5.0
168
+	 * @return void
169
+	 */
170
+	protected static function _register_routes()
171
+	{
172
+		EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
173
+		EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
174
+		EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
175
+		EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
176
+		do_action('AHEE__EED_Messages___register_routes');
177
+	}
178
+
179
+
180
+	/**
181
+	 * This is called when a browser display trigger is executed.
182
+	 * The browser display trigger is typically used when a already generated message is displayed directly in the
183
+	 * browser.
184
+	 *
185
+	 * @since 4.9.0
186
+	 * @param WP $WP
187
+	 * @throws EE_Error
188
+	 * @throws InvalidArgumentException
189
+	 * @throws ReflectionException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidInterfaceException
192
+	 */
193
+	public function browser_trigger($WP)
194
+	{
195
+		// ensure controller is loaded
196
+		self::_load_controller();
197
+		$token = self::getRequest()->getRequestParam('token');
198
+		try {
199
+			$mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
200
+			self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
201
+		} catch (EE_Error $e) {
202
+			$error_msg = esc_html__(
203
+				'Please note that a system message failed to send due to a technical issue.',
204
+				'event_espresso'
205
+			);
206
+			// add specific message for developers if WP_DEBUG in on
207
+			$error_msg .= '||' . $e->getMessage();
208
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209
+		}
210
+	}
211
+
212
+
213
+	/**
214
+	 * This is called when a browser error trigger is executed.
215
+	 * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
216
+	 * message and display it.
217
+	 *
218
+	 * @since 4.9.0
219
+	 * @param $WP
220
+	 * @throws EE_Error
221
+	 * @throws InvalidArgumentException
222
+	 * @throws InvalidDataTypeException
223
+	 * @throws InvalidInterfaceException
224
+	 */
225
+	public function browser_error_trigger($WP)
226
+	{
227
+		$token = self::getRequest()->getRequestParam('token');
228
+		if ($token) {
229
+			$message = EEM_Message::instance()->get_one_by_token($token);
230
+			if ($message instanceof EE_Message) {
231
+				header('HTTP/1.1 200 OK');
232
+				$error_msg = nl2br($message->error_message());
233
+				?>
234 234
                 <!DOCTYPE html>
235 235
                 <html>
236 236
                 <head></head>
237 237
                 <body>
238 238
                 <?php echo empty($error_msg)
239
-                    ? esc_html__(
240
-                        'Unfortunately, we were unable to capture the error message for this message.',
241
-                        'event_espresso'
242
-                    )
243
-                    : wp_kses(
244
-                        $error_msg,
245
-                        array(
246
-                            'a'      => array(
247
-                                'href'  => array(),
248
-                                'title' => array(),
249
-                            ),
250
-                            'span'   => array(),
251
-                            'div'    => array(),
252
-                            'p'      => array(),
253
-                            'strong' => array(),
254
-                            'em'     => array(),
255
-                            'br'     => array(),
256
-                        )
257
-                    ); ?>
239
+					? esc_html__(
240
+						'Unfortunately, we were unable to capture the error message for this message.',
241
+						'event_espresso'
242
+					)
243
+					: wp_kses(
244
+						$error_msg,
245
+						array(
246
+							'a'      => array(
247
+								'href'  => array(),
248
+								'title' => array(),
249
+							),
250
+							'span'   => array(),
251
+							'div'    => array(),
252
+							'p'      => array(),
253
+							'strong' => array(),
254
+							'em'     => array(),
255
+							'br'     => array(),
256
+						)
257
+					); ?>
258 258
                 </body>
259 259
                 </html>
260 260
                 <?php
261
-                exit;
262
-            }
263
-        }
264
-    }
265
-
266
-
267
-    /**
268
-     *  This runs when the msg_url_trigger route has initiated.
269
-     *
270
-     * @since 4.5.0
271
-     * @param WP $WP
272
-     * @throws EE_Error
273
-     * @throws InvalidArgumentException
274
-     * @throws ReflectionException
275
-     * @throws InvalidDataTypeException
276
-     * @throws InvalidInterfaceException
277
-     */
278
-    public function run($WP)
279
-    {
280
-        // ensure controller is loaded
281
-        self::_load_controller();
282
-        // attempt to process message
283
-        try {
284
-            /** @type EE_Message_To_Generate_From_Request $message_to_generate */
285
-            $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
286
-            self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
287
-        } catch (EE_Error $e) {
288
-            $error_msg = esc_html__(
289
-                'Please note that a system message failed to send due to a technical issue.',
290
-                'event_espresso'
291
-            );
292
-            // add specific message for developers if WP_DEBUG in on
293
-            $error_msg .= '||' . $e->getMessage();
294
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
295
-        }
296
-    }
297
-
298
-
299
-    /**
300
-     * This is triggered by the 'msg_cron_trigger' route.
301
-     *
302
-     * @param WP $WP
303
-     */
304
-    public function execute_batch_request($WP)
305
-    {
306
-        $this->run_cron();
307
-        header('HTTP/1.1 200 OK');
308
-        exit();
309
-    }
310
-
311
-
312
-    /**
313
-     * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
314
-     * request.
315
-     */
316
-    public function run_cron()
317
-    {
318
-        self::_load_controller();
319
-        $request = self::getRequest();
320
-        // get required vars
321
-        $cron_type = $request->getRequestParam('type');
322
-        $transient_key = $request->getRequestParam('key');
323
-
324
-        // now let's verify transient, if not valid exit immediately
325
-        if (! get_transient($transient_key)) {
326
-            /**
327
-             * trigger error so this gets in the error logs.  This is important because it happens on a non-user
328
-             * request.
329
-             */
330
-            trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
331
-        }
332
-
333
-        // if made it here, lets' delete the transient to keep the db clean
334
-        delete_transient($transient_key);
335
-
336
-        if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
337
-            $method = 'batch_' . $cron_type . '_from_queue';
338
-            if (method_exists(self::$_MSG_PROCESSOR, $method)) {
339
-                self::$_MSG_PROCESSOR->$method();
340
-            } else {
341
-                // no matching task
342
-                /**
343
-                 * trigger error so this gets in the error logs.  This is important because it happens on a non user
344
-                 * request.
345
-                 */
346
-                trigger_error(
347
-                    esc_attr(
348
-                        sprintf(
349
-                            esc_html__('There is no task corresponding to this route %s', 'event_espresso'),
350
-                            $cron_type
351
-                        )
352
-                    )
353
-                );
354
-            }
355
-        }
356
-
357
-        do_action('FHEE__EED_Messages__run_cron__end');
358
-    }
359
-
360
-
361
-    /**
362
-     * This is used to retrieve the template pack for the given name.
363
-     * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
364
-     * the default template pack is returned.
365
-     *
366
-     * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
367
-     * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
368
-     *                                   in generating the Pack class name).
369
-     * @return EE_Messages_Template_Pack
370
-     * @throws EE_Error
371
-     * @throws InvalidArgumentException
372
-     * @throws ReflectionException
373
-     * @throws InvalidDataTypeException
374
-     * @throws InvalidInterfaceException
375
-     */
376
-    public static function get_template_pack($template_pack_name)
377
-    {
378
-        EE_Registry::instance()->load_helper('MSG_Template');
379
-        return EEH_MSG_Template::get_template_pack($template_pack_name);
380
-    }
381
-
382
-
383
-    /**
384
-     * Retrieves an array of all template packs.
385
-     * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
386
-     *
387
-     * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
388
-     * @return EE_Messages_Template_Pack[]
389
-     * @throws EE_Error
390
-     * @throws InvalidArgumentException
391
-     * @throws ReflectionException
392
-     * @throws InvalidDataTypeException
393
-     * @throws InvalidInterfaceException
394
-     */
395
-    public static function get_template_packs()
396
-    {
397
-        EE_Registry::instance()->load_helper('MSG_Template');
398
-
399
-        // for backward compat, let's make sure this returns in the same format as originally.
400
-        $template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
401
-        $template_pack_collection->rewind();
402
-        $template_packs = array();
403
-        while ($template_pack_collection->valid()) {
404
-            $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
405
-            $template_pack_collection->next();
406
-        }
407
-        return $template_packs;
408
-    }
409
-
410
-
411
-    /**
412
-     * This simply makes sure the autoloaders are registered for the EE_messages system.
413
-     *
414
-     * @since 4.5.0
415
-     * @return void
416
-     * @throws EE_Error
417
-     */
418
-    public static function set_autoloaders()
419
-    {
420
-        if (empty(self::$_MSG_PATHS)) {
421
-            self::_set_messages_paths();
422
-            foreach (self::$_MSG_PATHS as $path) {
423
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
424
-            }
425
-            // add aliases
426
-            EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
427
-            EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
428
-        }
429
-    }
430
-
431
-
432
-    /**
433
-     * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
434
-     * for use by the Messages Autoloaders
435
-     *
436
-     * @since 4.5.0
437
-     * @return void.
438
-     */
439
-    protected static function _set_messages_paths()
440
-    {
441
-        $dir_ref = array(
442
-            'messages/message_type',
443
-            'messages/messenger',
444
-            'messages/defaults',
445
-            'messages/defaults/email',
446
-            'messages/data_class',
447
-            'messages/validators',
448
-            'messages/validators/email',
449
-            'messages/validators/html',
450
-            'shortcodes',
451
-        );
452
-        $paths = array();
453
-        foreach ($dir_ref as $index => $dir) {
454
-            $paths[ $index ] = EE_LIBRARIES . $dir;
455
-        }
456
-        self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
457
-    }
458
-
459
-
460
-    /**
461
-     * Takes care of loading dependencies
462
-     *
463
-     * @since 4.5.0
464
-     * @return void
465
-     * @throws EE_Error
466
-     * @throws InvalidArgumentException
467
-     * @throws ReflectionException
468
-     * @throws InvalidDataTypeException
469
-     * @throws InvalidInterfaceException
470
-     */
471
-    protected static function _load_controller()
472
-    {
473
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
474
-            EE_Registry::instance()->load_core('Request_Handler');
475
-            self::set_autoloaders();
476
-            self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
477
-            self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor');
478
-            self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
479
-        }
480
-    }
481
-
482
-
483
-    /**
484
-     * @param EE_Transaction $transaction
485
-     * @throws EE_Error
486
-     * @throws InvalidArgumentException
487
-     * @throws InvalidDataTypeException
488
-     * @throws InvalidInterfaceException
489
-     * @throws ReflectionException
490
-     */
491
-    public static function payment_reminder(EE_Transaction $transaction)
492
-    {
493
-        self::_load_controller();
494
-        $data = array($transaction, null);
495
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
496
-    }
497
-
498
-
499
-    /**
500
-     * Any messages triggers for after successful gateway payments should go in here.
501
-     *
502
-     * @param EE_Transaction  $transaction object
503
-     * @param EE_Payment|null $payment     object
504
-     * @return void
505
-     * @throws EE_Error
506
-     * @throws InvalidArgumentException
507
-     * @throws ReflectionException
508
-     * @throws InvalidDataTypeException
509
-     * @throws InvalidInterfaceException
510
-     */
511
-    public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
512
-    {
513
-        // if there's no payment object, then we cannot do a payment type message!
514
-        if (! $payment instanceof EE_Payment) {
515
-            return;
516
-        }
517
-        self::_load_controller();
518
-        $data = array($transaction, $payment);
519
-        EE_Registry::instance()->load_helper('MSG_Template');
520
-        $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
521
-        // if payment amount is less than 0 then switch to payment_refund message type.
522
-        $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
523
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
524
-    }
525
-
526
-
527
-    /**
528
-     * @param EE_Transaction $transaction
529
-     * @throws EE_Error
530
-     * @throws InvalidArgumentException
531
-     * @throws InvalidDataTypeException
532
-     * @throws InvalidInterfaceException
533
-     * @throws ReflectionException
534
-     */
535
-    public static function cancelled_registration(EE_Transaction $transaction)
536
-    {
537
-        self::_load_controller();
538
-        $data = array($transaction, null);
539
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
540
-    }
541
-
542
-
543
-    /**
544
-     * Trigger for Registration messages
545
-     * Note that what registration message type is sent depends on what the reg status is for the registrations on the
546
-     * incoming transaction.
547
-     *
548
-     * @param EE_Registration $registration
549
-     * @param array           $extra_details
550
-     * @return void
551
-     * @throws EE_Error
552
-     * @throws InvalidArgumentException
553
-     * @throws InvalidDataTypeException
554
-     * @throws InvalidInterfaceException
555
-     * @throws ReflectionException
556
-     * @throws EntityNotFoundException
557
-     */
558
-    public static function maybe_registration(EE_Registration $registration, $extra_details = array())
559
-    {
560
-
561
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
562
-            // no messages please
563
-            return;
564
-        }
565
-
566
-        // get all non-trashed registrations so we make sure we send messages for the right status.
567
-        $all_registrations = $registration->transaction()->registrations(
568
-            array(
569
-                array('REG_deleted' => false),
570
-                'order_by' => array(
571
-                    'Event.EVT_name'     => 'ASC',
572
-                    'Attendee.ATT_lname' => 'ASC',
573
-                    'Attendee.ATT_fname' => 'ASC',
574
-                ),
575
-            )
576
-        );
577
-        // cached array of statuses so we only trigger messages once per status.
578
-        $statuses_sent = array();
579
-        self::_load_controller();
580
-        $mtgs = array();
581
-
582
-        // loop through registrations and trigger messages once per status.
583
-        foreach ($all_registrations as $reg) {
584
-            // already triggered?
585
-            if (in_array($reg->status_ID(), $statuses_sent)) {
586
-                continue;
587
-            }
588
-
589
-            $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
590
-            $mtgs = array_merge(
591
-                $mtgs,
592
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
593
-                    $message_type,
594
-                    array($registration->transaction(), null, $reg->status_ID())
595
-                )
596
-            );
597
-            $statuses_sent[] = $reg->status_ID();
598
-        }
599
-
600
-        if (count($statuses_sent) > 1) {
601
-            $mtgs = array_merge(
602
-                $mtgs,
603
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
604
-                    'registration_summary',
605
-                    array($registration->transaction(), null)
606
-                )
607
-            );
608
-        }
609
-
610
-        // batch queue and initiate request
611
-        self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
612
-        self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
613
-    }
614
-
615
-
616
-    /**
617
-     * This is a helper method used to very whether a registration notification should be sent or
618
-     * not.  Prevents duplicate notifications going out for registration context notifications.
619
-     *
620
-     * @param EE_Registration $registration  [description]
621
-     * @param array           $extra_details [description]
622
-     * @return bool          true = send away, false = nope halt the presses.
623
-     */
624
-    protected static function _verify_registration_notification_send(
625
-        EE_Registration $registration,
626
-        $extra_details = array()
627
-    ) {
628
-        if (! $registration->is_primary_registrant()) {
629
-            return false;
630
-        }
631
-        $request = self::getRequest();
632
-        // first we check if we're in admin and not doing front ajax
633
-        if ($request->isAdmin() && ! $request->isFrontAjax()) {
634
-            $status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true);
635
-            // make sure appropriate admin params are set for sending messages
636
-            if (! $status_change['send_notifications']) {
637
-                // no messages sent please.
638
-                return false;
639
-            }
640
-        } else {
641
-            // frontend request (either regular or via AJAX)
642
-            // TXN is NOT finalized ?
643
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
644
-                return false;
645
-            }
646
-            // return visit but nothing changed ???
647
-            if (
648
-                isset($extra_details['revisit'], $extra_details['status_updates']) &&
649
-                $extra_details['revisit'] && ! $extra_details['status_updates']
650
-            ) {
651
-                return false;
652
-            }
653
-            // NOT sending messages && reg status is something other than "Not-Approved"
654
-            if (
655
-                ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
656
-                $registration->status_ID() !== EEM_Registration::status_id_not_approved
657
-            ) {
658
-                return false;
659
-            }
660
-        }
661
-        // release the kraken
662
-        return true;
663
-    }
664
-
665
-
666
-    /**
667
-     * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
668
-     * status id.
669
-     *
670
-     * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
671
-     *                    or EEH_MSG_Template::convert_reg_status_to_message_type
672
-     * @param string $reg_status
673
-     * @return array
674
-     * @throws EE_Error
675
-     * @throws InvalidArgumentException
676
-     * @throws ReflectionException
677
-     * @throws InvalidDataTypeException
678
-     * @throws InvalidInterfaceException
679
-     */
680
-    protected static function _get_reg_status_array($reg_status = '')
681
-    {
682
-        EE_Registry::instance()->load_helper('MSG_Template');
683
-        return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
684
-            ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
685
-            : EEH_MSG_Template::reg_status_to_message_type_array();
686
-    }
687
-
688
-
689
-    /**
690
-     * Simply returns the payment message type for the given payment status.
691
-     *
692
-     * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
693
-     *                   or EEH_MSG_Template::convert_payment_status_to_message_type
694
-     * @param string $payment_status The payment status being matched.
695
-     * @return bool|string The payment message type slug matching the status or false if no match.
696
-     * @throws EE_Error
697
-     * @throws InvalidArgumentException
698
-     * @throws ReflectionException
699
-     * @throws InvalidDataTypeException
700
-     * @throws InvalidInterfaceException
701
-     */
702
-    protected static function _get_payment_message_type($payment_status)
703
-    {
704
-        EE_Registry::instance()->load_helper('MSG_Template');
705
-        return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
706
-            ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
707
-            : false;
708
-    }
709
-
710
-
711
-    /**
712
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
713
-     *
714
-     * @access public
715
-     * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
716
-     * @return bool success/fail
717
-     * @throws EE_Error
718
-     * @throws InvalidArgumentException
719
-     * @throws InvalidDataTypeException
720
-     * @throws InvalidInterfaceException
721
-     * @throws ReflectionException
722
-     */
723
-    public static function process_resend(array $req_data = [])
724
-    {
725
-        self::_load_controller();
726
-        $request = self::getRequest();
727
-        // if $msgID in this request then skip to the new resend_message
728
-        if ($request->getRequestParam('MSG_ID')) {
729
-            return self::resend_message();
730
-        }
731
-
732
-        // make sure any incoming request data is set on the request so that it gets picked up later.
733
-        foreach ((array) $req_data as $request_key => $request_value) {
734
-            if (! $request->requestParamIsSet($request_key)) {
735
-                $request->setRequestParam($request_key, $request_value);
736
-            }
737
-        }
738
-
739
-        if (
740
-            ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()
741
-        ) {
742
-            return false;
743
-        }
744
-
745
-        try {
746
-            self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
747
-            self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
748
-        } catch (EE_Error $e) {
749
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
750
-            return false;
751
-        }
752
-        EE_Error::add_success(
753
-            esc_html__('Messages have been successfully queued for generation and sending.', 'event_espresso')
754
-        );
755
-        return true; // everything got queued.
756
-    }
757
-
758
-
759
-    /**
760
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
761
-     *
762
-     * @return bool
763
-     * @throws EE_Error
764
-     * @throws InvalidArgumentException
765
-     * @throws InvalidDataTypeException
766
-     * @throws InvalidInterfaceException
767
-     * @throws ReflectionException
768
-     */
769
-    public static function resend_message()
770
-    {
771
-        self::_load_controller();
772
-
773
-        $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
774
-        if (! $msgID) {
775
-            EE_Error::add_error(
776
-                esc_html__(
777
-                    'Something went wrong because there is no "MSG_ID" value in the request',
778
-                    'event_espresso'
779
-                ),
780
-                __FILE__,
781
-                __FUNCTION__,
782
-                __LINE__
783
-            );
784
-            return false;
785
-        }
786
-
787
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID);
788
-
789
-        // setup success message.
790
-        $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
791
-        EE_Error::add_success(
792
-            sprintf(
793
-                _n(
794
-                    'There was %d message queued for resending.',
795
-                    'There were %d messages queued for resending.',
796
-                    $count_ready_for_resend,
797
-                    'event_espresso'
798
-                ),
799
-                $count_ready_for_resend
800
-            )
801
-        );
802
-        return true;
803
-    }
804
-
805
-
806
-    /**
807
-     * Message triggers for manual payment applied by admin
808
-     *
809
-     * @param  EE_Payment $payment EE_payment object
810
-     * @return bool success/fail
811
-     * @throws EE_Error
812
-     * @throws InvalidArgumentException
813
-     * @throws ReflectionException
814
-     * @throws InvalidDataTypeException
815
-     * @throws InvalidInterfaceException
816
-     */
817
-    public static function process_admin_payment(EE_Payment $payment)
818
-    {
819
-        EE_Registry::instance()->load_helper('MSG_Template');
820
-        // we need to get the transaction object
821
-        $transaction = $payment->transaction();
822
-        if ($transaction instanceof EE_Transaction) {
823
-            $data = array($transaction, $payment);
824
-            $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
825
-
826
-            // if payment amount is less than 0 then switch to payment_refund message type.
827
-            $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
828
-
829
-            // if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
830
-            $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved
831
-                ? false : $message_type;
832
-
833
-            self::_load_controller();
834
-
835
-            self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
836
-
837
-            // get count of queued for generation
838
-            $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
839
-                array(
840
-                    EEM_Message::status_incomplete,
841
-                    EEM_Message::status_idle,
842
-                )
843
-            );
844
-
845
-            if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
846
-                add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
847
-                return true;
848
-            } else {
849
-                $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
850
-                    EEM_Message::instance()->stati_indicating_failed_sending()
851
-                );
852
-                /**
853
-                 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
854
-                 * IMMEDIATE generation.
855
-                 */
856
-                if ($count_failed > 0) {
857
-                    EE_Error::add_error(
858
-                        sprintf(
859
-                            _n(
860
-                                'The payment notification generation failed.',
861
-                                '%d payment notifications failed being sent.',
862
-                                $count_failed,
863
-                                'event_espresso'
864
-                            ),
865
-                            $count_failed
866
-                        ),
867
-                        __FILE__,
868
-                        __FUNCTION__,
869
-                        __LINE__
870
-                    );
871
-
872
-                    return false;
873
-                } else {
874
-                    add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
875
-                    return true;
876
-                }
877
-            }
878
-        } else {
879
-            EE_Error::add_error(
880
-                'Unable to generate the payment notification because the given value for the transaction is invalid.',
881
-                'event_espresso'
882
-            );
883
-            return false;
884
-        }
885
-    }
886
-
887
-
888
-    /**
889
-     * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
890
-     *
891
-     * @since   4.3.0
892
-     * @param  EE_Registration[] $registrations an array of EE_Registration objects
893
-     * @param  int               $grp_id        a specific message template group id.
894
-     * @return void
895
-     * @throws EE_Error
896
-     * @throws InvalidArgumentException
897
-     * @throws InvalidDataTypeException
898
-     * @throws InvalidInterfaceException
899
-     * @throws ReflectionException
900
-     */
901
-    public static function send_newsletter_message($registrations, $grp_id)
902
-    {
903
-        // make sure mtp is id and set it in the request later messages setup.
904
-        self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id);
905
-        self::_load_controller();
906
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
907
-    }
908
-
909
-
910
-    /**
911
-     * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
912
-     *
913
-     * @since   4.3.0
914
-     * @param    string          $registration_message_trigger_url
915
-     * @param    EE_Registration $registration
916
-     * @param string             $messenger
917
-     * @param string             $message_type
918
-     * @return string
919
-     * @throws EE_Error
920
-     * @throws InvalidArgumentException
921
-     * @throws InvalidDataTypeException
922
-     * @throws InvalidInterfaceException
923
-     */
924
-    public static function registration_message_trigger_url(
925
-        $registration_message_trigger_url,
926
-        EE_Registration $registration,
927
-        $messenger = 'html',
928
-        $message_type = 'invoice'
929
-    ) {
930
-        // whitelist $messenger
931
-        switch ($messenger) {
932
-            case 'pdf':
933
-                $sending_messenger = 'pdf';
934
-                $generating_messenger = 'html';
935
-                break;
936
-            case 'html':
937
-            default:
938
-                $sending_messenger = 'html';
939
-                $generating_messenger = 'html';
940
-                break;
941
-        }
942
-        // whitelist $message_type
943
-        switch ($message_type) {
944
-            case 'receipt':
945
-                $message_type = 'receipt';
946
-                break;
947
-            case 'invoice':
948
-            default:
949
-                $message_type = 'invoice';
950
-                break;
951
-        }
952
-        // verify that both the messenger AND the message type are active
953
-        if (
954
-            EEH_MSG_Template::is_messenger_active($sending_messenger)
955
-            && EEH_MSG_Template::is_mt_active($message_type)
956
-        ) {
957
-            // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
958
-            $template_query_params = array(
959
-                'MTP_is_active'    => true,
960
-                'MTP_messenger'    => $generating_messenger,
961
-                'MTP_message_type' => $message_type,
962
-                'Event.EVT_ID'     => $registration->event_ID(),
963
-            );
964
-            // get the message template group.
965
-            $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
966
-            // if we don't have an EE_Message_Template_Group then return
967
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
968
-                // remove EVT_ID from query params so that global templates get picked up
969
-                unset($template_query_params['Event.EVT_ID']);
970
-                // get global template as the fallback
971
-                $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
972
-            }
973
-            // if we don't have an EE_Message_Template_Group then return
974
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
975
-                return '';
976
-            }
977
-            // generate the URL
978
-            $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
979
-                $sending_messenger,
980
-                $generating_messenger,
981
-                'purchaser',
982
-                $message_type,
983
-                $registration,
984
-                $msg_template_group->ID(),
985
-                $registration->transaction_ID()
986
-            );
987
-        }
988
-        return $registration_message_trigger_url;
989
-    }
990
-
991
-
992
-    /**
993
-     * Use to generate and return a message preview!
994
-     *
995
-     * @param  string $type      This should correspond with a valid message type
996
-     * @param  string $context   This should correspond with a valid context for the message type
997
-     * @param  string $messenger This should correspond with a valid messenger.
998
-     * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
999
-     *                           preview
1000
-     * @return bool|string The body of the message or if send is requested, sends.
1001
-     * @throws EE_Error
1002
-     * @throws InvalidArgumentException
1003
-     * @throws InvalidDataTypeException
1004
-     * @throws InvalidInterfaceException
1005
-     * @throws ReflectionException
1006
-     */
1007
-    public static function preview_message($type, $context, $messenger, $send = false)
1008
-    {
1009
-        self::_load_controller();
1010
-        $mtg = new EE_Message_To_Generate(
1011
-            $messenger,
1012
-            $type,
1013
-            array(),
1014
-            $context,
1015
-            true
1016
-        );
1017
-        $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
1018
-        if ($generated_preview_queue instanceof EE_Messages_Queue) {
1019
-            // loop through all content for the preview and remove any persisted records.
1020
-            $content = '';
1021
-            foreach ($generated_preview_queue->get_message_repository() as $message) {
1022
-                $content = $message->content();
1023
-                if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
1024
-                    $message->delete();
1025
-                }
1026
-            }
1027
-            return $content;
1028
-        } else {
1029
-            return $generated_preview_queue;
1030
-        }
1031
-    }
1032
-
1033
-
1034
-    /**
1035
-     * This is a method that allows for sending a message using a messenger matching the string given and the provided
1036
-     * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
1037
-     * content found in the EE_Message objects in the queue.
1038
-     *
1039
-     * @since 4.9.0
1040
-     * @param string            $messenger            a string matching a valid active messenger in the system
1041
-     * @param string            $message_type         Although it seems contrary to the name of the method, a message
1042
-     *                                                type name is still required to send along the message type to the
1043
-     *                                                messenger because this is used for determining what specific
1044
-     *                                                variations might be loaded for the generated message.
1045
-     * @param EE_Messages_Queue $queue
1046
-     * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
1047
-     *                                                aggregate EE_Message object.
1048
-     * @return bool success or fail.
1049
-     * @throws EE_Error
1050
-     * @throws InvalidArgumentException
1051
-     * @throws ReflectionException
1052
-     * @throws InvalidDataTypeException
1053
-     * @throws InvalidInterfaceException
1054
-     */
1055
-    public static function send_message_with_messenger_only(
1056
-        $messenger,
1057
-        $message_type,
1058
-        EE_Messages_Queue $queue,
1059
-        $custom_subject = ''
1060
-    ) {
1061
-        self::_load_controller();
1062
-        /** @type EE_Message_To_Generate_From_Queue $message_to_generate */
1063
-        $message_to_generate = EE_Registry::instance()->load_lib(
1064
-            'Message_To_Generate_From_Queue',
1065
-            array(
1066
-                $messenger,
1067
-                $message_type,
1068
-                $queue,
1069
-                $custom_subject,
1070
-            )
1071
-        );
1072
-        return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
1073
-    }
1074
-
1075
-
1076
-    /**
1077
-     * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1078
-     *
1079
-     * @since 4.9.0
1080
-     * @param array $message_ids An array of message ids
1081
-     * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1082
-     *                           messages.
1083
-     * @throws EE_Error
1084
-     * @throws InvalidArgumentException
1085
-     * @throws InvalidDataTypeException
1086
-     * @throws InvalidInterfaceException
1087
-     * @throws ReflectionException
1088
-     */
1089
-    public static function generate_now($message_ids)
1090
-    {
1091
-        self::_load_controller();
1092
-        $messages = EEM_Message::instance()->get_all(
1093
-            array(
1094
-                0 => array(
1095
-                    'MSG_ID' => array('IN', $message_ids),
1096
-                    'STS_ID' => EEM_Message::status_incomplete,
1097
-                ),
1098
-            )
1099
-        );
1100
-        $generated_queue = false;
1101
-        if ($messages) {
1102
-            $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1103
-        }
1104
-
1105
-        if (! $generated_queue instanceof EE_Messages_Queue) {
1106
-            EE_Error::add_error(
1107
-                esc_html__(
1108
-                    'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
1109
-                    'event_espresso'
1110
-                ),
1111
-                __FILE__,
1112
-                __FUNCTION__,
1113
-                __LINE__
1114
-            );
1115
-        }
1116
-        return $generated_queue;
1117
-    }
1118
-
1119
-
1120
-    /**
1121
-     * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1122
-     * EEM_Message::status_idle
1123
-     *
1124
-     * @since 4.9.0
1125
-     * @param $message_ids
1126
-     * @return bool|EE_Messages_Queue false if no messages sent.
1127
-     * @throws EE_Error
1128
-     * @throws InvalidArgumentException
1129
-     * @throws InvalidDataTypeException
1130
-     * @throws InvalidInterfaceException
1131
-     * @throws ReflectionException
1132
-     */
1133
-    public static function send_now($message_ids)
1134
-    {
1135
-        self::_load_controller();
1136
-        $messages = EEM_Message::instance()->get_all(
1137
-            array(
1138
-                0 => array(
1139
-                    'MSG_ID' => array('IN', $message_ids),
1140
-                    'STS_ID' => array(
1141
-                        'IN',
1142
-                        array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1143
-                    ),
1144
-                ),
1145
-            )
1146
-        );
1147
-        $sent_queue = false;
1148
-        if ($messages) {
1149
-            $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1150
-        }
1151
-
1152
-        if (! $sent_queue instanceof EE_Messages_Queue) {
1153
-            EE_Error::add_error(
1154
-                esc_html__(
1155
-                    'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
1156
-                    'event_espresso'
1157
-                ),
1158
-                __FILE__,
1159
-                __FUNCTION__,
1160
-                __LINE__
1161
-            );
1162
-        } else {
1163
-            // can count how many sent by using the messages in the queue
1164
-            $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1165
-            if ($sent_count > 0) {
1166
-                EE_Error::add_success(
1167
-                    sprintf(
1168
-                        _n(
1169
-                            'There was %d message successfully sent.',
1170
-                            'There were %d messages successfully sent.',
1171
-                            $sent_count,
1172
-                            'event_espresso'
1173
-                        ),
1174
-                        $sent_count
1175
-                    )
1176
-                );
1177
-            } else {
1178
-                EE_Error::overwrite_errors();
1179
-                EE_Error::add_error(
1180
-                    esc_html__(
1181
-                        'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error.
261
+				exit;
262
+			}
263
+		}
264
+	}
265
+
266
+
267
+	/**
268
+	 *  This runs when the msg_url_trigger route has initiated.
269
+	 *
270
+	 * @since 4.5.0
271
+	 * @param WP $WP
272
+	 * @throws EE_Error
273
+	 * @throws InvalidArgumentException
274
+	 * @throws ReflectionException
275
+	 * @throws InvalidDataTypeException
276
+	 * @throws InvalidInterfaceException
277
+	 */
278
+	public function run($WP)
279
+	{
280
+		// ensure controller is loaded
281
+		self::_load_controller();
282
+		// attempt to process message
283
+		try {
284
+			/** @type EE_Message_To_Generate_From_Request $message_to_generate */
285
+			$message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
286
+			self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
287
+		} catch (EE_Error $e) {
288
+			$error_msg = esc_html__(
289
+				'Please note that a system message failed to send due to a technical issue.',
290
+				'event_espresso'
291
+			);
292
+			// add specific message for developers if WP_DEBUG in on
293
+			$error_msg .= '||' . $e->getMessage();
294
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
295
+		}
296
+	}
297
+
298
+
299
+	/**
300
+	 * This is triggered by the 'msg_cron_trigger' route.
301
+	 *
302
+	 * @param WP $WP
303
+	 */
304
+	public function execute_batch_request($WP)
305
+	{
306
+		$this->run_cron();
307
+		header('HTTP/1.1 200 OK');
308
+		exit();
309
+	}
310
+
311
+
312
+	/**
313
+	 * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
314
+	 * request.
315
+	 */
316
+	public function run_cron()
317
+	{
318
+		self::_load_controller();
319
+		$request = self::getRequest();
320
+		// get required vars
321
+		$cron_type = $request->getRequestParam('type');
322
+		$transient_key = $request->getRequestParam('key');
323
+
324
+		// now let's verify transient, if not valid exit immediately
325
+		if (! get_transient($transient_key)) {
326
+			/**
327
+			 * trigger error so this gets in the error logs.  This is important because it happens on a non-user
328
+			 * request.
329
+			 */
330
+			trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
331
+		}
332
+
333
+		// if made it here, lets' delete the transient to keep the db clean
334
+		delete_transient($transient_key);
335
+
336
+		if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
337
+			$method = 'batch_' . $cron_type . '_from_queue';
338
+			if (method_exists(self::$_MSG_PROCESSOR, $method)) {
339
+				self::$_MSG_PROCESSOR->$method();
340
+			} else {
341
+				// no matching task
342
+				/**
343
+				 * trigger error so this gets in the error logs.  This is important because it happens on a non user
344
+				 * request.
345
+				 */
346
+				trigger_error(
347
+					esc_attr(
348
+						sprintf(
349
+							esc_html__('There is no task corresponding to this route %s', 'event_espresso'),
350
+							$cron_type
351
+						)
352
+					)
353
+				);
354
+			}
355
+		}
356
+
357
+		do_action('FHEE__EED_Messages__run_cron__end');
358
+	}
359
+
360
+
361
+	/**
362
+	 * This is used to retrieve the template pack for the given name.
363
+	 * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
364
+	 * the default template pack is returned.
365
+	 *
366
+	 * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
367
+	 * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
368
+	 *                                   in generating the Pack class name).
369
+	 * @return EE_Messages_Template_Pack
370
+	 * @throws EE_Error
371
+	 * @throws InvalidArgumentException
372
+	 * @throws ReflectionException
373
+	 * @throws InvalidDataTypeException
374
+	 * @throws InvalidInterfaceException
375
+	 */
376
+	public static function get_template_pack($template_pack_name)
377
+	{
378
+		EE_Registry::instance()->load_helper('MSG_Template');
379
+		return EEH_MSG_Template::get_template_pack($template_pack_name);
380
+	}
381
+
382
+
383
+	/**
384
+	 * Retrieves an array of all template packs.
385
+	 * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
386
+	 *
387
+	 * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
388
+	 * @return EE_Messages_Template_Pack[]
389
+	 * @throws EE_Error
390
+	 * @throws InvalidArgumentException
391
+	 * @throws ReflectionException
392
+	 * @throws InvalidDataTypeException
393
+	 * @throws InvalidInterfaceException
394
+	 */
395
+	public static function get_template_packs()
396
+	{
397
+		EE_Registry::instance()->load_helper('MSG_Template');
398
+
399
+		// for backward compat, let's make sure this returns in the same format as originally.
400
+		$template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
401
+		$template_pack_collection->rewind();
402
+		$template_packs = array();
403
+		while ($template_pack_collection->valid()) {
404
+			$template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
405
+			$template_pack_collection->next();
406
+		}
407
+		return $template_packs;
408
+	}
409
+
410
+
411
+	/**
412
+	 * This simply makes sure the autoloaders are registered for the EE_messages system.
413
+	 *
414
+	 * @since 4.5.0
415
+	 * @return void
416
+	 * @throws EE_Error
417
+	 */
418
+	public static function set_autoloaders()
419
+	{
420
+		if (empty(self::$_MSG_PATHS)) {
421
+			self::_set_messages_paths();
422
+			foreach (self::$_MSG_PATHS as $path) {
423
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
424
+			}
425
+			// add aliases
426
+			EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
427
+			EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
428
+		}
429
+	}
430
+
431
+
432
+	/**
433
+	 * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
434
+	 * for use by the Messages Autoloaders
435
+	 *
436
+	 * @since 4.5.0
437
+	 * @return void.
438
+	 */
439
+	protected static function _set_messages_paths()
440
+	{
441
+		$dir_ref = array(
442
+			'messages/message_type',
443
+			'messages/messenger',
444
+			'messages/defaults',
445
+			'messages/defaults/email',
446
+			'messages/data_class',
447
+			'messages/validators',
448
+			'messages/validators/email',
449
+			'messages/validators/html',
450
+			'shortcodes',
451
+		);
452
+		$paths = array();
453
+		foreach ($dir_ref as $index => $dir) {
454
+			$paths[ $index ] = EE_LIBRARIES . $dir;
455
+		}
456
+		self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
457
+	}
458
+
459
+
460
+	/**
461
+	 * Takes care of loading dependencies
462
+	 *
463
+	 * @since 4.5.0
464
+	 * @return void
465
+	 * @throws EE_Error
466
+	 * @throws InvalidArgumentException
467
+	 * @throws ReflectionException
468
+	 * @throws InvalidDataTypeException
469
+	 * @throws InvalidInterfaceException
470
+	 */
471
+	protected static function _load_controller()
472
+	{
473
+		if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
474
+			EE_Registry::instance()->load_core('Request_Handler');
475
+			self::set_autoloaders();
476
+			self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
477
+			self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor');
478
+			self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
479
+		}
480
+	}
481
+
482
+
483
+	/**
484
+	 * @param EE_Transaction $transaction
485
+	 * @throws EE_Error
486
+	 * @throws InvalidArgumentException
487
+	 * @throws InvalidDataTypeException
488
+	 * @throws InvalidInterfaceException
489
+	 * @throws ReflectionException
490
+	 */
491
+	public static function payment_reminder(EE_Transaction $transaction)
492
+	{
493
+		self::_load_controller();
494
+		$data = array($transaction, null);
495
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
496
+	}
497
+
498
+
499
+	/**
500
+	 * Any messages triggers for after successful gateway payments should go in here.
501
+	 *
502
+	 * @param EE_Transaction  $transaction object
503
+	 * @param EE_Payment|null $payment     object
504
+	 * @return void
505
+	 * @throws EE_Error
506
+	 * @throws InvalidArgumentException
507
+	 * @throws ReflectionException
508
+	 * @throws InvalidDataTypeException
509
+	 * @throws InvalidInterfaceException
510
+	 */
511
+	public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
512
+	{
513
+		// if there's no payment object, then we cannot do a payment type message!
514
+		if (! $payment instanceof EE_Payment) {
515
+			return;
516
+		}
517
+		self::_load_controller();
518
+		$data = array($transaction, $payment);
519
+		EE_Registry::instance()->load_helper('MSG_Template');
520
+		$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
521
+		// if payment amount is less than 0 then switch to payment_refund message type.
522
+		$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
523
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
524
+	}
525
+
526
+
527
+	/**
528
+	 * @param EE_Transaction $transaction
529
+	 * @throws EE_Error
530
+	 * @throws InvalidArgumentException
531
+	 * @throws InvalidDataTypeException
532
+	 * @throws InvalidInterfaceException
533
+	 * @throws ReflectionException
534
+	 */
535
+	public static function cancelled_registration(EE_Transaction $transaction)
536
+	{
537
+		self::_load_controller();
538
+		$data = array($transaction, null);
539
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
540
+	}
541
+
542
+
543
+	/**
544
+	 * Trigger for Registration messages
545
+	 * Note that what registration message type is sent depends on what the reg status is for the registrations on the
546
+	 * incoming transaction.
547
+	 *
548
+	 * @param EE_Registration $registration
549
+	 * @param array           $extra_details
550
+	 * @return void
551
+	 * @throws EE_Error
552
+	 * @throws InvalidArgumentException
553
+	 * @throws InvalidDataTypeException
554
+	 * @throws InvalidInterfaceException
555
+	 * @throws ReflectionException
556
+	 * @throws EntityNotFoundException
557
+	 */
558
+	public static function maybe_registration(EE_Registration $registration, $extra_details = array())
559
+	{
560
+
561
+		if (! self::_verify_registration_notification_send($registration, $extra_details)) {
562
+			// no messages please
563
+			return;
564
+		}
565
+
566
+		// get all non-trashed registrations so we make sure we send messages for the right status.
567
+		$all_registrations = $registration->transaction()->registrations(
568
+			array(
569
+				array('REG_deleted' => false),
570
+				'order_by' => array(
571
+					'Event.EVT_name'     => 'ASC',
572
+					'Attendee.ATT_lname' => 'ASC',
573
+					'Attendee.ATT_fname' => 'ASC',
574
+				),
575
+			)
576
+		);
577
+		// cached array of statuses so we only trigger messages once per status.
578
+		$statuses_sent = array();
579
+		self::_load_controller();
580
+		$mtgs = array();
581
+
582
+		// loop through registrations and trigger messages once per status.
583
+		foreach ($all_registrations as $reg) {
584
+			// already triggered?
585
+			if (in_array($reg->status_ID(), $statuses_sent)) {
586
+				continue;
587
+			}
588
+
589
+			$message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
590
+			$mtgs = array_merge(
591
+				$mtgs,
592
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
593
+					$message_type,
594
+					array($registration->transaction(), null, $reg->status_ID())
595
+				)
596
+			);
597
+			$statuses_sent[] = $reg->status_ID();
598
+		}
599
+
600
+		if (count($statuses_sent) > 1) {
601
+			$mtgs = array_merge(
602
+				$mtgs,
603
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
604
+					'registration_summary',
605
+					array($registration->transaction(), null)
606
+				)
607
+			);
608
+		}
609
+
610
+		// batch queue and initiate request
611
+		self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
612
+		self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
613
+	}
614
+
615
+
616
+	/**
617
+	 * This is a helper method used to very whether a registration notification should be sent or
618
+	 * not.  Prevents duplicate notifications going out for registration context notifications.
619
+	 *
620
+	 * @param EE_Registration $registration  [description]
621
+	 * @param array           $extra_details [description]
622
+	 * @return bool          true = send away, false = nope halt the presses.
623
+	 */
624
+	protected static function _verify_registration_notification_send(
625
+		EE_Registration $registration,
626
+		$extra_details = array()
627
+	) {
628
+		if (! $registration->is_primary_registrant()) {
629
+			return false;
630
+		}
631
+		$request = self::getRequest();
632
+		// first we check if we're in admin and not doing front ajax
633
+		if ($request->isAdmin() && ! $request->isFrontAjax()) {
634
+			$status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true);
635
+			// make sure appropriate admin params are set for sending messages
636
+			if (! $status_change['send_notifications']) {
637
+				// no messages sent please.
638
+				return false;
639
+			}
640
+		} else {
641
+			// frontend request (either regular or via AJAX)
642
+			// TXN is NOT finalized ?
643
+			if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
644
+				return false;
645
+			}
646
+			// return visit but nothing changed ???
647
+			if (
648
+				isset($extra_details['revisit'], $extra_details['status_updates']) &&
649
+				$extra_details['revisit'] && ! $extra_details['status_updates']
650
+			) {
651
+				return false;
652
+			}
653
+			// NOT sending messages && reg status is something other than "Not-Approved"
654
+			if (
655
+				! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
656
+				$registration->status_ID() !== EEM_Registration::status_id_not_approved
657
+			) {
658
+				return false;
659
+			}
660
+		}
661
+		// release the kraken
662
+		return true;
663
+	}
664
+
665
+
666
+	/**
667
+	 * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
668
+	 * status id.
669
+	 *
670
+	 * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
671
+	 *                    or EEH_MSG_Template::convert_reg_status_to_message_type
672
+	 * @param string $reg_status
673
+	 * @return array
674
+	 * @throws EE_Error
675
+	 * @throws InvalidArgumentException
676
+	 * @throws ReflectionException
677
+	 * @throws InvalidDataTypeException
678
+	 * @throws InvalidInterfaceException
679
+	 */
680
+	protected static function _get_reg_status_array($reg_status = '')
681
+	{
682
+		EE_Registry::instance()->load_helper('MSG_Template');
683
+		return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
684
+			? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
685
+			: EEH_MSG_Template::reg_status_to_message_type_array();
686
+	}
687
+
688
+
689
+	/**
690
+	 * Simply returns the payment message type for the given payment status.
691
+	 *
692
+	 * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
693
+	 *                   or EEH_MSG_Template::convert_payment_status_to_message_type
694
+	 * @param string $payment_status The payment status being matched.
695
+	 * @return bool|string The payment message type slug matching the status or false if no match.
696
+	 * @throws EE_Error
697
+	 * @throws InvalidArgumentException
698
+	 * @throws ReflectionException
699
+	 * @throws InvalidDataTypeException
700
+	 * @throws InvalidInterfaceException
701
+	 */
702
+	protected static function _get_payment_message_type($payment_status)
703
+	{
704
+		EE_Registry::instance()->load_helper('MSG_Template');
705
+		return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
706
+			? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
707
+			: false;
708
+	}
709
+
710
+
711
+	/**
712
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
713
+	 *
714
+	 * @access public
715
+	 * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
716
+	 * @return bool success/fail
717
+	 * @throws EE_Error
718
+	 * @throws InvalidArgumentException
719
+	 * @throws InvalidDataTypeException
720
+	 * @throws InvalidInterfaceException
721
+	 * @throws ReflectionException
722
+	 */
723
+	public static function process_resend(array $req_data = [])
724
+	{
725
+		self::_load_controller();
726
+		$request = self::getRequest();
727
+		// if $msgID in this request then skip to the new resend_message
728
+		if ($request->getRequestParam('MSG_ID')) {
729
+			return self::resend_message();
730
+		}
731
+
732
+		// make sure any incoming request data is set on the request so that it gets picked up later.
733
+		foreach ((array) $req_data as $request_key => $request_value) {
734
+			if (! $request->requestParamIsSet($request_key)) {
735
+				$request->setRequestParam($request_key, $request_value);
736
+			}
737
+		}
738
+
739
+		if (
740
+			! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()
741
+		) {
742
+			return false;
743
+		}
744
+
745
+		try {
746
+			self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
747
+			self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
748
+		} catch (EE_Error $e) {
749
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
750
+			return false;
751
+		}
752
+		EE_Error::add_success(
753
+			esc_html__('Messages have been successfully queued for generation and sending.', 'event_espresso')
754
+		);
755
+		return true; // everything got queued.
756
+	}
757
+
758
+
759
+	/**
760
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
761
+	 *
762
+	 * @return bool
763
+	 * @throws EE_Error
764
+	 * @throws InvalidArgumentException
765
+	 * @throws InvalidDataTypeException
766
+	 * @throws InvalidInterfaceException
767
+	 * @throws ReflectionException
768
+	 */
769
+	public static function resend_message()
770
+	{
771
+		self::_load_controller();
772
+
773
+		$msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
774
+		if (! $msgID) {
775
+			EE_Error::add_error(
776
+				esc_html__(
777
+					'Something went wrong because there is no "MSG_ID" value in the request',
778
+					'event_espresso'
779
+				),
780
+				__FILE__,
781
+				__FUNCTION__,
782
+				__LINE__
783
+			);
784
+			return false;
785
+		}
786
+
787
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID);
788
+
789
+		// setup success message.
790
+		$count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
791
+		EE_Error::add_success(
792
+			sprintf(
793
+				_n(
794
+					'There was %d message queued for resending.',
795
+					'There were %d messages queued for resending.',
796
+					$count_ready_for_resend,
797
+					'event_espresso'
798
+				),
799
+				$count_ready_for_resend
800
+			)
801
+		);
802
+		return true;
803
+	}
804
+
805
+
806
+	/**
807
+	 * Message triggers for manual payment applied by admin
808
+	 *
809
+	 * @param  EE_Payment $payment EE_payment object
810
+	 * @return bool success/fail
811
+	 * @throws EE_Error
812
+	 * @throws InvalidArgumentException
813
+	 * @throws ReflectionException
814
+	 * @throws InvalidDataTypeException
815
+	 * @throws InvalidInterfaceException
816
+	 */
817
+	public static function process_admin_payment(EE_Payment $payment)
818
+	{
819
+		EE_Registry::instance()->load_helper('MSG_Template');
820
+		// we need to get the transaction object
821
+		$transaction = $payment->transaction();
822
+		if ($transaction instanceof EE_Transaction) {
823
+			$data = array($transaction, $payment);
824
+			$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
825
+
826
+			// if payment amount is less than 0 then switch to payment_refund message type.
827
+			$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
828
+
829
+			// if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
830
+			$message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved
831
+				? false : $message_type;
832
+
833
+			self::_load_controller();
834
+
835
+			self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
836
+
837
+			// get count of queued for generation
838
+			$count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
839
+				array(
840
+					EEM_Message::status_incomplete,
841
+					EEM_Message::status_idle,
842
+				)
843
+			);
844
+
845
+			if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
846
+				add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
847
+				return true;
848
+			} else {
849
+				$count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
850
+					EEM_Message::instance()->stati_indicating_failed_sending()
851
+				);
852
+				/**
853
+				 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
854
+				 * IMMEDIATE generation.
855
+				 */
856
+				if ($count_failed > 0) {
857
+					EE_Error::add_error(
858
+						sprintf(
859
+							_n(
860
+								'The payment notification generation failed.',
861
+								'%d payment notifications failed being sent.',
862
+								$count_failed,
863
+								'event_espresso'
864
+							),
865
+							$count_failed
866
+						),
867
+						__FILE__,
868
+						__FUNCTION__,
869
+						__LINE__
870
+					);
871
+
872
+					return false;
873
+				} else {
874
+					add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
875
+					return true;
876
+				}
877
+			}
878
+		} else {
879
+			EE_Error::add_error(
880
+				'Unable to generate the payment notification because the given value for the transaction is invalid.',
881
+				'event_espresso'
882
+			);
883
+			return false;
884
+		}
885
+	}
886
+
887
+
888
+	/**
889
+	 * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
890
+	 *
891
+	 * @since   4.3.0
892
+	 * @param  EE_Registration[] $registrations an array of EE_Registration objects
893
+	 * @param  int               $grp_id        a specific message template group id.
894
+	 * @return void
895
+	 * @throws EE_Error
896
+	 * @throws InvalidArgumentException
897
+	 * @throws InvalidDataTypeException
898
+	 * @throws InvalidInterfaceException
899
+	 * @throws ReflectionException
900
+	 */
901
+	public static function send_newsletter_message($registrations, $grp_id)
902
+	{
903
+		// make sure mtp is id and set it in the request later messages setup.
904
+		self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id);
905
+		self::_load_controller();
906
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
907
+	}
908
+
909
+
910
+	/**
911
+	 * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
912
+	 *
913
+	 * @since   4.3.0
914
+	 * @param    string          $registration_message_trigger_url
915
+	 * @param    EE_Registration $registration
916
+	 * @param string             $messenger
917
+	 * @param string             $message_type
918
+	 * @return string
919
+	 * @throws EE_Error
920
+	 * @throws InvalidArgumentException
921
+	 * @throws InvalidDataTypeException
922
+	 * @throws InvalidInterfaceException
923
+	 */
924
+	public static function registration_message_trigger_url(
925
+		$registration_message_trigger_url,
926
+		EE_Registration $registration,
927
+		$messenger = 'html',
928
+		$message_type = 'invoice'
929
+	) {
930
+		// whitelist $messenger
931
+		switch ($messenger) {
932
+			case 'pdf':
933
+				$sending_messenger = 'pdf';
934
+				$generating_messenger = 'html';
935
+				break;
936
+			case 'html':
937
+			default:
938
+				$sending_messenger = 'html';
939
+				$generating_messenger = 'html';
940
+				break;
941
+		}
942
+		// whitelist $message_type
943
+		switch ($message_type) {
944
+			case 'receipt':
945
+				$message_type = 'receipt';
946
+				break;
947
+			case 'invoice':
948
+			default:
949
+				$message_type = 'invoice';
950
+				break;
951
+		}
952
+		// verify that both the messenger AND the message type are active
953
+		if (
954
+			EEH_MSG_Template::is_messenger_active($sending_messenger)
955
+			&& EEH_MSG_Template::is_mt_active($message_type)
956
+		) {
957
+			// need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
958
+			$template_query_params = array(
959
+				'MTP_is_active'    => true,
960
+				'MTP_messenger'    => $generating_messenger,
961
+				'MTP_message_type' => $message_type,
962
+				'Event.EVT_ID'     => $registration->event_ID(),
963
+			);
964
+			// get the message template group.
965
+			$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
966
+			// if we don't have an EE_Message_Template_Group then return
967
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
968
+				// remove EVT_ID from query params so that global templates get picked up
969
+				unset($template_query_params['Event.EVT_ID']);
970
+				// get global template as the fallback
971
+				$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
972
+			}
973
+			// if we don't have an EE_Message_Template_Group then return
974
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
975
+				return '';
976
+			}
977
+			// generate the URL
978
+			$registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
979
+				$sending_messenger,
980
+				$generating_messenger,
981
+				'purchaser',
982
+				$message_type,
983
+				$registration,
984
+				$msg_template_group->ID(),
985
+				$registration->transaction_ID()
986
+			);
987
+		}
988
+		return $registration_message_trigger_url;
989
+	}
990
+
991
+
992
+	/**
993
+	 * Use to generate and return a message preview!
994
+	 *
995
+	 * @param  string $type      This should correspond with a valid message type
996
+	 * @param  string $context   This should correspond with a valid context for the message type
997
+	 * @param  string $messenger This should correspond with a valid messenger.
998
+	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
999
+	 *                           preview
1000
+	 * @return bool|string The body of the message or if send is requested, sends.
1001
+	 * @throws EE_Error
1002
+	 * @throws InvalidArgumentException
1003
+	 * @throws InvalidDataTypeException
1004
+	 * @throws InvalidInterfaceException
1005
+	 * @throws ReflectionException
1006
+	 */
1007
+	public static function preview_message($type, $context, $messenger, $send = false)
1008
+	{
1009
+		self::_load_controller();
1010
+		$mtg = new EE_Message_To_Generate(
1011
+			$messenger,
1012
+			$type,
1013
+			array(),
1014
+			$context,
1015
+			true
1016
+		);
1017
+		$generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
1018
+		if ($generated_preview_queue instanceof EE_Messages_Queue) {
1019
+			// loop through all content for the preview and remove any persisted records.
1020
+			$content = '';
1021
+			foreach ($generated_preview_queue->get_message_repository() as $message) {
1022
+				$content = $message->content();
1023
+				if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
1024
+					$message->delete();
1025
+				}
1026
+			}
1027
+			return $content;
1028
+		} else {
1029
+			return $generated_preview_queue;
1030
+		}
1031
+	}
1032
+
1033
+
1034
+	/**
1035
+	 * This is a method that allows for sending a message using a messenger matching the string given and the provided
1036
+	 * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
1037
+	 * content found in the EE_Message objects in the queue.
1038
+	 *
1039
+	 * @since 4.9.0
1040
+	 * @param string            $messenger            a string matching a valid active messenger in the system
1041
+	 * @param string            $message_type         Although it seems contrary to the name of the method, a message
1042
+	 *                                                type name is still required to send along the message type to the
1043
+	 *                                                messenger because this is used for determining what specific
1044
+	 *                                                variations might be loaded for the generated message.
1045
+	 * @param EE_Messages_Queue $queue
1046
+	 * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
1047
+	 *                                                aggregate EE_Message object.
1048
+	 * @return bool success or fail.
1049
+	 * @throws EE_Error
1050
+	 * @throws InvalidArgumentException
1051
+	 * @throws ReflectionException
1052
+	 * @throws InvalidDataTypeException
1053
+	 * @throws InvalidInterfaceException
1054
+	 */
1055
+	public static function send_message_with_messenger_only(
1056
+		$messenger,
1057
+		$message_type,
1058
+		EE_Messages_Queue $queue,
1059
+		$custom_subject = ''
1060
+	) {
1061
+		self::_load_controller();
1062
+		/** @type EE_Message_To_Generate_From_Queue $message_to_generate */
1063
+		$message_to_generate = EE_Registry::instance()->load_lib(
1064
+			'Message_To_Generate_From_Queue',
1065
+			array(
1066
+				$messenger,
1067
+				$message_type,
1068
+				$queue,
1069
+				$custom_subject,
1070
+			)
1071
+		);
1072
+		return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
1073
+	}
1074
+
1075
+
1076
+	/**
1077
+	 * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1078
+	 *
1079
+	 * @since 4.9.0
1080
+	 * @param array $message_ids An array of message ids
1081
+	 * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1082
+	 *                           messages.
1083
+	 * @throws EE_Error
1084
+	 * @throws InvalidArgumentException
1085
+	 * @throws InvalidDataTypeException
1086
+	 * @throws InvalidInterfaceException
1087
+	 * @throws ReflectionException
1088
+	 */
1089
+	public static function generate_now($message_ids)
1090
+	{
1091
+		self::_load_controller();
1092
+		$messages = EEM_Message::instance()->get_all(
1093
+			array(
1094
+				0 => array(
1095
+					'MSG_ID' => array('IN', $message_ids),
1096
+					'STS_ID' => EEM_Message::status_incomplete,
1097
+				),
1098
+			)
1099
+		);
1100
+		$generated_queue = false;
1101
+		if ($messages) {
1102
+			$generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1103
+		}
1104
+
1105
+		if (! $generated_queue instanceof EE_Messages_Queue) {
1106
+			EE_Error::add_error(
1107
+				esc_html__(
1108
+					'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
1109
+					'event_espresso'
1110
+				),
1111
+				__FILE__,
1112
+				__FUNCTION__,
1113
+				__LINE__
1114
+			);
1115
+		}
1116
+		return $generated_queue;
1117
+	}
1118
+
1119
+
1120
+	/**
1121
+	 * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1122
+	 * EEM_Message::status_idle
1123
+	 *
1124
+	 * @since 4.9.0
1125
+	 * @param $message_ids
1126
+	 * @return bool|EE_Messages_Queue false if no messages sent.
1127
+	 * @throws EE_Error
1128
+	 * @throws InvalidArgumentException
1129
+	 * @throws InvalidDataTypeException
1130
+	 * @throws InvalidInterfaceException
1131
+	 * @throws ReflectionException
1132
+	 */
1133
+	public static function send_now($message_ids)
1134
+	{
1135
+		self::_load_controller();
1136
+		$messages = EEM_Message::instance()->get_all(
1137
+			array(
1138
+				0 => array(
1139
+					'MSG_ID' => array('IN', $message_ids),
1140
+					'STS_ID' => array(
1141
+						'IN',
1142
+						array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1143
+					),
1144
+				),
1145
+			)
1146
+		);
1147
+		$sent_queue = false;
1148
+		if ($messages) {
1149
+			$sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1150
+		}
1151
+
1152
+		if (! $sent_queue instanceof EE_Messages_Queue) {
1153
+			EE_Error::add_error(
1154
+				esc_html__(
1155
+					'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
1156
+					'event_espresso'
1157
+				),
1158
+				__FILE__,
1159
+				__FUNCTION__,
1160
+				__LINE__
1161
+			);
1162
+		} else {
1163
+			// can count how many sent by using the messages in the queue
1164
+			$sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1165
+			if ($sent_count > 0) {
1166
+				EE_Error::add_success(
1167
+					sprintf(
1168
+						_n(
1169
+							'There was %d message successfully sent.',
1170
+							'There were %d messages successfully sent.',
1171
+							$sent_count,
1172
+							'event_espresso'
1173
+						),
1174
+						$sent_count
1175
+					)
1176
+				);
1177
+			} else {
1178
+				EE_Error::overwrite_errors();
1179
+				EE_Error::add_error(
1180
+					esc_html__(
1181
+						'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error.
1182 1182
 					If there was an error, you can look at the messages in the message activity list table for any error messages.',
1183
-                        'event_espresso'
1184
-                    ),
1185
-                    __FILE__,
1186
-                    __FUNCTION__,
1187
-                    __LINE__
1188
-                );
1189
-            }
1190
-        }
1191
-        return $sent_queue;
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * Generate and send immediately from the given $message_ids
1197
-     *
1198
-     * @param array $message_ids EE_Message entity ids.
1199
-     * @throws EE_Error
1200
-     * @throws InvalidArgumentException
1201
-     * @throws InvalidDataTypeException
1202
-     * @throws InvalidInterfaceException
1203
-     * @throws ReflectionException
1204
-     */
1205
-    public static function generate_and_send_now(array $message_ids)
1206
-    {
1207
-        $generated_queue = self::generate_now($message_ids);
1208
-        // now let's just trigger sending immediately from this queue.
1209
-        $messages_sent = $generated_queue instanceof EE_Messages_Queue
1210
-            ? $generated_queue->execute()
1211
-            : 0;
1212
-        if ($messages_sent) {
1213
-            EE_Error::add_success(
1214
-                esc_html(
1215
-                    sprintf(
1216
-                        _n(
1217
-                            'There was %d message successfully generated and sent.',
1218
-                            'There were %d messages successfully generated and sent.',
1219
-                            $messages_sent,
1220
-                            'event_espresso'
1221
-                        ),
1222
-                        $messages_sent
1223
-                    )
1224
-                )
1225
-            );
1226
-            // errors would be added via the generate_now method.
1227
-        }
1228
-    }
1229
-
1230
-
1231
-    /**
1232
-     * This will queue the incoming message ids for resending.
1233
-     * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1234
-     *
1235
-     * @since 4.9.0
1236
-     * @param array $message_ids An array of EE_Message IDs
1237
-     * @return bool true means messages were successfully queued for resending, false means none were queued for
1238
-     *                           resending.
1239
-     * @throws EE_Error
1240
-     * @throws InvalidArgumentException
1241
-     * @throws InvalidDataTypeException
1242
-     * @throws InvalidInterfaceException
1243
-     * @throws ReflectionException
1244
-     */
1245
-    public static function queue_for_resending($message_ids)
1246
-    {
1247
-        self::_load_controller();
1248
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1249
-
1250
-        // get queue and count
1251
-        $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1252
-
1253
-        if (
1254
-            $queue_count > 0
1255
-        ) {
1256
-            EE_Error::add_success(
1257
-                sprintf(
1258
-                    _n(
1259
-                        '%d message successfully queued for resending.',
1260
-                        '%d messages successfully queued for resending.',
1261
-                        $queue_count,
1262
-                        'event_espresso'
1263
-                    ),
1264
-                    $queue_count
1265
-                )
1266
-            );
1267
-            /**
1268
-             * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1269
-             */
1270
-        } elseif (
1271
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1272
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1273
-        ) {
1274
-            $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1275
-            if ($queue_count > 0) {
1276
-                EE_Error::add_success(
1277
-                    sprintf(
1278
-                        _n(
1279
-                            '%d message successfully sent.',
1280
-                            '%d messages successfully sent.',
1281
-                            $queue_count,
1282
-                            'event_espresso'
1283
-                        ),
1284
-                        $queue_count
1285
-                    )
1286
-                );
1287
-            } else {
1288
-                EE_Error::add_error(
1289
-                    esc_html__(
1290
-                        'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1291
-                        'event_espresso'
1292
-                    ),
1293
-                    __FILE__,
1294
-                    __FUNCTION__,
1295
-                    __LINE__
1296
-                );
1297
-            }
1298
-        } else {
1299
-            EE_Error::add_error(
1300
-                esc_html__(
1301
-                    'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1302
-                    'event_espresso'
1303
-                ),
1304
-                __FILE__,
1305
-                __FUNCTION__,
1306
-                __LINE__
1307
-            );
1308
-        }
1309
-        return (bool) $queue_count;
1310
-    }
1311
-
1312
-
1313
-    /**
1314
-     * debug
1315
-     *
1316
-     * @param string          $class
1317
-     * @param string          $func
1318
-     * @param string          $line
1319
-     * @param \EE_Transaction $transaction
1320
-     * @param array           $info
1321
-     * @param bool            $display_request
1322
-     * @throws EE_Error
1323
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1324
-     */
1325
-    protected static function log(
1326
-        $class = '',
1327
-        $func = '',
1328
-        $line = '',
1329
-        EE_Transaction $transaction,
1330
-        $info = array(),
1331
-        $display_request = false
1332
-    ) {
1333
-        if (defined('EE_DEBUG') && EE_DEBUG) {
1334
-            if ($transaction instanceof EE_Transaction) {
1335
-                // don't serialize objects
1336
-                $info = EEH_Debug_Tools::strip_objects($info);
1337
-                $info['TXN_status'] = $transaction->status_ID();
1338
-                $info['TXN_reg_steps'] = $transaction->reg_steps();
1339
-                if ($transaction->ID()) {
1340
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1341
-                    EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1342
-                }
1343
-            }
1344
-        }
1345
-    }
1346
-
1347
-
1348
-    /**
1349
-     *  Resets all the static properties in this class when called.
1350
-     */
1351
-    public static function reset()
1352
-    {
1353
-        self::$_EEMSG = null;
1354
-        self::$_message_resource_manager = null;
1355
-        self::$_MSG_PROCESSOR = null;
1356
-        self::$_MSG_PATHS = null;
1357
-        self::$_TMP_PACKS = array();
1358
-    }
1183
+						'event_espresso'
1184
+					),
1185
+					__FILE__,
1186
+					__FUNCTION__,
1187
+					__LINE__
1188
+				);
1189
+			}
1190
+		}
1191
+		return $sent_queue;
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * Generate and send immediately from the given $message_ids
1197
+	 *
1198
+	 * @param array $message_ids EE_Message entity ids.
1199
+	 * @throws EE_Error
1200
+	 * @throws InvalidArgumentException
1201
+	 * @throws InvalidDataTypeException
1202
+	 * @throws InvalidInterfaceException
1203
+	 * @throws ReflectionException
1204
+	 */
1205
+	public static function generate_and_send_now(array $message_ids)
1206
+	{
1207
+		$generated_queue = self::generate_now($message_ids);
1208
+		// now let's just trigger sending immediately from this queue.
1209
+		$messages_sent = $generated_queue instanceof EE_Messages_Queue
1210
+			? $generated_queue->execute()
1211
+			: 0;
1212
+		if ($messages_sent) {
1213
+			EE_Error::add_success(
1214
+				esc_html(
1215
+					sprintf(
1216
+						_n(
1217
+							'There was %d message successfully generated and sent.',
1218
+							'There were %d messages successfully generated and sent.',
1219
+							$messages_sent,
1220
+							'event_espresso'
1221
+						),
1222
+						$messages_sent
1223
+					)
1224
+				)
1225
+			);
1226
+			// errors would be added via the generate_now method.
1227
+		}
1228
+	}
1229
+
1230
+
1231
+	/**
1232
+	 * This will queue the incoming message ids for resending.
1233
+	 * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1234
+	 *
1235
+	 * @since 4.9.0
1236
+	 * @param array $message_ids An array of EE_Message IDs
1237
+	 * @return bool true means messages were successfully queued for resending, false means none were queued for
1238
+	 *                           resending.
1239
+	 * @throws EE_Error
1240
+	 * @throws InvalidArgumentException
1241
+	 * @throws InvalidDataTypeException
1242
+	 * @throws InvalidInterfaceException
1243
+	 * @throws ReflectionException
1244
+	 */
1245
+	public static function queue_for_resending($message_ids)
1246
+	{
1247
+		self::_load_controller();
1248
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1249
+
1250
+		// get queue and count
1251
+		$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1252
+
1253
+		if (
1254
+			$queue_count > 0
1255
+		) {
1256
+			EE_Error::add_success(
1257
+				sprintf(
1258
+					_n(
1259
+						'%d message successfully queued for resending.',
1260
+						'%d messages successfully queued for resending.',
1261
+						$queue_count,
1262
+						'event_espresso'
1263
+					),
1264
+					$queue_count
1265
+				)
1266
+			);
1267
+			/**
1268
+			 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1269
+			 */
1270
+		} elseif (
1271
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1272
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1273
+		) {
1274
+			$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1275
+			if ($queue_count > 0) {
1276
+				EE_Error::add_success(
1277
+					sprintf(
1278
+						_n(
1279
+							'%d message successfully sent.',
1280
+							'%d messages successfully sent.',
1281
+							$queue_count,
1282
+							'event_espresso'
1283
+						),
1284
+						$queue_count
1285
+					)
1286
+				);
1287
+			} else {
1288
+				EE_Error::add_error(
1289
+					esc_html__(
1290
+						'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1291
+						'event_espresso'
1292
+					),
1293
+					__FILE__,
1294
+					__FUNCTION__,
1295
+					__LINE__
1296
+				);
1297
+			}
1298
+		} else {
1299
+			EE_Error::add_error(
1300
+				esc_html__(
1301
+					'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1302
+					'event_espresso'
1303
+				),
1304
+				__FILE__,
1305
+				__FUNCTION__,
1306
+				__LINE__
1307
+			);
1308
+		}
1309
+		return (bool) $queue_count;
1310
+	}
1311
+
1312
+
1313
+	/**
1314
+	 * debug
1315
+	 *
1316
+	 * @param string          $class
1317
+	 * @param string          $func
1318
+	 * @param string          $line
1319
+	 * @param \EE_Transaction $transaction
1320
+	 * @param array           $info
1321
+	 * @param bool            $display_request
1322
+	 * @throws EE_Error
1323
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1324
+	 */
1325
+	protected static function log(
1326
+		$class = '',
1327
+		$func = '',
1328
+		$line = '',
1329
+		EE_Transaction $transaction,
1330
+		$info = array(),
1331
+		$display_request = false
1332
+	) {
1333
+		if (defined('EE_DEBUG') && EE_DEBUG) {
1334
+			if ($transaction instanceof EE_Transaction) {
1335
+				// don't serialize objects
1336
+				$info = EEH_Debug_Tools::strip_objects($info);
1337
+				$info['TXN_status'] = $transaction->status_ID();
1338
+				$info['TXN_reg_steps'] = $transaction->reg_steps();
1339
+				if ($transaction->ID()) {
1340
+					$index = 'EE_Transaction: ' . $transaction->ID();
1341
+					EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1342
+				}
1343
+			}
1344
+		}
1345
+	}
1346
+
1347
+
1348
+	/**
1349
+	 *  Resets all the static properties in this class when called.
1350
+	 */
1351
+	public static function reset()
1352
+	{
1353
+		self::$_EEMSG = null;
1354
+		self::$_message_resource_manager = null;
1355
+		self::$_MSG_PROCESSOR = null;
1356
+		self::$_MSG_PATHS = null;
1357
+		self::$_TMP_PACKS = array();
1358
+	}
1359 1359
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
                 'event_espresso'
205 205
             );
206 206
             // add specific message for developers if WP_DEBUG in on
207
-            $error_msg .= '||' . $e->getMessage();
207
+            $error_msg .= '||'.$e->getMessage();
208 208
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209 209
         }
210 210
     }
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
                 'event_espresso'
291 291
             );
292 292
             // add specific message for developers if WP_DEBUG in on
293
-            $error_msg .= '||' . $e->getMessage();
293
+            $error_msg .= '||'.$e->getMessage();
294 294
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
295 295
         }
296 296
     }
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
         $transient_key = $request->getRequestParam('key');
323 323
 
324 324
         // now let's verify transient, if not valid exit immediately
325
-        if (! get_transient($transient_key)) {
325
+        if ( ! get_transient($transient_key)) {
326 326
             /**
327 327
              * trigger error so this gets in the error logs.  This is important because it happens on a non-user
328 328
              * request.
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
         delete_transient($transient_key);
335 335
 
336 336
         if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
337
-            $method = 'batch_' . $cron_type . '_from_queue';
337
+            $method = 'batch_'.$cron_type.'_from_queue';
338 338
             if (method_exists(self::$_MSG_PROCESSOR, $method)) {
339 339
                 self::$_MSG_PROCESSOR->$method();
340 340
             } else {
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
         $template_pack_collection->rewind();
402 402
         $template_packs = array();
403 403
         while ($template_pack_collection->valid()) {
404
-            $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
404
+            $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();
405 405
             $template_pack_collection->next();
406 406
         }
407 407
         return $template_packs;
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
         );
452 452
         $paths = array();
453 453
         foreach ($dir_ref as $index => $dir) {
454
-            $paths[ $index ] = EE_LIBRARIES . $dir;
454
+            $paths[$index] = EE_LIBRARIES.$dir;
455 455
         }
456 456
         self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
457 457
     }
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
      */
471 471
     protected static function _load_controller()
472 472
     {
473
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
473
+        if ( ! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
474 474
             EE_Registry::instance()->load_core('Request_Handler');
475 475
             self::set_autoloaders();
476 476
             self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
     public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
512 512
     {
513 513
         // if there's no payment object, then we cannot do a payment type message!
514
-        if (! $payment instanceof EE_Payment) {
514
+        if ( ! $payment instanceof EE_Payment) {
515 515
             return;
516 516
         }
517 517
         self::_load_controller();
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
     public static function maybe_registration(EE_Registration $registration, $extra_details = array())
559 559
     {
560 560
 
561
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
561
+        if ( ! self::_verify_registration_notification_send($registration, $extra_details)) {
562 562
             // no messages please
563 563
             return;
564 564
         }
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
         EE_Registration $registration,
626 626
         $extra_details = array()
627 627
     ) {
628
-        if (! $registration->is_primary_registrant()) {
628
+        if ( ! $registration->is_primary_registrant()) {
629 629
             return false;
630 630
         }
631 631
         $request = self::getRequest();
@@ -633,14 +633,14 @@  discard block
 block discarded – undo
633 633
         if ($request->isAdmin() && ! $request->isFrontAjax()) {
634 634
             $status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true);
635 635
             // make sure appropriate admin params are set for sending messages
636
-            if (! $status_change['send_notifications']) {
636
+            if ( ! $status_change['send_notifications']) {
637 637
                 // no messages sent please.
638 638
                 return false;
639 639
             }
640 640
         } else {
641 641
             // frontend request (either regular or via AJAX)
642 642
             // TXN is NOT finalized ?
643
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
643
+            if ( ! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
644 644
                 return false;
645 645
             }
646 646
             // return visit but nothing changed ???
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
 
732 732
         // make sure any incoming request data is set on the request so that it gets picked up later.
733 733
         foreach ((array) $req_data as $request_key => $request_value) {
734
-            if (! $request->requestParamIsSet($request_key)) {
734
+            if ( ! $request->requestParamIsSet($request_key)) {
735 735
                 $request->setRequestParam($request_key, $request_value);
736 736
             }
737 737
         }
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
         self::_load_controller();
772 772
 
773 773
         $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
774
-        if (! $msgID) {
774
+        if ( ! $msgID) {
775 775
             EE_Error::add_error(
776 776
                 esc_html__(
777 777
                     'Something went wrong because there is no "MSG_ID" value in the request',
@@ -964,14 +964,14 @@  discard block
 block discarded – undo
964 964
             // get the message template group.
965 965
             $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
966 966
             // if we don't have an EE_Message_Template_Group then return
967
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
967
+            if ( ! $msg_template_group instanceof EE_Message_Template_Group) {
968 968
                 // remove EVT_ID from query params so that global templates get picked up
969 969
                 unset($template_query_params['Event.EVT_ID']);
970 970
                 // get global template as the fallback
971 971
                 $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
972 972
             }
973 973
             // if we don't have an EE_Message_Template_Group then return
974
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
974
+            if ( ! $msg_template_group instanceof EE_Message_Template_Group) {
975 975
                 return '';
976 976
             }
977 977
             // generate the URL
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
             $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1103 1103
         }
1104 1104
 
1105
-        if (! $generated_queue instanceof EE_Messages_Queue) {
1105
+        if ( ! $generated_queue instanceof EE_Messages_Queue) {
1106 1106
             EE_Error::add_error(
1107 1107
                 esc_html__(
1108 1108
                     'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
             $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1150 1150
         }
1151 1151
 
1152
-        if (! $sent_queue instanceof EE_Messages_Queue) {
1152
+        if ( ! $sent_queue instanceof EE_Messages_Queue) {
1153 1153
             EE_Error::add_error(
1154 1154
                 esc_html__(
1155 1155
                     'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
@@ -1337,7 +1337,7 @@  discard block
 block discarded – undo
1337 1337
                 $info['TXN_status'] = $transaction->status_ID();
1338 1338
                 $info['TXN_reg_steps'] = $transaction->reg_steps();
1339 1339
                 if ($transaction->ID()) {
1340
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1340
+                    $index = 'EE_Transaction: '.$transaction->ID();
1341 1341
                     EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1342 1342
                 }
1343 1343
             }
Please login to merge, or discard this patch.